tx-decode.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python
  2. # This file is part of DarkFi (https://dark.fi)
  3. #
  4. # Copyright (C) 2020-2025 Dyne.org foundation
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as
  8. # published by the Free Software Foundation, either version 3 of the
  9. # License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. import argparse, sys, base64, json
  19. from darkfi_sdk.tx import Transaction
  20. def main(argv):
  21. parser = argparse.ArgumentParser(description='Tool to decode Darkfid base64 transaction')
  22. parser.add_argument('--format', default='info', help='Output format. options are info and json, defaults to info')
  23. parser.add_argument("tx", nargs="?", help="The base64 transaction data")
  24. args = parser.parse_args()
  25. if args.tx:
  26. base64_tx = args.tx
  27. else:
  28. base64_tx = sys.stdin.read().strip()
  29. tx_bytes = base64.b64decode(base64_tx)
  30. tx = Transaction.decode(tx_bytes)
  31. if args.format == 'json':
  32. print(json.dumps(tx.__dict__, indent=4))
  33. else:
  34. print(tx)
  35. main(sys.argv)