STEEM Transaction 签名学习笔记 (二)/ 投票操作的流程 by oflyhigh

View this thread on steempeak.com
· @oflyhigh ·
$77.16
STEEM Transaction 签名学习笔记 (二)/ 投票操作的流程
昨天写完[STEEM 签名学习笔记 (一)/ 读操作与写操作](https://steemit.com/steemdev/@oflyhigh/3ppeth-steem)以后,发现完全不知道如何进行下去。我觉得我自己给自己挖了个坑,然后掉进坑里,出不来了。

貌似我需要先从坑里爬上来,然后找一部梯子,然后把梯子竖到坑里,然后我再从梯子爬上来,感觉逻辑有点混乱呢?哪里不对呢?

![](https://steemitimages.com/DQmVjh8Dc3HmTcH94PFAuioFGKkHjq7zxFBdkyZSxusXbaL/image.png)

-----

# 投票操作的流程(wallet)

以投票操作为例,来学习。

看了一下wallet的实现:
![](https://steemitimages.com/DQmSz8GEh5Sk1XAem5jRjW91FuQNPfrjzM5GF2TPuYjt57X/image.png)

貌似怎么看,怎么简单,大致流程如下:

* 声明`vote_operation`结构体实例
* 给结构体实例赋初值
* 声明`signed_transaction`结构体实例
* 将`vote_operation`实例添加到`signed_transaction`实例中
* 将`signed_transaction`实例广播出去

# 投票操作的流程实例

对应到我们前一篇文章中,来看看每个结构体都长啥样?
```
['vote',
	 {'author': 'oflyhigh.test',
	  'permlink': '6r3tt4-test',
	  'voter': 'oflyhigh',
	  'weight': 2000}]
```
填充完***`vote_operation`*** 应该是这个样子。

```
{'expiration': '',
 'extensions': [],
 'operations': [],
 'ref_block_num': 0,
 'ref_block_prefix': 0,
 'signatures': []}
```
一个空的`transaction`应该长成这样,`signed_transaction`由`transaction`继承而来。

而`signed_transaction`负责把这些内容填完整。
填完整以后是这个样子:
![](https://steemitimages.com/DQmawUBGAnYtFx86pT4Ji4WNiaET3AdhoHsLdXeiai2SYmf/image.png)

将填完整后的`transaction`广播出去的操作我们上节已经演示了***如何用curl进行操作***,这节就不再赘述了。

# `signed_transaction`做了啥

如果按照我们上述分析,貌似将操作打包并完成签名也没啥难度啊,然而事实是难点都在***signed_transaction***这完成的。那么它做了啥呢?

因为,投票操作没有`extensions`,所以我们暂时不予考虑。

将`operation`添加到`transaction`中也没啥难度。那么去除这些以外,它实际做了三件事:

* 设置超时时间:`expiration`
![](https://steemitimages.com/DQmbHWzWvDHAWnJCydiUmSeSVKfw7my7qoRJ3KuNMC3j23e/image.png)
* 设置`ref_block_num` 和 `ref_block_prefix`
![](https://steemitimages.com/DQmPPmW8hQv3ThCzf8nJBdavZgCLQxiGb8tDVYAaF3ZipdZ/image.png)
* 对`transaction`进行签名: 添加`signatures`部分
![](https://steemitimages.com/DQmUdja61qYzU8Tqr4VSk93DBDCS8s12Xs3EQBEvD1grJWw/image.png)

好吧,这三个操作我还没搞明白呢,等我明天学习明白一点点再继续毁人不倦。

(封面图源 :[pixabay](https://pixabay.com))
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 156 others
properties (23)
post_id17,939,928
authoroflyhigh
permlinksteem-transaction
categorysteemdev
json_metadata"{"app": "steemit/0.1", "format": "markdown", "links": ["https://steemit.com/steemdev/@oflyhigh/3ppeth-steem", "https://pixabay.com"], "image": ["https://steemitimages.com/DQmVjh8Dc3HmTcH94PFAuioFGKkHjq7zxFBdkyZSxusXbaL/image.png"], "tags": ["steemdev", "steem", "signature", "cn", "cn-programming"]}"
created2017-11-17 10:15:15
last_update2017-11-17 10:15:15
depth0
children13
net_rshares35,611,514,191,160
last_payout2017-11-24 10:15:15
cashout_time1969-12-31 23:59:59
total_payout_value63.923 SBD
curator_payout_value13.233 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length1,820
author_reputation1,148,153,621,496,884
root_title"STEEM Transaction 签名学习笔记 (二)/ 投票操作的流程"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (220)
@onlinemoneybank ·
Nice post..
👍  ,
properties (23)
post_id17,939,986
authoronlinemoneybank
permlinkre-oflyhigh-steem-transaction-20171117t101531560z
categorysteemdev
json_metadata"{"app": "steemit/0.1", "tags": ["steemdev"]}"
created2017-11-17 10:16:18
last_update2017-11-17 10:16:18
depth1
children0
net_rshares1,381,047,528
last_payout2017-11-24 10:16:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length11
author_reputation-100,770,481,413
root_title"STEEM Transaction 签名学习笔记 (二)/ 投票操作的流程"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (2)
@benjaminj ·
Brilliant job bro.
👍  
properties (23)
post_id17,941,484
authorbenjaminj
permlinkre-oflyhigh-steem-transaction-20171117t103451940z
categorysteemdev
json_metadata"{"app": "steemit/0.1", "tags": ["steemdev"]}"
created2017-11-17 10:40:09
last_update2017-11-17 10:40:09
depth1
children0
net_rshares0
last_payout2017-11-24 10:40:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length18
author_reputation2,996,861,459,862
root_title"STEEM Transaction 签名学习笔记 (二)/ 投票操作的流程"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@rajag234 ·
Just Steem
![](https://steemitimages.com/DQmRQeNTjCWF9MZZtAihVdzUyUMERDLbydARupFuJB6tRXC/image.png)
properties (22)
post_id17,941,690
authorrajag234
permlinkre-oflyhigh-steem-transaction-20171117t104342652z
categorysteemdev
json_metadata"{"app": "steemit/0.1", "image": ["https://steemitimages.com/DQmRQeNTjCWF9MZZtAihVdzUyUMERDLbydARupFuJB6tRXC/image.png"], "tags": ["steemdev"]}"
created2017-11-17 10:43:48
last_update2017-11-17 10:43:48
depth1
children0
net_rshares0
last_payout2017-11-24 10:43:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length99
author_reputation1,895,735,652,406
root_title"STEEM Transaction 签名学习笔记 (二)/ 投票操作的流程"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@rozetaylar ·
you done best ever post on steemit i like it very much,
properties (22)
post_id17,942,044
authorrozetaylar
permlinkre-oflyhigh-steem-transaction-20171117t105049972z
categorysteemdev
json_metadata"{"app": "steemit/0.1", "tags": ["steemdev"]}"
created2017-11-17 10:49:48
last_update2017-11-17 10:49:48
depth1
children0
net_rshares0
last_payout2017-11-24 10:49:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length55
author_reputation25,638,280,156
root_title"STEEM Transaction 签名学习笔记 (二)/ 投票操作的流程"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@shajj ·
very good post thanks for sharing
properties (22)
post_id17,942,118
authorshajj
permlinkre-oflyhigh-steem-transaction-20171117t105058615z
categorysteemdev
json_metadata"{"app": "steemit/0.1", "tags": ["steemdev"]}"
created2017-11-17 10:51:00
last_update2017-11-17 10:51:00
depth1
children0
net_rshares0
last_payout2017-11-24 10:51:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length33
author_reputation30,902,954,325,135
root_title"STEEM Transaction 签名学习笔记 (二)/ 投票操作的流程"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@mine-mation ·
????
properties (22)
post_id17,942,251
authormine-mation
permlinkre-oflyhigh-steem-transaction-20171117t105333700z
categorysteemdev
json_metadata"{"app": "steemit/0.1", "tags": ["steemdev"]}"
created2017-11-17 10:53:36
last_update2017-11-17 10:53:36
depth1
children0
net_rshares0
last_payout2017-11-24 10:53:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length4
author_reputation3,353,942,058
root_title"STEEM Transaction 签名学习笔记 (二)/ 投票操作的流程"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@yousafmaier ·
$0.04
very good
👍  
properties (23)
post_id17,942,298
authoryousafmaier
permlinkre-oflyhigh-steem-transaction-20171117t105422785z
categorysteemdev
json_metadata"{"app": "steemit/0.1", "tags": ["steemdev"]}"
created2017-11-17 10:54:30
last_update2017-11-17 10:54:30
depth1
children0
net_rshares17,814,941,062
last_payout2017-11-24 10:54:30
cashout_time1969-12-31 23:59:59
total_payout_value0.035 SBD
curator_payout_value0.002 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length9
author_reputation2,492,680,789,327
root_title"STEEM Transaction 签名学习笔记 (二)/ 投票操作的流程"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@sujanbarua1 ·
nice man  

Please
Upvote
Follow
Resteem
id name-- https://steemit.com/@sujanbarua1
properties (22)
post_id17,942,718
authorsujanbarua1
permlinkre-oflyhigh-steem-transaction-20171117t110200384z
categorysteemdev
json_metadata"{"app": "steemit/0.1", "links": ["https://steemit.com/@sujanbarua1"], "tags": ["steemdev"]}"
created2017-11-17 11:02:03
last_update2017-11-17 11:02:03
depth1
children0
net_rshares0
last_payout2017-11-24 11:02:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length83
author_reputation1,348,962,882,591
root_title"STEEM Transaction 签名学习笔记 (二)/ 投票操作的流程"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@shenchensucc ·
我也要开始写写读书笔记,哈哈,最近在学习。
properties (22)
post_id17,956,330
authorshenchensucc
permlinkre-oflyhigh-steem-transaction-20171117t141154141z
categorysteemdev
json_metadata"{"app": "steemit/0.1", "tags": ["steemdev"]}"
created2017-11-17 14:11:54
last_update2017-11-17 14:11:54
depth1
children1
net_rshares0
last_payout2017-11-24 14:11:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length21
author_reputation313,809,918,917,512
root_title"STEEM Transaction 签名学习笔记 (二)/ 投票操作的流程"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@oflyhigh ·
好好学习,天天向上
properties (22)
post_id17,958,340
authoroflyhigh
permlinkre-shenchensucc-re-oflyhigh-steem-transaction-20171117t143705980z
categorysteemdev
json_metadata"{"app": "steemit/0.1", "tags": ["steemdev"]}"
created2017-11-17 14:37:06
last_update2017-11-17 14:37:06
depth2
children0
net_rshares0
last_payout2017-11-24 14:37:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length9
author_reputation1,148,153,621,496,884
root_title"STEEM Transaction 签名学习笔记 (二)/ 投票操作的流程"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@smartree ·
干货笔记、干活教程,赞++
properties (22)
post_id17,959,056
authorsmartree
permlinkre-oflyhigh-steem-transaction-20171117t144639420z
categorysteemdev
json_metadata"{"app": "steemit/0.1", "tags": ["steemdev"]}"
created2017-11-17 14:46:39
last_update2017-11-17 14:46:39
depth1
children0
net_rshares0
last_payout2017-11-24 14:46:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length13
author_reputation19,201,419,386
root_title"STEEM Transaction 签名学习笔记 (二)/ 投票操作的流程"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@klausv587 ·
截图看起来有些不清晰,如果可以直接贴出代码的链接就更好了
properties (22)
post_id18,005,367
authorklausv587
permlinkre-oflyhigh-steem-transaction-20171118t032920701z
categorysteemdev
json_metadata"{"app": "steemit/0.1", "tags": ["steemdev"]}"
created2017-11-18 03:29:21
last_update2017-11-18 03:29:21
depth1
children0
net_rshares0
last_payout2017-11-25 03:29:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length28
author_reputation558,041,717,476
root_title"STEEM Transaction 签名学习笔记 (二)/ 投票操作的流程"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@engzp ·
老兄,请继续加油!
properties (22)
post_id18,084,518
authorengzp
permlinkre-oflyhigh-steem-transaction-20171119t005235901z
categorysteemdev
json_metadata"{"app": "steemit/0.1", "tags": ["steemdev"]}"
created2017-11-19 00:52:45
last_update2017-11-19 00:52:45
depth1
children0
net_rshares0
last_payout2017-11-26 00:52:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length9
author_reputation247,995,867,762
root_title"STEEM Transaction 签名学习笔记 (二)/ 投票操作的流程"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000