Skip to content

Instantly share code, notes, and snippets.

@iamalwaysuncomfortable
Created February 4, 2022 01:15
Show Gist options
  • Save iamalwaysuncomfortable/19f111a637b66327ea4dbb0ee1402b83 to your computer and use it in GitHub Desktop.
Save iamalwaysuncomfortable/19f111a637b66327ea4dbb0ee1402b83 to your computer and use it in GitHub Desktop.
Get sent mobilecoin txos
import asyncio
from forest.payments_monitor import Mobster
mobster = Mobster()
##There are 2 ways to get spent txos
# 1 - get by txo map (I believe this works even if you import your acct to a new FS instance)
async def get_sent_txos_from_txo_history() -> list:
acct = await mobster.get_account()
txos = await mobster.req_("get_all_txos_for_account", account_id=acct)
sent_txos = [
data
for data in txos["result"]["txo_map"].values()
if data["account_status_map"][acct]["txo_status"] == "txo_status_spent"
and not data["received_account_id"] == acct
]
return sent_txos
# 2 - get by transaction log (requires a local db of tx log data,
# if you've ever switched DBs without porting them
# you won't get your full transaction history
async def get_txos_from_transaction_log() -> list:
acct = await mobster.get_account()
tx_logs = await mobster.req_(
"get_all_transaction_logs_for_account", account_id=acct
)
sent_txos_from_logs = []
for tx_log_id, log in tx_logs["result"]["transaction_log_map"].items():
if log["output_txos"]:
for txo in log["output_txos"]:
if txo["recipient_address_id"] and txo["recipient_address_id"] != acct:
sent_txos_from_logs += [
dict(
recipient_address=txo["recipient_address_id"],
tx_log_id=tx_log_id,
amount=txo["value_pmob"],
)
]
return sent_txos_from_logs
if __name__ == "__main__":
txos_1 = asyncio.run(get_sent_txos_from_txo_history())
txos_2 = asyncio.run(get_txos_from_transaction_log())
print(txos_1)
print(txos_1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment