mirror of
git://holbrook.no/eth-address-index
synced 2026-04-27 11:11:04 +02:00
Implement external signer
This commit is contained in:
@@ -14,7 +14,9 @@ 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
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
@@ -27,19 +29,49 @@ 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('-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('-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('-o', '--owner-address', dest='o', type=str, help='Address to use to sign endorsement transaction')
|
||||
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('-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')
|
||||
args = argparser.parse_args()
|
||||
|
||||
if args.v:
|
||||
if args.vv:
|
||||
logg.setLevel(logging.DEBUG)
|
||||
elif args.v:
|
||||
logg.setLevel(logging.INFO)
|
||||
|
||||
block_last = args.w
|
||||
block_all = args.ww
|
||||
|
||||
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
|
||||
|
||||
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)
|
||||
logg.debug('now have key for signer address {}'.format(signer_address))
|
||||
signer = EIP155Signer(keystore)
|
||||
|
||||
chain_pair = args.i.split(':')
|
||||
chain_id = int(chain_pair[1])
|
||||
|
||||
helper = EthTxExecutor(
|
||||
w3,
|
||||
signer_address,
|
||||
signer,
|
||||
chain_id,
|
||||
block=args.ww,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
|
||||
|
||||
f = open(os.path.join(args.abi_dir, 'TokenUniqueSymbolIndex.json'), 'r')
|
||||
abi = json.load(f)
|
||||
f.close()
|
||||
@@ -51,11 +83,6 @@ def main():
|
||||
t = w3.eth.contract(abi=erc20_abi, address=args.address)
|
||||
token_symbol = t.functions.symbol().call()
|
||||
|
||||
w3.eth.defaultAccount = w3.eth.accounts[0]
|
||||
if args.o != None:
|
||||
w3.eth.defaultAccount = args.o
|
||||
logg.debug('owner address {}'.format(w3.eth.defaultAccount))
|
||||
|
||||
c = w3.eth.contract(abi=abi, address=args.r)
|
||||
|
||||
h = hashlib.new('sha256')
|
||||
@@ -63,8 +90,13 @@ def main():
|
||||
z = h.digest()
|
||||
logg.info('token symbol {} => {}'.format(token_symbol, z.hex()))
|
||||
|
||||
tx_hash = c.functions.register('0x' + z.hex(), args.address).transact()
|
||||
print(tx_hash.hex())
|
||||
(tx_hash, rcpt) = helper.sign_and_send(
|
||||
[
|
||||
c.functions.register('0x' + z.hex(), args.address).buildTransaction,
|
||||
],
|
||||
)
|
||||
|
||||
print(tx_hash)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -13,7 +13,9 @@ 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
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
@@ -26,17 +28,47 @@ 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('-o', '--owner', dest='o', type=str, help='Accounts declarator owner')
|
||||
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')
|
||||
args = argparser.parse_args()
|
||||
|
||||
if args.v:
|
||||
if args.vv:
|
||||
logg.setLevel(logging.DEBUG)
|
||||
elif args.v:
|
||||
logg.setLevel(logging.INFO)
|
||||
|
||||
block_last = args.w
|
||||
block_all = args.ww
|
||||
|
||||
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
|
||||
|
||||
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)
|
||||
logg.debug('now have key for signer address {}'.format(signer_address))
|
||||
signer = EIP155Signer(keystore)
|
||||
|
||||
chain_pair = args.i.split(':')
|
||||
chain_id = int(chain_pair[1])
|
||||
|
||||
helper = EthTxExecutor(
|
||||
w3,
|
||||
signer_address,
|
||||
signer,
|
||||
chain_id,
|
||||
block=args.ww,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
|
||||
|
||||
f = open(os.path.join(args.abi_dir, 'TokenUniqueSymbolIndex.json'), 'r')
|
||||
abi = json.load(f)
|
||||
f.close()
|
||||
@@ -45,16 +77,14 @@ def main():
|
||||
bytecode = f.read()
|
||||
f.close()
|
||||
|
||||
w3.eth.defaultAccount = w3.eth.accounts[0]
|
||||
if args.o != None:
|
||||
w3.eth.defaultAccount = args.o
|
||||
logg.debug('owner address {}'.format(w3.eth.defaultAccount))
|
||||
|
||||
c = w3.eth.contract(abi=abi, bytecode=bytecode)
|
||||
tx_hash = c.constructor().transact()
|
||||
|
||||
rcpt = w3.eth.getTransactionReceipt(tx_hash)
|
||||
|
||||
(tx_hash, rcpt) = helper.sign_and_send(
|
||||
[
|
||||
c.constructor().buildTransaction,
|
||||
],
|
||||
force_wait=True,
|
||||
)
|
||||
print(rcpt.contractAddress)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user