update handlers
This commit is contained in:
parent
71d157a482
commit
24172aa4b5
29
parse.py
29
parse.py
@ -329,13 +329,20 @@ def generate_private_key():
|
||||
account = web3.eth.account.create()
|
||||
return account.address,w3.to_hex(account.key)
|
||||
|
||||
def store_key_in_keystore(private_key, key_name, store_name):
|
||||
def store_key_in_keystore(private_key, key_name, address):
|
||||
|
||||
keystore_dir = "custodial_store"
|
||||
# Create the directory if it doesn't exist
|
||||
if not os.path.exists(keystore_dir):
|
||||
os.makedirs(keystore_dir)
|
||||
|
||||
keystore = {
|
||||
'key_name': key_name,
|
||||
'private_key': private_key,
|
||||
'store_name': store_name,
|
||||
'address': address,
|
||||
}
|
||||
store_path = f"{key_name}.json"
|
||||
|
||||
store_path = os.path.join(keystore_dir, f"{key_name}.json")
|
||||
|
||||
# Save to JSON file (simulated keystore)
|
||||
with open(store_path, 'w') as f:
|
||||
@ -353,7 +360,6 @@ def store_voucher(voucher_creator,voucher_symbol,voucher_address):
|
||||
|
||||
|
||||
def key_create_handler(cmd):
|
||||
store_name = cmd.t
|
||||
key_name = str(cmd.f).split(":")[1]
|
||||
|
||||
if cmd.k is None:
|
||||
@ -362,7 +368,7 @@ def key_create_handler(cmd):
|
||||
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)
|
||||
store_key_in_keystore(private_key, key_name, address)
|
||||
return address
|
||||
|
||||
|
||||
@ -370,7 +376,10 @@ def voucher_create_handler(cmd):
|
||||
name = cmd.n
|
||||
symbol = cmd.s
|
||||
|
||||
command = f'ge-publish --private-key {privatekey} ' \
|
||||
if privatekey.startswith("0x"):
|
||||
private_key = privatekey[2:]
|
||||
|
||||
command = f'ge-publish --private-key {private_key} ' \
|
||||
f'--rpc {rpc} --gas-fee-cap {gasCap} --chainid {chainId} ' \
|
||||
f'p erc20 --name "{name}" --symbol "{symbol}"'
|
||||
|
||||
@ -401,7 +410,8 @@ def voucher_transfer_handler(cmd):
|
||||
|
||||
if str(cmd.t).startswith("NameAgent"):
|
||||
key_name = str(cmd.t).split(":")[1]
|
||||
with open(f"{key_name}.json", "r") as file:
|
||||
store_path = os.path.join("custodial_store", f"{key_name}.json")
|
||||
with open(store_path, "r") as file:
|
||||
data = json.load(file)
|
||||
acct = w3.eth.account.from_key(data["private_key"])
|
||||
to = acct.address
|
||||
@ -430,7 +440,8 @@ def voucher_mint_handler(cmd):
|
||||
value = cmd.v
|
||||
if str(cmd.t).startswith("NameAgent"):
|
||||
key_name = str(cmd.t).split(":")[1]
|
||||
with open(f"{key_name}.json", "r") as file:
|
||||
store_path = os.path.join("custodial_store", f"{key_name}.json")
|
||||
with open(store_path, "r") as file:
|
||||
data = json.load(file)
|
||||
acct = w3.eth.account.from_key(data["private_key"])
|
||||
to = acct.address
|
||||
@ -535,7 +546,7 @@ if __name__ == '__main__':
|
||||
o = Router()
|
||||
o.register(CmdId.KEY_CREATE,foo_handler)
|
||||
o.register(CmdId.VOUCHER_CREATE,foo_handler)
|
||||
o.register(CmdId.VOUCHER_MINT, voucher_mint_handler)
|
||||
o.register(CmdId.VOUCHER_MINT, foo_handler)
|
||||
o.register(CmdId.VOUCHER_TRANSFER,foo_handler)
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
|
Loading…
Reference in New Issue
Block a user