Compare commits

..

No commits in common. "f6c0e2de04ca7a03b32d65a815e637dd81e9ce83" and "2bfc1ce3b2db4fa4e5b9e31727eea557c29cdf7f" have entirely different histories.

2 changed files with 16 additions and 55 deletions

View File

@ -1,5 +1,4 @@
import json
import re
import ply.lex as lex
import ply.yacc as yacc
import enum
@ -319,10 +318,6 @@ 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()
@ -335,7 +330,7 @@ def store_key_in_keystore(private_key, key_name, store_name):
'private_key': private_key,
'store_name': store_name,
}
store_path = f"{key_name}.json"
store_path = f"{store_name}_{key_name}.json"
# Save to JSON file (simulated keystore)
with open(store_path, 'w') as f:
@ -343,14 +338,6 @@ 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
@ -384,31 +371,20 @@ 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]
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]
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')
command = (
f'cast send --private-key {privatekey} '
f'--rpc-url {rpc} '
f'--nonce {nonce} '
f'{s} '
f'"transfer(address,uint256)" {to} {value}'
)
@ -424,22 +400,8 @@ def voucher_transfer_handler(cmd):
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:
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]
s = "0x" + str(cmd.a).split(":")[1]
to = "0x" + str(cmd.t).split(":")[1]
command = (
f'cast send --private-key {privatekey} '
@ -524,10 +486,10 @@ class WaitGet:
if __name__ == '__main__':
ifc = None
o = Router()
o.register(CmdId.KEY_CREATE,foo_handler)
o.register(CmdId.KEY_CREATE,key_create_handler)
o.register(CmdId.VOUCHER_CREATE,voucher_create_handler)
o.register(CmdId.VOUCHER_MINT, foo_handler)
o.register(CmdId.VOUCHER_TRANSFER,foo_handler)
o.register(CmdId.VOUCHER_MINT, voucher_create_handler)
o.register(CmdId.VOUCHER_TRANSFER,voucher_transfer_handler)
if len(sys.argv) > 1:
ifc = FileGet(o, sys.argv[1])

View File

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