Last active
June 11, 2021 07:01
-
-
Save youngkiu/d7ddf60e3f47bfe60f8ce06c24a064ac to your computer and use it in GitHub Desktop.
View Transactions.Actions of Nine Chronicles Agent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from functools import reduce | |
def get_agent_transactions(agent_address): | |
query = ''' | |
query($agent: Address) { | |
chainQuery { | |
transactionQuery{ | |
signerTransactions: transactions(signer: $agent) { | |
id | |
} | |
involvedAddressTransactions: transactions(involvedAddress: $agent) { | |
id | |
} | |
} | |
} | |
} | |
''' | |
variables = {'agent': agent_address} | |
response = requests.post('http://localhost:23061/graphql', | |
json={'query': query, 'variables': variables}) | |
results = response.json() | |
transactions = \ | |
results['data']['chainQuery']['transactionQuery']['signerTransactions'] + \ | |
results['data']['chainQuery']['transactionQuery']['involvedAddressTransactions'] | |
tx_ids = reduce(lambda acc, cur: acc + [cur['id']], transactions, []) | |
print('\n'.join(tx_ids)) | |
return tx_ids | |
def get_transaction_actions(tx_ids, type_id): | |
query = ''' | |
query($TxId: ID) { | |
chainQuery { | |
transactionQuery { | |
transaction(id: $TxId) { | |
actions { | |
inspection | |
} | |
} | |
} | |
} | |
} | |
''' | |
for tx_id in tx_ids: | |
variables = {'TxId': tx_id} | |
response = requests.post('http://localhost:23061/graphql', | |
json={'query': query, 'variables': variables}) | |
results = response.json() | |
actions = results['data']['chainQuery']['transactionQuery']['transaction']['actions'] | |
print(f'TxId: {tx_id}') | |
for action in actions: | |
if type_id in action['inspection']: | |
print(f'action({type_id}):', action['inspection']) | |
if __name__ == '__main__': | |
# http://explorer.libplanet.io/9c-main/account/?0x66D8A5E165196310497b0fc1Efc10B65d8538563 | |
_agent_address = '0x66D8A5E165196310497b0fc1Efc10B65d8538563' | |
_tx_ids = get_agent_transactions(_agent_address) | |
# _tx_ids = [ | |
# 'b7b9e2bfd0af0fb4e8118a77ef9a4df0264d61d1df55274fc1a63d132d14c4eb', | |
# 'fa8c22b133d33d26bb80c93d29f044125e39376dab285fff4b0d270327d6a26e', | |
# ] | |
_type_id = 'transfer_asset' | |
get_transaction_actions(_tx_ids, _type_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment