在之前[更新了一下bitshares节点以及轻钱包](https://steemit.com/bitshares/@oflyhigh/7vyz83-bitshares)文章中,我们提到了除了修复了一些BUG以外,还增加了一些新功能,比如说新的API: ***`get_account_history_by_operations`***。但是光知道有新的API,不去用一下肯定是不行的,至少也要测试一下嘛。  # cli_wallet 中测试 首先cli_wallet连接到节点上 `./cli_wallet -w mywallet -s ws://127.0.0.1:8090` 其中: `-w mywallet` 指定钱包文件 `-s ws://127.0.0.1:8090` 指定rpc节点 首次连接钱包会提示设置密码: >`Please use the set_password method to initialize a new wallet before continuing` `set_password passwd` 在提示符后边输入上述指令,设置密码(请使用复杂密码,上述示例仅供参考) 输入`help`可以查看指令列表。 其中***`get_account_history_by_operations`***说明如下: > `account_history_operation_detail get_account_history_by_operations(string name, vector<uint16_t> operation_types, uint32_t start, int limit)` 按照这个说明,我们的指令应该是这个样子: `get_account_history_by_operations oflyhigh [] 1 10` 可惜返回如下内容:  我想了一下,可能和我节点***`account_history插件`***只开通两天有关,也就是两天之前的操作都找不到。 随便去bts浏览器那找了或比较活跃的账户,比如这个demo.btsbots  我们也可以指定操作类型列表来只提取我们感兴趣的操作类型  # curl 直接访问RPC节点 钱包操作,相当于钱包程序直接帮你封装了对RPC节点的访问,那么我们是否可以直接访问RPC节点呢?答案是可以的。 在使用之前,我们依旧首先看看它是如何被定义的  >`history_operation_detail history_api::get_account_history_by_operations(account_id_type account, vector<uint16_t> operation_types, uint32_t start, unsigned limit)` 和钱包中定义比较相似,但是需要注意的是***第一个参数是account_id_type而不是用户名***,我传入用户名一直出错。 还是用上边的用户作为例子,我们首先用公众号获取***用户id***  我们组合成下列CURL调用: `curl --data '{"jsonrpc": "2.0", "method": "call", "params": ["history", "get_account_history_by_operations", ["1.2.36449", [], 1, 10]], "id": 1}' http://127.0.0.1:8090/rpc`  然而这是什么鬼?为什么没有数据呢? 仔细研究了一下钱包实现,原来这个***`uint32_t start`***参数也大有说道,这玩意不是我想象的从1开始,而是需要知道具体的id,那么咋知道呢?这就略复杂了 #### 用户统计数据对象 首先要找到用户统计数据对象,我们知道了用户ID,可以用***`get_accounts`***或者***`get_objects`***获取。 比如: `curl --data '{"jsonrpc": "2.0", "method": "call", "params": ["database", "get_accounts", [["1.2.36449"]]], "id": 1}' http://127.0.0.1:8090/rpc` 其中统计对象为:  #### 读取统计对象 `curl --data '{"jsonrpc": "2.0", "method": "call", "params": ["database", "get_objects", [["2.6.36449"]]], "id": 1}' http://127.0.0.1:8090/rpc`  好了,这里边有一个`removed_ops`以及`total_ops` ***(注:和节点相关,不同节点上这个数值有所差异)*** 简单的来讲,已经`removed`的`ops`我们是读取不到的,我们只能读取`total_ops`与`removed_ops`之间的数据。 所以我们可以构造下列指令 `curl --data '{"jsonrpc": "2.0", "method": "call", "params": ["history", "get_account_history_by_operations", ["1.2.36449", [], 29650, 5]], "id": 1}' http://127.0.0.1:8090/rpc` 读取最近五条记录,返回结果有点多,并且没有返回txid  也就是说txid是cli_wallet中给生成的,看了一下代码,果然如此  # 结论 原本以为很简单的API,如果使用RPC节点访问,还真的很复杂呢。不过一番探索下来,也了解了不少东西。回头看看能不能做个简单的脚本来使用这个API。想必应该很好玩。 # 参考链接 * [更新了一下bitshares节点以及轻钱包](https://steemit.com/bitshares/@oflyhigh/7vyz83-bitshares) * https://github.com/bitshares/bitshares-core/releases/tag/2.0.180202 * https://github.com/bitshares/bitshares-core/pull/430
author | oflyhigh |
---|---|
permlink | bitshares-api-getaccounthistorybyoperations-cliwallet-and-rpc |
category | bitshares |
json_metadata | {"tags":["bitshares","api","rpc","cn-programming","cn"],"image":["https://steemitimages.com/DQmbetK9MHQbWok8gPBTMkvuJQe6meQP5rRKdXQbwgvCUc5/image.png","https://steemitimages.com/DQmdXuXZUy6oyxinAXQghvYDThDyL41ZSgC1DLzk1E4KcZB/image.png","https://steemitimages.com/DQmYLrNDSu2zmXttwNFd5jpRzFaryzKi4tVHiJyJM72PyWB/image.png","https://steemitimages.com/DQmPGKT7BYgtVyeku9c6TJcq5zc4mNZ46X5rmrphjw71gPQ/image.png","https://steemitimages.com/DQmXrcWE9fsAhDGX2unoGXbB2xNHFiUgmfo19PJUrGaD3jZ/image.png","https://steemitimages.com/DQmbGv195pe7kx4ZCSVjDGsKy1e9b99AYB2gmJGvzb2MkTB/image.png","https://steemitimages.com/DQmee9EdswRPbTkqzQbo2N8FdoMe4MTjrWijGyYeh4VAus2/image.png","https://steemitimages.com/DQmeUfkjhRqhWuRm8v6NsZ8iW54PsHRz4xmU5PDTa7yCC4T/image.png","https://steemitimages.com/DQmVkP1AN8iZumzk4knaQJ2ch5p8ACp1AkinQXLeXgp5weF/image.png","https://steemitimages.com/DQmaigjJrsWJpbkULFCL6paxzCaBDcoBuzDo7pbqnrFQFsj/image.png","https://steemitimages.com/DQmdNwSeQdinCodnE19SHS3KPo6xbyqs2B6RaKwdXD3FySP/image.png"],"links":["https://steemit.com/bitshares/@oflyhigh/7vyz83-bitshares","https://github.com/bitshares/bitshares-core/releases/tag/2.0.180202","https://github.com/bitshares/bitshares-core/pull/430"],"app":"steemit/0.1","format":"markdown"} |
created | 2018-02-04 14:47:12 |
last_update | 2018-02-04 14:47:12 |
depth | 0 |
children | 5 |
last_payout | 2018-02-11 14:47:12 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 126.761 HBD |
curator_payout_value | 20.627 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 3,696 |
author_reputation | 6,384,208,821,488,228 |
root_title | "测试了一下bitshares新API: get_account_history_by_operations (cli_wallet & rpc)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 34,905,074 |
net_rshares | 21,533,750,045,025 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
pharesim | 0 | 76,461,002,831 | 0.05% | ||
abit | 0 | 4,123,036,215,425 | 100% | ||
mark-waser | 0 | 98,780,880,596 | 100% | ||
spiry-btc | 0 | 575,491,655 | 25% | ||
slowwalker | 0 | 657,414,850,660 | 5% | ||
vi1son | 0 | 113,746,694,758 | 100% | ||
blockchainbilly | 0 | 18,891,110,710 | 50% | ||
deanliu | 0 | 1,257,593,553,188 | 100% | ||
joythewanderer | 0 | 203,738,925,035 | 40% | ||
ace108 | 0 | 253,645,332,117 | 25% | ||
tensaix2j | 0 | 2,665,729,827 | 100% | ||
laoyao | 0 | 33,390,750,978 | 100% | ||
somebody | 0 | 1,208,400,524,469 | 100% | ||
midnightoil | 0 | 13,669,420,779 | 100% | ||
btsabc | 0 | 4,718,256,671 | 100% | ||
xiaohui | 0 | 808,721,475,022 | 100% | ||
oflyhigh | 0 | 2,259,228,962,186 | 100% | ||
xiaokongcom | 0 | 9,869,369,829 | 100% | ||
archiles | 0 | 107,116,116 | 100% | ||
ericsim1991 | 0 | 105,618,246 | 100% | ||
yulan | 0 | 14,183,314,096 | 100% | ||
ericsim1989 | 0 | 104,900,624 | 100% | ||
rivalhw | 0 | 429,283,846,707 | 20% | ||
chinadaily | 0 | 154,643,489,745 | 100% | ||
helene | 0 | 453,802,573,634 | 100% | ||
ethansteem | 0 | 178,502,816,350 | 100% | ||
sweetsssj | 0 | 3,037,406,522,951 | 10% | ||
englishtchrivy | 0 | 24,667,779,082 | 6% | ||
davidjkelley | 0 | 5,087,490,792 | 100% | ||
digital-wisdom | 0 | 54,285,755,235 | 100% | ||
ethical-ai | 0 | 18,249,886,184 | 100% | ||
jwaser | 0 | 20,856,129,407 | 100% | ||
profitgenerator | 0 | 1,420,324,227 | 100% | ||
damarth | 0 | 279,717,599,657 | 3% | ||
bwaser | 0 | 4,766,049,870 | 100% | ||
ellepdub | 0 | 1,582,757,769 | 100% | ||
herpetologyguy | 0 | 250,657,034,248 | 100% | ||
morgan.waser | 0 | 10,668,009,413 | 100% | ||
handyman | 0 | 3,791,700,468 | 100% | ||
amylee | 0 | 96,389,118,008 | 100% | ||
mrtv2 | 0 | 54,907,344,531 | 100% | ||
strong-ai | 0 | 15,510,076,305 | 100% | ||
dylanhobalart | 0 | 2,110,927,272 | 9% | ||
steemtruth | 0 | 27,387,421,468 | 10% | ||
lalala | 0 | 38,126,277,262 | 100% | ||
dapeng | 0 | 43,528,538,210 | 25% | ||
devilwsy | 0 | 2,122,762,417 | 100% | ||
janiceting | 0 | 2,121,064,184 | 100% | ||
abraomarcos | 0 | 2,128,648,411 | 100% | ||
lydiachan | 0 | 36,361,775,962 | 100% | ||
technoprogressiv | 0 | 11,809,890,066 | 100% | ||
dragon40 | 0 | 2,222,841,643 | 10% | ||
jackhircus | 0 | 128,637,077,650 | 68% | ||
blackbunny | 0 | 52,925,048,694 | 100% | ||
da-dawn | 0 | 3,226,922,116 | 12% | ||
ripperone | 0 | 1,213,504,387,216 | 26% | ||
lingfei | 0 | 36,519,278,503 | 100% | ||
yyyy | 0 | 432,552,802 | 100% | ||
alexis555 | 0 | 1,757,695,619,500 | 26% | ||
prepstothepros | 0 | 147,723,146,708 | 18% | ||
trafalgar | 0 | 779,657,966,258 | 3% | ||
laodr | 0 | 167,176,888,380 | 100% | ||
austinsandersco | 0 | 780,364,216 | 70% | ||
kingofdew | 0 | 40,636,956,624 | 100% | ||
emcvay | 0 | 176,691,782 | 10% | ||
mandagoi | 0 | 9,649,850,804 | 21% | ||
ribalinux | 0 | 4,067,462,025 | 10% | ||
wylo | 0 | 610,853,733 | 100% | ||
susanlo | 0 | 46,701,896,234 | 100% | ||
jkkim | 0 | 98,080,256 | 10% | ||
ebejammin | 0 | 5,639,191,693 | 100% | ||
nanosesame | 0 | 25,382,056,518 | 30% | ||
revelim | 0 | 8,480,027,983 | 20% | ||
cryptohustler | 0 | 25,462,529,697 | 100% | ||
exec | 0 | 77,190,168,525 | 100% | ||
eval | 0 | 761,165,213 | 100% | ||
michaelwilshaw | 0 | 4,233,147,510 | 10% | ||
speeding | 0 | 3,654,139,847 | 100% | ||
walkinharmony | 0 | 18,920,498,759 | 50% | ||
asterix87 | 0 | 11,477,568,251 | 100% | ||
abetterworld | 0 | 3,152,995,416 | 100% | ||
raili | 0 | 8,160,102,243 | 100% | ||
that1consultant | 0 | 299,168,041 | 100% | ||
sanzo | 0 | 304,355,700 | 100% | ||
hope-on-fire | 0 | 3,251,541,615 | 100% | ||
steem-star | 0 | 458,755,697 | 100% | ||
davaowhenyo | 0 | 605,286,229 | 100% | ||
allenshayzar | 0 | 605,286,229 | 100% | ||
raku | 0 | 617,220,000 | 100% | ||
resteeming | 0 | 614,860,000 | 100% | ||
ravenousappetite | 0 | 605,285,888 | 100% | ||
aabb | 0 | 8,102,279,194 | 100% | ||
ety001 | 0 | 5,366,279,653 | 100% | ||
auntigormint | 0 | 576,117,084 | 100% | ||
mrliga | 0 | 16,436,308,543 | 100% | ||
imbritish | 0 | 190,878,623 | 38% | ||
twinkledrop | 0 | 158,214,255,668 | 100% | ||
sweethoney | 0 | 118,913,378 | 100% | ||
liangfengyouren | 0 | 1,262,230,700 | 50% | ||
duekie | 0 | 273,568,379 | 100% | ||
idx | 0 | 21,652,628,436 | 100% | ||
chaofanjun | 0 | 10,231,683,441 | 100% | ||
exprmnt | 0 | 614,860,000 | 100% | ||
lancy | 0 | 4,957,215,490 | 92% | ||
bearpaw | 0 | 2,452,644,117 | 100% | ||
ericsim | 0 | 264,236,627 | 100% | ||
freedom-fighter | 0 | 611,431,266 | 100% | ||
technologynepal | 0 | 617,220,000 | 100% | ||
rosatravels | 0 | 23,252,125,889 | 20% | ||
veronicazhu | 0 | 1,796,656,761 | 100% | ||
dgorbunov | 0 | 568,019,798 | 100% | ||
tiffanyrej | 0 | 3,268,440,833 | 100% | ||
khalilad | 0 | 615,320,000 | 100% | ||
ms8988 | 0 | 609,169,649 | 100% | ||
felixkwt | 0 | 608,042,471 | 100% | ||
stakuza | 0 | 615,483,841 | 100% | ||
wangwenjing | 0 | 1,118,865,947 | 10% | ||
ikonik | 0 | 466,812,060 | 100% | ||
zenactivity | 0 | 498,931,738 | 100% | ||
vfxness | 0 | 3,758,219,175 | 100% | ||
lemminon | 0 | 615,320,000 | 100% | ||
heyeshuang | 0 | 640,150,970 | 100% | ||
peterschilder | 0 | 8,963,406,863 | 70% | ||
fastiduos | 0 | 615,320,000 | 100% | ||
ivysrono | 0 | 40,824,347,537 | 100% | ||
weavingwords | 0 | 57,632,301,887 | 100% | ||
nitro.live | 0 | 17,398,185,786 | 100% | ||
chaerin | 0 | 612,767,658 | 100% | ||
muzakirpb | 0 | 102,052,561 | 9% | ||
cnbuddy | 0 | 3,931,213,495 | 0.53% | ||
deanyeong | 0 | 1,806,628,038 | 80% | ||
chann | 0 | 3,357,432,723 | 10% | ||
lebin | 0 | 32,235,836,040 | 50% | ||
embutv | 0 | 3,550,493,173 | 100% | ||
saury | 0 | 259,305,253 | 100% | ||
candiru | 0 | 339,997,350 | 100% | ||
ipman62 | 0 | 64,612,900 | 100% | ||
serenawu | 0 | 52,580,624,230 | 100% | ||
sterineye | 0 | 617,121,285 | 100% | ||
patrickzhou | 0 | 14,436,541,875 | 100% | ||
growingpower | 0 | 1,324,481,791 | 75% | ||
neexal | 0 | 82,633,815 | 100% | ||
wyp | 0 | 567,825,683 | 100% | ||
wangyc | 0 | 251,607,465 | 100% | ||
fun2learn | 0 | 2,622,582,792 | 35% | ||
amfy | 0 | 320,625,494 | 100% | ||
calist | 0 | 116,687,059 | 100% | ||
mehdielattar2012 | 0 | 534,224,598 | 100% | ||
hamdani-ishak | 0 | 484,992,749 | 100% | ||
madein | 0 | 61,569,036 | 25% | ||
luisanapjp | 0 | 92,187,288 | 100% | ||
wickedgoose | 0 | 131,371,950 | 100% | ||
popmusic | 0 | 602,530,255 | 100% | ||
bxl9426 | 0 | 602,159,130 | 100% | ||
bitpizza | 0 | 614,472,186 | 100% | ||
sannyputra | 0 | 384,044,509 | 100% | ||
abdulmanna | 0 | 104,522,662 | 100% | ||
satoshiroller | 0 | 61,733,500 | 20% | ||
cryptoknight27 | 0 | 614,462,771 | 100% | ||
riazmirwani | 0 | 534,582,594 | 100% | ||
shogunms | 0 | 614,461,622 | 100% | ||
randomeno | 0 | 61,445,840 | 100% | ||
python-think | 0 | 0 | 100% |
it is good article. thanks for share us.
author | afrin12 |
---|---|
permlink | re-oflyhigh-bitshares-api-getaccounthistorybyoperations-cliwallet-and-rpc-20180204t145204853z |
category | bitshares |
json_metadata | {"tags":["bitshares"],"app":"steemit/0.1"} |
created | 2018-02-04 14:52:15 |
last_update | 2018-02-04 14:52:15 |
depth | 1 |
children | 0 |
last_payout | 2018-02-11 14:52:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 40 |
author_reputation | 67,981,012,465 |
root_title | "测试了一下bitshares新API: get_account_history_by_operations (cli_wallet & rpc)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 34,906,105 |
net_rshares | 0 |
o.O
author | aftabkhan10 |
---|---|
permlink | re-oflyhigh-bitshares-api-getaccounthistorybyoperations-cliwallet-and-rpc-20180204t151739286z |
category | bitshares |
json_metadata | {"tags":["bitshares"],"app":"steemit/0.1"} |
created | 2018-02-04 15:17:39 |
last_update | 2018-02-04 15:17:39 |
depth | 1 |
children | 0 |
last_payout | 2018-02-11 15:17:39 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 3 |
author_reputation | 67,607,529,862,002 |
root_title | "测试了一下bitshares新API: get_account_history_by_operations (cli_wallet & rpc)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 34,911,139 |
net_rshares | 0 |
demo.btsbots 也是个大神,他的机器人至今还没有修好😂
author | ety001 |
---|---|
permlink | re-oflyhigh-bitshares-api-getaccounthistorybyoperations-cliwallet-and-rpc-20180205t123059431z |
category | bitshares |
json_metadata | {"tags":["bitshares"],"app":"steemit/0.1"} |
created | 2018-02-05 12:31:00 |
last_update | 2018-02-05 12:31:00 |
depth | 1 |
children | 0 |
last_payout | 2018-02-12 12:31:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 32 |
author_reputation | 57,395,188,397,494 |
root_title | "测试了一下bitshares新API: get_account_history_by_operations (cli_wallet & rpc)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 35,135,380 |
net_rshares | 0 |
author | moyse |
---|---|
permlink | re-oflyhigh-bitshares-api-getaccounthistorybyoperations-cliwallet-and-rpc-20180204t145457722z |
category | bitshares |
json_metadata | {"tags":["bitshares"],"app":"steemit/0.1"} |
created | 2018-02-04 14:55:00 |
last_update | 2018-02-04 14:55:00 |
depth | 1 |
children | 0 |
last_payout | 2018-02-11 14:55:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 31 |
author_reputation | 5,860,270,290,556 |
root_title | "测试了一下bitshares新API: get_account_history_by_operations (cli_wallet & rpc)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 34,906,661 |
net_rshares | 520,223,724 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
moyse | 0 | 310,416,693 | 100% | ||
spike2016 | 0 | 209,807,031 | 100% |
very nice post i like ur post awesome
author | sagorkhan |
---|---|
permlink | re-oflyhigh-bitshares-api-getaccounthistorybyoperations-cliwallet-and-rpc-20180204t173929631z |
category | bitshares |
json_metadata | {"tags":["bitshares"],"app":"steemit/0.1"} |
created | 2018-02-04 17:39:33 |
last_update | 2018-02-04 17:39:33 |
depth | 1 |
children | 0 |
last_payout | 2018-02-11 17:39:33 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 37 |
author_reputation | 1,245,938,181,729 |
root_title | "测试了一下bitshares新API: get_account_history_by_operations (cli_wallet & rpc)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 34,940,045 |
net_rshares | 0 |