[关闭]
@sqfasd 2016-08-27T03:55:16.000000Z 字数 7664 阅读 231

asch 前端接口整理

未分类


1 登录

post /api/accounts/open2/

根据密码生成publicKey

  1. var publicKey = AschJS.crypto.getKeys(secret).publicKey;
  2. var address = AschJS.crypto.getAddress(publicKey);

request

  1. {
  2. publicKey: "768f216d8ce119afc5c5181f9bed1ba81ef88241e322bbb882898aa766acdad3"
  3. }

response

  1. {
  2. "success": true,
  3. "account": {
  4. "address": "10174159498857769178",
  5. "unconfirmedBalance": 10000000000000000,
  6. "balance": 10000000000000000,
  7. "unconfirmedSignature": false,
  8. "secondSignature": false,
  9. "secondPublicKey": "",
  10. "multisignatures": [],
  11. "u_multisignatures": []
  12. },
  13. "latestBlock": {
  14. "height": 171,
  15. "timestamp": 804390
  16. },
  17. "version": {
  18. "version": "0.9.0",
  19. "build": "development"
  20. }
  21. }

2 查看同步信息

get /api/loader/status/sync

功能

返回后端同步状态

response

  1. {
  2. "success": true,
  3. "syncing": false, // 是否在同步中,如果为true,目前没有数据可以展示
  4. "blocks": 0,
  5. "height": 92403
  6. }

3 获取委托人信息

get /api/delegates/get/?publicKey=a28242b61ee3c0a71da60ea2e1fcd976bb7b3a48e65f5c2487a53707658fcc0b

response

4 获取账户信息

每10秒调用1次,用来刷新余额

get /api/accounts?address=4205898691220223329L

response

  1. {
  2. "success": true,
  3. "account": {
  4. "address": "4205898691220223329L",
  5. "unconfirmedBalance": "0",
  6. "balance": "0",
  7. "publicKey": "a28242b61ee3c0a71da60ea2e1fcd976bb7b3a48e65f5c2487a53707658fcc0b",
  8. "unconfirmedSignature": 0,
  9. "secondSignature": 0,
  10. "secondPublicKey": null,
  11. "multisignatures": [ ],
  12. "u_multisignatures": [ ]
  13. }
  14. "latestBlock": {
  15. "height": 171,
  16. "timestamp": 804390
  17. },
  18. "version": {
  19. "version": "0.9.0",
  20. "build": "development"
  21. }
  22. }

5 查询版本信息

get /api/peers/version

response

  1. {
  2. "success": true,
  3. "version": "0.3.1",
  4. "build": "v12:40:51 29/05/2016
  5. "
  6. }

6 获取我的交易

get /api/transactions?limit=8&orderBy=t_timestamp:desc&recipientId=2323236473289675612L&senderPublicKey=58d55f95d6383d526a150e69c767c9eb78b2dd6ebe55837cbb133319a3d7c5bc

response

  1. {
  2. "success": true,
  3. "transactions": [
  4. {
  5. "id": "10616007179419450740",
  6. "height": 20548,
  7. "blockId": "7174726601767749312",
  8. "type": 0,
  9. "timestamp": 239838,
  10. "senderPublicKey": "58d55f95d6383d526a150e69c767c9eb78b2dd6ebe55837cbb133319a3d7c5bc",
  11. "senderId": "2323236473289675612L",
  12. "recipientId": "3347762178747334519L",
  13. "amount": 549300000000, // 除以100000000
  14. "fee": 10000000,
  15. "signature": "bed865e8b593e9109bfa60b1a589043d536a93c46f8bb93b309392cea5d4d2c0aca95c50612d70885cfdad95c989802a84bbe9ff707c32170205527d19fa5b08",
  16. "signatures": null,
  17. "confirmations": 71996,
  18. "asset": { }
  19. }
  20. ],
  21. "count": "4"
  22. }

7 获取最新的区块

get /api/blocks/?limit=25&offset=0&orderBy=height:desc

response

  1. {
  2. "success": true,
  3. "count": 92712,
  4. "blocks": [
  5. {
  6. "id": "13692206355581061757",
  7. "version": 0,
  8. "timestamp": 1003680,
  9. "height": 92698,
  10. "previousBlock": "6044206022367095159",
  11. "numberOfTransactions": 0, // 交易数
  12. "totalAmount": 0, // 金额
  13. "totalFee": 0, // 手续费
  14. "reward": 0, // 奖励
  15. "payloadLength": 0,
  16. "payloadHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
  17. "generatorPublicKey": "c379455ea222666817e8b6d7673fb47f3594ab0516441efbcf93c0ab0d9ab15f",
  18. "generatorId": "3779220164400008665L",
  19. "blockSignature": "0004890452e44395613e9a2706d4900212b0ff16566c74a0542934a47ad7c40e896a3864a53682962bca42eb05ecd8865f58d0deadca16fa27c5006661d7ac02",
  20. "confirmations": 15,
  21. "totalForged": "0"
  22. }
  23. ]
  24. }

8. 查询一个区块的交易列表

get /api/transactions/?blockId=17268131061983930289

response

  1. {
  2. "success": true,
  3. "transactions": [
  4. {
  5. "id": "2716730522464841952",
  6. "height": 92898,
  7. "blockId": "17268131061983930289",
  8. "type": 0,
  9. "timestamp": 1005680,
  10. "senderPublicKey": "8bb89840b902ed812da1c6a7e732de152544ae9c1ac2e8cc291d97730fe8f3ef",
  11. "senderId": "5500617461256760551L",
  12. "recipientId": "13805841947687830643L",
  13. "amount": 4980000000,
  14. "fee": 10000000,
  15. "signature": "e52602799bf2c8234b09852c367ae3da478ba5055579bc9e3fe9d8165e95132b39d64fb70181c3a5bbb54d2025d1de0453a1f783f8dc3aba351c227b41e9d50a",
  16. "signatures": null,
  17. "confirmations": 1,
  18. "asset": { }
  19. }
  20. ],
  21. "count": "1"
  22. }

9. 获取入围受托人列表

get /api/delegates/?limit=101&offset=0&orderBy=rate:asc&address=17110047919889272525L

response

  1. {
  2. "success": true,
  3. "delegates": [
  4. {
  5. "username": "genesis_60",
  6. "address": "17110047919889272525L",
  7. "publicKey": "0186d6cbee0c9b1a9783e7202f57fc234b1d98197ada1cc29cfbdf697a636ef1",
  8. "vote": 9999989590000000,
  9. "producedblocks": 186,
  10. "missedblocks": 0,
  11. "rate": 1,
  12. "approval": "100.00",
  13. "productivity": "100.00",
  14. "voted": true
  15. }
  16. ],
  17. "totalCount": 102
  18. }

10. 获取我的投票列表

get /api/accounts/delegates/?address=11845914371838695861L

response

  1. {
  2. "success": true,
  3. "delegates": [
  4. {
  5. "username": "genesis_60",
  6. "address": "17110047919889272525L",
  7. "publicKey": "0186d6cbee0c9b1a9783e7202f57fc234b1d98197ada1cc29cfbdf697a636ef1",
  8. "vote": 9999989590000000,
  9. "producedblocks": 186,
  10. "missedblocks": 0,
  11. "rate": 1,
  12. "approval": "100.00",
  13. "productivity": "100.00"
  14. }
  15. ]
  16. }

11. 获取某个受托人锻造的区块列表

get /api/blocks/?generatorPublicKey=4fe5cd087a319956ddc05725651e56486961b7d5733ecd23e26e463bf9253bb5&limit=25&offset=0&orderBy=height:desc

response

  1. {
  2. "success": true,
  3. "blocks": [
  4. {
  5. "id": "7404786028080528531",
  6. "version": 0,
  7. "timestamp": 1881510,
  8. "height": 18549,
  9. "previousBlock": "4390936161708856388",
  10. "numberOfTransactions": 0,
  11. "totalAmount": 0,
  12. "totalFee": 0,
  13. "reward": 0,
  14. "payloadLength": 0,
  15. "payloadHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
  16. "generatorPublicKey": "4fe5cd087a319956ddc05725651e56486961b7d5733ecd23e26e463bf9253bb5",
  17. "generatorId": "15685993315437640088L",
  18. "blockSignature": "e61d789268fef92513e953d98a2a9aa18a1ccc79a3417ad7074ac72e1aa10906493879eb01a105848e191a47fa7718789ad529b62c90dfde0276a4ef6a171d08",
  19. "confirmations": "28",
  20. "totalForged": 0
  21. }
  22. ],
  23. "count": 185
  24. }

12. 获取某个受托人的信息

get /api/delegates/get/?publicKey=4fe5cd087a319956ddc05725651e56486961b7d5733ecd23e26e463bf9253bb5

response

  1. {
  2. "success": true,
  3. "delegate": {
  4. "username": "genesis_5",
  5. "address": "15685993315437640088L",
  6. "publicKey": "4fe5cd087a319956ddc05725651e56486961b7d5733ecd23e26e463bf9253bb5",
  7. "vote": 8949999780000000,
  8. "producedblocks": 185,
  9. "missedblocks": 0,
  10. "rate": 28,
  11. "approval": "89.50",
  12. "productivity": "100.00",
  13. "fees": 10,
  14. "rewards": 20,
  15. "forged": 30
  16. }
  17. }

13 交易

asch系统的所有写操作都是通过发起一个交易来完成的。
交易数据通过一个叫做asch-js的库来创建,然后再通过一个POST接口发布出去

POST接口规格如下:

  1. url: /peer/transactions
  2. 设置一个header, key为magic,value为43194d2b
  3. payload为asch-js创建出来的交易数据

库安装

  1. npm install asch-js

13.1 二级支付密码

  1. var asch = require('asch-js');
  2. var transaction = asch.signature.createSignature(password, secondPassword);
  3. POST(transaction);

13.2 转账

  1. var asch = require('asch-js');
  2. var targetAddress = "15685993315437640088L";
  3. var amount = 100;
  4. var password = 'first password';
  5. var secondPassword =user.secondPassword || undefined;
  6. // 其中password是在用户登录的时候记录下来的,secondPassword需要每次让用户输入
  7. // 可以通过user.secondPublicKey 来判断用户是否有二级密码,如果没有,则不必输入,以下几个交易类型类似
  8. var transaction = asch.transaction.createTransaction(targetAddress, amount, password, secondPassword);
  9. POST(transaction);

13.3 注册受托人

  1. var asch = require('asch-js');
  2. var transaction = asch.delegate.createDelegate(password, userName, user.secondPassword || undefined);
  3. POST(transaction);

13.4 投票 & 取消投票

  1. var asch = require('asch-js');
  2. // 投票内容是一个列表,列表中的每一个元素是一个符号加上所选择的受托人的公钥,符号为+表示投票,符号为-表示取消投票
  3. var voteContent = [
  4. '+4fe5cd087a319956ddc05725651e56486961b7d5733ecd23e26e463bf9253bb5',
  5. '-0186d6cbee0c9b1a9783e7202f57fc234b1d98197ada1cc29cfbdf697a636ef1'
  6. ];
  7. var transaction = asch.vote.createVote(password, voteContent, secondPassword || undefined);
  8. POST(transaction);

13.5 注册应用

  1. ...

14 获取谁投了我的票

get /api/delegates/voters/?publicKey=4fe5cd087a319956ddc05725651e56486961b7d5733ecd23e26e463bf9253bb5

response

  1. {
  2. "success": true,
  3. "accounts": [
  4. {
  5. "address": "18221003081100215902",
  6. "publicKey": "1418e0fdf902d42dfb40e41948bad2917ecd01f467b3b1cd2729a6ea93dd238e",
  7. "balance": 39700000000
  8. }
  9. ]
  10. }

15 获取节点列表

get /api/peers?limit=20&offset=0

response

  1. {
  2. "success": true,
  3. "peers": [
  4. {
  5. "ip": "45.32.19.241",
  6. "port": 4096,
  7. "state": 2,
  8. "os": "linux3.13.0-87-generic",
  9. "version": "0.9.1"
  10. }
  11. ]
  12. }

16 获取应用列表

get /api/dapps

  1. {
  2. "success": true,
  3. "dapps": [
  4. {
  5. "name": "Asch Dapp Hello World",
  6. "description": "hello world of asch dapp",
  7. "tags": "",
  8. "link": "https://github.com/sqfasd/hello.zip",
  9. "type": 0,
  10. "category": 1,
  11. "icon": "https://www.asch.so/logo.png",
  12. "transactionId": "4640739300565224189"
  13. }
  14. ]
  15. }

17 获取已安装应用列表

get /api/dapps/installed

  1. {
  2. "success": true,
  3. "dapps": [
  4. {
  5. "name": "Asch Dapp Hello World",
  6. "description": "hello world of asch dapp",
  7. "tags": "",
  8. "link": "https://github.com/sqfasd/hello.zip",
  9. "type": 0,
  10. "category": 1,
  11. "icon": "https://www.asch.so/logo.png",
  12. "transactionId": "4640739300565224189"
  13. }
  14. ]
  15. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注