create account

RE: Part 6: Coding on Hive with Python - Interacting with the Hive-Engine Side Chain by learncode

View this thread on: hive.blogpeakd.comecency.com

Viewing a response to: @javivisan/re-learncode-rchi94

· @learncode ·
Hello,

I have not found a simple way to get a list of incoming delegations for a token.

This snippet of code will tell the total amount of incoming or outgoing delegation.

> from hiveengine.wallet import Wallet
> Wallet('learncode').get_token('SWAP.HIVE')  

>> {'_id': 254860, 'account': 'learncode', 'symbol': 'SWAP.HIVE', 'balance': '0.00000000', 'stake': '0', 'pendingUnstake': '0', 'delegationsIn': '0', 'delegationsOut': '0', 'pendingUndelegations': '0'}

It may be possible to query the data you want my making a JSON RPC request. A good reference is the documentation here: https://github.com/hive-engine/steemsmartcontracts-wiki.
properties (22)
authorlearncode
permlinkre-javivisan-rcmdvf
categoryprogramming
json_metadata{"tags":["programming"],"app":"peakd/2022.05.8"}
created2022-05-29 01:09:18
last_update2022-05-29 01:09:18
depth2
children5
last_payout2022-06-05 01:09:18
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_length641
author_reputation682,726,195,093
root_title"Part 6: Coding on Hive with Python - Interacting with the Hive-Engine Side Chain"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id113,597,619
net_rshares0
@javivisan ·
I'm going to see the documentation to find a solution.
Your post helped me a lot, thanks!!!
properties (22)
authorjavivisan
permlinkre-learncode-rcnixf
categoryprogramming
json_metadata{"tags":["programming"],"app":"peakd/2022.05.8"}
created2022-05-29 15:56:03
last_update2022-05-29 15:56:03
depth3
children4
last_payout2022-06-05 15:56:03
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_length91
author_reputation276,953,032,680,683
root_title"Part 6: Coding on Hive with Python - Interacting with the Hive-Engine Side Chain"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id113,614,190
net_rshares0
@learncode ·
Thank you for the feedback. 

Just following up on your question about getting the list of incoming delegations to an account. I found a simple way to request this data using the hiveengine API object.

Here's what it looks like:
> from hiveengine.api import Api
> api = Api()
> api.find("tokens", "delegations", query={"to": "learncode"})

In this case, the "tokens" string is the contract name, the "delegations" string is the table name, and the query is like a search filter for MongoDB. 

There are additional filters you can use, as documented at https://github.com/hive-engine/steemsmartcontracts-wiki/blob/master/Tokens-Contract.md#delegations

> fields:
from = account that initiated the delegation
to = account that received the delegation
symbol = symbol of the token delegated
quantity = quantity of tokens delegated

So you can request the list of delegations based on the account delegated to or from, the symbol for the token, and the quantity. I believe you can include logical statements in the query also, to do things like only return results where the quantity is greater than N.

Example:
> api.find("tokens", "delegations", query={"to": "learncode", "from": "javivisan", "symbol": "BEE"})
👍  
properties (23)
authorlearncode
permlinkre-javivisan-rct8lw
categoryprogramming
json_metadata{"tags":["programming"],"app":"peakd/2022.05.8"}
created2022-06-01 17:58:45
last_update2022-06-01 17:58:45
depth4
children3
last_payout2022-06-08 17:58:45
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_length1,210
author_reputation682,726,195,093
root_title"Part 6: Coding on Hive with Python - Interacting with the Hive-Engine Side Chain"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id113,704,471
net_rshares9,288,244,991
author_curate_reward""
vote details (1)
@javivisan ·
The code works great!!!! Thank you so much, I had been looking for a solution to the problem for months.
!PGM !PIZZA
properties (22)
authorjavivisan
permlinkre-learncode-rcte9m
categoryprogramming
json_metadata{"tags":["programming"],"app":"peakd/2022.05.9"}
created2022-06-01 20:01:00
last_update2022-06-01 20:01:00
depth5
children1
last_payout2022-06-08 20:01:00
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_length116
author_reputation276,953,032,680,683
root_title"Part 6: Coding on Hive with Python - Interacting with the Hive-Engine Side Chain"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id113,707,457
net_rshares0
@poshtoken ·
https://twitter.com/HiveTrending/status/1532068157258489856
<sub> The rewards earned on this comment will go directly to the people(@hivetrending) sharing the post on Twitter as long as they are registered with @poshtoken. Sign up at https://hiveposh.com.</sub>
properties (22)
authorposhtoken
permlinkre-learncode-re-javivisan-rct8lw14474
categoryprogramming
json_metadata"{"app":"Poshtoken 0.0.1","payoutToUser":["hivetrending"]}"
created2022-06-01 18:36:36
last_update2022-06-01 18:36:36
depth5
children0
last_payout2022-06-08 18:36: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_length262
author_reputation5,378,745,551,921,936
root_title"Part 6: Coding on Hive with Python - Interacting with the Hive-Engine Side Chain"
beneficiaries
0.
accountreward.app
weight10,000
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id113,705,363
net_rshares0