@sqfasd
2016-08-27T11:55:16.000000Z
字数 7664
阅读 1431
未分类
post /api/accounts/open2/
var publicKey = AschJS.crypto.getKeys(secret).publicKey;
var address = AschJS.crypto.getAddress(publicKey);
{
publicKey: "768f216d8ce119afc5c5181f9bed1ba81ef88241e322bbb882898aa766acdad3"
}
{
"success": true,
"account": {
"address": "10174159498857769178",
"unconfirmedBalance": 10000000000000000,
"balance": 10000000000000000,
"unconfirmedSignature": false,
"secondSignature": false,
"secondPublicKey": "",
"multisignatures": [],
"u_multisignatures": []
},
"latestBlock": {
"height": 171,
"timestamp": 804390
},
"version": {
"version": "0.9.0",
"build": "development"
}
}
get /api/loader/status/sync
返回后端同步状态
{
"success": true,
"syncing": false, // 是否在同步中,如果为true,目前没有数据可以展示
"blocks": 0,
"height": 92403
}
get /api/delegates/get/?publicKey=a28242b61ee3c0a71da60ea2e1fcd976bb7b3a48e65f5c2487a53707658fcc0b
每10秒调用1次,用来刷新余额
get /api/accounts?address=4205898691220223329L
{
"success": true,
"account": {
"address": "4205898691220223329L",
"unconfirmedBalance": "0",
"balance": "0",
"publicKey": "a28242b61ee3c0a71da60ea2e1fcd976bb7b3a48e65f5c2487a53707658fcc0b",
"unconfirmedSignature": 0,
"secondSignature": 0,
"secondPublicKey": null,
"multisignatures": [ ],
"u_multisignatures": [ ]
}
"latestBlock": {
"height": 171,
"timestamp": 804390
},
"version": {
"version": "0.9.0",
"build": "development"
}
}
get /api/peers/version
{
"success": true,
"version": "0.3.1",
"build": "v12:40:51 29/05/2016
"
}
get /api/transactions?limit=8&orderBy=t_timestamp:desc&recipientId=2323236473289675612L&senderPublicKey=58d55f95d6383d526a150e69c767c9eb78b2dd6ebe55837cbb133319a3d7c5bc
{
"success": true,
"transactions": [
{
"id": "10616007179419450740",
"height": 20548,
"blockId": "7174726601767749312",
"type": 0,
"timestamp": 239838,
"senderPublicKey": "58d55f95d6383d526a150e69c767c9eb78b2dd6ebe55837cbb133319a3d7c5bc",
"senderId": "2323236473289675612L",
"recipientId": "3347762178747334519L",
"amount": 549300000000, // 除以100000000
"fee": 10000000,
"signature": "bed865e8b593e9109bfa60b1a589043d536a93c46f8bb93b309392cea5d4d2c0aca95c50612d70885cfdad95c989802a84bbe9ff707c32170205527d19fa5b08",
"signatures": null,
"confirmations": 71996,
"asset": { }
}
],
"count": "4"
}
get /api/blocks/?limit=25&offset=0&orderBy=height:desc
{
"success": true,
"count": 92712,
"blocks": [
{
"id": "13692206355581061757",
"version": 0,
"timestamp": 1003680,
"height": 92698,
"previousBlock": "6044206022367095159",
"numberOfTransactions": 0, // 交易数
"totalAmount": 0, // 金额
"totalFee": 0, // 手续费
"reward": 0, // 奖励
"payloadLength": 0,
"payloadHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"generatorPublicKey": "c379455ea222666817e8b6d7673fb47f3594ab0516441efbcf93c0ab0d9ab15f",
"generatorId": "3779220164400008665L",
"blockSignature": "0004890452e44395613e9a2706d4900212b0ff16566c74a0542934a47ad7c40e896a3864a53682962bca42eb05ecd8865f58d0deadca16fa27c5006661d7ac02",
"confirmations": 15,
"totalForged": "0"
}
]
}
get /api/transactions/?blockId=17268131061983930289
{
"success": true,
"transactions": [
{
"id": "2716730522464841952",
"height": 92898,
"blockId": "17268131061983930289",
"type": 0,
"timestamp": 1005680,
"senderPublicKey": "8bb89840b902ed812da1c6a7e732de152544ae9c1ac2e8cc291d97730fe8f3ef",
"senderId": "5500617461256760551L",
"recipientId": "13805841947687830643L",
"amount": 4980000000,
"fee": 10000000,
"signature": "e52602799bf2c8234b09852c367ae3da478ba5055579bc9e3fe9d8165e95132b39d64fb70181c3a5bbb54d2025d1de0453a1f783f8dc3aba351c227b41e9d50a",
"signatures": null,
"confirmations": 1,
"asset": { }
}
],
"count": "1"
}
get /api/delegates/?limit=101&offset=0&orderBy=rate:asc&address=17110047919889272525L
{
"success": true,
"delegates": [
{
"username": "genesis_60",
"address": "17110047919889272525L",
"publicKey": "0186d6cbee0c9b1a9783e7202f57fc234b1d98197ada1cc29cfbdf697a636ef1",
"vote": 9999989590000000,
"producedblocks": 186,
"missedblocks": 0,
"rate": 1,
"approval": "100.00",
"productivity": "100.00",
"voted": true
}
],
"totalCount": 102
}
get /api/accounts/delegates/?address=11845914371838695861L
{
"success": true,
"delegates": [
{
"username": "genesis_60",
"address": "17110047919889272525L",
"publicKey": "0186d6cbee0c9b1a9783e7202f57fc234b1d98197ada1cc29cfbdf697a636ef1",
"vote": 9999989590000000,
"producedblocks": 186,
"missedblocks": 0,
"rate": 1,
"approval": "100.00",
"productivity": "100.00"
}
]
}
get /api/blocks/?generatorPublicKey=4fe5cd087a319956ddc05725651e56486961b7d5733ecd23e26e463bf9253bb5&limit=25&offset=0&orderBy=height:desc
{
"success": true,
"blocks": [
{
"id": "7404786028080528531",
"version": 0,
"timestamp": 1881510,
"height": 18549,
"previousBlock": "4390936161708856388",
"numberOfTransactions": 0,
"totalAmount": 0,
"totalFee": 0,
"reward": 0,
"payloadLength": 0,
"payloadHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"generatorPublicKey": "4fe5cd087a319956ddc05725651e56486961b7d5733ecd23e26e463bf9253bb5",
"generatorId": "15685993315437640088L",
"blockSignature": "e61d789268fef92513e953d98a2a9aa18a1ccc79a3417ad7074ac72e1aa10906493879eb01a105848e191a47fa7718789ad529b62c90dfde0276a4ef6a171d08",
"confirmations": "28",
"totalForged": 0
}
],
"count": 185
}
get /api/delegates/get/?publicKey=4fe5cd087a319956ddc05725651e56486961b7d5733ecd23e26e463bf9253bb5
{
"success": true,
"delegate": {
"username": "genesis_5",
"address": "15685993315437640088L",
"publicKey": "4fe5cd087a319956ddc05725651e56486961b7d5733ecd23e26e463bf9253bb5",
"vote": 8949999780000000,
"producedblocks": 185,
"missedblocks": 0,
"rate": 28,
"approval": "89.50",
"productivity": "100.00",
"fees": 10,
"rewards": 20,
"forged": 30
}
}
asch系统的所有写操作都是通过发起一个交易来完成的。
交易数据通过一个叫做asch-js的库来创建,然后再通过一个POST接口发布出去
POST接口规格如下:
/peer/transactions
库安装
npm install asch-js
var asch = require('asch-js');
var transaction = asch.signature.createSignature(password, secondPassword);
POST(transaction);
var asch = require('asch-js');
var targetAddress = "15685993315437640088L";
var amount = 100;
var password = 'first password';
var secondPassword =user.secondPassword || undefined;
// 其中password是在用户登录的时候记录下来的,secondPassword需要每次让用户输入
// 可以通过user.secondPublicKey 来判断用户是否有二级密码,如果没有,则不必输入,以下几个交易类型类似
var transaction = asch.transaction.createTransaction(targetAddress, amount, password, secondPassword);
POST(transaction);
var asch = require('asch-js');
var transaction = asch.delegate.createDelegate(password, userName, user.secondPassword || undefined);
POST(transaction);
var asch = require('asch-js');
// 投票内容是一个列表,列表中的每一个元素是一个符号加上所选择的受托人的公钥,符号为+表示投票,符号为-表示取消投票
var voteContent = [
'+4fe5cd087a319956ddc05725651e56486961b7d5733ecd23e26e463bf9253bb5',
'-0186d6cbee0c9b1a9783e7202f57fc234b1d98197ada1cc29cfbdf697a636ef1'
];
var transaction = asch.vote.createVote(password, voteContent, secondPassword || undefined);
POST(transaction);
...
get /api/delegates/voters/?publicKey=4fe5cd087a319956ddc05725651e56486961b7d5733ecd23e26e463bf9253bb5
{
"success": true,
"accounts": [
{
"address": "18221003081100215902",
"publicKey": "1418e0fdf902d42dfb40e41948bad2917ecd01f467b3b1cd2729a6ea93dd238e",
"balance": 39700000000
}
]
}
get /api/peers?limit=20&offset=0
{
"success": true,
"peers": [
{
"ip": "45.32.19.241",
"port": 4096,
"state": 2,
"os": "linux3.13.0-87-generic",
"version": "0.9.1"
}
]
}
get /api/dapps
{
"success": true,
"dapps": [
{
"name": "Asch Dapp Hello World",
"description": "hello world of asch dapp",
"tags": "",
"link": "https://github.com/sqfasd/hello.zip",
"type": 0,
"category": 1,
"icon": "https://www.asch.so/logo.png",
"transactionId": "4640739300565224189"
}
]
}
get /api/dapps/installed
{
"success": true,
"dapps": [
{
"name": "Asch Dapp Hello World",
"description": "hello world of asch dapp",
"tags": "",
"link": "https://github.com/sqfasd/hello.zip",
"type": 0,
"category": 1,
"icon": "https://www.asch.so/logo.png",
"transactionId": "4640739300565224189"
}
]
}