Created
December 30, 2016 09:28
-
-
Save AnthonyAkentiev/8360966796d3a3d1128af0902f0d85f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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