Compare commits
2 Commits
2bfc1ce3b2
...
f6c0e2de04
Author | SHA1 | Date | |
---|---|---|---|
f6c0e2de04 | |||
541d083fc7 |
60
parse.py
60
parse.py
@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import re
|
||||||
import ply.lex as lex
|
import ply.lex as lex
|
||||||
import ply.yacc as yacc
|
import ply.yacc as yacc
|
||||||
import enum
|
import enum
|
||||||
@ -318,6 +319,10 @@ class Router:
|
|||||||
def noop_handler(cmd):
|
def noop_handler(cmd):
|
||||||
return str(cmd)
|
return str(cmd)
|
||||||
|
|
||||||
|
|
||||||
|
def remove_ansi_escape_codes(text):
|
||||||
|
return re.sub(r'\u001b\[.*?m', '', text)
|
||||||
|
|
||||||
def generate_private_key():
|
def generate_private_key():
|
||||||
"""Generate a new private key."""
|
"""Generate a new private key."""
|
||||||
web3 = Web3()
|
web3 = Web3()
|
||||||
@ -330,7 +335,7 @@ def store_key_in_keystore(private_key, key_name, store_name):
|
|||||||
'private_key': private_key,
|
'private_key': private_key,
|
||||||
'store_name': store_name,
|
'store_name': store_name,
|
||||||
}
|
}
|
||||||
store_path = f"{store_name}_{key_name}.json"
|
store_path = f"{key_name}.json"
|
||||||
|
|
||||||
# Save to JSON file (simulated keystore)
|
# Save to JSON file (simulated keystore)
|
||||||
with open(store_path, 'w') as f:
|
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
|
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):
|
def key_create_handler(cmd):
|
||||||
store_name = cmd.t
|
store_name = cmd.t
|
||||||
@ -371,20 +384,31 @@ def voucher_create_handler(cmd):
|
|||||||
if "contract_address=" in word:
|
if "contract_address=" in word:
|
||||||
contract_address = word.split("=")[1]
|
contract_address = word.split("=")[1]
|
||||||
print("Voucher created with Address:",contract_address)
|
print("Voucher created with Address:",contract_address)
|
||||||
|
store_voucher(privatekey,symbol,remove_ansi_escape_codes(contract_address))
|
||||||
return contract_address
|
return contract_address
|
||||||
|
|
||||||
def voucher_transfer_handler(cmd):
|
def voucher_transfer_handler(cmd):
|
||||||
value = cmd.v # Amount to transfer
|
value = cmd.v # Amount to transfer
|
||||||
s = "0x" + str(cmd.a).split(":")[1]
|
if str(cmd.a).startswith("NameAgent"):
|
||||||
to = "0x" + str(cmd.t).split(":")[1]
|
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]
|
||||||
|
|
||||||
account = w3.eth.account.from_key(privatekey)
|
if str(cmd.t).startswith("NameAgent"):
|
||||||
nonce = w3.eth.get_transaction_count(account.address,'pending')
|
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 = (
|
command = (
|
||||||
f'cast send --private-key {privatekey} '
|
f'cast send --private-key {privatekey} '
|
||||||
f'--rpc-url {rpc} '
|
f'--rpc-url {rpc} '
|
||||||
f'--nonce {nonce} '
|
|
||||||
f'{s} '
|
f'{s} '
|
||||||
f'"transfer(address,uint256)" {to} {value}'
|
f'"transfer(address,uint256)" {to} {value}'
|
||||||
)
|
)
|
||||||
@ -400,8 +424,22 @@ def voucher_transfer_handler(cmd):
|
|||||||
|
|
||||||
def voucher_mint_handler(cmd):
|
def voucher_mint_handler(cmd):
|
||||||
value = cmd.v
|
value = cmd.v
|
||||||
s = "0x" + str(cmd.a).split(":")[1]
|
if str(cmd.t).startswith("NameAgent"):
|
||||||
to = "0x" + str(cmd.t).split(":")[1]
|
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 = (
|
command = (
|
||||||
f'cast send --private-key {privatekey} '
|
f'cast send --private-key {privatekey} '
|
||||||
@ -486,10 +524,10 @@ class WaitGet:
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
ifc = None
|
ifc = None
|
||||||
o = Router()
|
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_CREATE,voucher_create_handler)
|
||||||
o.register(CmdId.VOUCHER_MINT, voucher_create_handler)
|
o.register(CmdId.VOUCHER_MINT, foo_handler)
|
||||||
o.register(CmdId.VOUCHER_TRANSFER,voucher_transfer_handler)
|
o.register(CmdId.VOUCHER_TRANSFER,foo_handler)
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
ifc = FileGet(o, sys.argv[1])
|
ifc = FileGet(o, sys.argv[1])
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
KEY_CREATE - lockkey custodialstore
|
VOUCHER_CREATE - KSF KenyanSafaru 6
|
||||||
VOUCHER_CREATE - stm stopcoin 6
|
KEY_CREATE - lockkey custodialstore
|
||||||
VOUCHER_TRANSFER - 0x0d3D8A97f970fbdf7486274b02A8308d8aCcE6a1 5000000 0xEa436D1d29a46880b0E956c22187314A8777B463 0xEef7Ad2cCCB317E6898F43eA2B5b1BD1E9C13b1
|
KEY_CREATE - testkey custodialstwo
|
||||||
VOUCHER_MINT - 0x2e8ce655BEfBee9b29A34fcecb3193462e4d0999 5000000 0x74096a72495fe95710c675e78bd4a10f2bfe08bc
|
VOUCHER_MINT - KSF 50000000 lockkey
|
||||||
|
VOUCHER_TRANSFER - 0x0d3D8A97f970fbdf7486274b02A8308d8aCcE6a1 5000000 lockkey 0x74096a72495fe95710c675e78bd4a10f2bfe08bc
|
Loading…
Reference in New Issue
Block a user