create account

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

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

Viewing a response to: @learncode/part-6-coding-on-hive-with-python-interacting-with-the-hive-engine-side-chain

· @javivisan ·
Dear @learncode, thank you very much for your post, it has been very helpful.
Is it possible to get the data of members who have delegated a token to an account?
I need their account name and the delegated amount.

We have a clan account in Splinterlands where all members delegate tokens and I want to send the generated earnings to each member based on the amount delegated.

Looking forward to hearing from you.
Kind regards,
properties (22)
authorjavivisan
permlinkre-learncode-rchi94
categoryprogramming
json_metadata{"tags":["programming"],"app":"peakd/2022.05.8"}
created2022-05-26 09:55:51
last_update2022-05-26 09:55:51
depth1
children6
last_payout2022-06-02 09:55:51
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_length428
author_reputation278,890,055,091,696
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,530,039
net_rshares0
@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_reputation278,890,055,091,696
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)