github.com/darrenli6/fabric-sdk-example@v0.0.0-20220109053535-94b13b56df8c/imocc/chaincode/badexample/badexample.go (about) 1 package main 2 3 import ( 4 "github.com/hyperledger/fabric/core/chaincode/shim" 5 pb "github.com/hyperledger/fabric/protos/peer" 6 "fmt" 7 "math/rand" 8 "time" 9 "strconv" 10 "bytes" 11 ) 12 13 type BadExampleCC struct {} 14 15 // Init is called during Instantiate transaction after the chaincode container 16 // has been established for the first time, allowing the chaincode to 17 // initialize its internal data 18 func (c *BadExampleCC) Init(stub shim.ChaincodeStubInterface) pb.Response { 19 return shim.Success(nil) 20 } 21 22 // Invoke is called to update or query the ledger in a proposal transaction. 23 // Updated state variables are not committed to the ledger until the 24 // transaction is committed. 25 func (c *BadExampleCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response { 26 return shim.Success(bytes.NewBufferString(strconv.Itoa(int(rand.Int63n(time.Now().Unix())))).Bytes()) 27 } 28 29 func main() { 30 err := shim.Start(new(BadExampleCC)) 31 if err != nil { 32 fmt.Printf("Error starting Simple chaincode: %s", err) 33 } 34 }