Skip to content

Commit

Permalink
improve cli docs; some other xbr bits (#1382)
Browse files Browse the repository at this point in the history
* improve cli docs; some other xbr bits
* expand xbr cli
  • Loading branch information
oberstet committed May 12, 2020
1 parent 80fe02d commit d99c094
Show file tree
Hide file tree
Showing 13 changed files with 838 additions and 596 deletions.
10 changes: 10 additions & 0 deletions Makefile
Expand Up @@ -73,6 +73,16 @@ docs:
spelling:
cd docs && sphinx-build -b spelling . _spelling

run_docs:
twistd --nodaemon web --port=tcp:8090 --path=./docs/build/html/

test_xbr_cli:
xbrnetwork
xbrnetwork version
xbrnetwork get-member
xbrnetwork get-market --market=1388ddf6-fe36-4201-b1aa-cb7e36b4cfb3
xbrnetwork get-actor
xbrnetwork get-actor --market=1388ddf6-fe36-4201-b1aa-cb7e36b4cfb3

test_mnemonic:
# python -m pytest -rsx autobahn/xbr/test/test_mnemonic.py
Expand Down
2 changes: 1 addition & 1 deletion autobahn/_version.py
Expand Up @@ -24,4 +24,4 @@
#
###############################################################################

__version__ = '20.4.3'
__version__ = '20.5.1.dev1'
2 changes: 1 addition & 1 deletion autobahn/wamp/serializer.py
Expand Up @@ -311,7 +311,7 @@ def unserialize(self, payload, isBinary=None):
self._unserialized_rated_messages += int(math.ceil(float(len(payload)) / self.RATED_MESSAGE_SIZE))

# maybe auto-reset and trigger user callback ..
if self._autoreset_callback and ((self._autoreset_duration and (time_ns() - self._stats_reset) >= self._autoreset_duration) or(self._autoreset_rated_messages and self.stats_rated_messages() >= self._autoreset_rated_messages)):
if self._autoreset_callback and ((self._autoreset_duration and (time_ns() - self._stats_reset) >= self._autoreset_duration) or (self._autoreset_rated_messages and self.stats_rated_messages() >= self._autoreset_rated_messages)):
stats = self.stats(reset=True)
self._autoreset_callback(stats)

Expand Down
1 change: 1 addition & 0 deletions autobahn/xbr/__init__.py
Expand Up @@ -35,6 +35,7 @@

from autobahn.xbr._abi import XBR_TOKEN_ABI, XBR_NETWORK_ABI, XBR_MARKET_ABI, XBR_CATALOG_ABI, XBR_CHANNEL_ABI # noqa
from autobahn.xbr._abi import XBR_DEBUG_TOKEN_ADDR, XBR_DEBUG_NETWORK_ADDR, XBR_DEBUG_MARKET_ADDR, XBR_DEBUG_CATALOG_ADDR, XBR_DEBUG_CHANNEL_ADDR # noqa
from autobahn.xbr._abi import XBR_DEBUG_TOKEN_ADDR_SRC, XBR_DEBUG_NETWORK_ADDR_SRC, XBR_DEBUG_MARKET_ADDR_SRC, XBR_DEBUG_CATALOG_ADDR_SRC, XBR_DEBUG_CHANNEL_ADDR_SRC # noqa
from autobahn.xbr._interfaces import IMarketMaker, IProvider, IConsumer, ISeller, IBuyer # noqa
from autobahn.xbr._util import make_w3, pack_uint256, unpack_uint256 # noqa

Expand Down
49 changes: 32 additions & 17 deletions autobahn/xbr/_abi.py
Expand Up @@ -35,13 +35,11 @@
# print('Using eth_hash backend {}'.format(keccak256))
import web3

XBR_TOKEN_FN = pkg_resources.resource_filename('autobahn', 'xbr/contracts/XBRToken.json')
XBR_NETWORK_FN = pkg_resources.resource_filename('autobahn', 'xbr/contracts/XBRNetwork.json')
XBR_MARKET_FN = pkg_resources.resource_filename('autobahn', 'xbr/contracts/XBRMarket.json')
XBR_CATALOG_FN = pkg_resources.resource_filename('autobahn', 'xbr/contracts/XBRCatalog.json')
XBR_CHANNEL_FN = pkg_resources.resource_filename('autobahn', 'xbr/contracts/XBRChannel.json')


#
# Set default XBR contract addresses to
# XBR v20.4.2 @ Rinkeby (https://github.com/crossbario/xbr-protocol/issues/106)
#
if 'XBR_DEBUG_TOKEN_ADDR' in os.environ:
_token_adr = os.environ['XBR_DEBUG_TOKEN_ADDR']
try:
Expand All @@ -50,9 +48,10 @@
except Exception as e:
raise RuntimeError('could not parse Ethereum address for XBR_DEBUG_TOKEN_ADDR={} - {}'.format(_token_adr, e))
XBR_DEBUG_TOKEN_ADDR = _token_adr
XBR_DEBUG_TOKEN_ADDR_SRC = 'env'
else:
XBR_DEBUG_TOKEN_ADDR = '0x0000000000000000000000000000000000000000'
print('WARNING: The XBR smart contracts are not yet deployed to public networks. Please set XBR_DEBUG_TOKEN_ADDR manually.')
XBR_DEBUG_TOKEN_ADDR = '0x8d41eF64D49eA1550B4b41a8959D856601441503'
XBR_DEBUG_TOKEN_ADDR_SRC = 'builtin'

if 'XBR_DEBUG_NETWORK_ADDR' in os.environ:
_netw_adr = os.environ['XBR_DEBUG_NETWORK_ADDR']
Expand All @@ -62,9 +61,10 @@
except Exception as e:
raise RuntimeError('could not parse Ethereum address for XBR_DEBUG_NETWORK_ADDR={} - {}'.format(_netw_adr, e))
XBR_DEBUG_NETWORK_ADDR = _netw_adr
XBR_DEBUG_NETWORK_ADDR_SRC = 'env'
else:
XBR_DEBUG_NETWORK_ADDR = '0x0000000000000000000000000000000000000000'
print('WARNING: The XBR smart contracts are not yet deployed to public networks. Please set XBR_DEBUG_NETWORK_ADDR manually.')
XBR_DEBUG_NETWORK_ADDR = '0xBfB616f885D581328FC6c3ad53481231Cc9b1bcf'
XBR_DEBUG_NETWORK_ADDR_SRC = 'builtin'

if 'XBR_DEBUG_MARKET_ADDR' in os.environ:
_mrkt_adr = os.environ['XBR_DEBUG_MARKET_ADDR']
Expand All @@ -74,9 +74,10 @@
except Exception as e:
raise RuntimeError('could not parse Ethereum address for XBR_DEBUG_MARKET_ADDR={} - {}'.format(_mrkt_adr, e))
XBR_DEBUG_MARKET_ADDR = _mrkt_adr
XBR_DEBUG_MARKET_ADDR_SRC = 'env'
else:
XBR_DEBUG_MARKET_ADDR = '0x0000000000000000000000000000000000000000'
print('WARNING: The XBR smart contracts are not yet deployed to public networks. Please set XBR_DEBUG_MARKET_ADDR manually.')
XBR_DEBUG_MARKET_ADDR = '0x27d4E6534134d9B1b5E2190cf8Ea170C8D05fb66'
XBR_DEBUG_MARKET_ADDR_SRC = 'builtin'

if 'XBR_DEBUG_CATALOG_ADDR' in os.environ:
_ctlg_adr = os.environ['XBR_DEBUG_CATALOG_ADDR']
Expand All @@ -86,9 +87,10 @@
except Exception as e:
raise RuntimeError('could not parse Ethereum address for XBR_DEBUG_CATALOG_ADDR={} - {}'.format(_ctlg_adr, e))
XBR_DEBUG_CATALOG_ADDR = _ctlg_adr
XBR_DEBUG_CATALOG_ADDR_SRC = 'env'
else:
XBR_DEBUG_CATALOG_ADDR = '0x0000000000000000000000000000000000000000'
print('WARNING: The XBR smart contracts are not yet deployed to public networks. Please set XBR_DEBUG_CATALOG_ADDR manually.')
XBR_DEBUG_CATALOG_ADDR = '0x96284C34bD2A805589F9673F2534ED691672cAa0'
XBR_DEBUG_CATALOG_ADDR_SRC = 'builtin'

if 'XBR_DEBUG_CHANNEL_ADDR' in os.environ:
_chnl_adr = os.environ['XBR_DEBUG_CHANNEL_ADDR']
Expand All @@ -98,19 +100,32 @@
except Exception as e:
raise RuntimeError('could not parse Ethereum address for XBR_DEBUG_CHANNEL_ADDR={} - {}'.format(_chnl_adr, e))
XBR_DEBUG_CHANNEL_ADDR = _chnl_adr
XBR_DEBUG_CHANNEL_ADDR_SRC = 'env'
else:
XBR_DEBUG_CHANNEL_ADDR = '0x0000000000000000000000000000000000000000'
print('WARNING: The XBR smart contracts are not yet deployed to public networks. Please set XBR_DEBUG_CHANNEL_ADDR manually.')
XBR_DEBUG_CHANNEL_ADDR = '0xA20C8bA0e86606cCBEE14A50acA0604Ce667F508'
XBR_DEBUG_CHANNEL_ADDR_SRC = 'builtin'


def _load_json(contract_name):
fn = pkg_resources.resource_filename('autobahn', 'xbr/contracts/{}.json'.format(contract_name))
# fn = os.path.join(os.path.dirname(__file__), '../build/contracts/{}.json'.format(contract_name))
with open(fn) as f:
data = json.loads(f.read())
return data


#
# XBR contract ABI file names
#
XBR_TOKEN_FN = pkg_resources.resource_filename('autobahn', 'xbr/contracts/XBRToken.json')
XBR_NETWORK_FN = pkg_resources.resource_filename('autobahn', 'xbr/contracts/XBRNetwork.json')
XBR_MARKET_FN = pkg_resources.resource_filename('autobahn', 'xbr/contracts/XBRMarket.json')
XBR_CATALOG_FN = pkg_resources.resource_filename('autobahn', 'xbr/contracts/XBRCatalog.json')
XBR_CHANNEL_FN = pkg_resources.resource_filename('autobahn', 'xbr/contracts/XBRChannel.json')


#
# XBR contract ABIs
#
XBR_TOKEN_ABI = _load_json('XBRToken')['abi']
XBR_NETWORK_ABI = _load_json('XBRNetwork')['abi']
XBR_MARKET_ABI = _load_json('XBRMarket')['abi']
Expand Down

0 comments on commit d99c094

Please sign in to comment.