Initial commit
This commit is contained in:
1
python/okota/accounts_index/__init__.py
Normal file
1
python/okota/accounts_index/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .accounts_index import *
|
||||
54
python/okota/accounts_index/accounts_index.py
Normal file
54
python/okota/accounts_index/accounts_index.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# standard imports
|
||||
import os
|
||||
|
||||
# external imports
|
||||
from chainlib.eth.tx import (
|
||||
TxFormat,
|
||||
)
|
||||
from chainlib.eth.contract import (
|
||||
ABIContractEncoder,
|
||||
ABIContractType,
|
||||
)
|
||||
from eth_accounts_index.interface import AccountsIndex
|
||||
|
||||
moddir = os.path.dirname(__file__)
|
||||
datadir = os.path.join(moddir, '..', 'data')
|
||||
|
||||
|
||||
class AccountsIndexAddressDeclarator(AccountsIndex):
|
||||
|
||||
__abi = None
|
||||
__bytecode = None
|
||||
|
||||
@staticmethod
|
||||
def abi():
|
||||
if AccountsIndexAddressDeclarator.__abi == None:
|
||||
f = open(os.path.join(datadir, 'AccountsIndexAddressDeclarator.json'), 'r')
|
||||
AccountsIndexAddressDeclarator.__abi = json.load(f)
|
||||
f.close()
|
||||
return AccountsIndexAddressDeclarator.__abi
|
||||
|
||||
|
||||
@staticmethod
|
||||
def bytecode():
|
||||
if AccountsIndexAddressDeclarator.__bytecode == None:
|
||||
f = open(os.path.join(datadir, 'AccountsIndexAddressDeclarator.bin'))
|
||||
AccountsIndexAddressDeclarator.__bytecode = f.read()
|
||||
f.close()
|
||||
return AccountsIndexAddressDeclarator.__bytecode
|
||||
|
||||
|
||||
@staticmethod
|
||||
def gas(code=None):
|
||||
return 700000
|
||||
|
||||
|
||||
def constructor(self, sender_address, context_address, address_declarator_address):
|
||||
code = AccountsIndexAddressDeclarator.bytecode()
|
||||
tx = self.template(sender_address, None, use_nonce=True)
|
||||
enc = ABIContractEncoder()
|
||||
enc.address(context_address)
|
||||
enc.address(address_declarator_address)
|
||||
code += enc.get()
|
||||
tx = self.set_code(tx, code)
|
||||
return self.build(tx)
|
||||
85
python/okota/accounts_index/runnable/deploy.py
Normal file
85
python/okota/accounts_index/runnable/deploy.py
Normal file
@@ -0,0 +1,85 @@
|
||||
"""Deploys accounts index, registering arbitrary number of writers
|
||||
|
||||
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
|
||||
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
||||
|
||||
"""
|
||||
|
||||
# standard imports
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
# external imports
|
||||
import chainlib.eth.cli
|
||||
from chainlib.chain import ChainSpec
|
||||
from chainlib.eth.connection import EthHTTPConnection
|
||||
from chainlib.eth.tx import receipt
|
||||
|
||||
# local imports
|
||||
from eth_address_declarator.accounts_index import AccountsIndexAddressDeclarator
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
|
||||
arg_flags = chainlib.eth.cli.argflag_std_write
|
||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
||||
argparser.add_argument('--address-declarator', type=str, required=True, dest='address_declarator', help='address declarator backend address')
|
||||
argparser.add_argument('--token-address', type=str, required=True, dest='token_address', help='token address context for accounts registry')
|
||||
args = argparser.parse_args()
|
||||
|
||||
extra_args = {
|
||||
'address_declarator': None,
|
||||
'token_address': None,
|
||||
}
|
||||
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=AccountsIndexAddressDeclarator.gas())
|
||||
|
||||
wallet = chainlib.eth.cli.Wallet()
|
||||
wallet.from_config(config)
|
||||
|
||||
rpc = chainlib.eth.cli.Rpc(wallet=wallet)
|
||||
conn = rpc.connect_by_config(config)
|
||||
|
||||
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
||||
|
||||
|
||||
def main():
|
||||
signer = rpc.get_signer()
|
||||
signer_address = rpc.get_sender_address()
|
||||
|
||||
gas_oracle = rpc.get_gas_oracle()
|
||||
nonce_oracle = rpc.get_nonce_oracle()
|
||||
|
||||
address_declarator = config.get('_ADDRESS_DECLARATOR')
|
||||
if not config.true('_UNSAFE') and not is_checksum_address(address_declarator):
|
||||
raise ValueError('address declarator {} is not a valid checksum address'.format(address_declarator))
|
||||
|
||||
token_address = config.get('_TOKEN_ADDRESS')
|
||||
if not config.true('_UNSAFE') and not is_checksum_address(token_address):
|
||||
raise ValueError('token {} is not a valid checksum address'.format(token_address))
|
||||
|
||||
c = AccountsIndexAddressDeclarator(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
|
||||
|
||||
(tx_hash_hex, o) = c.constructor(signer_address, token_address, address_declarator)
|
||||
|
||||
if config.get('_RPC_SEND'):
|
||||
conn.do(o)
|
||||
if config.get('_WAIT'):
|
||||
r = conn.wait(tx_hash_hex)
|
||||
if r['status'] == 0:
|
||||
sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
|
||||
sys.exit(1)
|
||||
# TODO: pass through translator for keys (evm tester uses underscore instead of camelcase)
|
||||
address = r['contractAddress']
|
||||
|
||||
print(address)
|
||||
else:
|
||||
print(tx_hash_hex)
|
||||
else:
|
||||
print(o)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
1
python/okota/data/AccountsIndexAddressDeclarator.bin
Normal file
1
python/okota/data/AccountsIndexAddressDeclarator.bin
Normal file
File diff suppressed because one or more lines are too long
1
python/okota/data/AccountsIndexAddressDeclarator.json
Normal file
1
python/okota/data/AccountsIndexAddressDeclarator.json
Normal file
@@ -0,0 +1 @@
|
||||
[{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"address","name":"_addressDeclaratorAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addedAccount","type":"address"},{"indexed":true,"internalType":"uint256","name":"accountIndex","type":"uint256"}],"name":"AddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"add","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"addressDeclaratorAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"have","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
[{"inputs":[{"internalType":"address","name":"_addressDeclaratorAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addedAccount","type":"address"},{"indexed":true,"internalType":"uint256","name":"accountIndex","type":"uint256"}],"name":"AddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"add","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"addressDeclaratorAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_key","type":"bytes32"}],"name":"addressOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"entry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"entryCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"register","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"registry","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
||||
1
python/okota/token_index/__init__.py
Normal file
1
python/okota/token_index/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .interface import *
|
||||
77
python/okota/token_index/index.py
Normal file
77
python/okota/token_index/index.py
Normal file
@@ -0,0 +1,77 @@
|
||||
# Author: Louis Holbrook <dev@holbrook.no> 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
# File-version: 1
|
||||
# Description: Python interface to abi and bin files for token index with address declarator backend
|
||||
|
||||
# standard imports
|
||||
import logging
|
||||
import json
|
||||
import os
|
||||
import hashlib
|
||||
|
||||
# external imports
|
||||
from chainlib.eth.contract import (
|
||||
ABIContractEncoder,
|
||||
ABIContractType,
|
||||
abi_decode_single,
|
||||
)
|
||||
from chainlib.eth.tx import (
|
||||
TxFactory,
|
||||
TxFormat,
|
||||
)
|
||||
from chainlib.jsonrpc import JSONRPCRequest
|
||||
from chainlib.eth.constant import ZERO_ADDRESS
|
||||
from hexathon import (
|
||||
add_0x,
|
||||
)
|
||||
|
||||
# local imports
|
||||
from .interface import (
|
||||
TokenUniqueSymbolIndex,
|
||||
to_identifier,
|
||||
)
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
moddir = os.path.dirname(__file__)
|
||||
datadir = os.path.join(moddir, '..', 'data')
|
||||
|
||||
|
||||
|
||||
class TokenUniqueSymbolIndexAddressDeclarator(TokenUniqueSymbolIndex):
|
||||
|
||||
__abi = None
|
||||
__bytecode = None
|
||||
|
||||
|
||||
@staticmethod
|
||||
def abi():
|
||||
if TokenUniqueSymbolIndexAddressDeclarator.__abi == None:
|
||||
f = open(os.path.join(datadir, 'TokenUniqueSymbolIndexAddressDeclarator.json'), 'r')
|
||||
TokenUniqueSymbolIndexAddressDeclarator.__abi = json.load(f)
|
||||
f.close()
|
||||
return TokenUniqueSymbolIndexAddressDeclarator.__abi
|
||||
|
||||
|
||||
@staticmethod
|
||||
def bytecode():
|
||||
if TokenUniqueSymbolIndexAddressDeclarator.__bytecode == None:
|
||||
f = open(os.path.join(datadir, 'TokenUniqueSymbolIndexAddressDeclarator.bin'))
|
||||
TokenUniqueSymbolIndexAddressDeclarator.__bytecode = f.read()
|
||||
f.close()
|
||||
return TokenUniqueSymbolIndexAddressDeclarator.__bytecode
|
||||
|
||||
|
||||
@staticmethod
|
||||
def gas(code=None):
|
||||
return 2000000
|
||||
|
||||
|
||||
def constructor(self, sender_address, address_declarator_address):
|
||||
code = TokenUniqueSymbolIndexAddressDeclarator.bytecode()
|
||||
tx = self.template(sender_address, None, use_nonce=True)
|
||||
enc = ABIContractEncoder()
|
||||
enc.address(address_declarator_address)
|
||||
code += enc.get()
|
||||
tx = self.set_code(tx, code)
|
||||
return self.build(tx)
|
||||
113
python/okota/token_index/interface.py
Normal file
113
python/okota/token_index/interface.py
Normal file
@@ -0,0 +1,113 @@
|
||||
# Author: Louis Holbrook <dev@holbrook.no> 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
# File-version: 1
|
||||
# Description: Python interface to abi and bin files for faucet contracts
|
||||
|
||||
# standard imports
|
||||
import logging
|
||||
import json
|
||||
import os
|
||||
import hashlib
|
||||
|
||||
# external imports
|
||||
from chainlib.eth.contract import (
|
||||
ABIContractEncoder,
|
||||
ABIContractType,
|
||||
abi_decode_single,
|
||||
)
|
||||
from chainlib.eth.tx import (
|
||||
TxFactory,
|
||||
TxFormat,
|
||||
)
|
||||
from chainlib.jsonrpc import JSONRPCRequest
|
||||
from chainlib.eth.constant import ZERO_ADDRESS
|
||||
from hexathon import (
|
||||
add_0x,
|
||||
)
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
moddir = os.path.dirname(__file__)
|
||||
datadir = os.path.join(moddir, '..', 'data')
|
||||
|
||||
|
||||
def to_identifier(s):
|
||||
h = hashlib.new('sha256')
|
||||
h.update(s.encode('utf-8'))
|
||||
return h.digest().hex()
|
||||
|
||||
|
||||
class TokenUniqueSymbolIndex(TxFactory):
|
||||
|
||||
def register(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
||||
enc = ABIContractEncoder()
|
||||
enc.method('register')
|
||||
enc.typ(ABIContractType.ADDRESS)
|
||||
enc.address(address)
|
||||
data = enc.get()
|
||||
tx = self.template(sender_address, contract_address, use_nonce=True)
|
||||
tx = self.set_code(tx, data)
|
||||
tx = self.finalize(tx, tx_format)
|
||||
return tx
|
||||
|
||||
|
||||
def address_of(self, contract_address, token_symbol, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||
j = JSONRPCRequest(id_generator)
|
||||
o = j.template()
|
||||
o['method'] = 'eth_call'
|
||||
enc = ABIContractEncoder()
|
||||
enc.method('addressOf')
|
||||
enc.typ(ABIContractType.BYTES32)
|
||||
token_symbol_digest = to_identifier(token_symbol)
|
||||
enc.bytes32(token_symbol_digest)
|
||||
data = add_0x(enc.get())
|
||||
tx = self.template(sender_address, contract_address)
|
||||
tx = self.set_code(tx, data)
|
||||
o['params'].append(self.normalize(tx))
|
||||
o = j.finalize(o)
|
||||
return o
|
||||
|
||||
|
||||
def entry(self, contract_address, idx, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||
j = JSONRPCRequest(id_generator)
|
||||
o = j.template()
|
||||
o['method'] = 'eth_call'
|
||||
enc = ABIContractEncoder()
|
||||
enc.method('entry')
|
||||
enc.typ(ABIContractType.UINT256)
|
||||
enc.uint256(idx)
|
||||
data = add_0x(enc.get())
|
||||
tx = self.template(sender_address, contract_address)
|
||||
tx = self.set_code(tx, data)
|
||||
o['params'].append(self.normalize(tx))
|
||||
o = j.finalize(o)
|
||||
return o
|
||||
|
||||
|
||||
def entry_count(self, contract_address, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||
j = JSONRPCRequest(id_generator)
|
||||
o = j.template()
|
||||
o['method'] = 'eth_call'
|
||||
enc = ABIContractEncoder()
|
||||
enc.method('entryCount')
|
||||
data = add_0x(enc.get())
|
||||
tx = self.template(sender_address, contract_address)
|
||||
tx = self.set_code(tx, data)
|
||||
o['params'].append(self.normalize(tx))
|
||||
o = j.finalize(o)
|
||||
return o
|
||||
|
||||
|
||||
@classmethod
|
||||
def parse_address_of(self, v):
|
||||
return abi_decode_single(ABIContractType.ADDRESS, v)
|
||||
|
||||
|
||||
@classmethod
|
||||
def parse_entry(self, v):
|
||||
return abi_decode_single(ABIContractType.ADDRESS, v)
|
||||
|
||||
|
||||
@classmethod
|
||||
def parse_entry_count(self, v):
|
||||
return abi_decode_single(ABIContractType.UINT256, v)
|
||||
78
python/okota/token_index/runnable/deploy.py
Normal file
78
python/okota/token_index/runnable/deploy.py
Normal file
@@ -0,0 +1,78 @@
|
||||
"""Deploys the token symbol index
|
||||
|
||||
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
|
||||
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
||||
|
||||
"""
|
||||
|
||||
# standard imports
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
# external imports
|
||||
import chainlib.eth.cli
|
||||
from chainlib.chain import ChainSpec
|
||||
from chainlib.eth.tx import receipt
|
||||
|
||||
# local imports
|
||||
from eth_address_declarator.token_index.index import TokenUniqueSymbolIndexAddressDeclarator
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
|
||||
arg_flags = chainlib.eth.cli.argflag_std_write
|
||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
||||
argparser.add_argument('--address-declarator', type=str, required=True, dest='address_declarator', help='address declarator backend address')
|
||||
args = argparser.parse_args()
|
||||
|
||||
extra_args = {
|
||||
'address_declarator': None,
|
||||
}
|
||||
|
||||
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=TokenUniqueSymbolIndexAddressDeclarator.gas())
|
||||
|
||||
wallet = chainlib.eth.cli.Wallet()
|
||||
wallet.from_config(config)
|
||||
|
||||
rpc = chainlib.eth.cli.Rpc(wallet=wallet)
|
||||
conn = rpc.connect_by_config(config)
|
||||
|
||||
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
||||
|
||||
|
||||
def main():
|
||||
signer = rpc.get_signer()
|
||||
signer_address = rpc.get_sender_address()
|
||||
|
||||
gas_oracle = rpc.get_gas_oracle()
|
||||
nonce_oracle = rpc.get_nonce_oracle()
|
||||
|
||||
address_declarator = config.get('_ADDRESS_DECLARATOR')
|
||||
if not config.true('_UNSAFE') and not is_checksum_address(address_declarator):
|
||||
raise ValueError('address declarator {} is not a valid checksum address'.format(address_declarator))
|
||||
|
||||
c = TokenUniqueSymbolIndexAddressDeclarator(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
|
||||
|
||||
(tx_hash_hex, o) = c.constructor(signer_address, config.get('_ADDRESS_DECLARATOR'))
|
||||
if config.get('_RPC_SEND'):
|
||||
conn.do(o)
|
||||
if config.get('_WAIT'):
|
||||
r = conn.wait(tx_hash_hex)
|
||||
if r['status'] == 0:
|
||||
sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
|
||||
sys.exit(1)
|
||||
# TODO: pass through translator for keys (evm tester uses underscore instead of camelcase)
|
||||
address = r['contractAddress']
|
||||
|
||||
print(address)
|
||||
else:
|
||||
print(tx_hash_hex)
|
||||
else:
|
||||
print(o)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
7
python/requirements.txt
Normal file
7
python/requirements.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
confini>=0.3.6rc3,<0.5.0
|
||||
crypto-dev-signer>=0.4.15rc2,<=0.4.15
|
||||
chainlib-eth>=0.0.9a13,<=0.1.0
|
||||
eth_erc20>=0.1.2a3,<=0.2.0
|
||||
eth-address-index>=0.2.4a1,<=0.3.0
|
||||
eth-accounts-index>=0.1.2a3,<=0.2.0
|
||||
#eth-token-index>=0.2.4a1,<=0.3.0
|
||||
50
python/setup.cfg
Normal file
50
python/setup.cfg
Normal file
@@ -0,0 +1,50 @@
|
||||
[metadata]
|
||||
name = okota
|
||||
version = 0.0.1a1
|
||||
description = Signed metadata declarations for ethereum addresses
|
||||
author = Louis Holbrook
|
||||
author_email = dev@holbrook.no
|
||||
url = https://gitlab.com/cicnet/okota
|
||||
keywords =
|
||||
ethereum
|
||||
classifiers =
|
||||
Programming Language :: Python :: 3
|
||||
Operating System :: OS Independent
|
||||
Development Status :: 3 - Alpha
|
||||
Environment :: No Input/Output (Daemon)
|
||||
Intended Audience :: Developers
|
||||
License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
||||
Topic :: Internet
|
||||
#Topic :: Blockchain :: EVM
|
||||
license = GPL3
|
||||
licence_files =
|
||||
LICENSE
|
||||
|
||||
[options]
|
||||
include_package_data = True
|
||||
python_requires = >= 3.6
|
||||
packages =
|
||||
okota.token_index
|
||||
okota.accounts_index
|
||||
|
||||
[options.extras_require]
|
||||
testing =
|
||||
eth-tester==0.5.0b2
|
||||
py-evm==0.3.0a20
|
||||
|
||||
[options.package_data]
|
||||
* =
|
||||
#data/AddressDeclarator.json
|
||||
#data/AddressDeclarator.bin
|
||||
#data/GiftableToken.bin
|
||||
#data/GifttableToken.json
|
||||
data/TokenUniqueSymbolIndexAddressDeclarator.bin
|
||||
data/TokenUniqueSymbolIndexAddressDeclarator.json
|
||||
data/AccountsIndexAddressDeclarator.bin
|
||||
data/AccountsIndexAddressDeclarator.json
|
||||
data/ERC20.json
|
||||
|
||||
[options.entry_points]
|
||||
console_scripts =
|
||||
okota-accounts-index-deploy = okota.accounts_index.runnable.deploy:main
|
||||
okota-token-index-deploy = okota.token_index.runnable.deploy:main
|
||||
25
python/setup.py
Normal file
25
python/setup.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from setuptools import setup
|
||||
|
||||
requirements = []
|
||||
f = open('requirements.txt', 'r')
|
||||
while True:
|
||||
l = f.readline()
|
||||
if l == '':
|
||||
break
|
||||
requirements.append(l.rstrip())
|
||||
f.close()
|
||||
|
||||
test_requirements = []
|
||||
f = open('test_requirements.txt', 'r')
|
||||
while True:
|
||||
l = f.readline()
|
||||
if l == '':
|
||||
break
|
||||
test_requirements.append(l.rstrip())
|
||||
f.close()
|
||||
|
||||
|
||||
setup(
|
||||
install_requires=requirements,
|
||||
tests_require=test_requirements,
|
||||
)
|
||||
2
python/test_requirements.txt
Normal file
2
python/test_requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
eth-tester==0.5.0b3
|
||||
py-evm==0.3.0a20
|
||||
72
python/tests/test_accounts_index.py
Normal file
72
python/tests/test_accounts_index.py
Normal file
@@ -0,0 +1,72 @@
|
||||
# standard imports
|
||||
import unittest
|
||||
import logging
|
||||
import hashlib
|
||||
|
||||
# external imports
|
||||
from eth_accounts_index import AccountsIndex
|
||||
from chainlib.eth.nonce import RPCNonceOracle
|
||||
from giftable_erc20_token import GiftableToken
|
||||
from chainlib.eth.tx import receipt
|
||||
from chainlib.eth.contract import ABIContractEncoder
|
||||
from eth_address_declarator import Declarator
|
||||
from eth_address_declarator.unittest import TestAddressDeclaratorBase
|
||||
|
||||
# local imports
|
||||
from okota.accounts_index import AccountsIndexAddressDeclarator
|
||||
|
||||
# test imports
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
class TestAccountsIndex(TestAddressDeclaratorBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAccountsIndex, self).setUp()
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||
|
||||
c = AccountsIndexAddressDeclarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = c.constructor(self.accounts[0], self.foo_token_address, self.address)
|
||||
r = self.rpc.do(o)
|
||||
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.rpc.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
self.accounts_index_address = r['contract_address']
|
||||
logg.debug('accounts index deployed with address {}'.format(self.accounts_index_address))
|
||||
|
||||
|
||||
def test_accounts_index_address_declarator(self):
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||
c = AccountsIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash, o) = c.add(self.accounts_index_address, self.accounts[0], self.accounts[1])
|
||||
r = self.rpc.do(o)
|
||||
self.assertEqual(tx_hash, r)
|
||||
|
||||
o = receipt(tx_hash)
|
||||
rcpt = self.rpc.do(o)
|
||||
|
||||
self.helper.mine_block()
|
||||
o = c.have(self.accounts_index_address, self.accounts[1], sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
|
||||
c = Declarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
o = c.declaration(self.address, self.accounts[0], self.accounts[1], sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
proofs = c.parse_declaration(r)
|
||||
|
||||
enc = ABIContractEncoder()
|
||||
enc.address(self.foo_token_address)
|
||||
token_address_padded = enc.get()
|
||||
logg.debug('proof {} {}'.format(proofs, token_address_padded))
|
||||
h = hashlib.sha256()
|
||||
h.update(bytes.fromhex(token_address_padded))
|
||||
r = h.digest()
|
||||
self.assertEqual(r.hex(), proofs[0])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
87
python/tests/test_tokenindex.py
Normal file
87
python/tests/test_tokenindex.py
Normal file
@@ -0,0 +1,87 @@
|
||||
# standard imports
|
||||
import os
|
||||
import unittest
|
||||
import json
|
||||
import logging
|
||||
import hashlib
|
||||
|
||||
# external imports
|
||||
from chainlib.eth.unittest.ethtester import EthTesterCase
|
||||
from chainlib.eth.nonce import RPCNonceOracle
|
||||
from chainlib.eth.tx import receipt
|
||||
from giftable_erc20_token import GiftableToken
|
||||
from chainlib.eth.tx import unpack
|
||||
from hexathon import strip_0x
|
||||
from chainlib.eth.contract import ABIContractEncoder
|
||||
from eth_address_declarator import Declarator
|
||||
|
||||
# local imports
|
||||
from okota.token_index.index import (
|
||||
TokenUniqueSymbolIndexAddressDeclarator as TokenIndex,
|
||||
to_identifier,
|
||||
)
|
||||
|
||||
# test imports
|
||||
from eth_address_declarator.unittest import TestAddressDeclaratorBase
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
testdir = os.path.dirname(__file__)
|
||||
|
||||
|
||||
class TestTokenIndex(TestAddressDeclaratorBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestTokenIndex, self).setUp()
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||
c = TokenIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = c.constructor(self.accounts[0], self.address)
|
||||
self.rpc.do(o)
|
||||
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.rpc.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
self.token_index_address = r['contract_address']
|
||||
|
||||
|
||||
def test_register(self):
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||
c = TokenIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
|
||||
(tx_hash_hex, o) = c.register(self.token_index_address, self.accounts[0], self.foo_token_address)
|
||||
self.rpc.do(o)
|
||||
e = unpack(bytes.fromhex(strip_0x(o['params'][0])), self.chain_spec)
|
||||
|
||||
o = receipt(tx_hash_hex)
|
||||
r = self.rpc.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
o = c.address_of(self.token_index_address, 'FOO', sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
address = c.parse_address_of(r)
|
||||
self.assertEqual(address, strip_0x(self.foo_token_address))
|
||||
|
||||
o = c.entry(self.token_index_address, 0, sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
address = c.parse_entry(r)
|
||||
self.assertEqual(address, strip_0x(self.foo_token_address))
|
||||
|
||||
o = c.entry_count(self.token_index_address, sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
count = c.parse_entry_count(r)
|
||||
self.assertEqual(count, 1)
|
||||
|
||||
c = Declarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||
o = c.declaration(self.address, self.accounts[0], self.foo_token_address, sender_address=self.accounts[0])
|
||||
r = self.rpc.do(o)
|
||||
proofs = c.parse_declaration(r)
|
||||
|
||||
token_symbol_identifier = to_identifier('FOO')
|
||||
|
||||
self.assertEqual(token_symbol_identifier, proofs[0])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user