You are viewing a single comment's thread from:

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

in #programming2 years ago

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,

Sort:  

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.

I'm going to see the documentation to find a solution.
Your post helped me a lot, thanks!!!

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"})


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.

The code works great!!!! Thank you so much, I had been looking for a solution to the problem for months.
!PGM !PIZZA

Sent 0.1 PGM - 0.1 LVL- 1 STARBITS - 0.01 MOTA - 0.05 DEC - 15 SBT tokens to @learncode

remaining commands 1

BUY AND STAKE THE PGM TO SEND A LOT OF TOKENS!

The tokens that the command sends are: 0.1 PGM-0.1 LVL-2.5 BUDS-0.01 MOTA-0.05 DEC-15 SBT-1 STARBITS-0.00000001 BTC (SWWAP.BTC)

image.png
Discord image.png

Support the curation account @ pgm-curator with a delegation 10 HP - 50 HP - 100 HP - 500 HP - 1000 HP

Get potential votes from @ pgm-curator by paying in PGM, here is a guide

I'm a bot, if you want a hand ask @ zottone444