前言
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、輸入引數
欄位 | 欄位名 | 型別 | 是否必傳 | 備註 |
---|---|---|---|---|
sender | 呼叫者 | String | 是 | 呼叫者地址 |
from | 傳送方賬戶 | String | 是 | |
to | 接收者賬戶 | String | 是 | |
amount | DDC數量 | BigInteger | 否 | DDC721不傳 |
ddcURI | DDC資源識別符號 | String | 是 | |
memo | 附加資料 | String | 是 | |
nonce | Nonce值 | BigInteger | 是 | |
deadline | 過期時間 | BigInteger | 是 | |
signature | 簽名值 | String | 是 |
4、輸出引數
欄位 | 欄位名 | 型別 | 備註 |
---|---|---|---|
transactionId | 交易雜湊 | String | |
processed | 執行資訊 | Processed |
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、輸入引數
欄位 | 欄位名 | 型別 | 是否必傳 | 備註 |
---|---|---|---|---|
sender | 呼叫者 | String | 是 | 呼叫者地址 |
from | 傳送方賬戶 | String | 是 | |
to | 接收者賬戶 | String | 是 | |
amounts | DDC數量列表 | List<BigInteger> | 是 | |
ddcURIs | DDC資源識別符號列表 | List<String> | 是 | |
memo | 附加資料 | String | 是 | |
nonce | Nonce值 | BigInteger | 是 | |
deadline | 過期時間 | BigInteger | 是 | |
signature | 簽名值 | String | 是 |
4、輸出引數
欄位 | 欄位名 | 型別 | 備註 |
---|---|---|---|
transactionId | 交易雜湊 | String | |
processed | 執行資訊 | Processed |
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、輸入引數
欄位 | 欄位名 | 型別 | 是否必傳 | 備註 |
---|---|---|---|---|
sender | 呼叫者 | String | 是 | 呼叫者地址 |
from | 傳送方賬戶 | String | 是 | |
to | 接收者賬戶 | String | 是 | |
ddcId | DDC唯一標識 | BigInteger | 是 | |
amount | DDC數量 | BigInteger | 否 | DDC721不傳 |
memo | 附加資料 | String | 是 | |
nonce | Nonce值 | BigInteger | 是 | |
deadline | 過期時間 | BigInteger | 是 | |
signature | 簽名值 | String | 是 |
4、輸出引數
欄位 | 欄位名 | 型別 | 備註 |
---|---|---|---|
transactionId | 交易雜湊 | String | |
processed | 執行資訊 | Processed |
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、輸入引數
欄位 | 欄位名 | 型別 | 是否必傳 | 備註 |
---|---|---|---|---|
sender | 呼叫者 | String | 是 | 呼叫者地址 |
from | 傳送方賬戶 | String | 是 | |
to | 接收者賬戶 | String | 是 | |
ddcIds | DDC唯一標識列表 | List<BigInteger> | 是 | |
amounts | DDC數量列表 | List<BigInteger> | 是 | |
memo | 附加資料 | String | 是 | |
nonce | Nonce值 | BigInteger | 是 | |
deadline | 過期時間 | BigInteger | 是 | |
signature | 簽名值 | String | 是 |
4、輸出引數
欄位 | 欄位名 | 型別 | 備註 |
---|---|---|---|
transactionId | 交易雜湊 | String | |
processed | 執行資訊 | Processed |
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、輸入引數
欄位 | 欄位名 | 型別 | 是否必傳 | 備註 |
---|---|---|---|---|
sender | 呼叫者 | String | 是 | 呼叫者地址 |
owner | 擁有者賬戶 | String | 是 | |
ddcId | DDC唯一標識 | BigInteger | 是 | |
nonce | Nonce值 | BigInteger | 是 | |
deadline | 過期時間 | BigInteger | 是 | |
signature | 簽名值 | String | 是 |
4、輸出引數
欄位 | 欄位名 | 型別 | 備註 |
---|---|---|---|
transactionId | 交易雜湊 | String | |
processed | 執行資訊 | Processed |
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、輸入引數
欄位 | 欄位名 | 型別 | 是否必傳 | 備註 |
---|---|---|---|---|
sender | 呼叫者 | String | 是 | 呼叫者地址 |
owner | 擁有者賬戶 | String | 是 | |
ddcIds | DDC唯一標識列表 | List<BigInteger> | 是 | |
nonce | Nonce值 | BigInteger | 是 | |
deadline | 過期時間 | BigInteger | 是 | |
signature | 簽名值 | String | 是 |
4、輸出引數
欄位 | 欄位名 | 型別 | 備註 |
---|---|---|---|
transactionId | 交易雜湊 | String | |
processed | 執行資訊 | Processed |
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"
}