钱包API接入文档说明
参考钱包版本: Wallet0.4.40
钱包账户信息文档文档: 钱包账户信息、签名、配置文件说明
主网的钱包服务地址: 39.107.247.86:13659
测试网的钱包服务地址: 47.93.196.236:13659
业务发送说明:发送交易数据可以采用同步或异步方式,同步方式可以获取因为格式等造成的错误信息;异步为async,同步为 block
一 首页模块
1 lamb余额的数量
账户信息接口 /auth/accounts/${address}
例如 http://47.93.196.236:13659/auth/accounts/lambda1v664znyhztfx3m0v0uua497r5cptg3rd2ytnm8查找coins 中denom 为 ulamb 即可
{
"type": "auth/Account",
"value": {
"address": "lambda1v664znyhztfx3m0v0uua497r5cptg3rd2ytnm8",
"coins": [{
"denom": "ubtc",
"amount": "1000000"
}, {
"denom": "ulamb",
"amount": "3000000"
}],
"public_key": null,
"account_number": "502",
"sequence": "0"
}
}
2 质押tbb的数量
查询个人质押信息的接口 `/staking/delegators/${addr}/delegations`
[
{
"delegator_address": "lambda1thj5fv8d0dsh3aealhpxm9mvgxjfh87s224esr",
"validator_address": "lambdavaloper1thj5fv8d0dsh3aealhpxm9mvgxjfh87suwuj2h",
"shares": "767676003.820176389957445490"
}
]
这里需要注意shares 表示质押量占的份数,如果要换算为质押量TBB,需要进行计算
shares*(tokens/delegator_shares)
节点的信息中包含delegator_shares 和 tokens
通过节点列表接口可以获取到这两个值 这里在计算的时候建议使用bignumber,
读取节点列表
/staking/validators?status=unbonding //禁闭中
/staking/validators?status=bonded //质押中
/staking/validators?status=unbonded //未解禁
unbonding是反质押中,或被禁闭中 unbonded是反质押完成 或 被禁的节点过了21天还没解禁
[
{
"operator_address": "lambdavaloper1prrcl9674j4aqrgrzmys5e28lkcxmntxuvjpcl",
"consensus_pubkey": "lambdavalconspub1zcjduepqp7ccjeshlpslrzjj75je5kn6dhtq8l5nnl6h5jtavgsf5tyekfsqe4mnh9",
"jailed": false,
"status": 2,
"tokens": "2680066666",
"delegator_shares": "2680066666.000000000000000000",
"description": {
"moniker": "cv-moniker-2",
"identity": "",
"website": "",
"details": ""
},
"unbonding_height": "0",
"unbonding_time": "1970-01-01T00:00:00Z",
"commission": {
"rate": "0.250000000000000000",
"max_rate": "0.250000000000000000",
"max_change_rate": "0.010000000000000000",
"update_time": "2019-12-25T16:56:40.666534478Z"
},
"min_self_delegation": "666666666"
},
]
3 质押tbb获得奖励的数量
1 获取用户的质押列表接口
`/staking/delegators/${addr}/delegations`
2 一个节点下质押获取的奖励的数量接口
`/distribution/delegators/${delegatorAddr}/rewards/${validatorAddr}`
[
{
"denom": "ulamb",
"amount": "3514296927.123515563816500000"
}
]
这里需要注意传入地址的格式 ${delegatorAddr} 为用户的lamb地址
${validatorAddr} 为验证节点的操作地址 操作地址的前缀为 lambdavaloper
地址之间转换 见钱包账户信息、签名、配置文件说明
4 节点收益的数量
获取节点收益的接口
`/distribution/validators/${validatorAddr}`
{
"operator_address": "lambda1prrcl9674j4aqrgrzmys5e28lkcxmntx2gm2zt",
"self_bond_rewards": [{ //自己质押的收益
"denom": "ulamb",
"amount": "1318824629026.957070122504282575"
}],
"val_commission": [{ //收取矿工的佣金
"denom": "ulamb",
"amount": "827774754064.482428092893265856"
}]
}
目前钱包里节点收益 的取值为val_commission 的属性
5 存储挖矿收益的数量
获取存储挖矿的收益 接口
`/distribution/miners/${MinerAddress}`
这里的${MinerAddress} 为矿工操作格式的地址 地址之间转换 见钱包账户信息、签名、配置文件说明
6 获取最新交易列表、交易详情
/txs?sender=${addr}&page=1000000 获取最新发送的交易
/txs?recipient=${addr}&page=1000000 获取最新接受的交易
根据交易哈希获取交易详情
`/txs/${hash}`
7 获取用户资产列表
1 获取用户有哪些资产
/auth/accounts/${address}
{
"type": "auth/Account",
"value": {
"address": "lambda1v664znyhztfx3m0v0uua497r5cptg3rd2ytnm8",
"coins": [{
"denom": "ubtc",
"amount": "1000000"
}, {
"denom": "ulamb",
"amount": "3000000"
}],
"public_key": null,
"account_number": "502",
"sequence": "0"
}
}
2 获取区块链上资产的列表
/asset/all
[
{
"address": "lambda1a83p8s9gs5hua09xn5ktmahepst3vzg92wkp4e",
"asset": {
"denom": "ubtc", //资产名称
"amount": "90000000000000000"
},
"Token": {
"denom": "ulamb",
"amount": "1000000000000"
},
"name": "BTC Coin",
"mintable": true,
"curr_supply": {
"denom": "ubtc",
"amount": "90000000000000000"
},
"lock_supply": {
"denom": "ubtc",
"amount": "0"
}
},
{
"address": "lambda1a83p8s9gs5hua09xn5ktmahepst3vzg92wkp4e",
"asset": {
"denom": "uhpt",
"amount": "90000000000000000"
},
"Token": {
"denom": "ulamb",
"amount": "1000000000000"
},
"name": "HPT Coin",
"mintable": true,
"curr_supply": {
"denom": "uhpt",
"amount": "90000000000000000"
},
"lock_supply": {
"denom": "uhpt",
"amount": "0"
}
}
]
8 发起交易lamb和获取gas
① 模拟交易获取gas
模拟接口获取gas
/bank/accounts/${senderAddress}/transfers
类型 post
发送数据类型 json
钱包里面默认的gas的价格为 2.5e-6 交易的费用为 gas*gas的价格
【转账交易的例子 post 的内容】
{
"base_req": {
"sequence": "208",
"from": "lambda163q4m634nq8les4nuvdvz49tk6ae**********",
"account_number": "6",
"chain_id": "lambda-chain-test4.0",
"simulate": true,
"memo": ""
},
"amount": [{
"amount": "1000000",
"denom": "ulamb"
}],
"from_address": "lambda163q4m634nq8les4nuvdvz49tk6ae**********",
"to_address": "lambda16cheh6j34ncyunwgfkq2940cs8222jka0fsp4k"
}
返回结果
{"gas_estimate":"28077"}
② 数据签名
用于进行签名的数据结构
{
"account_number": "1", //通过用户信息获取
"chain_id": "lambda-chain-test2.5", //链的版本号 通过最新的区块信息获取
"fee": {//手续费
"amount": [{
"amount": "101745",
"denom": "ulamb"
}],
"gas": "40698" //gas
},
"memo": "", //备注
"msgs": [{
"type": "cosmos-sdk/MsgSend", //交易类型
"value": {
"amount": [{
"amount": "1000000", //交易的数量
"denom": "ulamb" //交易的代币类型
}],
"from_address": "lambda1prrcl9674j4aqrgrzmys5e28lkcxmntx2gm2zt", //发送地址
"to_address": "lambda1hynqrp2f80jqs86gu8nd5wwcnek2wwd3esszg0" //接受地址
}
}],
"sequence": "125" //通过获取用户信息接口获取
}
每次发起交易前,均要通过账户信息接口获取最新的sequence
chain_id 可以通过 节点信息接口 /node_info
获取
③ 发送数据
{
"tx": {
"msg": [{
"type": "cosmos-sdk/MsgSend",
"value": {
"amount": [{
"amount": "1000000",
"denom": "ulamb"
}],
"from_address": "lambda1prrcl9674j4aqrgrzmys5e28lkcxmntx2gm2zt",
"to_address": "lambda1hynqrp2f80jqs86gu8nd5wwcnek2wwd3esszg0"
}
}],
"fee": {
"amount": [{
"amount": "101745",
"denom": "ulamb"
}],
"gas": "40698"
},
"signatures": [{
"signature": //签名的结果
"fa9bUlNRA3qa9PEYR2py6CgpQbbqVsuKhJRowMdlf90byj7M/2B1YQsu6EPAk1V/tLkKiNwEadkAKNFUxZngGA==",
"pub_key": {
"type": "tendermint/PubKeySecp256k1",
"value": "AjmQ01Z+IoHuKLdPaFzV6IJQB88ahW2qv2rEw2H4B5dq" //公钥
}
}],
"memo": ""
},
"mode": "async" 发送交易的方式async 为异步,block 为同步
}
9 提取质押TBB的奖励
提取奖励:提取奖励不需要传入数值,只需要传入 节点操作地址和质押人地址即可
发送交易的接口:同交易接口
签名的数据结构
{
"account_number": "1",
"chain_id": "lambda-chain-test2.5",
"fee": {
"amount": [{
"amount": "635848",
"denom": "ulamb"
}],
"gas": "254339"
},
"memo": "",
"msgs": [{
"type": "cosmos-sdk/MsgWithdrawDelegationReward",
"value": {
"delegator_address": "lambda1prrcl9674j4aqrgrzmys5e28lkcxmntx2gm2zt", //质押人地址
"validator_address": "lambdavaloper1prrcl9674j4aqrgrzmys5e28lkcxmntxuvjpcl" //节点地址
}
}, {
"type": "cosmos-sdk/MsgWithdrawDelegationReward",
"value": {
"delegator_address": "lambda1prrcl9674j4aqrgrzmys5e28lkcxmntx2gm2zt",
"validator_address": "lambdavaloper1r340rrv9fs95gqy5087e2mtz82vvwrglt6amx3"
}
}, {
"type": "cosmos-sdk/MsgWithdrawDelegationReward",
"value": {
"delegator_address": "lambda1prrcl9674j4aqrgrzmys5e28lkcxmntx2gm2zt",
"validator_address": "lambdavaloper1thj5fv8d0dsh3aealhpxm9mvgxjfh87suwuj2h"
}
}],
"sequence": "127"
}
发送交易的数据结构
{
"tx": {
"msg": [{
"type": "cosmos-sdk/MsgWithdrawDelegationReward",
"value": {
"delegator_address": "lambda1prrcl9674j4aqrgrzmys5e28lkcxmntx2gm2zt",
"validator_address": "lambdavaloper1prrcl9674j4aqrgrzmys5e28lkcxmntxuvjpcl"
}
}, {
"type": "cosmos-sdk/MsgWithdrawDelegationReward",
"value": {
"delegator_address": "lambda1prrcl9674j4aqrgrzmys5e28lkcxmntx2gm2zt",
"validator_address": "lambdavaloper1r340rrv9fs95gqy5087e2mtz82vvwrglt6amx3"
}
}, {
"type": "cosmos-sdk/MsgWithdrawDelegationReward",
"value": {
"delegator_address": "lambda1prrcl9674j4aqrgrzmys5e28lkcxmntx2gm2zt",
"validator_address": "lambdavaloper1thj5fv8d0dsh3aealhpxm9mvgxjfh87suwuj2h"
}
}],
"fee": {
"amount": [{
"amount": "635848",
"denom": "ulamb"
}],
"gas": "254339"
},
"signatures": [{
"signature": "CNxU2hyIL1Az8Mb+Btt3APP1f476Q+Z/bTzmpsTQV2l3Od5TLfTlgS4hJkhLsCHlzXbCCJlhDz9d2OK3IvupCQ==",
"pub_key": {
"type": "tendermint/PubKeySecp256k1",
"value": "AjmQ01Z+IoHuKLdPaFzV6IJQB88ahW2qv2rEw2H4B5dq"
}
}],
"memo": ""
},
"mode": "async"
}
10 提取节点收益
签名数据格式
{
"account_number": "1",
"chain_id": "lambda-chain-test2.5",
"fee": {
"amount": [{
"amount": "636128",
"denom": "ulamb"
}],
"gas": "254451"
},
"memo": "",
"msgs": [{
"type": "cosmos-sdk/MsgWithdrawValidatorCommission",
"value": {
"validator_address": "lambdavaloper1prrcl9674j4aqrgrzmys5e28lkcxmntxuvjpcl" //节点的操作地址
}
}],
"sequence": "128"
}
发送数据格式
{
"tx": {
"msg": [{
"type": "cosmos-sdk/MsgWithdrawValidatorCommission",
"value": {
"validator_address": "lambdavaloper1prrcl9674j4aqrgrzmys5e28lkcxmntxuvjpcl"
}
}],
"fee": {
"amount": [{
"amount": "636128",
"denom": "ulamb"
}],
"gas": "254451"
},
"signatures": [{
"signature": "iCa63qOUVNsxIsynOuPtrZRtqWYz5IWGz62