hyperledger / fabric-sdk-go

https://wiki.hyperledger.org/display/fabric
Apache License 2.0
911 stars 508 forks source link

Add WithInit() to support chaincodes that require init #236

Closed jimthematrix closed 2 years ago

jimthematrix commented 2 years ago

Even though the latest recommendation from the Fabric team is to step away from requiring init, a lot of customers still use this approach, and the official docs for Fabric chaincode lifecycle still describes the --init-required parameter, finally the fabric-samples that is used widely by tire-kickers still implements InitLedger().

Added a new SubmitInit() instead of modifying the existing signature to allow backward compatibility

codecov[bot] commented 2 years ago

Codecov Report

Merging #236 (1c704ae) into main (7a94fbc) will increase coverage by 0.00%. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #236   +/-   ##
=======================================
  Coverage   76.21%   76.22%           
=======================================
  Files         193      193           
  Lines       14098    14103    +5     
=======================================
+ Hits        10745    10750    +5     
  Misses       2385     2385           
  Partials      968      968           
Impacted Files Coverage Δ
pkg/gateway/transaction.go 88.39% <100.00%> (+0.54%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 7a94fbc...1c704ae. Read the comment docs.

troyronda commented 2 years ago

@andrew-coleman Do you have any comments about the additional function in the Gateway package?

bestbeforetoday commented 2 years ago

There are already TransactionOption functional options to set endorsing peers and transient data when calling CreateTransaction(). I think this would be a better fit for creating a Transaction with the isInit flag set. Something like:

func WithInit() TransactionOption {
    return func(txn *Transaction) error {
        txn.isInit = true
        return nil
    }
}
andrew-coleman commented 2 years ago

Hi Jim, if we were to implement this in the new fabric-gateway Go API, we would almost certainly adopt the pattern as suggested by Mark in the previous comment. Would you be able to do that here?

jimthematrix commented 2 years ago

@bestbeforetoday @andrew-coleman thanks for suggesting the options approach, I can switch to that in this PR.

andrew-coleman commented 2 years ago

Thanks Jim!