Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding write function to chaincode #1

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion examples/chaincode/go/chaincode_example02/chaincode_example02.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,38 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface, function string
return nil, nil
}

func (t *SimpleChaincode) write(stub *shim.ChaincodeStub, args []string) ([]byte, error) {
var key, value string
var err error
fmt.Println("Storing the health parameters in hyperledger fabric...")

if len(args) != 2 {
return nil, errors.New("Incorrect number of arguments. Expecting 2. name of the key and value to set")
}

key = args[0] //rename for fun
value = args[1]
err = stub.PutState(key, []byte(value)) //write the variable into the chaincode state
if err != nil {
return nil, err
}


return nil, nil
}

// Transaction makes payment of X units from A to B
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
if function == "delete" {
// Deletes an entity from its state
return t.delete(stub, args)
}


if function == "write" {
fmt.Println("Calling write()")
return t.write(stub, args)
}

var A, B string // Entities
var Aval, Bval int // Asset holdings
var X int // Transaction value
Expand Down