Skip to content

Commit

Permalink
Use algorand explorer (ulamlabs#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
DedicatedDev authored May 13, 2021
1 parent 63c6041 commit b595f05
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
4 changes: 2 additions & 2 deletions backend/nft_market/api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def index_operations(asset_pk, update_timestamp=False, params=None):
limit=1,
txn_type="appl",
)
response = algorand.indexer.search_transactions(**params)
response = algorand.explorer.search_transactions(**params)
txs = response["transactions"]
if len(txs) == 0:
return
Expand Down Expand Up @@ -214,7 +214,7 @@ def index_holder(asset_pk, prev_tx=None, params=None):
txn_type="axfer",
min_amount=0,
)
response = algorand.indexer.search_transactions(**params)
response = algorand.explorer.search_transactions(**params)
txs = response["transactions"]

txs = list(filter(is_non_zero_asset_tx, txs))
Expand Down
75 changes: 75 additions & 0 deletions backend/nft_market/services/algorand.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import base64

import requests
from algosdk.v2client.algod import AlgodClient
from algosdk.v2client.indexer import IndexerClient
from django.conf import settings
Expand All @@ -7,3 +10,75 @@
indexer = IndexerClient(
settings.PURESTAKE_API_KEY, settings.PURESTAKE_INDEXER_URL, headers
)


class Explorer:
def search_transactions(
self,
limit=None,
next_page=None,
note_prefix=None,
txn_type=None,
sig_type=None,
txid=None,
min_round=None,
max_round=None,
asset_id=None,
start_time=None,
end_time=None,
min_amount=None,
max_amount=None,
address=None,
address_role=None,
exclude_close_to=False,
application_id=None,
rekey_to=False,
):
query = dict()
if limit:
query["limit"] = limit
if next_page:
query["next"] = next_page
if note_prefix:
query["note-prefix"] = base64.b64encode(note_prefix).decode()
if txn_type:
query["tx-type"] = txn_type
if sig_type:
query["sig-type"] = sig_type
if txid:
query["txid"] = txid
if min_round:
query["min-round"] = min_round
if max_round:
query["max-round"] = max_round
if asset_id:
query["asset-id"] = asset_id
if end_time:
query["before-time"] = end_time
if start_time:
query["after-time"] = start_time
if min_amount:
query["currency-greater-than"] = min_amount
if max_amount:
query["currency-less-than"] = max_amount
if address:
query["address"] = address
if address_role:
query["address-role"] = address_role
if exclude_close_to:
query["exclude-close-to"] = "true"
if application_id:
query["application-id"] = application_id
if rekey_to:
query["rekey-to"] = "true"
r = requests.get(
"https://testnet.algoexplorerapi.io/idx2/v2/transactions",
params=query,
headers={
"content-type": "application/json",
},
)
return r.json()


explorer = Explorer()
2 changes: 1 addition & 1 deletion backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ uWSGI = "^2.0.19"
dj-database-url = "^0.5.0"
django-storages = {extras = ["google"], version = "^1.11.1"}
psycopg2-binary = "^2.8.6"
requests = "^2.25.1"

[tool.poetry.dev-dependencies]
black = "^20.8b1"
Expand Down

0 comments on commit b595f05

Please sign in to comment.