mirror of
git://holbrook.no/eth-address-index
synced 2025-01-08 01:57:33 +01:00
Add list runnable script
This commit is contained in:
parent
2abecb287e
commit
a2dc6de76b
@ -6,6 +6,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# standard imports
|
# standard imports
|
||||||
|
import sys
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import argparse
|
import argparse
|
||||||
@ -24,6 +25,7 @@ from eth_token_index import TokenUniqueSymbolIndex
|
|||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
default_format = 'terminal'
|
||||||
|
|
||||||
script_dir = os.path.dirname(__file__)
|
script_dir = os.path.dirname(__file__)
|
||||||
data_dir = os.path.join(script_dir, '..', 'data')
|
data_dir = os.path.join(script_dir, '..', 'data')
|
||||||
@ -32,8 +34,10 @@ 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('-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('-i', '--chain-spec', dest='i', type=str, default='Ethereum:1', help='Chain specification string')
|
||||||
argparser.add_argument('-a', '--contract-address', dest='a', type=str, required=True, help='Token endorsement contract address')
|
argparser.add_argument('-a', '--contract-address', dest='a', type=str, required=True, help='Token endorsement contract address')
|
||||||
|
argparser.add_argument('-f', '--format', dest='f', type=str, default=default_format, help='Output format [human, brief]')
|
||||||
argparser.add_argument('-v', action='store_true', help='Be verbose')
|
argparser.add_argument('-v', action='store_true', help='Be verbose')
|
||||||
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
|
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
|
||||||
|
argparser.add_argument('token_symbol', type=str, nargs='?', help='Token symbol to return address for')
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
if args.vv:
|
if args.vv:
|
||||||
@ -44,24 +48,49 @@ elif args.v:
|
|||||||
rpc = EthHTTPConnection(args.p)
|
rpc = EthHTTPConnection(args.p)
|
||||||
contract_address = args.a
|
contract_address = args.a
|
||||||
|
|
||||||
|
token_symbol = args.token_symbol
|
||||||
|
fmt = args.f
|
||||||
|
|
||||||
def main():
|
|
||||||
ct = ERC20()
|
def out_element(e, fmt=default_format, w=sys.stdout):
|
||||||
c = TokenUniqueSymbolIndex()
|
if fmt == 'brief':
|
||||||
o = c.entry_count(contract_address)
|
w.write(e[1] + '\n')
|
||||||
|
else:
|
||||||
|
w.write('{} {}\n'.format(e[0], e[1]))
|
||||||
|
|
||||||
|
|
||||||
|
def element(ifc, contract_address, token_symbol, fmt=fmt, w=sys.stdout):
|
||||||
|
o = ifc.address_of(contract_address, token_symbol)
|
||||||
r = rpc.do(o)
|
r = rpc.do(o)
|
||||||
count = TokenUniqueSymbolIndex.parse_entry_count(r)
|
a = ifc.parse_address_of(r)
|
||||||
|
out_element((token_symbol, a), fmt, w)
|
||||||
|
|
||||||
|
|
||||||
|
def ls(ifc, contract_address, token_ifc, fmt=fmt, w=sys.stdout):
|
||||||
|
o = ifc.entry_count(contract_address)
|
||||||
|
r = rpc.do(o)
|
||||||
|
count = ifc.parse_entry_count(r)
|
||||||
|
logg.debug('count {}'.format(count))
|
||||||
|
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
o = c.entry(contract_address, i)
|
o = ifc.entry(contract_address, i)
|
||||||
r = rpc.do(o)
|
r = rpc.do(o)
|
||||||
token_address = TokenUniqueSymbolIndex.parse_entry(r)
|
token_address = ifc.parse_entry(r)
|
||||||
|
|
||||||
o = ct.symbol(token_address)
|
o = token_ifc.symbol(token_address)
|
||||||
r = rpc.do(o)
|
r = rpc.do(o)
|
||||||
token_symbol = ERC20.parse_symbol(r)
|
token_symbol = token_ifc.parse_symbol(r)
|
||||||
|
|
||||||
print('{} {}'.format(token_symbol, token_address))
|
element(ifc, contract_address, token_symbol, fmt, w)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
token_ifc = ERC20()
|
||||||
|
ifc = TokenUniqueSymbolIndex()
|
||||||
|
if token_symbol != None:
|
||||||
|
element(ifc, contract_address, token_ifc, token_symbol, fmt, sys.stdout)
|
||||||
|
else:
|
||||||
|
ls(ifc, contract_address, token_ifc, fmt, sys.stdout)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = eth-address-index
|
name = eth-address-index
|
||||||
version = 0.1.1a2
|
version = 0.1.1a3
|
||||||
description = Signed metadata declarations for ethereum addresses
|
description = Signed metadata declarations for ethereum addresses
|
||||||
author = Louis Holbrook
|
author = Louis Holbrook
|
||||||
author_email = dev@holbrook.no
|
author_email = dev@holbrook.no
|
||||||
|
Loading…
Reference in New Issue
Block a user