Learn Steem & Hive API - #02 - Check delegations from specific account | 檢查特定帳戶的授權情況

What's up guys,

As mentioned in the last post about convert vesting shares to SP/HP I would like to learn more about Steem / Hive's API since I have been told they are almost identical. Learning one side will definitely know how to interact with the other. By doing so, I get to kill two birds with one stone!

如上一篇文章所述轉化 vesting_shares 到 SP or HP 。我想了解更多有關Steem / Hive API,而且因為是 Fork 的原因,除了 library 的名字外,它們幾乎完全相同。 學習一邊肯定可以在另一邊使用上。 一石二鳥,顯然是很劃算的!


For Steem, I start with the steem-python from Github repo by @steemit.

Steem 我用了 steemit 官方發佈的 GitHhub.

For Hive, I start with forked hive-python from Github repo by @pharesim.

至於,Hive 我用了 @pharesim 發佈的 GitHub.


To avoid getting too wordy, I will be using Hive as an example since they are identical.

為了避免文章過於冗長,我將以Hive為例,因為它們的用法是完全相同的。


We need to import the installed Hive library so that we can get info from the blockchain.

我們需要導入已安裝的Hive庫,以便我們可以從區塊鏈中獲取信息。

from hive import Hive
from hive.converter import Converter
h = Hive() # <=== Where the magic happens

Below is a self-define function called check_vesting_delegations(username) taking a username as an input, and returning a python dictionary that includes two key-value pairs which are active_delegationsand expiring_delegations.

下面是一個名為check_vesting_delegations(username)的自定義函數,以username作為輸入,並返回一個python字典,該字典包含兩個鍵值對,即active_delegationsexpiring_delegations

def check_vesting_delegations(username):
  active_delegations = h.get_vesting_delegations(username, '', 20)
  expiring_delegations = h.get_expiring_vesting_delegations(username, "2018-01-01T00:00:00", 20)
  return {
    "active_delegations": active_delegations,
    "expiring_delegations": expiring_delegations
  }

The magic happens again with the h client. It allows us to find active delegations and expiring delegations by calling h.get_vesting_delegations() and h.get_expiring_vesting_delegations()

Both functions will each return a list object that includes either the active or expiring delegations info that related to the username account.

Here is an example list object if username has only 1 delegation with another_account. And the expiring delegation will be quite similar.

神奇的事再次出現在h客戶端上。 它允許我們通過調用h.get_vesting_delegations()h.get_expiring_vesting_delegations()來查找活動的委託和到期的委託。

這兩個函數都將返回一個列表對象,該列表對象包含與username帳戶相關的活動或即將到期的委託信息。

這是一個示例列表對象,如果username僅具有1個another_account授權。

即將到期的授權也是非常相似,這此就不細說了。

[{
  "id": 1323635,
  "delegator": "username",
  "delegatee": "another_account",
  "vesting_shares": "196190.718952 VESTS",
  "min_delegation_time": "2020-02-12T18:03:18"
}]

Now that we know how to check delegations from a specific account. Let's see what we will learn about next time.

現在,我們知道如何檢查特定帳戶的授權情況了。

Cheers!