中移链元交易功能对接说明
作者:BSN研习社
- 2023-03-03 北京
本文字数:15352 字
阅读完需:约 50 分钟
前言
12月5日,由中国移动信息技术中心研发的中移链“元交易”功能,已在BSN-DDC基础网络正式上线。中移链“元交易”是将多个连续的中移链链操作打包整合,保障操作事务统一、一致的快捷交易开发工具包。在中移链原有链上应用开发SDK的基础上,中移链“元交易”降低了区块链业务应用的开发复杂度,对构建高效便捷的区块链应用开发经济模型提供了重要支撑。
复制代码
一、元交易功能
(一)功能简介
“元交易”是由平台方代终端用户(DDC的拥有者)发起DDC铸造、转移或者销毁的相关交易,且本功能由平台方代付资源费和手续费。在传统的交易模式中,如发起铸造、转移、销毁等操作时,需要终端用户拥有足额的链资源和DDC合约中的手续费,并且流程较长且复杂。本次中国移动信息技术中心研发的中移链“元交易”功能,通过将交易的发起方从终端用户变更为平台方,控制发起方的数量,使发起方充值链资源变得容易,同时从根本上解决了终端用户操作复杂的弊端。
复制代码
(二)应用场景
1、终端用户根据交易请求参数和权限私钥,离线生成元交易的签名,并将签名值发送给平台方,由平台方代为发起元交易执行;
2、终端用户将私钥托管给平台方,平台方根据交易请求参数和权限私钥,生成元交易的签名并发起元交易执行。
复制代码
二、元交易签名
(一)基于 ddc-sdk-java 进行元交易签名
1、平台方添加终端用户的公钥,参考 ddc-sdk 中的 addMetaUser 方法
1)测试用例
@Test
public void addMetaUser() {
//设置平台方账户私钥
ChainConfig.setPk("5Jj3bPpWtbJex5DGXCLjE8c5Gr9SudFRogkwXvd1KHGGa7ZWYS1");
DDCPermissionService ddcPermissionService = new DDCPermissionServiceImpl();
//平台方账户、终端用户账户、终端用户账户公钥
PushedTransaction pt1 = ddcPermissionService.addMetaUser("ddcplatform1", "ddcconsumer1", "EOS6R3jYqb3uZsVgzJz4HVLcYV94CLkr3u9unEzm5rpuAqUos7fqK");
System.out.println(JSONUtil.toJsonStr(pt1));
}
复制代码
2)输出结果
{
"transactionId":"3ea5f2b4e21642f6862a0120a11ff9ef0fd54bc34f4d5c79884bc66b5f5bd86e",
"processed":{
"id":"3ea5f2b4e21642f6862a0120a11ff9ef0fd54bc34f4d5c79884bc66b5f5bd86e",
"blockNum":169181,
"blockTime":"2023-02-01T06:23:56.000",
"receipt":{
"cpuUsageUs":278,
"netUsageWords":21,
"status":"executed"
},
"elapsed":278,
"netUsage":168,
"scheduled":false,
"actionTraces":[
{
"actionOrdinal":1,
"creatorActionOrdinal":0,
"closestUnnotifiedAncestorActionOrdinal":0,
"receipt":{
"abiSequence":1,
"actDigest":"d3950f01d30eeee961fb2e2335b00cfdf098b19a6671d18189bf59454f8410df",
"authSequence":[
[
"ddcplatform1",
"11"
]
],
"codeSequence":1,
"globalSequence":169952,
"receiver":"ddccontract1",
"recvSequence":69
},
"receiver":"ddccontract1",
"act":{
"account":"ddccontract1",
"authorization":[
{
"actor":"ddcplatform1",
"permission":"active"
}
],
"data":{
"sender":"ddcplatform1",
"account":"ddcconsumer1",
"pubKey":"EOS6R3jYqb3uZsVgzJz4HVLcYV94CLkr3u9unEzm5rpuAqUos7fqK"
},
"hexData":"10e4a52b9b58514a10ae921a4f8a504a35454f533652336a59716233755a7356677a4a7a3448564c6359563934434c6b72337539756e457a6d357270754171556f733766714b",
"name":"addmetauser"
},
"contextFree":false,
"elapsed":125,
"console":"",
"trxId":"3ea5f2b4e21642f6862a0120a11ff9ef0fd54bc34f4d5c79884bc66b5f5bd86e",
"blockNum":169181,
"blockTime":"2023-02-01T06:23:56.000",
"accountRamDeltas":[
],
"accountDiskDeltas":[
],
"returnValueHexData":"",
"inlineTraces":[
]
}
]
}
}
复制代码
2、终端用户根据 DDC 拥有者查询 Nonce 值,参考 ddc-sdk 中的 getNonce 方法
1)测试用例
@Test
public void getMetaNonce() {
DDC1155Service ddc1155Service = new DDC1155ServiceImpl();
//终端用户账户
BigInteger nonce = ddc1155Service.getNonce("ddcconsumer1");
System.out.println("nonce:" + nonce);
}
复制代码
2)输出结果
nonce:2
复制代码
3、终端用户根据交易请求参数,生成签名所需的摘要数据(以元交易生成为例)
1)测试用例
@Test
public void getMetaMintDigest() {
BigInteger amount = BigInteger.valueOf(10);
String ddcURI = "https://bitnodes.io/0001";
String memo = "memo0001";
//上一步获取的nonce值
BigInteger nonce = BigInteger.valueOf(2);
//过期时间(时间戳:秒)
BigInteger deadline = BigInteger.valueOf(1671096761);
DDC1155MetaTransaction metaTransaction = new DDC1155MetaTransaction();
String digest = metaTransaction.getSafeMintDigest("ddcplatform1", "ddcconsumer1", "ddcconsumer1", amount, ddcURI, memo, nonce, deadline);
System.out.println("digest:" + digest);
}
复制代码
2)输出结果
digest:baa58785f08da6bfe06e3675423478f8039a55f5aaf57eea195b47b9ebb6732c
复制代码
4、终端用户根据权限私钥和摘要数据,生成元交易签名
1)测试用例
@Test
public void getMetaMintSignature() {
//终端用户账户私钥
String privateKey = "5JAT6ZYDhvvWVP2UMat84BhCyu5U3PYMYtkzqXEgoPoyhdJJfV1";
//上一步获取的摘要值
String digest = "baa58785f08da6bfe06e3675423478f8039a55f5aaf57eea195b47b9ebb6732c";
DDC1155MetaTransaction metaTransaction = new DDC1155MetaTransaction();
String signature = metaTransaction.generateSignature(privateKey, digest.getBytes(StandardCharsets.UTF_8));
System.out.println("signature:" + signature);
}
复制代码
2)输出结果
signature:SIG_K1_K8W87kgEkB3EwUUTSzqU5WjnuQJ5Q11mcUx7PGJhCG5ZgALHzmxep8s9AVWXyXAEfhc9xb1Bz53biadmnRBkyRzWnYGU8W
复制代码
(二)基于 ddc-sdk-js 进行元交易签名
1、平台方添加终端用户的公钥,参考 ddc-sdk 中的 addMetaUser 方法 1)测试用例
import EOSDDC from 'eos-ts-sdk';
const addMetaUserTest = (sender='ddcplatform1',account='ddcconsumer1') => {
const privateKey = "5JAT6ZYDhvvWVP2UMat84BhCyu5U3PYMYtkzqXEgoPoyhdJJfV1";
const pubKey= "EOS6R3jYqb3uZsVgzJz4HVLcYV94CLkr3u9unEzm5rpuAqUos7fqK";
let ddcPermissionService = new EOSDDC('http://101.42.251.173:3921', 'ddccontract1');
const result1 = ddcPermissionService.addMetaUser(sender, account, pubKey,privateKey);
console.log(result1);
}
复制代码
2)输出结果
{
"transaction_id": "4b2b33a6e380ba4726ce6360a91435fe93ec304b0e06ee2170de5a537f254769",
"processed": {
"id": "4b2b33a6e380ba4726ce6360a91435fe93ec304b0e06ee2170de5a537f254769",
"block_num": 2363,
"block_time": "2023-01-31T07:13:47.000",
"producer_block_id": null,
"receipt": {
"status": "executed",
"cpu_usage_us": 270,
"net_usage_words": 21
},
"elapsed": 270,
"net_usage": 168,
"scheduled": false,
"action_traces": [
{
"action_ordinal": 1,
"creator_action_ordinal": 0,
"closest_unnotified_ancestor_action_ordinal": 0,
"receipt": {
"receiver": "ddccontract1",
"act_digest": "d3950f01d30eeee961fb2e2335b00cfdf098b19a6671d18189bf59454f8410df",
"global_sequence": 3129,
"recv_sequence": 64,
"auth_sequence": [
[
"ddcplatform1",
6
]
],
"code_sequence": 1,
"abi_sequence": 1
},
"receiver": "ddccontract1",
"act": {
"account": "ddccontract1",
"name": "addmetauser",
"authorization": [
{
"actor": "ddcplatform1",
"permission": "active"
}
],
"data": {
"sender": "ddcplatform1",
"account": "ddcconsumer1",
"pubKey": "EOS6R3jYqb3uZsVgzJz4HVLcYV94CLkr3u9unEzm5rpuAqUos7fqK"
},
"hex_data": "10e4a52b9b58514a10ae921a4f8a504a35454f533652336a59716233755a7356677a4a7a3448564c6359563934434c6b72337539756e457a6d357270754171556f733766714b"
},
"context_free": false,
"elapsed": 135,
"console": "",
"trx_id": "4b2b33a6e380ba4726ce6360a91435fe93ec304b0e06ee2170de5a537f254769",
"block_num": 2363,
"block_time": "2023-01-31T07:13:47.000",
"producer_block_id": null,
"account_ram_deltas": [ ],
"account_disk_deltas": [ ],
"except": null,
"error_code": null,
"return_value_hex_data": "",
"inline_traces": [ ]
}
],
"account_ram_delta": null,
"except": null,
"error_code": null
}
}
复制代码
2、终端用户根据 DDC 拥有者查询 Nonce 值,参考 ddc-sdk 中的 getNonce 方法
1)测试用例
const getNonce1155 = async () => {
const Meta1155 = new EOSDDC(
'http://101.42.251.173:3921',
'ddccontract1',
);
const nonce = await Meta1155.getNonce('ddcconsumer1');
console.log(`nonce:${nonce}`);
return nonce;
};
复制代码
2)输出结果
nonce:2
复制代码
3、终端用户根据交易请求参数,生成签名所需的摘要数据(以元交易生成为例)
1)测试用例
const getMetaMintDigest1155 = async () => {
const amount = 10;
const ddcURI = 'https://bitnodes.io/0001';
const memo = 'memo0001';
const deadline = 1671096761;
const nonce = await getNonce1155();
const ddc1155 = new DDC1155MetaTransaction('ddccontract1');
const digest = await ddc1155.getSafeMintDigest(
'ddcplatform1',
'ddcconsumer1',
'ddcconsumer1',
amount,
ddcURI,
memo,
nonce,
deadline,
);
console.log(`digest:${digest}`);
return digest;
};
复制代码
2)输出结果
digest:baa58785f08da6bfe06e3675423478f8039a55f5aaf57eea195b47b9ebb6732c
复制代码
4、终端用户根据权限私钥和摘要数据,生成元交易签名 1)测试用例
const getMetaMintSignature1155 = async () => {
const key = '5JAT6ZYDhvvWVP2UMat84BhCyu5U3PYMYtkzqXEgoPoyhdJJfV1';
const digest = await getMetaMintDigest1155(); // baa58785f08da6bfe06e3675423478f8039a55f5aaf57eea195b47b9ebb6732c
const ddc1155 = new DDC1155MetaTransaction('ddccontract1');
const signature = await ddc1155.generateSignature(key, digest);
console.log(`signature:${signature}`);
return signature;
};
复制代码
2)输出结果
signature:SIG_K1_K8W87kgEkB3EwUUTSzqU5WjnuQJ5Q11mcUx7PGJhCG5ZgALHzmxep8s9AVWXyXAEfhc9xb1Bz53biadmnRBkyRzWnYGU8W
复制代码
三、元交易方法调用
(一)元交易生成
1、功能介绍
终端用户可以通过授权平台方调用该方法对 DDC 进行元交易生成,注:调用此接口所消耗的能量值和业务费对应的是平台方账户。
复制代码
2、方法定义
1) SDK 方法定义:
DDC721Service PushedTransaction metaSafeMint(String sender, String from, String to, String ddcURI, String memo, BigInteger nonce, BigInteger deadline, String signature);
DDC1155Service PushedTransaction metaSafeMint(String sender, String from, String to, BigInteger amount, String ddcURI, String memo, BigInteger nonce, BigInteger deadline, String signature);
2) EOS 合约方法:
metamint(name sender,name from, name to, uint64_t amount, std::string ddc_uri, uint64_t business_type, std::string memo, uint64_t nonce, uint64_t deadline, signature signature);
复制代码
3、输入参数
4、输出参数
5、API 调用
1)测试用例(以 DDC1155 为例)
@Test
public void metaSafeMint1155() {
BigInteger amount = BigInteger.valueOf(10);
String ddcURI = "https://bitnodes.io/0001";
String memo = "memo0001";
BigInteger deadline = BigInteger.valueOf(1671096761);
DDC1155Service ddc1155Service = new DDC1155ServiceImpl();
BigInteger nonce = ddc1155Service.getNonce(accountList.get(2));
DDC1155MetaTransaction metaTransaction = new DDC1155MetaTransaction();
String digest = metaTransaction.getSafeMintDigest(accountList.get(1), accountList.get(2), accountList.get(2), amount, ddcURI, memo, nonce, deadline);
String signature = metaTransaction.generateSignature(privateKey, digest.getBytes(StandardCharsets.UTF_8));
PushedTransaction pt = ddc1155Service.metaSafeMint(accountList.get(1), accountList.get(2), accountList.get(2), amount, ddcURI, memo, nonce, deadline, signature);
Map<String, Object> trxMap = ChainUtil.getInstance().parseTrxResp(pt);
System.out.println(JSONUtil.parse(trxMap));
}
复制代码
2) 输出结果
{
"actionTraces":[
{
"actData":{
"ddc_id":6899,
"account":"ddcplatform1",
"business_type":2,
"func_name":"mint",
"fee":"0.0001 FEE",
"balance":"8.2350 FEE"
},
"actAccount":"ddccontract1",
"actName":"receiptpay"
},
{
"actData":{
"sender":"ddcplatform1",
"to":"ddcconsumer1",
"ddc_id":6899,
"ddc_uri":"https://bitnodes.io/0001",
"allowed":1,
"amount":10,
"business_type":2,
"ddc_name":"",
"ddc_symbol":""
},
"actAccount":"ddccontract1",
"actName":"receiptmint"
},
{
"actData":{
"sender":"ddcplatform1",
"from":"ddcconsumer1",
"to":"ddcconsumer1",
"amount":10,
"ddc_uri":"https://bitnodes.io/0001",
"business_type":2,
"memo":"memo0001",
"nonce":77,
"deadline":1671096761,
"signature":"SIG_K1_K5wAsgrAAoAyafBVXSXQQ8qSn6N7tY6XiyJ3wYvv1Bky3fZbYQJmuVw94wYnAqfqRfNZ7Zt7umMiSroArYSbu3vVbphZmh"
},
"actAccount":"ddccontract1",
"actName":"metamint"
}
],
"blockNum":8126659,
"blockTime":"2022-12-28T07:03:12.000",
"transactionId":"9d2e99de165568cd74ef4b779c73f4afa2085e023b1d80ccbd521237c9c1efa2"
}
复制代码
(二)元交易批量生成
1、功能介绍
终端用户可以通过授权平台方调用该方法对 DDC 进行元交易批量安全生成,注:调用此接口所消耗的能量值和业务费对应的是平台方账户。
复制代码
2、方法定义
1) SDK 方法定义:
DDC1155Service PushedTransaction metaSafeMintBatch(String sender, String from, String to, List<BigInteger> amounts, List<String> ddcURIs, String memo, BigInteger nonce, BigInteger deadline, String signature);
2) EOS 合约方法:
metamintbatc(name sender, name from,name to, std::vector<uint64_t> amounts, std::vector<std::string> ddc_uris, uint64_t business_type, std::string memo, uint64_t nonce, uint64_t deadline, signature signature);
复制代码
3、输入参数
4、输出参数
5、API 调用
1)测试用例
@Test
public void metaSafeMintBatch1155() {
List<BigInteger> amounts = Arrays.asList(BigInteger.valueOf(20), BigInteger.valueOf(30));
List<String> ddcURIs = Arrays.asList("http://ddcUrl1", "http://ddcUrl2");
String memo = "memo0001";
BigInteger deadline = BigInteger.valueOf(1671096761);
DDC1155Service ddc1155Service = new DDC1155ServiceImpl();
BigInteger nonce = ddc1155Service.getNonce(accountList.get(2));
DDC1155MetaTransaction metaTransaction = new DDC1155MetaTransaction();
String digest = metaTransaction.getSafeMintBatchDigest(accountList.get(1), accountList.get(2), accountList.get(2), amounts, ddcURIs, memo, nonce, deadline);
String signature = metaTransaction.generateSignature(privateKey, digest.getBytes(StandardCharsets.UTF_8));
PushedTransaction pt = ddc1155Service.metaSafeMintBatch(accountList.get(1), accountList.get(2), accountList.get(2), amounts, ddcURIs, memo, nonce, deadline, signature);
Map<String, Object> trxMap = ChainUtil.getInstance().parseTrxResp(pt);
System.out.println(JSONUtil.parse(trxMap));
}
复制代码
2) 输出结果
{
"actionTraces":[
{
"actData":{
"ddc_id":6900,
"account":"ddcplatform1",
"business_type":2,
"func_name":"mintbatch",
"fee":"0.0001 FEE",
"balance":"8.2349 FEE"
},
"actAccount":"ddccontract1",
"actName":"receiptpay"
},
{
"actData":{
"sender":"ddcplatform1",
"to":"ddcconsumer1",
"ddc_id":6900,
"ddc_uri":"http://ddcUrl1",
"allowed":1,
"amount":20,
"business_type":2,
"ddc_name":"",
"ddc_symbol":""
},
"actAccount":"ddccontract1",
"actName":"receiptmint"
},
{
"actData":{
"ddc_id":6901,
"account":"ddcplatform1",
"business_type":2,
"func_name":"mintbatch",
"fee":"0.0001 FEE",
"balance":"8.2348 FEE"
},
"actAccount":"ddccontract1",
"actName":"receiptpay"
},
{
"actData":{
"sender":"ddcplatform1",
"to":"ddcconsumer1",
"ddc_id":6901,
"ddc_uri":"http://ddcUrl2",
"allowed":1,
"amount":30,
"business_type":2,
"ddc_name":"",
"ddc_symbol":""
},
"actAccount":"ddccontract1",
"actName":"receiptmint"
},
{
"actData":{
"sender":"ddcplatform1",
"from":"ddcconsumer1",
"to":"ddcconsumer1",
"amounts":[
20,
30
],
"ddc_uris":[
"http://ddcUrl1",
"http://ddcUrl2"
],
"business_type":2,
"memo":"memo0001",
"nonce":78,
"deadline":1671096761,
"signature":"SIG_K1_KfJAvnwbWXxzijNhZKsnLs4M1xHYYb3uABPho9VJcoHpQBbpGUphFXRpEAQJuhar8jzdxs4TTt1JY7giSRVuFKYD5XYBBN"
},
"actAccount":"ddccontract1",
"actName":"metamintbatc"
}
],
"blockNum":8127577,
"blockTime":"2022-12-28T07:10:51.000",
"transactionId":"75f44ef74a241e2e341d16056e6ee379b25cf1b73a51a942a244839a974da21c"
}
复制代码
(三)元交易转移
1、功能介绍
DDC 拥有者或 DDC 授权者通过授权平台方调用该方法对 DDC 进行元交易转移,注:调用此接口所消耗的能量值和业务费对应的是平台方账户。
复制代码
2、方法定义
1) SDK 方法定义:
DDC721Service PushedTransaction metaSafeTransferFrom(String sender, String from, String to, BigInteger ddcId, String memo, BigInteger nonce, BigInteger deadline, String signature);
DDC1155Service PushedTransaction metaSafeTransferFrom(String sender, String from, String to, BigInteger ddcId, BigInteger amount, String memo, BigInteger nonce, BigInteger deadline, String signature);
2) EOS 合约方法:
metatransfer(name sender, name from, name to, uint64_t ddc_id, uint64_t amount, std::string memo, uint64_t business_type, uint64_t nonce, uint64_t deadline, signature signature);
复制代码
3、输入参数
4、输出参数
5、API 调用
1)测试用例(以 DDC1155 为例)
@Test
public void metaSafeTransferFrom1155() {
BigInteger ddcId = BigInteger.valueOf(136);
BigInteger amount = BigInteger.valueOf(2);
String memo = "memo0001";
BigInteger deadline = BigInteger.valueOf(1671096761);
DDC1155Service ddc1155Service = new DDC1155ServiceImpl();
BigInteger nonce = ddc1155Service.getNonce(accountList.get(2));
DDC1155MetaTransaction metaTransaction = new DDC1155MetaTransaction();
String digest = metaTransaction.getSafeTransferFromDigest(accountList.get(1), accountList.get(2), accountList.get(2), ddcId, amount, memo, nonce, deadline);
String signature = metaTransaction.generateSignature(privateKey, digest.getBytes(StandardCharsets.UTF_8));
PushedTransaction pt = ddc1155Service.metaSafeTransferFrom(accountList.get(1), accountList.get(2), accountList.get(2), ddcId, amount, memo, nonce, deadline, signature);
Map<String, Object> trxMap = ChainUtil.getInstance().parseTrxResp(pt);
System.out.println(JSONUtil.parse(trxMap));
}
复制代码
2) 输出结果
{
"actionTraces":[
{
"actData":{
"ddc_id":136,
"account":"ddcplatform1",
"business_type":2,
"func_name":"transfer",
"fee":"0.0001 FEE",
"balance":"8.2347 FEE"
},
"actAccount":"ddccontract1",
"actName":"receiptpay"
},
{
"actData":{
"sender":"ddcplatform1",
"from":"ddcconsumer1",
"to":"ddcconsumer1",
"ddc_id":136,
"amount":2,
"memo":"memo0001",
"business_type":2,
"nonce":79,
"deadline":1671096761,
"signature":"SIG_K1_KkQvq6AnrCxS2hzdqYhsqJB3AtZeQW5RJfviSMGaBYgaHXdVAFdEzW8Q5nkQMd4k7LdWprSCKLmUM49JBFGtY9TrTv9hL4"
},
"actAccount":"ddccontract1",
"actName":"metatransfer"
}
],
"blockNum":8128554,
"blockTime":"2022-12-28T07:18:59.500",
"transactionId":"d26f43175c9b07ae3ace53122edc82ee704484168479672cccadf6ed6ea33818"
}
复制代码
(四)元交易批量转移
1、功能介绍
DDC 拥有者或 DDC 授权者可以通过授权平台方调用该方法对 DDC进行元交易批量转移,注:调用此接口所消耗的能量值和业务费对应的是平台方账户。
复制代码
2、方法定义
1) SDK 方法定义:
DDC1155Service PushedTransaction metaSafeBatchTransferFrom(String sender, String from, String to, List<BigInteger> ddcIds, List<BigInteger> amounts, String memo, BigInteger nonce, BigInteger deadline, String signature);
2) EOS 合约方法:
metatransbat (name sender, name from, name to, std::vector<uint64_t> ddc_ids, std::vector<uint64_t> amounts, std::string memo, uint64_t business_type, uint64_t nonce, uint64_t deadline, signature signature);
复制代码
3、输入参数
4、输出参数
5、API 调用
1)测试用例
@Test
public void metaSafeBatchTransferFrom1155() {
List<BigInteger> ddcIds = Arrays.asList(BigInteger.valueOf(137), BigInteger.valueOf(138));
List<BigInteger> amounts = Arrays.asList(BigInteger.valueOf(2), BigInteger.valueOf(3));
String memo = "memo0001";
BigInteger deadline = BigInteger.valueOf(1671096761);
DDC1155Service ddc1155Service = new DDC1155ServiceImpl();
BigInteger nonce = ddc1155Service.getNonce(accountList.get(2));
DDC1155MetaTransaction metaTransaction = new DDC1155MetaTransaction();
String digest = metaTransaction.getSafeBatchTransferFromDigest(accountList.get(1), accountList.get(2), accountList.get(2), ddcIds, amounts, memo, nonce, deadline);
String signature = metaTransaction.generateSignature(privateKey, digest.getBytes(StandardCharsets.UTF_8));
PushedTransaction pt = ddc1155Service.metaSafeBatchTransferFrom(accountList.get(1), accountList.get(2), accountList.get(2), ddcIds, amounts, memo, nonce, deadline, signature);
Map<String, Object> trxMap = ChainUtil.getInstance().parseTrxResp(pt);
System.out.println(JSONUtil.parse(trxMap));
}
复制代码
2) 输出结果
{
"actionTraces":[
{
"actData":{
"ddc_id":137,
"account":"ddcplatform1",
"business_type":2,
"func_name":"batchtrans",
"fee":"0.0001 FEE",
"balance":"8.2346 FEE"
},
"actAccount":"ddccontract1",
"actName":"receiptpay"
},
{
"actData":{
"ddc_id":138,
"account":"ddcplatform1",
"business_type":2,
"func_name":"batchtrans",
"fee":"0.0001 FEE",
"balance":"8.2345 FEE"
},
"actAccount":"ddccontract1",
"actName":"receiptpay"
},
{
"actData":{
"sender":"ddcplatform1",
"from":"ddcconsumer1",
"to":"ddcconsumer1",
"ddc_ids":[
137,
138
],
"amounts":[
2,
3
],
"memo":"memo0001",
"business_type":2,
"nonce":80,
"deadline":1671096761,
"signature":"SIG_K1_KWTUkvmwpYiTK9jvZcrWSJSs9p9XnX2Br6odYv7fVzQ6qZmQrhfXXf5VEMAvrwLo9Ufs3pijh4u9JioT2wKwFFx5dF4dvW"
},
"actAccount":"ddccontract1",
"actName":"metatransbat"
}
],
"blockNum":8129207,
"blockTime":"2022-12-28T07:24:26.000",
"transactionId":"a4c2049569c305f094ffd6c568711796b8eb4df4e21b8b326077491844d6ca01"
}
复制代码
(五)元交易销毁
1、功能介绍
DDC 拥有者或 DDC 授权者可以通过授权平台方调用该方法对 DDC进行元交易销毁,注:调用此接口所消耗的能量值和业务费对应的是平台方账户。
复制代码
2、方法定义
1) SDK 方法定义:
DDC721Service PushedTransaction metaBurn(String sender, String owner, BigInteger ddcId, BigInteger nonce, BigInteger deadline, String signature);
DDC1155Service PushedTransaction metaBurn(String sender, String owner, BigInteger ddcId, BigInteger nonce, BigInteger deadline, String signature);
2) EOS 合约方法:
metaburn(name sender, name owner, uint64_t ddc_id, uint64_t business_type, uint64_t nonce, uint64_t deadline, signature signature);
复制代码
3、输入参数
4、输出参数
5、API 调用
1)测试用例(以 DDC1155 为例)
@Test
public void metaBurn1155() {
BigInteger ddcId = BigInteger.valueOf(139);
BigInteger deadline = BigInteger.valueOf(1671096761);
DDC1155Service ddc1155Service = new DDC1155ServiceImpl();
BigInteger nonce = ddc1155Service.getNonce(accountList.get(2));
DDC1155MetaTransaction metaTransaction = new DDC1155MetaTransaction();
String digest = metaTransaction.getBurnDigest(accountList.get(1), accountList.get(2), ddcId, nonce, deadline);
String signature = metaTransaction.generateSignature(privateKey, digest.getBytes(StandardCharsets.UTF_8));
PushedTransaction pt = ddc1155Service.metaBurn(accountList.get(1), accountList.get(2), ddcId, nonce, deadline, signature);
Map<String, Object> trxMap = ChainUtil.getInstance().parseTrxResp(pt);
System.out.println(JSONUtil.parse(trxMap));
}
复制代码
2) 输出结果
{
"actionTraces":[
{
"actData":{
"ddc_id":139,
"account":"ddcplatform1",
"business_type":2,
"func_name":"burn",
"fee":"0.0001 FEE",
"balance":"8.2343 FEE"
},
"actAccount":"ddccontract1",
"actName":"receiptpay"
},
{
"actData":{
"sender":"ddcplatform1",
"owner":"ddcconsumer1",
"ddc_id":139,
"business_type":2,
"nonce":82,
"deadline":1671096761,
"signature":"SIG_K1_Kk7xG8Ux1Nu7jjF4zx4p98BLb4cZHVxwTbTV1L9nxU4zXiaRQoeNGq4WDv33hdFZ3pGrLyrcK5XwSkPR7sn7vdm3hdi2yG"
},
"actAccount":"ddccontract1",
"actName":"metaburn"
}
],
"blockNum":8129841,
"blockTime":"2022-12-28T07:29:43.000",
"transactionId":"863711b5f8a4aa17ec167ecf073c62c4c2491754bed29064b1935c19bcf84929"
}
复制代码
(六)元交易批量销毁
1、功能介绍
DDC 拥有者或 DDC 授权者可以通过授权平台方调用该方法对 DDC进行元交易批量销毁,注:调用此接口所消耗的能量值和业务费对应的是平台方账户。
复制代码
2、方法定义
1) SDK 方法定义:
DDC1155Service PushedTransaction metaBurnBatch(String sender, String owner, List<BigInteger> ddcIds, BigInteger nonce, BigInteger deadline, String signature);
2) EOS 合约方法:
metaburnbatc(name sender, name owner, std::vector<uint64_t> ddc_ids, uint64_t business_type, uint64_t nonce, uint64_t deadline, signature signature);
复制代码
3、输入参数
4、输出参数
5、API 调用
1)测试用例
@Test
public void metaBurnBatch1155() {
List<BigInteger> ddcIds = Arrays.asList(BigInteger.valueOf(137), BigInteger.valueOf(138));
BigInteger deadline = BigInteger.valueOf(1671096761);
DDC1155Service ddc1155Service = new DDC1155ServiceImpl();
BigInteger nonce = ddc1155Service.getNonce(accountList.get(2));
DDC1155MetaTransaction metaTransaction = new DDC1155MetaTransaction();
String digest = metaTransaction.getBurnBatchDigest(accountList.get(1), accountList.get(2), ddcIds, nonce, deadline);
String signature = metaTransaction.generateSignature(privateKey, digest.getBytes(StandardCharsets.UTF_8));
PushedTransaction pt = ddc1155Service.metaBurnBatch(accountList.get(1), accountList.get(2), ddcIds, nonce, deadline, signature);
Map<String, Object> trxMap = ChainUtil.getInstance().parseTrxResp(pt);
System.out.println(JSONUtil.parse(trxMap));
}
复制代码
2) 输出结果
{
"actionTraces":[
{
"actData":{
"ddc_id":137,
"account":"ddcplatform1",
"business_type":2,
"func_name":"burnbatch",
"fee":"0.0001 FEE",
"balance":"8.2342 FEE"
},
"actAccount":"ddccontract1",
"actName":"receiptpay"
},
{
"actData":{
"ddc_id":138,
"account":"ddcplatform1",
"business_type":2,
"func_name":"burnbatch",
"fee":"0.0001 FEE",
"balance":"8.2341 FEE"
},
"actAccount":"ddccontract1",
"actName":"receiptpay"
},
{
"actData":{
"sender":"ddcplatform1",
"owner":"ddcconsumer1",
"ddc_ids":[
137,
138
],
"business_type":2,
"nonce":83,
"deadline":1671096761,
"signature":"SIG_K1_K4TC8gPC3iLQcrrKYRS7kgsNKX2xh6AB8CSyaRyN6fYfiAow3YMctBGg2z9pyS7RPuXmidn6GVapJ4k7scMxRFJPzAFc8X"
},
"actAccount":"ddccontract1",
"actName":"metaburnbatc"
}
],
"blockNum":8130284,
"blockTime":"2022-12-28T07:33:24.500",
"transactionId":"9352f902710cf44133729b1730565c95a5900d7d51f95bef1f043f2de42bae71"
}
复制代码
划线
评论
复制
发布于: 刚刚阅读数: 6
BSN研习社
关注
还未添加个人签名 2021-11-05 加入
还未添加个人简介
评论