add command to add token to token index
This commit is contained in:
parent
78fc736ed7
commit
9aaa125948
60
parse.py
60
parse.py
@ -69,6 +69,9 @@ privatekey = os.getenv("PRIVATE_KEY")
|
||||
chainId = os.getenv("CHAIN_ID")
|
||||
rpc = os.getenv("RPC")
|
||||
gasCap = os.getenv("GAS_FEE_CAP")
|
||||
master_private_key = os.getenv("MASTER_PRIVATE_KEY")
|
||||
token_index = os.getenv("TOKEN_INDEX")
|
||||
gas_topup = os.getenv("GAS_TOPUP")
|
||||
|
||||
w3 = Web3(Web3.HTTPProvider(rpc))
|
||||
|
||||
@ -368,7 +371,7 @@ def load_gas(address,nonce):
|
||||
global call_count
|
||||
command = (
|
||||
f'cast send {address} '
|
||||
f'--value 0.01ether '
|
||||
f'--value {gas_topup} '
|
||||
f'--nonce {nonce} '
|
||||
f'--private-key {privatekey} '
|
||||
f'--rpc-url {rpc} '
|
||||
@ -385,8 +388,9 @@ def load_gas(address,nonce):
|
||||
def store_voucher(voucher_creator,voucher_symbol,voucher_address):
|
||||
vouchers = []
|
||||
voucher = {
|
||||
voucher_symbol: voucher_address,
|
||||
'owner': voucher_creator
|
||||
'voucher_address': voucher_address,
|
||||
'owner': voucher_creator,
|
||||
'symbol': voucher_symbol
|
||||
}
|
||||
vouchers.append(voucher)
|
||||
try:
|
||||
@ -422,25 +426,21 @@ def voucher_create_handler(cmd):
|
||||
name = cmd.n
|
||||
symbol = cmd.s
|
||||
|
||||
random_ascii = ''.join(random.choices(string.ascii_letters, k=3))
|
||||
|
||||
random_ascii = ''.join(random.choices(string.ascii_letters, k=2))
|
||||
try:
|
||||
with open("vouchers.json", 'r') as f:
|
||||
existing_vouchers = json.load(f)
|
||||
except (FileNotFoundError):
|
||||
existing_vouchers = []
|
||||
voucher_symbols = list(map(lambda symbol: symbol['symbol'], existing_vouchers))
|
||||
|
||||
for voucher in existing_vouchers:
|
||||
try:
|
||||
value = voucher[cmd.s]
|
||||
if symbol in voucher_symbols:
|
||||
symbol = symbol + random_ascii
|
||||
print(f"Value for {symbol}: {value}")
|
||||
except KeyError:
|
||||
#Skip appending random ascii letters
|
||||
print("Symbol does not exist")
|
||||
|
||||
if privatekey.startswith("0x"):
|
||||
private_key = privatekey[2:]
|
||||
|
||||
#Command to create a voucher
|
||||
command = f'ge-publish --private-key {private_key} --json ' \
|
||||
f'--rpc {rpc} --gas-fee-cap {gasCap} --chainid {chainId} ' \
|
||||
f'p erc20 --name "{name}" --symbol "{symbol}"'
|
||||
@ -458,6 +458,18 @@ def voucher_create_handler(cmd):
|
||||
message = f"Voucher {name} created with address {contract_address} and symbol {symbol}"
|
||||
store_voucher(private_key,symbol,contract_address)
|
||||
printMessage(message)
|
||||
|
||||
#Command to add the token to the token index
|
||||
add_token = (
|
||||
f'cast send --private-key {master_private_key} '
|
||||
f'--rpc-url {rpc} '
|
||||
f'{token_index} '
|
||||
f'"add(address)" {contract_address} '
|
||||
f' --json '
|
||||
)
|
||||
result2 = subprocess.run(add_token, shell=True, capture_output=True, text=True)
|
||||
if result2.returncode != 0:
|
||||
raise subprocess.CalledProcessError(result.returncode, command, output=result.stdout, stderr=result.stderr)
|
||||
return contract_address
|
||||
|
||||
def voucher_transfer_handler(cmd):
|
||||
@ -466,7 +478,13 @@ def voucher_transfer_handler(cmd):
|
||||
voucher_name = str(cmd.a).split(":")[1]
|
||||
with open("vouchers.json", "r") as file:
|
||||
data = json.load(file)
|
||||
s = data[voucher_name]
|
||||
|
||||
voucher_symbols = list(map(lambda symbol: symbol['symbol'], data))
|
||||
voucher_address = list(map(lambda address: address['voucher_address'], data))
|
||||
if voucher_name in voucher_symbols:
|
||||
index = voucher_symbols.index(voucher_name)
|
||||
s = voucher_address[index]
|
||||
|
||||
elif str(cmd.a).startswith("AddressAgent"):
|
||||
s = "0x" + str(cmd.a).split(":")[1]
|
||||
else:
|
||||
@ -497,6 +515,8 @@ def voucher_transfer_handler(cmd):
|
||||
if result.stderr:
|
||||
raise ValueError(f"Command failed with error: {result.stderr}")
|
||||
data = json.loads(result.stdout)
|
||||
message = f"Transfered {value} {voucher_name} to {to} "
|
||||
printMessage(message)
|
||||
return data["transactionHash"]
|
||||
|
||||
|
||||
@ -517,11 +537,17 @@ def voucher_mint_handler(cmd):
|
||||
raise ValueError(f"Invalid command: {cmd.t}. Expected 'NameAgent' or 'AddressAgent'.")
|
||||
|
||||
if str(cmd.a).startswith("NameAgent"):
|
||||
voucher_name = str(cmd.a).split(":")[1]
|
||||
voucher_symbol = str(cmd.a).split(":")[1]
|
||||
with open("vouchers.json", "r") as file:
|
||||
data = json.load(file)
|
||||
s = data[voucher_name]
|
||||
privatekey = data["owner"]
|
||||
voucher_symbols = list(map(lambda symbol: symbol['symbol'], data))
|
||||
voucher_address = list(map(lambda address: address['voucher_address'], data))
|
||||
voucher_owners = list(map(lambda address: address['owner'], data))
|
||||
if voucher_symbol in voucher_symbols:
|
||||
index = voucher_symbols.index(voucher_symbol)
|
||||
s = voucher_address[index]
|
||||
privatekey = voucher_owners[index]
|
||||
|
||||
elif str(cmd.a).startswith("AddressAgent"):
|
||||
s = "0x" + str(cmd.a).split(":")[1]
|
||||
else:
|
||||
@ -540,6 +566,8 @@ def voucher_mint_handler(cmd):
|
||||
if result.stderr:
|
||||
raise ValueError(f"Command failed with error: {result.stderr}")
|
||||
data = json.loads(result.stdout)
|
||||
message = f"Added supply to {voucher_symbol} with value {value} and address {voucher_address}"
|
||||
printMessage(message)
|
||||
return data["transactionHash"]
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user