Skip to content

Instantly share code, notes, and snippets.

@AnthonyAkentiev
Created December 30, 2016 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AnthonyAkentiev/8360966796d3a3d1128af0902f0d85f1 to your computer and use it in GitHub Desktop.
Save AnthonyAkentiev/8360966796d3a3d1128af0902f0d85f1 to your computer and use it in GitHub Desktop.
// Transaction makes payment of X units from A to B
func (t *ChaincodeExample) MakePayment(stub shim.ChaincodeStubInterface, param *example02.PaymentParams) error {
var err error
// Get the state from the ledger
src, err := t.GetState(stub, param.PartySrc)
if err != nil {
return err
}
dst, err := t.GetState(stub, param.PartyDst)
if err != nil {
return err
}
// Perform the execution
X := int(param.Amount)
src = src - X
dst = dst + X
fmt.Printf("Aval = %d, Bval = %d\n", src, dst)
// Write the state back to the ledger
err = stub.PutState(param.PartySrc, []byte(strconv.Itoa(src)))
if err != nil {
return err
}
err = stub.PutState(param.PartyDst, []byte(strconv.Itoa(dst)))
if err != nil {
return err
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment