-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add saga blockchain * add basic unit tests for saga * saga: added test files and update gitignore to ignore genesis json file * saga: remove wrong text --------- Co-authored-by: Nick Plante <nap@zerosum.org>
- Loading branch information
1 parent
9e1b4ff
commit ea0ca57
Showing
21 changed files
with
2,874 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
""" | ||
usage: python3 staketaxcsv/report_saga.py <walletaddress> [--format all|cointracking|koinly|..] | ||
Prints transactions and writes CSV(s) to _reports/SAGA*.csv | ||
""" | ||
|
||
import logging | ||
|
||
|
||
import staketaxcsv.saga.processor | ||
from staketaxcsv.saga.config import localconfig | ||
from staketaxcsv.saga.progress import SECONDS_PER_PAGE, ProgressSaga | ||
from staketaxcsv.saga.genesis import genesis_airdrop | ||
from staketaxcsv.common import report_util | ||
from staketaxcsv.common.Cache import Cache | ||
from staketaxcsv.common.Exporter import Exporter | ||
from staketaxcsv.settings_csv import SAGA_NODE, TICKER_SAGA | ||
from staketaxcsv.common.ibc import api_lcd | ||
from staketaxcsv.common.ibc.tx_data import TxDataLcd | ||
from staketaxcsv.common.ibc.decorators import set_ibc_cache | ||
|
||
|
||
def main(): | ||
report_util.main_default(TICKER_SAGA) | ||
|
||
|
||
def read_options(options): | ||
report_util.read_common_options(localconfig, options) | ||
logging.info("localconfig: %s", localconfig.__dict__) | ||
|
||
|
||
def _txdata(): | ||
max_txs = localconfig.limit | ||
return TxDataLcd(SAGA_NODE, max_txs, limit_per_query=20) | ||
|
||
|
||
def wallet_exists(wallet_address): | ||
return api_lcd.make_lcd_api(SAGA_NODE).account_exists(wallet_address) | ||
|
||
|
||
def txone(wallet_address, txid): | ||
elem = _txdata().get_tx(txid) | ||
|
||
exporter = Exporter(wallet_address, localconfig, TICKER_SAGA) | ||
txinfo = staketaxcsv.saga.processor.process_tx(wallet_address, elem, exporter) | ||
|
||
return exporter | ||
|
||
|
||
def estimate_duration(wallet_address): | ||
return SECONDS_PER_PAGE * _txdata().get_txs_pages_count(wallet_address) | ||
|
||
|
||
@set_ibc_cache() | ||
def txhistory(wallet_address): | ||
""" Configure localconfig based on options dictionary. """ | ||
progress = ProgressSaga() | ||
exporter = Exporter(wallet_address, localconfig, TICKER_SAGA) | ||
txdata = _txdata() | ||
|
||
# Fetch count of transactions to estimate progress more accurately | ||
count_pages = txdata.get_txs_pages_count(wallet_address) | ||
progress.set_estimate(count_pages) | ||
|
||
# Fetch transactions | ||
elems = txdata.get_txs_all(wallet_address, progress) | ||
|
||
progress.report_message(f"Processing {len(elems)} transactions... ") | ||
staketaxcsv.saga.processor.process_txs(wallet_address, elems, exporter) | ||
|
||
return exporter | ||
|
||
|
||
@set_ibc_cache() | ||
def txhistory(wallet_address): | ||
""" Configure localconfig based on options dictionary. """ | ||
progress = ProgressSaga() | ||
exporter = Exporter(wallet_address, localconfig, TICKER_SAGA) | ||
txdata = _txdata() | ||
|
||
# Fetch/add genesis airdrop to csv | ||
progress.report_message("Getting genesis airdrop amount...") | ||
genesis_airdrop(wallet_address, exporter) | ||
|
||
# Fetch count of transactions to estimate progress more accurately | ||
count_pages = txdata.get_txs_pages_count(wallet_address) | ||
progress.set_estimate(count_pages) | ||
|
||
# Fetch transactions | ||
elems = txdata.get_txs_all(wallet_address, progress) | ||
|
||
progress.report_message(f"Processing {len(elems)} transactions... ") | ||
staketaxcsv.saga.processor.process_txs(wallet_address, elems, exporter) | ||
|
||
return exporter | ||
|
||
|
||
if __name__ == "__main__": | ||
logging.basicConfig(level=logging.INFO) | ||
main() |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from staketaxcsv.common.config import config | ||
from staketaxcsv.settings_csv import MINTSCAN_MAX_TXS | ||
|
||
|
||
class localconfig(config): | ||
|
||
start_date = None | ||
end_date = None | ||
limit = MINTSCAN_MAX_TXS |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
MINTSCAN_LABEL_SAGA = "saga" | ||
CURRENCY_SAGA = "SAGA" | ||
EXCHANGE_SAGA = "saga_blockchain" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import json | ||
import logging | ||
import os | ||
import requests | ||
|
||
import staketaxcsv.saga.constants as co | ||
from staketaxcsv.saga.make_tx import make_genesis_airdrop_tx | ||
|
||
GENESIS_JSON = os.environ.get("STAKETAX_SAGA_GENESIS_JSON", os.path.join(os.path.dirname(__file__), "genesis.json")) | ||
GENESIS_URL = "https://raw.githubusercontent.com/sagaxyz/mainnet/main/genesis/genesis.json" | ||
|
||
|
||
def genesis_airdrop(wallet_address, exporter): | ||
amount_saga = _genesis_airdrop_saga_amount(wallet_address) | ||
if amount_saga: | ||
row = make_genesis_airdrop_tx(amount_saga, wallet_address) | ||
exporter.ingest_row(row) | ||
|
||
|
||
def _genesis_airdrop_saga_amount(wallet_address): | ||
data = _get_genesis_data() | ||
|
||
balances = data["app_state"]["bank"]["balances"] | ||
for balance in balances: | ||
if balance["address"] == wallet_address: | ||
amount = balance["coins"][0]["amount"] | ||
return float(amount) / 1000000 | ||
|
||
return 0 | ||
|
||
|
||
def _get_genesis_data(): | ||
if not os.path.exists(GENESIS_JSON): | ||
logging.info("Fetching genesis url %s ...", GENESIS_URL) | ||
response = requests.get(GENESIS_URL) | ||
with open(GENESIS_JSON, 'w') as file: | ||
file.write(response.text) | ||
|
||
with open(GENESIS_JSON, 'r') as file: | ||
data = json.load(file) | ||
return data |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from staketaxcsv.common.Exporter import Row | ||
from staketaxcsv.common.ExporterTypes import TX_TYPE_AIRDROP | ||
from staketaxcsv.saga import constants as co | ||
|
||
|
||
def make_genesis_airdrop_tx(amount_saga, wallet_address): | ||
row = Row( | ||
timestamp="2024-04-08 00:00:00", # timestamp of height 1 (https://www.mintscan.io/saga/block/1) | ||
tx_type=TX_TYPE_AIRDROP, | ||
received_amount=amount_saga, | ||
received_currency=co.CURRENCY_SAGA, | ||
sent_amount="", | ||
sent_currency="", | ||
fee="", | ||
fee_currency="", | ||
exchange=co.EXCHANGE_SAGA, | ||
wallet_address=wallet_address, | ||
txid="saga_genesis_airdrop", | ||
url="" | ||
) | ||
return row |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import logging | ||
|
||
import staketaxcsv.saga.constants as co | ||
import staketaxcsv.common.ibc.handle | ||
import staketaxcsv.common.ibc.processor | ||
from staketaxcsv.saga.config import localconfig | ||
from staketaxcsv.settings_csv import SAGA_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 = staketaxcsv.common.ibc.processor.txinfo( | ||
wallet_address, elem, co.MINTSCAN_LABEL_SAGA, SAGA_NODE) | ||
txinfo.url = "https://www.mintscan.io/saga/tx/{}".format(txinfo.txid) | ||
|
||
if txinfo.is_failed: | ||
staketaxcsv.common.ibc.processor.handle_failed_transaction(exporter, txinfo) | ||
return txinfo | ||
|
||
for msginfo in txinfo.msgs: | ||
result = staketaxcsv.common.ibc.processor.handle_message(exporter, txinfo, msginfo, localconfig.debug) | ||
if result: | ||
continue | ||
|
||
staketaxcsv.common.ibc.handle.handle_unknown_detect_transfers(exporter, txinfo, msginfo) | ||
|
||
return txinfo |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from staketaxcsv.saga.config import localconfig | ||
from staketaxcsv.common.progress import Progress | ||
|
||
SECONDS_PER_PAGE = 4 | ||
|
||
|
||
class ProgressSaga(Progress): | ||
|
||
def __init__(self): | ||
super().__init__(localconfig) | ||
|
||
def set_estimate(self, count_pages): | ||
self.add_stage("default", count_pages, SECONDS_PER_PAGE) |
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
Oops, something went wrong.