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

交易发起方提交(commitSend)

该方法用于在跨链资产交换发起方所属区块链上执行提交操作,即解锁发起方所属区块链上对应资产,使得其可以继续处理下一笔跨链操作。

本例中,该方法将删除发起方所属区块链上args[0]对应的数据锁,代表该笔跨链资产交换操作在发起方已端到端完成。unlockAccount方法的实现请参考解锁跨链资产(unlockAccount)

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

/*
 * commitSend is the third step of two-phase cross-chain transaction process, it will be executed on the client side and unlock the related assets/data
 * In this example, this function will unlock server side's local account(second arg),
 * 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) commitSend(stub shim.ChaincodeStubInterface, args []string) pb.Response {
	if len(args) != 4 {
		return shim.Error("Incorrect number of arguments. Expecting 4")
	}
        txID := args[3]
	// unlock client side's local account
	account := args[0]
	err := unlockAccount(stub, txID, account)
	if err != nil {
		return shim.Error(err.Error())
	}
	return shim.Success(nil)
}

相关文档