在使用/fork接口之前,先阅读API文档的接口规范,
点击查看API接口文档
如下图所示:
这里可以看到,拼接一个可用的API接口,先在G节点控制台拿到API接口地址和接口密钥,如下图:
API接口地址复制到这里:https://c0.6dgs.opencom.cn/node.testphone.coin
API接口密钥复制到这里:appid=10001&secret_key=bfc51077860b2927be95c0807766ca56
按规范拼接API的接口URL:https://c0.6dgs.opencom.cn/node.testphone.coin/fork?appid=10001&secret_key=bfc51077860b2927be95c0807766ca56
这里在【API接口地址】后面添加了/fork?,还有API接口密钥,这样,一个有效的/fork接口地址就生产了。
我们看API文档,/fork接口需要哪些参数,如下图:
这里我们先不使用dst_token参数和space参数,但token_root一定懂得如何拼接出来,我们的token_name为coin,故token_root为coin_0000000000000000
所以,创建token-id的第一个fork接口URL拼接如下:
https://c0.6dgs.opencom.cn/node.testphone.coin/fork?appid=10001&secret_key=bfc51077860b2927be95c0807766ca56&token=coin_0000000000000000
得到的返回结果如下:
{"ret":true,"msg":"success","txid":"txid_23YMEoYHpz1o9xgE","token_x":"coin_24ugygVxTD2nz2Gy","token_y":"coin_0000000000000000","x_state":{"token_state_p":"[\"coin_0000000000000000\"]","token_state_val":"0","token_height":0,"pre_txid":"null","private_key":"CSBFzUX1vB8wSH3Qjxi47Lvwgvvx63F4QhWMfzyrWpFM","public_key":"yFnXjsj5v3EtPBrFdWTq28rdw6NWoYd6VYxyxKA7JHZD","token":"coin_24ugygVxTD2nz2Gy"},"y_state":{"token_state_p":"[]","token_state_val":"0","token_height":1,"private_key":"8egL8ivrhE3KkpW639f1fXv1Qb97psiudMqs5Kfb2WmL","public_key":"yizNoHddKNvchoikGRdrTaqeDJptUh9XvpnRiDfb85vz","token":"coin_0000000000000000"}
ret=true代表fork成功,token_x=coin_24ugygVxTD2nz2Gy为成功创建的token-id。
使用dst_token,例如dst_token=coin_1234567890123456,API接口拼接如下:
https://c0.6dgs.opencom.cn/node.testphone.coin/fork?appid=10001&secret_key=bfc51077860b2927be95c0807766ca56&token=coin_0000000000000000&dst_token=coin_1234567890123456
返回结果:{"ret":true,"msg":"success","txid":"txid_29LwnN76HqgB7wth","token_x":"coin_1234567890123456","token_y":"coin_0000000000000000","x_state":{"token_state_p":"[\"coin_0000000000000000\"]","token_state_val":"0","token_height":0,"pre_txid":"null","private_key":"vyDFhhHixhQzcfBFJ7tk65jW2qAm6Cymz4Vv3nZsPYh","public_key":"246WqwPJKiYWkoNuTVhcohdMoiNeQYxw836rQKmxH6mjV","token":"coin_1234567890123456"},"y_state":{"token_state_p":"[]","token_state_val":"0","token_height":2,"private_key":"8egL8ivrhE3KkpW639f1fXv1Qb97psiudMqs5Kfb2WmL","public_key":"yizNoHddKNvchoikGRdrTaqeDJptUh9XvpnRiDfb85vz","token":"coin_0000000000000000"}}
可以看到ret=true,代表fork新帐户调用成功,同时返回token_x=coin_1234567890123456;
这里注意,因为token-id的唯一性,所以多次调用同一个/fork接口URL,创建dst_token=coin_1234567890123456会在第二次调用以后全部返回失败结果如下:
{"ret":false,"msg":"wallet new token failed! "}
意思是:token-id已经存在于G节点中了,所以fork创建该dst_token失败了(不能多次fork同一个目标token-id)。
使用space,例如space=area1,API接口拼接如下:
https://c0.6dgs.opencom.cn/node.testphone.coin/fork?appid=10001&secret_key=bfc51077860b2927be95c0807766ca56&token=coin_0000000000000000&space=area1
点击上述链接,调用结果如下:
{"ret":true,"msg":"success","txid":"txid_2xsSRiHRqJuW3RV8","token_x":"coin_area1y79Ex4TMH4p","token_y":"coin_0000000000000000","x_state":{"token_state_p":"[\"coin_0000000000000000\"]","token_state_val":"0","token_height":0,"pre_txid":"null","private_key":"6XTEu7e3uFrjXnxToy9Y9TsiNhMU99hqH7ZCd1iYjqGM","public_key":"uzhxkTGeszukKUaS9Y9brk7fj6hsDWBQBWWBbhNsujFN","token":"coin_area1y79Ex4TMH4p"},"y_state":{"token_state_p":"[]","token_state_val":"0","token_height":3,"private_key":"8egL8ivrhE3KkpW639f1fXv1Qb97psiudMqs5Kfb2WmL","public_key":"yizNoHddKNvchoikGRdrTaqeDJptUh9XvpnRiDfb85vz","token":"coin_0000000000000000"}}
再次点击链接 ,调用结果如下:
{"ret":true,"msg":"success","txid":"txid_2wwqmUUNBvaSr5uk","token_x":"coin_area12zFnNW9XR1R","token_y":"coin_0000000000000000","x_state":{"token_state_p":"[\"coin_0000000000000000\"]","token_state_val":"0","token_height":0,"pre_txid":"null","private_key":"7UuXdeeqH3ug2YjgZ7VZRCz2Ujm4CmWVs4oZEz9CXcpC","public_key":"25EPKuHSTHR2mn93cNz2sRtiNyiXds88j7JtuXmmJDi5L","token":"coin_area12zFnNW9XR1R"},"y_state":{"token_state_p":"[]","token_state_val":"0","token_height":5,"private_key":"8egL8ivrhE3KkpW639f1fXv1Qb97psiudMqs5Kfb2WmL","public_key":"yizNoHddKNvchoikGRdrTaqeDJptUh9XvpnRiDfb85vz","token":"coin_0000000000000000"}}
可见多次fork出来的token-id均不一样,但是都带有area1前缀(coin_area1y79Ex4TMH4p、coin_area12zFnNW9XR1R),space参数会形成以该参数为前缀的随机token-id(16位英文+数字的ID)
【注】space用于生成带来命名前缀的token-id,这在编程中非常实用(形成了命名空间)。而dst_token参数用于生成目标token-id,当两个参数同时存在时,优先使用dst_token参数 。
我们回去看看G节点的数据管理,查看链数据如下图:
由此可见,一次fork创建帐户的交易纪录(txid),会在新创建的token-id纪录一行数据(首行数据必然为fork,并且仅能fork一次),同时也会在父节点帐户token_root纪录一次数据
点击了解云组件-数据结构-六度共识同步算法