add explit nonce value to cast commands
This commit is contained in:
parent
7b9bff6541
commit
01d7de89c2
39
parse.py
39
parse.py
@ -382,7 +382,7 @@ def find_custodial_address(key_name):
|
||||
filename = f"{key_name}.json"
|
||||
file_path = os.path.join(directory, filename)
|
||||
|
||||
# Check if the file exists
|
||||
# Check if the file exists with the keyname
|
||||
if os.path.isfile(file_path):
|
||||
with open(file_path, "r") as f:
|
||||
custodial_account = json.load(f)
|
||||
@ -422,10 +422,11 @@ def store_key_in_keystore(keystore_dir, private_key, key_name, address):
|
||||
return store_path
|
||||
|
||||
|
||||
def load_gas(address):
|
||||
def load_gas(address,nonce):
|
||||
command = (
|
||||
f"cast send {address} "
|
||||
f"--value {gas_topup} "
|
||||
f"--nonce {nonce} "
|
||||
f"--private-key {master_private_key} "
|
||||
f"--rpc-url {rpc} "
|
||||
f" --json "
|
||||
@ -465,6 +466,7 @@ def create_custodialaccount():
|
||||
|
||||
|
||||
def do_custodial_token_transfer(transfer):
|
||||
#token transfer custodial endpoint
|
||||
url = "http://localhost:5003/api/v2/token/transfer"
|
||||
|
||||
headers = {
|
||||
@ -520,6 +522,8 @@ def key_create_handler(cmd):
|
||||
store_name = cmd.t
|
||||
|
||||
keystore_dir = "user_store"
|
||||
master_address = w3.eth.account.from_key(master_private_key)
|
||||
nonce = w3.eth.get_transaction_count(master_address.address,'pending')
|
||||
|
||||
if cmd.k is None:
|
||||
address, private_key = generate_private_key()
|
||||
@ -537,7 +541,8 @@ def key_create_handler(cmd):
|
||||
private_key = None
|
||||
keystore_dir = "custodialstore"
|
||||
|
||||
load_gas(address)
|
||||
|
||||
load_gas(address,nonce)
|
||||
|
||||
store_key_in_keystore(keystore_dir, private_key, key_name, address)
|
||||
return address
|
||||
@ -588,18 +593,22 @@ def voucher_create_handler(cmd):
|
||||
|
||||
store_voucher(private_key, symbol, contract_address)
|
||||
|
||||
# sleep for 5 second to allow chain to sync
|
||||
time.sleep(5)
|
||||
|
||||
master_address = w3.eth.account.from_key(master_private_key)
|
||||
nonce = w3.eth.get_transaction_count(master_address.address,'pending')
|
||||
|
||||
# Command to add the token to the token index
|
||||
add_token_to_index = (
|
||||
f"cast send --private-key {master_private_key} "
|
||||
f"--nonce {nonce} "
|
||||
f"--rpc-url {rpc} "
|
||||
f"{token_index} "
|
||||
f'"add(address)" {contract_address} '
|
||||
f" --json "
|
||||
)
|
||||
|
||||
# sleep for 5 second to allow chain to sync
|
||||
time.sleep(5)
|
||||
|
||||
result2 = subprocess.run(
|
||||
add_token_to_index, shell=True, capture_output=True, text=True
|
||||
)
|
||||
@ -653,7 +662,7 @@ def voucher_transfer_handler(cmd):
|
||||
to = custodial_address
|
||||
token_transfer.to_address = to
|
||||
else:
|
||||
store_path = os.path.join("custodial_store", f"{key_name}.json")
|
||||
store_path = os.path.join("user_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"])
|
||||
@ -674,7 +683,7 @@ def voucher_transfer_handler(cmd):
|
||||
is_custodial_address = True
|
||||
token_transfer.from_address = custodial_address
|
||||
else:
|
||||
store_path = os.path.join("custodial_store", f"{key_name}.json")
|
||||
store_path = os.path.join("user_store", f"{key_name}.json")
|
||||
with open(store_path, "r") as file:
|
||||
data = json.load(file)
|
||||
from_private_key = data["private_key"]
|
||||
@ -719,11 +728,15 @@ def voucher_mint_handler(cmd):
|
||||
value = cmd.v
|
||||
if str(cmd.t).startswith("NameAgent"):
|
||||
key_name = str(cmd.t).split(":")[1]
|
||||
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
|
||||
custodial_address = find_custodial_address(key_name)
|
||||
if custodial_address is not None:
|
||||
to = custodial_address
|
||||
else:
|
||||
store_path = os.path.join("user_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
|
||||
elif str(cmd.t).startswith("AddressAgent"):
|
||||
to = "0x" + str(cmd.t).split(":")[1]
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user