Skip to content

Commit

Permalink
feat: support agoric BLD (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
arirubinstein authored Aug 2, 2022
1 parent 583dbc8 commit ff8af30
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/bld/config_bld.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from common.config import config


class localconfig(config):

ibc_addresses = {}
2 changes: 2 additions & 0 deletions src/bld/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EXCHANGE_BLD = "bld_blockchain"
MINTSCAN_LABEL_BLD = "bld"
26 changes: 26 additions & 0 deletions src/bld/processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import logging
import common.ibc.processor
import bld.constants as co
import common.ibc.processor
import common.ibc.handle
from bld.config_bld import localconfig
from settings_csv import BLD_NODE


def process_txs(wallet_address, elems, exporter):
for elem in elems:
process_tx(wallet_address, elem, exporter)


def process_tx(wallet_address, elem, exporter):
txinfo = common.ibc.processor.txinfo(
wallet_address, elem, co.MINTSCAN_LABEL_BLD, localconfig.ibc_addresses, BLD_NODE, co.EXCHANGE_BLD)

for msginfo in txinfo.msgs:
result = common.ibc.processor.handle_message(exporter, txinfo, msginfo, localconfig.debug)
if result:
continue

common.ibc.handle.handle_unknown_detect_transfers(exporter, txinfo, msginfo)

return txinfo
13 changes: 13 additions & 0 deletions src/bld/progress_bld.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from bld.config_bld import localconfig
from common.progress import Progress

SECONDS_PER_PAGE = 4


class ProgressBld(Progress):

def __init__(self):
super().__init__(localconfig)

def set_estimate(self, count_pages):
self.add_stage("default", count_pages, SECONDS_PER_PAGE)
89 changes: 89 additions & 0 deletions src/report_bld.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""
usage: python3 report_bld.py <walletaddress> [--format all|cointracking|koinly|..]
Prints transactions and writes CSV(s) to _reports/BLD*.csv
"""

import logging
import pprint

from bld.config_bld import localconfig
from bld.progress_bld import SECONDS_PER_PAGE, ProgressBld
from common import report_util
from common.Cache import Cache
from common.Exporter import Exporter
from common.ExporterTypes import FORMAT_DEFAULT
from settings_csv import TICKER_BLD, BLD_NODE
import bld.processor
import common.ibc.api_lcd


def main():
wallet_address, export_format, txid, options = report_util.parse_args(TICKER_BLD)

if txid:
_read_options(options)
exporter = txone(wallet_address, txid)
exporter.export_print()
if export_format != FORMAT_DEFAULT:
report_util.export_format_for_txid(exporter, export_format, txid)
else:
exporter = txhistory(wallet_address, options)
report_util.run_exports(TICKER_BLD, wallet_address, exporter, export_format)


def _read_options(options):
report_util.read_common_options(localconfig, options)
logging.info("localconfig: %s", localconfig.__dict__)


def wallet_exists(wallet_address):
return common.ibc.api_lcd.LcdAPI(BLD_NODE).account_exists(wallet_address)


def txone(wallet_address, txid):
elem = common.ibc.api_lcd.LcdAPI(BLD_NODE).get_tx(txid)

print("Transaction data:")
pprint.pprint(elem)

exporter = Exporter(wallet_address, localconfig, TICKER_BLD)
txinfo = bld.processor.process_tx(wallet_address, elem, exporter)
txinfo.print()
return exporter


def estimate_duration(wallet_address, options):
max_txs = localconfig.limit
return SECONDS_PER_PAGE * common.ibc.api_lcd.get_txs_pages_count(BLD_NODE, wallet_address, max_txs)


def txhistory(wallet_address, options):
# Configure localconfig based on options
_read_options(options)
if localconfig.cache:
localconfig.ibc_addresses = Cache().get_ibc_addresses()
logging.info("Loaded ibc_addresses from cache ...")

max_txs = localconfig.limit
progress = ProgressBld()
exporter = Exporter(wallet_address, localconfig, TICKER_BLD)

# Fetch count of transactions to estimate progress more accurately
count_pages = common.ibc.api_lcd.get_txs_pages_count(BLD_NODE, wallet_address, max_txs, debug=localconfig.debug)
progress.set_estimate(count_pages)

# Fetch transactions
elems = common.ibc.api_lcd.get_txs_all(BLD_NODE, wallet_address, progress, max_txs, debug=localconfig.debug)

progress.report_message(f"Processing {len(elems)} transactions... ")
bld.processor.process_txs(wallet_address, elems, exporter)

if localconfig.cache:
Cache().set_ibc_addresses(localconfig.ibc_addresses)
return exporter


if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
main()
2 changes: 2 additions & 0 deletions src/settings_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
ALGO_INDEXER_NODE = os.environ.get("ALGO_INDEXER_NODE", "https://algoindexer.algoexplorerapi.io")
ALGO_NFDOMAINS = os.environ.get("ALGO_NFDOMAINS", "https://api.nf.domains")
ATOM_NODE = os.environ.get("ATOM_NODE", "")
BLD_NODE = os.environ.get("BLD_NODE", "https://main.api.agoric.net")
BTSG_NODE = os.environ.get("BTSG_NODE", "https://lcd.explorebitsong.com")
COVALENT_NODE = os.environ.get("COVALENT_NODE", "https://api.covalenthq.com")
DVPN_LCD_NODE = os.environ.get("DVPN_LCD_NODE", "https://lcd.sentinel.co")
Expand All @@ -26,6 +27,7 @@

TICKER_ALGO = "ALGO"
TICKER_ATOM = "ATOM"
TICKER_BLD = "BLD"
TICKER_BTSG = "BTSG"
TICKER_DVPN = "DVPN"
TICKER_EVMOS = "EVMOS"
Expand Down

0 comments on commit ff8af30

Please sign in to comment.