From 5061aace416abc1014b2abce8c09c5e9346033c7 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 25 Nov 2024 12:37:52 +0300 Subject: [PATCH] update handler --- parse.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/parse.py b/parse.py index 7345d0c..51a729b 100644 --- a/parse.py +++ b/parse.py @@ -321,8 +321,8 @@ def noop_handler(cmd): def generate_private_key(): """Generate a new private key.""" web3 = Web3() - account = web3.eth.account.create() - return account.address + account = web3.eth.account.create() + return account.address,w3.to_hex(account.key) def store_key_in_keystore(private_key, key_name, store_name): keystore = { @@ -342,8 +342,13 @@ def store_key_in_keystore(private_key, key_name, store_name): def key_create_handler(cmd): store_name = cmd.t key_name = str(cmd.f).split(":")[1] - private_key = cmd.k - address = generate_private_key() + + if cmd.k is None: + address,private_key = generate_private_key() + else: + if private_key.startswith("0x"): + private_key = private_key[2:] + address = w3.eth.account.from_key(privatekey) store_key_in_keystore(private_key, key_name, store_name) return address @@ -483,7 +488,7 @@ if __name__ == '__main__': o = Router() o.register(CmdId.KEY_CREATE,key_create_handler) o.register(CmdId.VOUCHER_CREATE,voucher_create_handler) - o.register(CmdId.VOUCHER_MINT, voucher_mint_handler) + o.register(CmdId.VOUCHER_MINT, voucher_create_handler) o.register(CmdId.VOUCHER_TRANSFER,voucher_transfer_handler) if len(sys.argv) > 1: