Python Steem Libraries 0.1.1

in #steem8 years ago

New:

  • [Docs] Added Transactions docs
  • [Transactions] Python Processing and Signing of Transactions
  • [Transactions] Allow for signing of Comments

Bugs fixed:

  • [Examples] Update Examples
  • [Account] Fixed missing prefix
  • [Examples] Updates
  • [API] Fix get_account
  • [API] background cleanup and 'wallet'/'node' references

Manual Constructing and Signing of Transactions

The new transactions feature allows to manually construct, sign and
broadcast transactions using python3. That means that no cli_wallet is
required any longer.

Loading Transactions Class

We load the class for manual transaction construction via:

from steembase import transactions

Construction

Now we can use the predefined transaction formats, e.g. vote or
comment as follows:

  1. define the expiration time
  2. define a JSON object that contains all data for that transaction
  3. load that data into the corresponding operations class
  4. collect multiple operations
  5. get some blockchain parameters to prevent replay attack
  6. Construct the actual transaction from the list of operations
  7. sign the transaction with the corresponding private key(s)

Example A: Vote

expiration = transactions.formatTimeFromNow(60)
op = transactions.Vote(
    **{"voter": voter,
       "author": message["author"],
       "permlink": message["permlink"],
       "weight": int(weight)}
)
ops    = [transactions.Operation(op)]
ref_block_num, ref_block_prefix = transactions.getBlockParams(rpc)
tx     = transactions.Signed_Transaction(ref_block_num=ref_block_num,
                                         ref_block_prefix=ref_block_prefix,
                                         expiration=expiration,
                                         operations=ops)
tx = tx.sign([wif])

Example A: Comment

# Expiration time 60 seconds in the future
expiration = transactions.formatTimeFromNow(60)
op = transactions.Comment(
    **{"parent_author": parent_author,
       "parent_permlink": parent_permlink,
       "author": author,
       "permlink": postPermlink,
       "title": postTitle,
       "body": postBody,
       "json_metadata": ""}
)
ops    = [transactions.Operation(op)]
ref_block_num, ref_block_prefix = transactions.getBlockParams(rpc)
tx     = transactions.Signed_Transaction(ref_block_num=ref_block_num,
                                         ref_block_prefix=ref_block_prefix,
                                         expiration=expiration,
                                         operations=ops)
tx = tx.sign([wif])

Broadcasting

For broadcasting, we first need to convert the transactions class into a
JSON object. After that, we can braodcast this to the network:

# Convert python class to JSON
tx = transactions.JsonObj(tx)

# Broadcast JSON to network
rpc.broadcast_transaction(tx, api="network_broadcast"):
Sort:  

I know it's been a long time, but what exactly is expiration? I keep getting expiration errors...

The expiration is meant for the network to make sure a unconfirmed transactions is not added if it is expired.
I think should cannot use an expiration time larger than 30 seconds

Thank you, I have figured out the problem now. I had use my own node to be able to go back in time for more than just 30 seconds.

Coin Marketplace

STEEM 0.28
TRX 0.12
JST 0.033
BTC 66996.44
ETH 3098.15
USDT 1.00
SBD 3.72