@@ -29,6 +29,7 @@ type Transaction struct {
2929 request * channel.Request
3030 endorsingPeers []string
3131 collections []string
32+ isInit bool
3233 eventch chan * fab.TxStatusEvent
3334}
3435
@@ -83,6 +84,15 @@ func WithCollections(collections ...string) TransactionOption {
8384 }
8485}
8586
87+ // WithInit is an option that makes the transaction fulfill the --init-required condition before the chaincode
88+ // can be invoked to process regular transactions
89+ func WithInit () TransactionOption {
90+ return func (txn * Transaction ) error {
91+ txn .isInit = true
92+ return nil
93+ }
94+ }
95+
8696// Evaluate a transaction function and return its results.
8797// The transaction function will be evaluated on the endorsing peers but
8898// the responses will not be sent to the ordering service and hence will
@@ -119,21 +129,12 @@ func (txn *Transaction) Evaluate(args ...string) ([]byte, error) {
119129// will be evaluated on the endorsing peers and then submitted to the ordering service
120130// for committing to the ledger.
121131func (txn * Transaction ) Submit (args ... string ) ([]byte , error ) {
122- return txn .submit (false , args ... )
123- }
124-
125- // SubmitInit sends an initialization transaction, for chaincodes that requires init before processing regular transactions
126- func (txn * Transaction ) SubmitInit (args ... string ) ([]byte , error ) {
127- return txn .submit (true , args ... )
128- }
129-
130- func (txn * Transaction ) submit (isInit bool , args ... string ) ([]byte , error ) {
131132 bytes := make ([][]byte , len (args ))
132133 for i , v := range args {
133134 bytes [i ] = []byte (v )
134135 }
135136 txn .request .Args = bytes
136- txn .request .IsInit = isInit
137+ txn .request .IsInit = txn . isInit
137138
138139 var options []channel.RequestOption
139140 if txn .endorsingPeers != nil {
0 commit comments