更新时间:2021-12-30 GMT+08:00
分享

交易发起方回滚(rollbackSend)

该方法用于在跨链资产交换发起方所属区块链上执行回滚操作,即还原发起方所属区块链上对应资产至跨链资产交换开始前的状态,并解锁该资产,使得其可以继续处理下一笔跨链操作。

本例中,该方法将根据发起方所属区块链上args[0]对应数据锁中的PreValue进行资产回滚,并删除该数据锁,使发起方所属区块链上args[0]对应的资产回滚至跨链资产交换开始前的状态。

该方法为必选方法,需在智能合约中以相同命名定义该方法,否则将导致跨链资产交换失败。

/*
 * rollbackSend is the rollback function for client side, it will be executed when error happened during the cross-chain tx process
 * In this example, this function will recover the balance of client side's local account and unlock it,
 * so that it can be used by next cross-chain transaction
 * The example args[] is {"a","b","1","txid123"}
 * @Param args[0]: The name of the account on blockchain A that will transfer the amount of units to the account on blockchain B
 * @Param args[1]: The name of the account on blockchain B that will receive the amount of units from the account on blockchainA
 * @Param args[2]: The amount of unit that will be transferred from args[0](account on blockchain A) to args[1](account on blockchain B)
 * @Param args[3]: The id of this transaction that transfer units of one account to another account
 */
func (t *TCSExampleChaincode) rollbackSend(stub shim.ChaincodeStubInterface, args []string) pb.Response {
	if len(args) != 3 {
		return shim.Error("Incorrect number of arguments. Expecting 3")
	}
        txID := args[3]
	account := args[0]
	err := rollback(stub, txID, account)
	if err != nil {
		return shim.Error(err.Error())
	}
	return shim.Success(nil)
}

相关文档