thornode.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python3
  2. #
  3. # MMGen Wallet, a terminal-based cryptocurrency wallet
  4. # Copyright (C)2013-2025 The MMGen Project <mmgen@tuta.io>
  5. # Licensed under the GNU General Public License, Version 3:
  6. # https://www.gnu.org/licenses
  7. # Public project repositories:
  8. # https://github.com/mmgen/mmgen-wallet
  9. # https://gitlab.com/mmgen/mmgen-wallet
  10. """
  11. test.cmdtest_d.httpd.thornode: Thornode WSGI http server
  12. """
  13. import re, json
  14. from wsgiref.util import request_uri
  15. from . import HTTPD
  16. class ThornodeServer(HTTPD):
  17. name = 'thornode server'
  18. port = 18800
  19. content_type = 'application/json'
  20. request_pat = r'/bank/balances/(\S+)'
  21. def make_response_body(self, method, environ):
  22. req_str = request_uri(environ)
  23. m = re.search(self.request_pat, req_str)
  24. assert m[1], f'‘{req_str}’: malformed query path'
  25. data = {
  26. 'result': [
  27. {'denom': 'foocoin', 'amount': 321321321321},
  28. {'denom': 'rune', 'amount': 987654321321},
  29. {'denom': 'barcoin', 'amount': 123123123123},
  30. ]}
  31. return json.dumps(data).encode()