每天进步一点点:如何获取HIVE区块中的virtual operation
hive-105017·@oflyhigh·
0.000 HBD每天进步一点点:如何获取HIVE区块中的virtual operation
在HIVE区块链上有很多操作,比如说发帖、点赞、转账、投票见证人、设置见证人代理等,除了这些操作外,还有一类操作不是由我们发起,而是由区块链根据共识而产生,比如说见证人奖励、作者/策展奖励发放等等,这类操作被称为:virtual operation/虚拟操作。  (图源 :[pixabay](https://pixabay.com/)) 在https://hiveblocks.com/ 查看区块信息时,我们会看到transactions 以及virtual ops,比如以我生产的区块[55853428](https://hiveblocks.com/b/55853428)为例,我们会看到: >31 transactions in this block >32 virtual ops in this block 而这个块里边的virtual ops有以下几种类型: >producer_reward >author_reward >comment_reward >comment_payout_update >comment_benefactor_reward >curation_reward >effective_comment_vote 可以说包括好多virtual operation类型了。不过虽然使用区块链浏览器https://hiveblocks.com能看到区块中的virtual operation,但是有时候我们需要在程序中使用virtual operation,这时候总不能去https://hiveblocks.com用爬虫爬数据吧。 那么如何获取区块中的virtual operation呢?我首先想到的是使用`block_api.get_block`去读回指定区块并查看里边的virtual operation,然而发现读回上边我生成的区块中并没有返回virtual operation信息。 然后我又想到condenser_api会比block_api多返回一些信息,那我用`condenser_api.get_block`试试,结果发现问题依旧。 然后我又想到,也许是我的节点没有开放account_history_api,所以返回信息不全,于是用https://api.openhive.network 作为节点来测试`condenser_api.get_block`,结果也没有返回virtual operation信息。 于是看了一下代码,发现`condenser_api.get_block`就是封装的`block_api.get_block`并返回transaction_id列表而已: > 看样子`get_block`肯定是不会返回virtual operation啦,于是去开发者文档查询:https://developers.hive.io/apidefinitions,发现以下API可以返回virtual operation: >condenser_api.get_ops_in_block (下边api的封装) >account_history_api.get_ops_in_block >account_history_api.get_account_history (应该可以返回virtual operation,没测试) >account_history_api.enum_virtual_ops 最简单的当属`condenser_api.get_ops_in_block`啦: > 我们来测试一下访问我之前提到[55853428](https://hiveblocks.com/b/55853428),返回信息的尾部如下: > 看,果然返回virtual operation啦,可是等等,我记得明明这个块里有32个virtual operation,怎么最后一条的virtual_op是29呢?莫非是API节点的差异?换了N个API节点结果都一样,然后我仔细看了一下返回信息: > 发现头3条的virtual_op都是1,之后才是从2递增,看来这个virtual_op不是序号,哈哈,不管了,这个至少暂时不是我关注的。 其实我觉得`account_history_api.enum_virtual_ops`应该效率更高,因为可以通过设置filter来过滤指定的virtual_op,这样与节点间交互的数据就大幅减少了,效率应该会有所提高,回头去试一下。 # 相关链接 * https://hiveblocks.com/b/55853428 * https://developers.hive.io/apidefinitions/#condenser_api.get_ops_in_block * https://developers.hive.io/apidefinitions/#account_history_api.get_ops_in_block * https://developers.hive.io/apidefinitions/#account_history_api.enum_virtual_ops * https://gitlab.syncad.com/hive/hive/-/blob/master/libraries/protocol/include/hive/protocol/operations.hpp
👍 eval, justinashby, lnakuma, hivecur, glastar, deathwing.leo, joele, ew-and-patterns, dine77, lestrange, janaveda, dineroconopcion, localgrower, planosdeunacasa, alexanderlara, ubikalo, fsegredo1, kermosura, zonabitcoin, helengutier2, drricksanchez, netaterra, therealyme, soufianechakrouf, mermaidvampire, dallas27, pishio, nextgen622, fullofhope, noboxes, mamaloves, gringalicious, julian2013, ffcrossculture, sam99, archisteem, hymanadkins, itchyfeetdonica, travelgirl, kimzwarch, davidke20, japanguide, oflyhigh, aafeng, somebody, blackbunny, exec, joeyarnoldvn, voxmortis, pet.society, steemegg, deanliu, laoyao, bxt, bilpcoin.pay, midnightoil, helene, girolamomarotta, freakeao, xiaohui, ethansteem, lingfei, ioioioioi, sudefteri, lovelemon, jywahaha, thegames, akifane, kahvesizlik, rasalom, alexis555, steemaction, chireerocks, policewala, chireerocks.blog, joythewanderer, yogi, nanosesame, etherpunk, dailyke20, bert0, hmayak, poliwalt10, moleah, roberto58, jimhawkins, jrcornel, mtl1979, memeteca, tresor, bnk, laloretoyya, chocolatelover, mangou007, chenlocus, lordbutterfly, dses, gtpjfoodbank, dbfoodbank, weddinggift, fusion.lover, omnivori, itsmiessyonpeakd, luppers, penguinpablo, cryptonized, funnyman, alphacore, raiseup, davidesimoncini, jacuzzi, onepercentbetter, larry21, merlion, hungrybear, steemcleaners, hivewatchers, bilpcoinbpc, logic, seikatsumkt, eturnerx-honey, charitycurator, veenang, sasaadrian, abundancelife, holdonla, oldman28, da-dawn, ericaliu, zhangyan-123, ace108, passion-fruit, fortune-master, floatinglin, annepink, yanhan, evahe, good-karma, esteemapp, esteem.app, ecency, ecency.stats, me0852, paulmoon410, victory622, photographercr, susanli3769, azazqwe, jychbetter, philipmak, winniex, lovequeen, akhyar23, fasiulung, tingjie, abit, portraits, mrspointm, greenjuice, blogstats, rivalhw, cn-reader, adm, pedroerami,