Compare commits
6 Commits
master
...
v-seed-tes
Author | SHA1 | Date | |
---|---|---|---|
d1a4f2ee5d | |||
083e3e6b69 | |||
baf21fca96 | |||
a3d149a659 | |||
|
f25d45af4c | ||
|
fa64acac1d |
4
.env.example
Normal file
4
.env.example
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
PRIVATE_KEY=PRIVATE_KEY=1e1d0c151ajjajajsanakaka54ba
|
||||||
|
CHAIN_ID = 44787
|
||||||
|
RPC = https://alfajores-forno.celo-testnet.org
|
||||||
|
GAS_FEE_CAP = 35000000000
|
193
parse.py
193
parse.py
@ -4,9 +4,12 @@ import enum
|
|||||||
import uuid
|
import uuid
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
|
import select
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
from multiprocessing import Value
|
|
||||||
from multiprocessing import Pipe
|
from multiprocessing import Pipe
|
||||||
|
import subprocess
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
logg.setLevel(logging.DEBUG)
|
logg.setLevel(logging.DEBUG)
|
||||||
@ -49,6 +52,17 @@ def t_error(t):
|
|||||||
t.lexer.skip(1)
|
t.lexer.skip(1)
|
||||||
|
|
||||||
lexer = lex.lex()
|
lexer = lex.lex()
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
#Chain params
|
||||||
|
privatekey = os.getenv("PRIVATE_KEY")
|
||||||
|
chainId = os.getenv("CHAIN_ID")
|
||||||
|
rpc = os.getenv("RPC")
|
||||||
|
gasCap = os.getenv("GAS_FEE_CAP")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
#data = '''
|
#data = '''
|
||||||
#FOOBAR uf-2etg 0xa3bdefa momo 123
|
#FOOBAR uf-2etg 0xa3bdefa momo 123
|
||||||
@ -152,6 +166,7 @@ def p_key_create(p):
|
|||||||
if len(p) > 4:
|
if len(p) > 4:
|
||||||
o.k = p[4]
|
o.k = p[4]
|
||||||
p[0] = o
|
p[0] = o
|
||||||
|
print("PO",p[0])
|
||||||
|
|
||||||
|
|
||||||
def p_voucher_mint(p):
|
def p_voucher_mint(p):
|
||||||
@ -271,6 +286,7 @@ class Router:
|
|||||||
|
|
||||||
|
|
||||||
def exec(self, cmd):
|
def exec(self, cmd):
|
||||||
|
logg.debug("router exec {}".format(cmd))
|
||||||
if cmd.c & 0xa0 > 0:
|
if cmd.c & 0xa0 > 0:
|
||||||
return self.sync(cmd.i)
|
return self.sync(cmd.i)
|
||||||
fn = self.__routes[cmd.c]
|
fn = self.__routes[cmd.c]
|
||||||
@ -280,37 +296,174 @@ class Router:
|
|||||||
po.start()
|
po.start()
|
||||||
|
|
||||||
|
|
||||||
def __del__(self):
|
def finish(self):
|
||||||
|
print("syncing")
|
||||||
for k, v in self.__r.items():
|
for k, v in self.__r.items():
|
||||||
|
print("syncing key " + k)
|
||||||
r = self.sync(k)
|
r = self.sync(k)
|
||||||
logging.debug("synced " + k + ": " + r)
|
logg.debug("synced " + k + ": " + r)
|
||||||
|
print("synced " + k + ": " + r)
|
||||||
|
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
self.finish()
|
||||||
|
|
||||||
|
|
||||||
def noop_handler(cmd):
|
def noop_handler(cmd):
|
||||||
return str(cmd)
|
return str(cmd)
|
||||||
|
|
||||||
|
|
||||||
|
def key_create_handler(cmd):
|
||||||
|
mnemonic = cmd.i.replace('-', ' ')
|
||||||
|
command = f'cast wallet pk -v "{mnemonic}" 2 | cut -c 16-'
|
||||||
|
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
||||||
|
if result.returncode != 0:
|
||||||
|
raise subprocess.CalledProcessError(result.returncode, command, output=result.stdout, stderr=result.stderr)
|
||||||
|
if result.stderr:
|
||||||
|
raise ValueError(f"Command failed with error: {result.stderr}")
|
||||||
|
else:
|
||||||
|
privatekey = result.stdout.strip().split("\n")[1]
|
||||||
|
return privatekey
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def voucher_create_handler(cmd):
|
||||||
|
name = cmd.n
|
||||||
|
symbol = cmd.s
|
||||||
|
|
||||||
|
command = f'ge-publish --private-key {privatekey} ' \
|
||||||
|
f'--rpc {rpc} --gas-fee-cap {gasCap} --chainid {chainId} ' \
|
||||||
|
f'p erc20 --name "{name}" --symbol "{symbol}"'
|
||||||
|
|
||||||
|
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
||||||
|
if result.returncode != 0:
|
||||||
|
raise subprocess.CalledProcessError(result.returncode, command, output=result.stdout, stderr=result.stderr)
|
||||||
|
output = result.stderr.strip().split("\n")
|
||||||
|
contract_address = None
|
||||||
|
|
||||||
|
for word in output[1].split():
|
||||||
|
if "contract_address=" in word:
|
||||||
|
contract_address = word.split("=")[1]
|
||||||
|
print("Voucher created with Address:",contract_address)
|
||||||
|
return contract_address
|
||||||
|
|
||||||
|
def voucher_transfer_handler(cmd):
|
||||||
|
value = cmd.v # Amount to transfer
|
||||||
|
s = "0x" + str(cmd.a).split(":")[1]
|
||||||
|
to = "0x" + str(cmd.t).split(":")[1]
|
||||||
|
|
||||||
|
command = (
|
||||||
|
f'cast send --private-key {privatekey} '
|
||||||
|
f'--rpc-url {rpc} '
|
||||||
|
f'{s} '
|
||||||
|
f'"transfer(address,uint256)" {to} {value}'
|
||||||
|
)
|
||||||
|
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
||||||
|
if result.returncode != 0:
|
||||||
|
raise subprocess.CalledProcessError(result.returncode, command, output=result.stdout, stderr=result.stderr)
|
||||||
|
if result.stderr:
|
||||||
|
raise ValueError(f"Command failed with error: {result.stderr}")
|
||||||
|
return result.stdout
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def voucher_mint_handler(cmd):
|
||||||
|
value = cmd.v
|
||||||
|
s = "0x" + str(cmd.a).split(":")[1]
|
||||||
|
to = "0x" + str(cmd.t).split(":")[1]
|
||||||
|
command = (
|
||||||
|
f'cast send --private-key {privatekey}'
|
||||||
|
f'--rpc-url {rpc} '
|
||||||
|
f' {s} '
|
||||||
|
f'"mintTo(address,uint256)" {to} {value}'
|
||||||
|
)
|
||||||
|
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
||||||
|
if result.returncode != 0:
|
||||||
|
raise subprocess.CalledProcessError(result.returncode, command, output=result.stdout, stderr=result.stderr)
|
||||||
|
if result.stderr:
|
||||||
|
raise ValueError(f"Command failed with error: {result.stderr}")
|
||||||
|
return result.stdout
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def foo_handler(cmd):
|
def foo_handler(cmd):
|
||||||
return os.popen('eth-info -p https://celo.grassecon.net').read()
|
return os.popen('eth-info -p https://celo.grassecon.net').read()
|
||||||
|
|
||||||
|
|
||||||
parser = yacc.yacc()
|
parser = yacc.yacc()
|
||||||
|
|
||||||
cmds = [
|
running = True
|
||||||
"KEY_CREATE foo-bar Foo BAr",
|
|
||||||
"KEY_CREATE bar-baz Foo BAr 0xabcdef0",
|
|
||||||
"VOUCHER_MINT - 0xdeadbeef 13 0xfdaf",
|
class FileGet:
|
||||||
"VOUCHER_MINT baz-baz 0xdeadbeef 13 0xfdaf",
|
def __init__(self, o, fp):
|
||||||
"VOUCHER_MINT bar-bar 0xdeadbeef 42",
|
self.__running = True
|
||||||
"VOUCHER_CREATE foo-foo Foo Bar 42",
|
self.__o = o
|
||||||
"VOUCHER_CREATE inky-pinky-blinky Foo Bar 42 44 233",
|
self.__f = open(fp, 'r')
|
||||||
"VOUCHER_TRANSFER clyde-sue 0xbeeffeed0123 666 foo 0x0fdc",
|
|
||||||
]
|
def run(self):
|
||||||
for v in cmds:
|
while self.__running:
|
||||||
|
v = ifc.get()
|
||||||
|
if v == None:
|
||||||
|
break
|
||||||
|
v = v.strip('\n')
|
||||||
|
if len(v) == 0:
|
||||||
|
break
|
||||||
|
r = parser.parse(v)
|
||||||
|
self.__o.exec(r)
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
return self.__f.readline()
|
||||||
|
|
||||||
|
|
||||||
|
class WaitGet:
|
||||||
|
def __init__(self, o, *r):
|
||||||
|
self.__running = True
|
||||||
|
self.__o = o
|
||||||
|
self.__f = r
|
||||||
|
|
||||||
|
# TODO: router copy results in missing keys to sync when closing down
|
||||||
|
def __process(self, f):
|
||||||
|
while self.__running:
|
||||||
|
r = select.select([f], [], [])
|
||||||
|
v = r[0][0].recv()
|
||||||
|
if v == None:
|
||||||
|
break
|
||||||
|
v = v.strip('\n')
|
||||||
|
if len(v) == 0:
|
||||||
|
break
|
||||||
|
r = parser.parse(v)
|
||||||
|
self.__o.exec(r)
|
||||||
|
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
(fo, fi,) = Pipe()
|
||||||
|
p = Process(target=self.__process, args=(fo,))
|
||||||
|
p.start()
|
||||||
|
while self.__running:
|
||||||
|
v = input("> ")
|
||||||
|
if v == "":
|
||||||
|
fi.send(None)
|
||||||
|
break
|
||||||
|
fi.send(v)
|
||||||
|
p.join()
|
||||||
|
logg.debug('waitget run end')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
ifc = None
|
||||||
o = Router()
|
o = Router()
|
||||||
o.register(CmdId.KEY_CREATE, noop_handler)
|
o.register(CmdId.KEY_CREATE,key_create_handler)
|
||||||
o.register(CmdId.VOUCHER_MINT, noop_handler)
|
o.register(CmdId.VOUCHER_CREATE, voucher_create_handler)
|
||||||
o.register(CmdId.VOUCHER_CREATE, noop_handler)
|
o.register(CmdId.VOUCHER_MINT, voucher_mint_handler)
|
||||||
o.register(CmdId.VOUCHER_TRANSFER, foo_handler)
|
o.register(CmdId.VOUCHER_TRANSFER, voucher_transfer_handler)
|
||||||
r = parser.parse(v)
|
|
||||||
o.exec(r)
|
if len(sys.argv) > 1:
|
||||||
|
ifc = FileGet(o, sys.argv[1])
|
||||||
|
else:
|
||||||
|
ifc = WaitGet(o, sys.stdin)
|
||||||
|
|
||||||
|
ifc.run()
|
||||||
|
o.finish()
|
||||||
|
4
seed_commands.txt
Normal file
4
seed_commands.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
KEY_CREATE - lockkey custodialstore
|
||||||
|
VOUCHER_CREATE - stm stopcoin 6
|
||||||
|
VOUCHER_TRANSFER - 0x0d3D8A97f970fbdf7486274b02A8308d8aCcE6a1 5000000 0x74096A72495FE95710C675E78bd4A10f2BfE08BC 0xEef7Ad2cCCB317E6898F43eA2B5b1BD1E9C13b1A
|
||||||
|
VOUCHER_MINT - 0x2e8ce655BEfBee9b29A34fcecb3193462e4d0999 5000000 0x74096a72495fe95710c675e78bd4a10f2bfe08bc
|
Loading…
Reference in New Issue
Block a user