create account

update for beem: transaction id is returned when broadcasting by holger80

View this thread on: hive.blogpeakd.comecency.com
· @holger80 · (edited)
$64.48
update for beem: transaction id is returned when broadcasting
## Repository

https://github.com/holgern/beem<center>
![beem-logo](https://cdn.steemitimages.com/DQmcRrwLPSywSYMierfP6um6mejeMNGjN9Rxw7audJqTDgb/beem-logo)
</center>

[beem](https://github.com/holgern/beem) is a python library and command line tool for HIVE.  The current version is 0.24.2.

There is also a discord channel for beem: https://discord.gg/4HM592V

The newest beem version can be installed by:

```
pip install -U beem
```

Check that you are using hive nodes. The following command 

```
beempy updatenodes --hive
```

updates the nodelist and uses only hive nodes. After setting hive as default_chain, `beempy updatenodes` can be used.

The list of nodes can be checked with

```
beempy config
```

and

```
beempy currentnode
```

shows the currently connected node.

## Changelog for versions 0.24.2
* New UnknownTransaction exception that is raised when using get_transaction with an unknown trx_id
* New function is_transaction_existing which returns false, when a trx_id does not exists
* beempy info does not show information for a trx_id
* broadcast from TransactionBuilder can now return a trx_id, when set trx_id to True (default)
* sign and finalizeOp from Hive and Steem return now the trx_id in a field
* add export parameter to all broadcast commands in beempy
* When setting unsigned in beempy, the default value of expires is changed to 3600
* beempy history returns account history ops in a table or stored in a json file

## Transaction_id is added to the returned dict when broadcasting

The transaction id is now returned in the returned dict on sign() and finalizeOp() in Hive and Steem.

This allows it to easily check if an operation could successfully send.

```
beempy upvote -w 25 @hivehustlers/hivehustlers-say-hello-to-usdhustlerm-power-up-sundays
```
returns now
```
{
    "expiration": "2020-06-21T19:38:48",
    "ref_block_num": 60836,
    "ref_block_prefix": 3155918752,
    "operations": [
        [
            "vote",
            {
                "voter": "holger80",
                "author": "hivehustlers",
                "permlink": "hivehustlers-say-hello-to-usdhustlerm-power-up-sundays",
                "weight": 2500
            }
        ]
    ],
    "extensions": [],
    "signatures": [
        "2024c3ab9ecd69b010a414114cc956f517d9d664dd24d728829fcebcf9f89b885571099549cb3f537ede0190c638bd0906acbd07994c1d289664236f2ee93b7765"
    ],
    "trx_id": "68db2522d1724f02430788e37b27694cbf7eb3f4"
}
```

The same result could be obtained by
```
from beem.comment import Comment
c= Comment("@dustsweeper/dustsweeper-s-faq")
c.blockchain.wallet.unlock("my_pass")
ret = c.upvote(weight=25, voter="holger80")
print(ret["trx_id"])
```
which returns
```
6056e3d1d26bc4c2c637984c21aa841b7b3ea1a4
```

We can now check both trx_ids and verify that my two votes were successfully broadcasted.

```
from beem.blockchain import Blockchain
b = Blockchain()
trx1 = b.get_transaction("68db2522d1724f02430788e37b27694cbf7eb3f4")
print("Vote was broadcasted at block %d" % trx1["block_num"])
trx2 = b.get_transaction("6056e3d1d26bc4c2c637984c21aa841b7b3ea1a4")
print("Vote was broadcasted at block %d" % trx2["block_num"])
```

returns
```
Vote was broadcasted at block 44494269
Vote was broadcasted at block 44494376
```
This allows it to check if a transaction was broadcasted without the need to parse all blocks.

The information about the trx_id was also available in previous versions, but only when the transaction was build and send by hand with `TransactionBuilder`.

## beempy info can now be used to obtain information about a trx_id
The `info` command is now able to return information about a trx_id.
```
beempy info 68db2522d1724f02430788e37b27694cbf7eb3f4
```

## Account history check with beempy
```
beempy history
```
can be used to check if a transaction could be broadcasted.
```
beempy history -n 2
```
returns now
```
+----+---------------------------------------------------------------------------+
| Nr | Hist op                                                                   |
+----+---------------------------------------------------------------------------+
| 1  | {                                                                         |
|    |     "voter": "holger80",                                                  |
|    |     "author": "dustsweeper",                                              |
|    |     "permlink": "dustsweeper-s-faq",                                      |
|    |     "weight": 2500,                                                       |
|    |     "trx_id": "6056e3d1d26bc4c2c637984c21aa841b7b3ea1a4",                 |
|    |     "block": 44494376,                                                    |
|    |     "trx_in_block": 11,                                                   |
|    |     "op_in_trx": 0,                                                       |
|    |     "virtual_op": 0,                                                      |
|    |     "timestamp": "2020-06-21T19:43:42",                                   |
|    |     "account": "holger80",                                                |
|    |     "type": "vote",                                                       |
|    |     "_id": "d442e4c0b703020f99e7b739f37527fa9477ffa7",                    |
|    |     "index": 173814                                                       |
|    | }                                                                         |
| 2  | {                                                                         |
|    |     "voter": "holger80",                                                  |
|    |     "author": "hivehustlers",                                             |
|    |     "permlink": "hivehustlers-say-hello-to-usdhustlerm-power-up-sundays", |
|    |     "weight": 2500,                                                       |
|    |     "trx_id": "68db2522d1724f02430788e37b27694cbf7eb3f4",                 |
|    |     "block": 44494269,                                                    |
|    |     "trx_in_block": 10,                                                   |
|    |     "op_in_trx": 0,                                                       |
|    |     "virtual_op": 0,                                                      |
|    |     "timestamp": "2020-06-21T19:38:18",                                   |
|    |     "account": "holger80",                                                |
|    |     "type": "vote",                                                       |
|    |     "_id": "6e20f474ff58dcd188763339820105bdbf59a1d4",                    |
|    |     "index": 173813                                                       |
|    | }                                                                         |
+----+---------------------------------------------------------------------------+
```

The ``history` command can also be used to store the entiry account history as json file:
```
beempy history --number -1 --order 1 --virtual-ops --json-file my_hist.json holger80
```
where `--number -1` returns all ops (otherwise it is used to limit the number of returned ops), `--order 1` returns the ops in the correct order, `--virtual-ops` returns also virtual ops and `--json-file my_hist.json` stores the ops in a json file.

The stored ops in a json file can then be loaded and processed, e.g. with excel or similar tools.

It is also possible to limit the returned ops by setting one ore more op types with for example`--only-ops transfer,vote`.

## Transaction can be exported to a file with -e or --export in beempy

All beempy commands that broadcast something to the chain have now a `--export` parameter.

This can be used to do offline signing more easily.

```
beempy -dx upvote --export vote.json -w 25 @paragism/my-thoughts-on-yield-farming-and-bat-pump
```
The `-dx` parameter set the expiration time to a new default value of 3600 seconds, meaning I have 1 hour to sign and broadcast my transaction.

Now I can sign vote.json:
```
beempy sign -i vote.json -o vote_signed.json
```
(I do not need to enter my username, as I set holger80 as default account).

Due to the new changes, vote_signed.json has now a new field with the trx_id:
```
"trx_id": "c3306c892edf0528b09b1da9c003bca0a0dd7088"
```

I can now broadcast the trx:
```
beempy broadcast -f vote_signed.json
```
After a few seconds
```
beempy info c3306c892edf0528b09b1da9c003bca0a0dd7088
```
is returning details about the trx.



## How to check if a transaction was successfully broadcasted and retry when not

That a transaction could be broadcasted without error message is no guarantee that the transaction is written into the hive chain. There is a small probability that a block could not be signed by a witness in time or is rejected because of an invalid operation inside the block. Thus it is always a good idea to check if the transaction was written into the chain.

The new trx field can be used to easily build a loop in which it is checked if the trx_id is valid and known. When this is not the case, the transaction is broadcasted again:
```
from beem.blockchain import Blockchain
from beem.comment import Comment
import time
b = Blockchain()
c= Comment("@eveuncovered/roadtrip-east-varkaus")
c.blockchain.wallet.unlock("my_pass")
trx_id_found = False
count = 0
while not trx_id_found and count < 5:
    count += 1
    delay = 0
    print("broadcasting trx")
    ret = c.upvote(weight=25, voter="holger80")
    trx_id = ret["trx_id"]
    print("Trx_id: %s" % trx_id)
    while not trx_id_found and delay < 120:
        print("checking trx_id...")
        trx_id_found = b.is_transaction_existing(trx_id)
        time.sleep(10)
        delay += 10
if not trx_id_found:
    print("Could not broadcast!")
else:
    print("Transaction is written into the chain!")
```
returns
```
broadcasting trx
Trx_id: d3df7b16b2e8e21a2084af9c21775ea697d0d8a1
checking trx_id...
checking trx_id...
checking trx_id...
checking trx_id...
checking trx_id...
checking trx_id...
Transaction is written into the chain!
```
With the help of the new `is_transaction_existing` function it is quite easy to check if a transaction was successfully broadcasted.


___

*If you like what I do, consider casting a vote for me as witness on [Hivesigner](https://hivesigner.com/sign/account-witness-vote?witness=holger80&approve=1) or on [PeakD](https://peakd.com/witnesses)*
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 446 others
properties (23)
authorholger80
permlinkupdate-for-beem-transaction-id-is-returned-when-broadcasting
categoryhive-139531
json_metadata"{"canonical_url": "https://hive.blog/hive-139531/@holger80/update-for-beem-transaction-id-is-returned-when-broadcasting", "community": "hive-139531", "app": "beempy/0.24.3", "users": ["paragism", "hivehustlers", "eveuncovered", "dustsweeper"], "links": ["https://peakd.com/witnesses", "https://hivesigner.com/sign/account-witness-vote?witness=holger80&approve=1", "https://github.com/holgern/beem", "https://cdn.steemitimages.com/DQmcRrwLPSywSYMierfP6um6mejeMNGjN9Rxw7audJqTDgb/beem-logo", "https://discord.gg/4HM592V"], "tags": ["development", "beem", "python"]}"
created2020-06-21 20:47:36
last_update2020-06-21 20:51:18
depth0
children7
last_payout2020-06-28 20:47:36
cashout_time1969-12-31 23:59:59
total_payout_value38.232 HBD
curator_payout_value26.247 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length10,413
author_reputation358,857,509,568,825
root_title"update for beem: transaction id is returned when broadcasting"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,100,574
net_rshares173,582,123,272,395
author_curate_reward""
vote details (510)
@hiveboy ·
😯😯😯
👍  
properties (23)
authorhiveboy
permlinkqcbmgo
categoryhive-139531
json_metadata{"app":"hiveblog/0.1"}
created2020-06-22 09:31:36
last_update2020-06-22 09:31:36
depth1
children0
last_payout2020-06-29 09:31:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3
author_reputation412,839,840,096
root_title"update for beem: transaction id is returned when broadcasting"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,109,479
net_rshares518,176,927
author_curate_reward""
vote details (1)
@hivebuzz ·
Congratulations @holger80! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

<table><tr><td><img src="https://images.hive.blog/60x60/http://hivebuzz.me/badges/toppayoutweek.png"></td><td>Your post got the highest payout of the week</td></tr>
</table>

<sub>_You can view [your badges on your board](https://hivebuzz.me/@holger80) And compare to others on the [Ranking](https://hivebuzz.me/ranking)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>



###### Support the HiveBuzz project. [Vote](https://hivesigner.com/sign/update_proposal_votes?proposal_ids=%5B%22109%22%5D&approve=true) for [our proposal](https://peakd.com/me/proposals/109)!
properties (22)
authorhivebuzz
permlinkhivebuzz-notify-holger80-20200622t033535000z
categoryhive-139531
json_metadata{"image":["http://hivebuzz.me/notify.t6.png"]}
created2020-06-22 03:35:33
last_update2020-06-22 03:35:33
depth1
children0
last_payout2020-06-29 03:35:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length766
author_reputation369,424,490,717,359
root_title"update for beem: transaction id is returned when broadcasting"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,105,248
net_rshares0
@maxuvv ·
Hi @holger80, you have received a small bonus upvote from MAXUV.
This is to inform you that you now have [new MPATH tokens](https://hive-engine.com/?p=market&t=MPATH) in your Hive-Engine wallet.
Please [read this post](https://peakd.com/hive-167922/@mpath/mpath-weekly-report-and-token-distribution-26-april-2020) for more information.
Thanks for being a member of both MAXUV *and* MPATH!
properties (22)
authormaxuvv
permlinkre-update-for-beem-transaction-id-is-returned-when-broadcasting-20200621t204923z
categoryhive-139531
json_metadata"{"app": "rewarding/0.1.0"}"
created2020-06-21 20:49:24
last_update2020-06-21 20:49:24
depth1
children0
last_payout2020-06-28 20:49:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length393
author_reputation32,074,948,443
root_title"update for beem: transaction id is returned when broadcasting"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,100,601
net_rshares0
@sc-steemit ·
$0.05
Great addition to the functionality, will be a great helper to make sure things run smoothly. 
👍  
properties (23)
authorsc-steemit
permlinkre-holger80-qcb893
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.05.5"}
created2020-06-22 04:24:39
last_update2020-06-22 04:24:39
depth1
children0
last_payout2020-06-29 04:24:39
cashout_time1969-12-31 23:59:59
total_payout_value0.022 HBD
curator_payout_value0.023 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length94
author_reputation28,448,644,499,713
root_title"update for beem: transaction id is returned when broadcasting"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,105,820
net_rshares204,957,085,196
author_curate_reward""
vote details (1)
@sc-steemit · (edited)
$0.24
# Manage nodes that does not support TRX Lookups

This feature is very usefull, but some nodes has lookup by TRX disbaled, making the example code above crash and fail. With a few minor changes we can handle these issues.

```
import beemapi

.....
while not trx_id_found and delay < 120:
            print("- Checking trx_id....")
            try:
                trx_id_found = hiveBlockchain.is_transaction_existing(trx_id)
            except beemapi.exceptions.RPCError as err:
                old_node_url = hive.rpc.url
                hive.rpc.next()
                new_node_url = hive.rpc.url
                print("Caught RPC Error: %s " % (err))
                print("Switching from %s to %s" % (old_node_url, new_node_url))
            time.sleep(10)
            delay += 10
        if not trx_id_found:
            print("- Cound not broadcast!")
.....
```

What this code does is that if we have an exception with "RPCError" we will switch node to the next one.

### Example Output

```
- Checking trx_id....
Caught RPC Error: Assert Exception:false: This node's operator has disabled operation indexing by transaction_id
Switching from https://rpc.ausbit.dev to https://hive.roelandp.nl
- Checking trx_id....
- Checking trx_id....
```
👍  
properties (23)
authorsc-steemit
permlinkre-holger80-qcmiyr
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.06.2"}
created2020-06-28 06:49:39
last_update2020-06-28 08:17:09
depth1
children0
last_payout2020-07-05 06:49:39
cashout_time1969-12-31 23:59:59
total_payout_value0.122 HBD
curator_payout_value0.122 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,250
author_reputation28,448,644,499,713
root_title"update for beem: transaction id is returned when broadcasting"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,218,279
net_rshares1,049,238,203,186
author_curate_reward""
vote details (1)
@simplegame ·
$0.05
As always thanks for what you do.

Also the witness comment at the end worked! I went back and checked and did not have you voted. You are now!
👍  
properties (23)
authorsimplegame
permlinkre-holger80-qcapvm
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.05.5"}
created2020-06-21 21:47:48
last_update2020-06-21 21:47:48
depth1
children1
last_payout2020-06-28 21:47:48
cashout_time1969-12-31 23:59:59
total_payout_value0.022 HBD
curator_payout_value0.023 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length143
author_reputation136,655,333,876,456
root_title"update for beem: transaction id is returned when broadcasting"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,101,400
net_rshares204,755,032,005
author_curate_reward""
vote details (1)
@holger80 ·
Thanks for your support!
👍  , ,
properties (23)
authorholger80
permlinkre-simplegame-qccj6h
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.05.5"}
created2020-06-22 21:18:21
last_update2020-06-22 21:18:21
depth2
children0
last_payout2020-06-29 21:18:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length24
author_reputation358,857,509,568,825
root_title"update for beem: transaction id is returned when broadcasting"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,120,941
net_rshares12,557,454,885
author_curate_reward""
vote details (3)