Make daemon return net as in monero.const, cache the value

This commit is contained in:
Michał Sałaban 2020-01-22 04:45:42 +01:00
parent 2c85d23478
commit ccf5066739
3 changed files with 42 additions and 2 deletions

View file

@ -9,6 +9,7 @@ import requests
from .. import exceptions
from ..account import Account
from ..address import address, Address, SubAddress
from ..const import NET_MAIN, NET_TEST, NET_STAGE
from ..numbers import from_atomic, to_atomic, PaymentID
from ..seed import Seed
from ..transaction import Transaction, IncomingPayment, OutgoingPayment
@ -28,6 +29,9 @@ class JSONRPCDaemon(object):
:param verify_ssl_certs: verify SSL certificates when connecting
:param proxy_url: a proxy to use
"""
_net = None
def __init__(self, protocol='http', host='127.0.0.1', port=18081, path='/json_rpc',
user='', password='', timeout=30, verify_ssl_certs=True, proxy_url=None):
self.url = '{protocol}://{host}:{port}'.format(
@ -41,10 +45,25 @@ class JSONRPCDaemon(object):
self.verify_ssl_certs = verify_ssl_certs
self.proxies = {protocol: proxy_url}
def _set_net(self, info):
if info['mainnet']:
self._net = NET_MAIN
if info['testnet']:
self._net = NET_TEST
if info['stagenet']:
self._net = NET_STAGE
def info(self):
info = self.raw_jsonrpc_request('get_info')
self._set_net(info)
return info
def net(self):
if self._net:
return self._net
self.info()
return self._net
def send_transaction(self, blob, relay=True):
res = self.raw_request('/sendrawtransaction', {
'tx_as_hex': binascii.hexlify(blob),