Skip to content

Commit

Permalink
Support for other transaction types
Browse files Browse the repository at this point in the history
Added rawRequest to the parameters of NewTransaction

Signed-off-by: Alexandros Filios <[email protected]>
  • Loading branch information
alexandrosfilios authored and adecaro committed Oct 9, 2023
1 parent dc22e1f commit d57ba1d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
12 changes: 6 additions & 6 deletions platform/fabric/core/generic/transaction/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

type Factory interface {
NewTransaction(channel string, nonce []byte, creator []byte, txid string) (driver.Transaction, error)
NewTransaction(channel string, nonce []byte, creator []byte, txid string, rawRequest []byte) (driver.Transaction, error)
}

type Manager struct {
Expand All @@ -44,12 +44,12 @@ func (m *Manager) NewProposalResponseFromBytes(raw []byte) (driver.ProposalRespo
return NewProposalResponseFromBytes(raw)
}

func (m *Manager) NewTransaction(transactionType driver.TransactionType, creator view2.Identity, nonce []byte, txid string, channel string) (driver.Transaction, error) {
func (m *Manager) NewTransaction(transactionType driver.TransactionType, creator view2.Identity, nonce []byte, txid string, channel string, rawRequest []byte) (driver.Transaction, error) {
factory, ok := m.factories[transactionType]
if !ok {
return nil, errors.Errorf("transaction tyep [%d] not recognized", transactionType)
}
tx, err := factory.NewTransaction(channel, nonce, creator, txid)
tx, err := factory.NewTransaction(channel, nonce, creator, txid, rawRequest)
if err != nil {
return nil, err
}
Expand All @@ -66,7 +66,7 @@ func (m *Manager) NewTransactionFromBytes(channel string, raw []byte) (driver.Tr
if !ok {
return nil, errors.Errorf("transaction tyep [%d] not recognized", txRaw.Type)
}
tx, err := factory.NewTransaction(channel, nil, nil, "")
tx, err := factory.NewTransaction(channel, nil, nil, "", nil)
if err != nil {
return nil, err
}
Expand All @@ -86,7 +86,7 @@ func (m *Manager) NewTransactionFromEnvelopeBytes(channel string, raw []byte) (d
if !ok {
return nil, errors.Errorf("transaction tyep [%d] not recognized", cht)
}
tx, err := factory.NewTransaction(channel, nil, nil, "")
tx, err := factory.NewTransaction(channel, nil, nil, "", nil)
if err != nil {
return nil, err
}
Expand All @@ -110,7 +110,7 @@ func NewEndorserTransactionFactory(sp view.ServiceProvider, fns driver.FabricNet
return &EndorserTransactionFactory{sp: sp, fns: fns}
}

func (e *EndorserTransactionFactory) NewTransaction(channel string, nonce []byte, creator []byte, txid string) (driver.Transaction, error) {
func (e *EndorserTransactionFactory) NewTransaction(channel string, nonce []byte, creator []byte, txid string, rawRequest []byte) (driver.Transaction, error) {
ch, err := e.fns.Channel(channel)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion platform/fabric/driver/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type TransactionManager interface {
ComputeTxID(id *TxID) string
NewEnvelope() Envelope
NewProposalResponseFromBytes(raw []byte) (ProposalResponse, error)
NewTransaction(transactionType TransactionType, creator view.Identity, nonce []byte, txid string, channel string) (Transaction, error)
NewTransaction(transactionType TransactionType, creator view.Identity, nonce []byte, txid string, channel string, rawRequest []byte) (Transaction, error)
NewTransactionFromBytes(channel string, raw []byte) (Transaction, error)
NewTransactionFromEnvelopeBytes(channel string, raw []byte) (Transaction, error)
}
Expand Down
8 changes: 6 additions & 2 deletions platform/fabric/services/endorser/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (t *Builder) NewTransaction(opts ...fabric.TransactionOption) (*Transaction
fabricOptions.Nonce,
nil,
false,
fabricOptions.RawRequest,
&fabricOptions.TransactionType,
)
}
Expand Down Expand Up @@ -83,10 +84,10 @@ func (t *Builder) NewTransactionWithIdentity(id view.Identity) (*Transaction, er
}

func (t *Builder) newTransaction(creator []byte, network, channel string, nonce, raw []byte, envelope bool) (*Transaction, error) {
return t.newTransactionWithType(creator, network, channel, nonce, raw, envelope, nil)
return t.newTransactionWithType(creator, network, channel, nonce, raw, envelope, nil, nil)
}

func (t *Builder) newTransactionWithType(creator []byte, network, channel string, nonce, raw []byte, envelope bool, tType *fabric.TransactionType) (*Transaction, error) {
func (t *Builder) newTransactionWithType(creator []byte, network, channel string, nonce, raw []byte, envelope bool, rawRequest []byte, tType *fabric.TransactionType) (*Transaction, error) {
logger.Debugf("NewTransaction [%s,%s,%s]", view.Identity(creator).UniqueID(), channel, hash.Hashable(raw).String())
defer logger.Debugf("NewTransaction...done.")

Expand All @@ -106,6 +107,9 @@ func (t *Builder) newTransactionWithType(creator []byte, network, channel string
if tType != nil {
options = append(options, fabric.WithTransactionType(*tType))
}
if rawRequest != nil {
options = append(options, fabric.WithRawRequest(rawRequest))
}

var fabricTransaction *fabric.Transaction
var err error
Expand Down
16 changes: 9 additions & 7 deletions platform/fabric/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type TransactionOptions struct {
Nonce []byte
TxID string
Channel string
RawRequest []byte
TransactionType TransactionType
}

Expand Down Expand Up @@ -70,6 +71,13 @@ func WithTxID(txid string) TransactionOption {
}
}

func WithRawRequest(rawRequest []byte) TransactionOption {
return func(o *TransactionOptions) error {
o.RawRequest = rawRequest
return nil
}
}

func WithTransactionType(tt TransactionType) TransactionOption {
return func(o *TransactionOptions) error {
o.TransactionType = tt
Expand Down Expand Up @@ -369,13 +377,7 @@ func (t *TransactionManager) NewTransaction(opts ...TransactionOption) (*Transac
return nil, err
}

tx, err := t.fns.fns.TransactionManager().NewTransaction(
driver.TransactionType(options.TransactionType),
options.Creator,
options.Nonce,
options.TxID,
ch.Name(),
)
tx, err := t.fns.fns.TransactionManager().NewTransaction(driver.TransactionType(options.TransactionType), options.Creator, options.Nonce, options.TxID, ch.Name(), options.RawRequest)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit d57ba1d

Please sign in to comment.