Compare commits

...

2 Commits

Author SHA1 Message Date
f6c0e2de04
update handlers 2024-11-26 10:05:11 +03:00
541d083fc7
update commands 2024-11-26 10:04:26 +03:00
2 changed files with 55 additions and 16 deletions

View File

@ -1,4 +1,5 @@
import json
import re
import ply.lex as lex
import ply.yacc as yacc
import enum
@ -318,6 +319,10 @@ class Router:
def noop_handler(cmd):
return str(cmd)
def remove_ansi_escape_codes(text):
return re.sub(r'\u001b\[.*?m', '', text)
def generate_private_key():
"""Generate a new private key."""
web3 = Web3()
@ -330,7 +335,7 @@ def store_key_in_keystore(private_key, key_name, store_name):
'private_key': private_key,
'store_name': store_name,
}
store_path = f"{store_name}_{key_name}.json"
store_path = f"{key_name}.json"
# Save to JSON file (simulated keystore)
with open(store_path, 'w') as f:
@ -338,6 +343,14 @@ def store_key_in_keystore(private_key, key_name, store_name):
return store_path
def store_voucher(voucher_creator,voucher_symbol,voucher_address):
voucher = {
voucher_symbol: voucher_address,
'owner': voucher_creator
}
with open("vouchers.json", 'w') as f:
json.dump(voucher, f)
def key_create_handler(cmd):
store_name = cmd.t
@ -371,20 +384,31 @@ def voucher_create_handler(cmd):
if "contract_address=" in word:
contract_address = word.split("=")[1]
print("Voucher created with Address:",contract_address)
store_voucher(privatekey,symbol,remove_ansi_escape_codes(contract_address))
return contract_address
def voucher_transfer_handler(cmd):
value = cmd.v # Amount to transfer
if str(cmd.a).startswith("NameAgent"):
voucher_name = str(cmd.a).split(":")[1]
with open("vouchers.json", "r") as file:
data = json.load(file)
s = data[voucher_name]
elif str(cmd.a).startswith("AddressAgent"):
s = "0x" + str(cmd.a).split(":")[1]
to = "0x" + str(cmd.t).split(":")[1]
account = w3.eth.account.from_key(privatekey)
nonce = w3.eth.get_transaction_count(account.address,'pending')
if str(cmd.t).startswith("NameAgent"):
key_name = str(cmd.t).split(":")[1]
with open(f"{key_name}.json", "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]
command = (
f'cast send --private-key {privatekey} '
f'--rpc-url {rpc} '
f'--nonce {nonce} '
f'{s} '
f'"transfer(address,uint256)" {to} {value}'
)
@ -400,9 +424,23 @@ def voucher_transfer_handler(cmd):
def voucher_mint_handler(cmd):
value = cmd.v
s = "0x" + str(cmd.a).split(":")[1]
if str(cmd.t).startswith("NameAgent"):
key_name = str(cmd.t).split(":")[1]
with open(f"{key_name}.json", "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]
if str(cmd.a).startswith("NameAgent"):
voucher_name = str(cmd.a).split(":")[1]
with open("vouchers.json", "r") as file:
data = json.load(file)
s = data[voucher_name]
elif str(cmd.a).startswith("AddressAgent"):
s = "0x" + str(cmd.a).split(":")[1]
command = (
f'cast send --private-key {privatekey} '
f'--rpc-url {rpc} '
@ -486,10 +524,10 @@ class WaitGet:
if __name__ == '__main__':
ifc = None
o = Router()
o.register(CmdId.KEY_CREATE,key_create_handler)
o.register(CmdId.KEY_CREATE,foo_handler)
o.register(CmdId.VOUCHER_CREATE,voucher_create_handler)
o.register(CmdId.VOUCHER_MINT, voucher_create_handler)
o.register(CmdId.VOUCHER_TRANSFER,voucher_transfer_handler)
o.register(CmdId.VOUCHER_MINT, foo_handler)
o.register(CmdId.VOUCHER_TRANSFER,foo_handler)
if len(sys.argv) > 1:
ifc = FileGet(o, sys.argv[1])

View File

@ -1,4 +1,5 @@
VOUCHER_CREATE - KSF KenyanSafaru 6
KEY_CREATE - lockkey custodialstore
VOUCHER_CREATE - stm stopcoin 6
VOUCHER_TRANSFER - 0x0d3D8A97f970fbdf7486274b02A8308d8aCcE6a1 5000000 0xEa436D1d29a46880b0E956c22187314A8777B463 0xEef7Ad2cCCB317E6898F43eA2B5b1BD1E9C13b1
VOUCHER_MINT - 0x2e8ce655BEfBee9b29A34fcecb3193462e4d0999 5000000 0x74096a72495fe95710c675e78bd4a10f2bfe08bc
KEY_CREATE - testkey custodialstwo
VOUCHER_MINT - KSF 50000000 lockkey
VOUCHER_TRANSFER - 0x0d3D8A97f970fbdf7486274b02A8308d8aCcE6a1 5000000 lockkey 0x74096a72495fe95710c675e78bd4a10f2bfe08bc