Skip to content

Commit

Permalink
Updated transaction.py and scripts.py
Browse files Browse the repository at this point in the history
  • Loading branch information
QuixoteSystems committed Oct 12, 2022
1 parent f7d7750 commit 7601961
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 20 deletions.
Binary file modified koios_python/__pycache__/pool.cpython-310.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/scripts.cpython-310.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/transactions.cpython-310.pyc
Binary file not shown.
6 changes: 3 additions & 3 deletions koios_python/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def get_native_script_list(content_range="0-999"):
"""
custom_headers = {"Range": str(content_range)}
get_format = requests.post(NATIVE_SCRIPT_LIST_URL, headers \
= custom_headers)
= custom_headers, timeout=25)
get_format = json.loads(get_format.content)
return get_format

Expand All @@ -32,7 +32,7 @@ def get_plutus_script_list(content_range="0-999"):
"""
custom_headers = {"Range": str(content_range)}
get_format = requests.post(PLUTUS_SCRIPT_LIST_URL, headers \
= custom_headers)
= custom_headers, timeout=25)
get_format = json.loads(get_format.content)
return get_format

Expand All @@ -46,6 +46,6 @@ def get_script_redeemers(script_hash):
:rtype: list.
"""
query = requests.get( "https://api.koios.rest/api/v0/script_redeemers?_script_hash=" \
+ script_hash )
+ script_hash, timeout=25)
query = json.loads(query.content)
return query
28 changes: 14 additions & 14 deletions koios_python/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,44 @@
TX_UTXOS_URL


def get_tx_info(tx_hash):
def get_tx_info(*args):
"""
Get detailed information about transaction(s).
:param list tx_hash: list of transaction(s) hash to search and read data.
:return: list of all info about transaction(s).
:rtype: list.
"""
get_format = {"_tx_hashes": [tx_hash]}
tx_info = requests.post(TX_INFO_URL, json = get_format)
get_format = {"_tx_hashes": [args]}
tx_info = requests.post(TX_INFO_URL, json = get_format, timeout=10)
tx_info = json.loads(tx_info.content)
return tx_info


def get_tx_utxos(tx_hash):
def get_tx_utxos(*args):
"""
Get UTxO set (inputs/outputs) of transactions.
:param list tx_hash: list of transaction(s) hash to search and read utxos data.
:return: all info about utxos in transaction(s)
:rtype: list.
"""
get_format = {"_tx_hashes": [tx_hash]}
tx_utxos = requests.post(TX_UTXOS_URL, json = get_format)
get_format = {"_tx_hashes": [args]}
tx_utxos = requests.post(TX_UTXOS_URL, json = get_format, timeout=10)
tx_utxos = json.loads(tx_utxos.content)
return tx_utxos


def get_tx_metadata(tx_hash):
def get_tx_metadata(*args):
"""
Get metadata information (if any) for given transaction(s).
:param list tx_hash: list strings of transaction(s) hash to search and read utxos data.
:return: list of all info about utxos in transaction(s)
:rtype: list.
"""
get_format = {"_tx_hashes": [tx_hash]}
tx_metadata = requests.post(TX_METADATA_URL, json = get_format)
get_format = {"_tx_hashes": [args]}
tx_metadata = requests.post(TX_METADATA_URL, json = get_format, timeout=10)
tx_metadata = json.loads(tx_metadata.content)
return tx_metadata

Expand All @@ -59,7 +59,7 @@ def get_tx_metalabels(content_range="0-999"):
"""
custom_headers = {"Range": str(content_range)}
tx_metalabels = requests.get(TX_METALABELS_URL, headers \
= custom_headers)
= custom_headers, timeout=10)
tx_metalabels = json.loads(tx_metalabels.content)
return tx_metalabels

Expand All @@ -76,21 +76,21 @@ def submit_tx(file):
cbor_tx = cbor_tx.read()
cbor_header = {'Content-Type': 'application/cbor'}
submit = requests.post( SUBMIT_TX_URL, headers = cbor_header, \
data = cbor_tx)
data = cbor_tx, timeout=25)
submit = json.loads(submit.content)
return submit


def get_tx_status(tx_hash):
def get_tx_status(*args):
"""
Get the number of block confirmations for a given transaction hash list.
:param list tx_hash: list of transaction(s) hash to search and read utxos data.
:return: list of all info about utxos in transaction(s)
:rtype: list.
"""
get_format = {"_tx_hashes": [tx_hash]}
tx_status = requests.post( TX_STATUS_URL, json = get_format)
get_format = {"_tx_hashes": [args]}
tx_status = requests.post( TX_STATUS_URL, json = get_format, timeout=10)
tx_status = json.loads(tx_status.content)
return tx_status

4 changes: 1 addition & 3 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,4 @@
# "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy", 350))


pprint.pp(koios_python.get_pool_info("pool100wj94uzf54vup2hdzk0afng4dhjaqggt7j434mtgm8v2gfvfgp",
"pool102s2nqtea2hf5q0s4amj0evysmfnhrn4apyyhd4azcmsclzm96m",
"pool102vsulhfx8ua2j9fwl2u7gv57fhhutc3tp6juzaefgrn7ae35wm"))
pprint.pp(koios_python.get_tx_status("f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e"))

0 comments on commit 7601961

Please sign in to comment.