Commit 14604298 authored by zhourong's avatar zhourong

fix(*): handle dest rollback

parent 7bce9c1a
No preview for this file type
...@@ -118,7 +118,7 @@ func (t *Transfer) transfer(stub shim.ChaincodeStubInterface, args []string) pb. ...@@ -118,7 +118,7 @@ func (t *Transfer) transfer(stub shim.ChaincodeStubInterface, args []string) pb.
return shim.Error(err.Error()) return shim.Error(err.Error())
} }
args := strings.Join([]string{sender, receiver, amountArg}, ",") args := strings.Join([]string{sender, receiver, amountArg, "true"}, ",")
argsRb := strings.Join([]string{sender, amountArg}, ",") argsRb := strings.Join([]string{sender, amountArg}, ",")
b := util.ToChaincodeArgs(emitInterchainEventFunc, dstServiceID, "interchainCharge,,interchainRollback", args, "", argsRb) b := util.ToChaincodeArgs(emitInterchainEventFunc, dstServiceID, "interchainCharge,,interchainRollback", args, "", argsRb)
response := stub.InvokeChaincode(brokerContractName, b, channelID) response := stub.InvokeChaincode(brokerContractName, b, channelID)
...@@ -173,6 +173,7 @@ func (t *Transfer) interchainCharge(stub shim.ChaincodeStubInterface, args []str ...@@ -173,6 +173,7 @@ func (t *Transfer) interchainCharge(stub shim.ChaincodeStubInterface, args []str
sender := args[0] sender := args[0]
receiver := args[1] receiver := args[1]
amountArg := args[2] amountArg := args[2]
isRollback := args[3]
// check for sender info // check for sender info
if sender == "" { if sender == "" {
...@@ -189,7 +190,12 @@ func (t *Transfer) interchainCharge(stub shim.ChaincodeStubInterface, args []str ...@@ -189,7 +190,12 @@ func (t *Transfer) interchainCharge(stub shim.ChaincodeStubInterface, args []str
return shim.Error(fmt.Errorf("get balancee from %s %w", receiver, err).Error()) return shim.Error(fmt.Errorf("get balancee from %s %w", receiver, err).Error())
} }
balance += amount // TODO: deal with rollback failure (balance not enough)
if isRollback == "true" {
balance -= amount
} else {
balance += amount
}
err = stub.PutState(receiver, []byte(strconv.FormatUint(balance, 10))) err = stub.PutState(receiver, []byte(strconv.FormatUint(balance, 10)))
if err != nil { if err != nil {
return shim.Error(err.Error()) return shim.Error(err.Error())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment