Ledger resetting

A chaincode upgrade is like instantiation, and both result in the execution of the Init function. In the initial version of the chaincode, many ledger values were initialized, but unless we change that logic, those initial values will overwrite the current state of the ledger. Therefore, we add code to the Init function in chaincode/src/github.com/trade_workflow_v1/tradeWorkflow.go to emulate a no-op, but we also leave the original logic intact to ensure that values can be overwritten during an upgrade if there is a business need to do so, as the following code snippet illustrates:

func (t *TradeWorkflowChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { 
  ...... 
  // Upgrade Mode 1: leave ledger state as it was 
  if len(args) == 0 { 
    return shim.Success(nil) 
  } 
  // Upgrade mode 2: change all the names and account balances 
  if len(args) != 8 { 
    ...... 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.79.33