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

交易接收方提交(commitRecv)

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

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

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

/*
 * commitRecv is the forth step of two-phase cross-chain transaction process, it will be executed on the server 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) commitRecv(stub shim.ChaincodeStubInterface, args []string) pb.Response {
	if len(args) != 3 {
		return shim.Error("Incorrect number of arguments. Expecting 3")
	}
        txID := args[3]
	// unlock server side's local account
	account := args[1]
	err := unlockAccount(stub, txID, account)
	if err != nil {
		return shim.Error(err.Error())
	}
	return shim.Success(nil)
}

相关文档