mirror of
https://git.wownero.com/lza_menace/wownero-python.git
synced 2024-08-15 03:25:25 +00:00
Make daemon return net as in monero.const, cache the value
This commit is contained in:
parent
2c85d23478
commit
ccf5066739
3 changed files with 42 additions and 2 deletions
|
@ -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),
|
||||
|
|
|
@ -18,6 +18,10 @@ class Daemon(object):
|
|||
"""
|
||||
return self._backend.info()
|
||||
|
||||
@property
|
||||
def net(self):
|
||||
return self._backend.net()
|
||||
|
||||
def height(self):
|
||||
"""
|
||||
Return daemon's chain height.
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
from binascii import hexlify
|
||||
import responses
|
||||
|
||||
from monero.const import NET_STAGE
|
||||
from monero.daemon import Daemon
|
||||
from monero.backends.jsonrpc import JSONRPCDaemon
|
||||
from monero.transaction import Transaction
|
||||
|
||||
from .base import JSONTestCase
|
||||
|
||||
|
@ -27,6 +26,24 @@ class JSONRPCDaemonTestCase(JSONTestCase):
|
|||
self.assertTrue(self.daemon.info())
|
||||
self.assertEqual(self.daemon.height(), 294993)
|
||||
|
||||
@responses.activate
|
||||
def test_net(self):
|
||||
responses.add(responses.POST, self.jsonrpc_url,
|
||||
json=self._read('test_basic_info-get_info.json'),
|
||||
status=200)
|
||||
self.assertEqual(self.daemon.net, NET_STAGE)
|
||||
self.daemon.net
|
||||
self.assertEqual(len(responses.calls), 1, "net value has not been cached?")
|
||||
|
||||
@responses.activate
|
||||
def test_info_then_net(self):
|
||||
responses.add(responses.POST, self.jsonrpc_url,
|
||||
json=self._read('test_basic_info-get_info.json'),
|
||||
status=200)
|
||||
self.daemon.info()
|
||||
self.assertEqual(self.daemon.net, NET_STAGE)
|
||||
self.assertEqual(len(responses.calls), 1, "net value has not been cached?")
|
||||
|
||||
@responses.activate
|
||||
def test_mempool(self):
|
||||
responses.add(responses.POST, self.mempool_url,
|
||||
|
|
Loading…
Reference in a new issue