将多个操作(operation)放入一个事务中(transaction)

in #cn7 years ago

操作、事务、区块 以及区块链

先来简单介绍一下操作、事务以及区块

  • 操作(operation): 你在steemit上的每一项活动,发帖、回复、点赞、转账等都是操作
  • 事务(transaction): 事务中包含一个或者几个操作(可能是不同人不同种类操作)
  • 区块(block): 每个区块中可能包含一组(0组)或者N组事务
  • 区块链(blockchain): 一系列不断增加(3秒每个)的区块,就构成了STEEM区块链。

亦即:
区块链由区块组成、区块中包含事务,事务中包含操作,操作是我们在STEEM上活动的基本单位。

STEEMIT 一个事务中两个操作的例子


Image source

以发帖为例,我们发表帖子,可以选择发帖的同时投票,也可以选择不投票。

如果勾选了箭头所示的单选框,就会在发帖的同时给帖子投票。

发帖、投票是两个独立的操作,
发帖的同时给帖子投票就是把两个操作放到一个事务中


以我的帖子为例,发帖和投票在一个事务中有相同的transaction_id

如果我们在steemd上打开这个transaction就会看到里边有两项操作,发帖和投票。

Python 库处理发帖并投票的实现

Steemit Python 库也支持发帖的同时投票。
如果设置了对应参数,则在发帖操作以外

        post_op = operations.Comment(
            **{"parent_author": parent_author,
               "parent_permlink": parent_permlink,
               "author": author,
               "permlink": permlink,
               "title": title,
               "body": body,
               "json_metadata": json_metadata}
        )
        ops = [post_op]

额外增加了投票操作

        if self_vote:
            vote_op = operations.Vote(
                **{'voter': author,
                   'author': author,
                   'permlink': permlink,
                   'weight': 10000,
                   }
            )
        ops.append(vote_op)

通过这个例子可知,Python库是支持把多个操作放到一个事务中的

将多个操作放到一个事务中的例子

Steem 官方Python 库同时提供了一个将多个操作放到一个事务中的例子
详情可以参考这里:

https://github.com/steemit/steem-python/blob/master/docs/examples.rst

Batching Operations

Most of the time each transaction contains only one operation (for example, an upvote, a transfer or a new post). We can however cram multiple operations in a single transaction, to achieve better efficiency and size reduction.

This script will also teach us how to create and sign transactions ourselves.

代码太长,感兴趣的朋友自己去看吧。

我的测试

我修改了这个例子,并针对我的一个回复进行测试:


(两个操作在一个事务中,相同的transaction_id)


(两个操作在一个事务中,详情)

结论

使用使用官方Python库,将多个操作(operation)放入一个事务中(transaction)是切实可行的

Sort:  

其实嘛这样会暴露机器人的掌控者。

哈哈哈哈

This post received a 4.1% upvote from @randowhale thanks to @beautifulbella! For more information, click here!

test2

test a

test1

С ума сойти))

Wouuwww is very nice. This post gives many interesting and important information i like your post this terimakasi you have given and want to share information that is very important for us in steemit.semoga you always successful and can share interesting information again for its fore

like and upvote

Hi, all friend please upvote my post and follow me.

please comment me.@oflyhigh

I am very happy to join in steemit, your help is very I need it for the cost of my life

雖然看不明白,但也來湊湊熱鬧;)))

我刚来也是一窍不通

嗯嗯,我要多學習學習!:):)

Coin Marketplace

STEEM 0.19
TRX 0.13
JST 0.030
BTC 61397.32
ETH 3382.52
USDT 1.00
SBD 2.48