mirror of
git://holbrook.no/eth-address-index
synced 2025-01-08 01:57:33 +01:00
Rehabilitate token index runnables
This commit is contained in:
parent
4f753b990e
commit
799c97a7ed
@ -61,6 +61,11 @@ class TokenUniqueSymbolIndex(TxFactory):
|
||||
return TokenUniqueSymbolIndex.__bytecode
|
||||
|
||||
|
||||
@staticmethod
|
||||
def gas(code=None):
|
||||
return 1200000
|
||||
|
||||
|
||||
def constructor(self, sender_address):
|
||||
code = TokenUniqueSymbolIndex.bytecode()
|
||||
tx = self.template(sender_address, None, use_nonce=True)
|
||||
|
@ -6,6 +6,7 @@
|
||||
"""
|
||||
|
||||
# standard imports
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import argparse
|
||||
@ -13,18 +14,21 @@ import logging
|
||||
import hashlib
|
||||
|
||||
# third-party imports
|
||||
import web3
|
||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
||||
from crypto_dev_signer.keystore import DictKeystore
|
||||
from crypto_dev_signer.eth.helper import EthTxExecutor
|
||||
from crypto_dev_signer.keystore.dict import DictKeystore
|
||||
from chainlib.chain import ChainSpec
|
||||
from chainlib.eth.nonce import RPCNonceOracle
|
||||
from chainlib.eth.gas import RPCGasOracle
|
||||
from chainlib.eth.connection import EthHTTPConnection
|
||||
from chainlib.eth.tx import receipt
|
||||
from chainlib.eth.erc20 import ERC20
|
||||
|
||||
# local imports
|
||||
from eth_token_index import TokenUniqueSymbolIndex
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
|
||||
logging.getLogger('web3').setLevel(logging.WARNING)
|
||||
logging.getLogger('urllib3').setLevel(logging.WARNING)
|
||||
|
||||
script_dir = os.path.dirname(__file__)
|
||||
data_dir = os.path.join(script_dir, '..', 'data')
|
||||
|
||||
@ -34,12 +38,11 @@ argparser.add_argument('-w', action='store_true', help='Wait for the last transa
|
||||
argparser.add_argument('-ww', action='store_true', help='Wait for every transaction to be confirmed')
|
||||
argparser.add_argument('-y', '--key-file', dest='y', type=str, help='Ethereum keystore file to use for signing')
|
||||
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='Ethereum:1', help='Chain specification string')
|
||||
argparser.add_argument('-r', '--contract-address', dest='r', type=str, help='Token endorsement contract address')
|
||||
argparser.add_argument('-a', '--signer-address', dest='a', type=str, help='Accounts declarator owner')
|
||||
argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=data_dir, help='Directory containing bytecode and abi (default: {})'.format(data_dir))
|
||||
argparser.add_argument('-a', '--contract-address', dest='a', required=True, type=str, help='Token index contract address')
|
||||
argparser.add_argument('-v', action='store_true', help='Be verbose')
|
||||
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
|
||||
argparser.add_argument('address', type=str, help='Ethereum address to add declaration to')
|
||||
argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration')
|
||||
argparser.add_argument('token_address', type=str, help='Token address to add to index')
|
||||
args = argparser.parse_args()
|
||||
|
||||
if args.vv:
|
||||
@ -50,57 +53,53 @@ elif args.v:
|
||||
block_all = args.ww
|
||||
block_last = args.w or block_all
|
||||
|
||||
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
|
||||
passphrase_env = 'ETH_PASSPHRASE'
|
||||
if args.env_prefix != None:
|
||||
passphrase_env = args.env_prefix + '_' + passphrase_env
|
||||
passphrase = os.environ.get(passphrase_env)
|
||||
if passphrase == None:
|
||||
logg.warning('no passphrase given')
|
||||
passphrase=''
|
||||
|
||||
signer_address = None
|
||||
keystore = DictKeystore()
|
||||
if args.y != None:
|
||||
logg.debug('loading keystore file {}'.format(args.y))
|
||||
signer_address = keystore.import_keystore_file(args.y)
|
||||
signer_address = keystore.import_keystore_file(args.y, password=passphrase)
|
||||
logg.debug('now have key for signer address {}'.format(signer_address))
|
||||
signer = EIP155Signer(keystore)
|
||||
|
||||
chain_spec = ChainSpec.from_chain_str(args.i)
|
||||
chain_id = chain_spec.network_id()
|
||||
|
||||
helper = EthTxExecutor(
|
||||
w3,
|
||||
signer_address,
|
||||
signer,
|
||||
chain_id,
|
||||
block=args.ww,
|
||||
)
|
||||
rpc = EthHTTPConnection(args.p)
|
||||
nonce_oracle = RPCNonceOracle(signer_address, rpc)
|
||||
gas_oracle = RPCGasOracle(rpc, code_callback=TokenUniqueSymbolIndex.gas)
|
||||
contract_address = args.a
|
||||
token_address = args.token_address
|
||||
|
||||
|
||||
def main():
|
||||
f = open(os.path.join(args.abi_dir, 'TokenUniqueSymbolIndex.json'), 'r')
|
||||
abi = json.load(f)
|
||||
f.close()
|
||||
c = TokenUniqueSymbolIndex(signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle, chain_id=chain_id)
|
||||
(tx_hash_hex, o) = c.register(contract_address, signer_address, token_address)
|
||||
rpc.do(o)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = rpc.do(o)
|
||||
if r['status'] == 0:
|
||||
sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
|
||||
sys.exit(1)
|
||||
|
||||
f = open(os.path.join(args.abi_dir, 'ERC20.json'), 'r')
|
||||
erc20_abi = json.load(f)
|
||||
f.close()
|
||||
|
||||
t = w3.eth.contract(abi=erc20_abi, address=args.address)
|
||||
token_symbol = t.functions.symbol().call()
|
||||
|
||||
c = w3.eth.contract(abi=abi, address=args.r)
|
||||
|
||||
h = hashlib.new('sha256')
|
||||
h.update(token_symbol.encode('utf-8'))
|
||||
z = h.digest()
|
||||
logg.info('token symbol {} => {}'.format(token_symbol, z.hex()))
|
||||
|
||||
(tx_hash, rcpt) = helper.sign_and_send(
|
||||
[
|
||||
c.functions.register('0x' + z.hex(), args.address).buildTransaction,
|
||||
],
|
||||
)
|
||||
c = ERC20()
|
||||
o = c.symbol(token_address)
|
||||
r = rpc.do(o)
|
||||
token_symbol = ERC20.parse_symbol(r)
|
||||
|
||||
if block_last:
|
||||
helper.wait_for()
|
||||
|
||||
print(tx_hash)
|
||||
logg.info('added token {} at {} to token index {}'.format(token_symbol, token_address, contract_address))
|
||||
|
||||
print(tx_hash_hex)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -6,24 +6,27 @@
|
||||
"""
|
||||
|
||||
# standard imports
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
# third-party imports
|
||||
import web3
|
||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
||||
from crypto_dev_signer.keystore import DictKeystore
|
||||
from crypto_dev_signer.eth.helper import EthTxExecutor
|
||||
from crypto_dev_signer.keystore.dict import DictKeystore
|
||||
from chainlib.chain import ChainSpec
|
||||
from chainlib.eth.nonce import RPCNonceOracle
|
||||
from chainlib.eth.gas import RPCGasOracle
|
||||
from chainlib.eth.connection import EthHTTPConnection
|
||||
from chainlib.eth.tx import receipt
|
||||
|
||||
# local imports
|
||||
from eth_token_index import TokenUniqueSymbolIndex
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
|
||||
logging.getLogger('web3').setLevel(logging.WARNING)
|
||||
logging.getLogger('urllib3').setLevel(logging.WARNING)
|
||||
|
||||
script_dir = os.path.dirname(__file__)
|
||||
data_dir = os.path.join(script_dir, '..', 'data')
|
||||
|
||||
@ -32,11 +35,10 @@ argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8
|
||||
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='Ethereum:1', help='Chain specification string')
|
||||
argparser.add_argument('-w', action='store_true', help='Wait for the last transaction to be confirmed')
|
||||
argparser.add_argument('-ww', action='store_true', help='Wait for every transaction to be confirmed')
|
||||
argparser.add_argument('-a', '--signer-address', dest='a', type=str, help='Accounts declarator owner')
|
||||
argparser.add_argument('-y', '--key-file', dest='y', type=str, help='Ethereum keystore file to use for signing')
|
||||
argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=data_dir, help='Directory containing bytecode and abi (default: {})'.format(data_dir))
|
||||
argparser.add_argument('-v', action='store_true', help='Be verbose')
|
||||
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
|
||||
argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration')
|
||||
args = argparser.parse_args()
|
||||
|
||||
if args.vv:
|
||||
@ -47,46 +49,49 @@ elif args.v:
|
||||
block_last = args.w
|
||||
block_all = args.ww
|
||||
|
||||
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
|
||||
passphrase_env = 'ETH_PASSPHRASE'
|
||||
if args.env_prefix != None:
|
||||
passphrase_env = args.env_prefix + '_' + passphrase_env
|
||||
passphrase = os.environ.get(passphrase_env)
|
||||
if passphrase == None:
|
||||
logg.warning('no passphrase given')
|
||||
passphrase=''
|
||||
|
||||
signer_address = None
|
||||
keystore = DictKeystore()
|
||||
if args.y != None:
|
||||
logg.debug('loading keystore file {}'.format(args.y))
|
||||
signer_address = keystore.import_keystore_file(args.y)
|
||||
signer_address = keystore.import_keystore_file(args.y, password=passphrase)
|
||||
logg.debug('now have key for signer address {}'.format(signer_address))
|
||||
signer = EIP155Signer(keystore)
|
||||
|
||||
chain_spec = ChainSpec.from_chain_str(args.i)
|
||||
chain_id = chain_spec.network_id()
|
||||
|
||||
helper = EthTxExecutor(
|
||||
w3,
|
||||
signer_address,
|
||||
signer,
|
||||
chain_id,
|
||||
block=args.ww,
|
||||
)
|
||||
rpc = EthHTTPConnection(args.p)
|
||||
nonce_oracle = RPCNonceOracle(signer_address, rpc)
|
||||
gas_oracle = RPCGasOracle(rpc, code_callback=TokenUniqueSymbolIndex.gas)
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
f = open(os.path.join(args.abi_dir, 'TokenUniqueSymbolIndex.json'), 'r')
|
||||
abi = json.load(f)
|
||||
f.close()
|
||||
c = TokenUniqueSymbolIndex(signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle, chain_id=chain_id)
|
||||
(tx_hash_hex, o) = c.constructor(signer_address)
|
||||
rpc.do(o)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = rpc.do(o)
|
||||
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']
|
||||
|
||||
f = open(os.path.join(args.abi_dir, 'TokenUniqueSymbolIndex.bin'), 'r')
|
||||
bytecode = f.read()
|
||||
f.close()
|
||||
if block_last:
|
||||
rpc.wait(tx_hash_hex)
|
||||
|
||||
c = w3.eth.contract(abi=abi, bytecode=bytecode)
|
||||
print(address)
|
||||
|
||||
(tx_hash, rcpt) = helper.sign_and_send(
|
||||
[
|
||||
c.constructor().buildTransaction,
|
||||
],
|
||||
force_wait=True,
|
||||
)
|
||||
print(rcpt.contractAddress)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -13,26 +13,25 @@ import logging
|
||||
import hashlib
|
||||
|
||||
# third-party imports
|
||||
import web3
|
||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
||||
from crypto_dev_signer.keystore import DictKeystore
|
||||
from crypto_dev_signer.eth.helper import EthTxExecutor
|
||||
from crypto_dev_signer.keystore.dict import DictKeystore
|
||||
from chainlib.chain import ChainSpec
|
||||
from chainlib.eth.connection import EthHTTPConnection
|
||||
from chainlib.eth.erc20 import ERC20
|
||||
|
||||
# local imports
|
||||
from eth_token_index import TokenUniqueSymbolIndex
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
|
||||
logging.getLogger('web3').setLevel(logging.WARNING)
|
||||
logging.getLogger('urllib3').setLevel(logging.WARNING)
|
||||
|
||||
script_dir = os.path.dirname(__file__)
|
||||
data_dir = os.path.join(script_dir, '..', 'data')
|
||||
|
||||
argparser = argparse.ArgumentParser()
|
||||
argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
|
||||
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='Ethereum:1', help='Chain specification string')
|
||||
argparser.add_argument('-a', '--contract-address', dest='a', type=str, help='Token endorsement contract address')
|
||||
argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=data_dir, help='Directory containing bytecode and abi (default: {})'.format(data_dir))
|
||||
argparser.add_argument('-a', '--contract-address', dest='a', type=str, required=True, help='Token endorsement contract address')
|
||||
argparser.add_argument('-v', action='store_true', help='Be verbose')
|
||||
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
|
||||
args = argparser.parse_args()
|
||||
@ -42,39 +41,27 @@ if args.vv:
|
||||
elif args.v:
|
||||
logg.setLevel(logging.INFO)
|
||||
|
||||
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
|
||||
rpc = EthHTTPConnection(args.p)
|
||||
contract_address = args.a
|
||||
|
||||
|
||||
def main():
|
||||
f = open(os.path.join(args.abi_dir, 'TokenUniqueSymbolIndex.json'), 'r')
|
||||
abi = json.load(f)
|
||||
f.close()
|
||||
ct = ERC20()
|
||||
c = TokenUniqueSymbolIndex()
|
||||
o = c.entry_count(contract_address)
|
||||
r = rpc.do(o)
|
||||
count = TokenUniqueSymbolIndex.parse_entry_count(r)
|
||||
|
||||
f = open(os.path.join(args.abi_dir, 'ERC20.json'), 'r')
|
||||
erc20_abi = json.load(f)
|
||||
f.close()
|
||||
for i in range(count):
|
||||
o = c.entry(contract_address, i)
|
||||
r = rpc.do(o)
|
||||
token_address = TokenUniqueSymbolIndex.parse_entry(r)
|
||||
|
||||
o = ct.symbol(token_address)
|
||||
r = rpc.do(o)
|
||||
token_symbol = ERC20.parse_symbol(r)
|
||||
|
||||
index_contract = w3.eth.contract(address=args.a, abi=abi)
|
||||
|
||||
token_addresses = []
|
||||
i = 0
|
||||
while True:
|
||||
try:
|
||||
token_addresses.append(index_contract.functions.entry(i).call())
|
||||
except ValueError:
|
||||
break
|
||||
i += 1
|
||||
|
||||
|
||||
for token_address in token_addresses:
|
||||
symbol = ''
|
||||
erc20_contract = w3.eth.contract(address=token_address, abi=erc20_abi)
|
||||
try:
|
||||
symbol = erc20_contract.functions.symbol().call()
|
||||
except ValueError:
|
||||
logg.error('token {} does not have symbol method'.format(token_address))
|
||||
continue
|
||||
print('{} {}'.format(symbol, token_address))
|
||||
print('{} {}'.format(token_symbol, token_address))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user