Implement txs
This commit is contained in:
parent
7deffc93a4
commit
75ce19845e
@ -5,6 +5,16 @@ import logging
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
|
from chainlib.eth.gas import balance
|
||||||
|
from chainlib.eth.cli.config import Config
|
||||||
|
from chainlib.eth.cli.config import process_config
|
||||||
|
from chainlib.eth.cli.arg import ArgFlag
|
||||||
|
from chainlib.eth.cli.arg import Arg
|
||||||
|
from chainlib.eth.cli.arg import process_args
|
||||||
|
from chainlib.settings import ChainSettings
|
||||||
|
from chainlib.eth.settings import process_settings
|
||||||
|
from eth_contract_registry import Registry
|
||||||
|
import chainlib.eth.cli
|
||||||
from leveldir.uuid import UUIDDir
|
from leveldir.uuid import UUIDDir
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
@ -17,11 +27,57 @@ logging.basicConfig(level=logging.DEBUG)
|
|||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
data_path = os.environ.get('GAS3_DATA_DIR', 'data')
|
data_path = os.environ.get('GAS3_DATA_DIR', 'data')
|
||||||
|
registry = os.environ.get('CIC_REGISTRY_ADDRESS')
|
||||||
data_dir = UUIDDir(data_path)
|
data_dir = UUIDDir(data_path)
|
||||||
|
|
||||||
re_yield = re.compile('^/yield')
|
re_yield = re.compile('^/yield')
|
||||||
re_register = re.compile('^/register')
|
re_register = re.compile('^/register')
|
||||||
|
|
||||||
|
def process_settings_local(settings, config):
|
||||||
|
conn = settings.get('CONN')
|
||||||
|
o = balance(settings.get('SENDER_ADDRESS'))
|
||||||
|
r = conn.do(o)
|
||||||
|
logg.info('signing with address {} balance start {}'.format(settings.get('SENDER_ADDRESS'), int(r, 16)))
|
||||||
|
|
||||||
|
c = Registry(settings.get('CHAIN_SPEC'), gas_oracle=settings.get('GAS_ORACLE'))
|
||||||
|
#o = c.address_of(registry, 'registry', sender_address=settings.get('SENDER_ADDRESS'))
|
||||||
|
#o['params'][0]['gasPrice'] = "0x3b9aca00"
|
||||||
|
#o['params'][0]['gas'] = "0x7530"
|
||||||
|
#r = conn.do(o)
|
||||||
|
#logg.info('using registry {}'.format(r))
|
||||||
|
|
||||||
|
o = c.address_of(registry, 'accounts', sender_address=settings.get('SENDER_ADDRESS'))
|
||||||
|
r = conn.do(o)
|
||||||
|
accounts_index = c.parse_address_of(r)
|
||||||
|
settings.set('ACCOUNTS_CONTRACT', accounts_index)
|
||||||
|
logg.info('using accounts_index {}'.format(accounts_index))
|
||||||
|
|
||||||
|
o = c.address_of(registry, 'faucet', sender_address=settings.get('SENDER_ADDRESS'))
|
||||||
|
r = conn.do(o)
|
||||||
|
faucet = c.parse_address_of(r)
|
||||||
|
settings.set('FAUCET_CONTRACT', faucet)
|
||||||
|
logg.info('using faucet {}'.format(faucet))
|
||||||
|
|
||||||
|
return settings
|
||||||
|
|
||||||
|
|
||||||
|
arg_flags = ArgFlag()
|
||||||
|
arg = Arg(arg_flags)
|
||||||
|
flags = arg_flags.STD_WRITE | arg_flags.WALLET | arg_flags.EXEC
|
||||||
|
argparser = chainlib.eth.cli.ArgumentParser()
|
||||||
|
argparser = process_args(argparser, arg, flags)
|
||||||
|
args = argparser.parse_args()
|
||||||
|
|
||||||
|
config = Config()
|
||||||
|
config = process_config(config, arg, args, flags)
|
||||||
|
logg.debug('config loaded:\n{}'.format(config))
|
||||||
|
|
||||||
|
settings = ChainSettings()
|
||||||
|
settings = process_settings(settings, config)
|
||||||
|
settings = process_settings_local(settings, config)
|
||||||
|
logg.debug('settings loaded:\n{}'.format(settings))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def application(env, start_response):
|
def application(env, start_response):
|
||||||
req = urllib.parse.urlparse(env['REQUEST_URI'])
|
req = urllib.parse.urlparse(env['REQUEST_URI'])
|
||||||
@ -30,10 +86,10 @@ def application(env, start_response):
|
|||||||
|
|
||||||
r = ''
|
r = ''
|
||||||
if re.match(re_yield, req.path):
|
if re.match(re_yield, req.path):
|
||||||
r = do_yield(req, env, data_dir)
|
r = do_yield(req, env, data_dir, settings)
|
||||||
elif re.match(re_register, req.path):
|
elif re.match(re_register, req.path):
|
||||||
try:
|
try:
|
||||||
r = do_register(req, env, data_dir)
|
r = do_register(req, env, data_dir, settings)
|
||||||
except gas3.error.Used:
|
except gas3.error.Used:
|
||||||
scode = 410
|
scode = 410
|
||||||
stext = 'Code already used'
|
stext = 'Code already used'
|
||||||
@ -50,7 +106,6 @@ def application(env, start_response):
|
|||||||
r = str(e)
|
r = str(e)
|
||||||
else:
|
else:
|
||||||
r = ''
|
r = ''
|
||||||
|
|
||||||
|
|
||||||
l = len(r)
|
l = len(r)
|
||||||
status = str(scode) + ' ' + stext
|
status = str(scode) + ' ' + stext
|
||||||
|
@ -5,7 +5,7 @@ import logging
|
|||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def do_yield(req, env, data_dir):
|
def do_yield(req, env, data_dir, settings):
|
||||||
u = uuid.uuid4()
|
u = uuid.uuid4()
|
||||||
data_dir.add(u, b'\x00')
|
data_dir.add(u, b'\x00')
|
||||||
return str(u)
|
return str(u)
|
||||||
|
@ -4,6 +4,8 @@ import logging
|
|||||||
# external imports
|
# external imports
|
||||||
from chainlib.eth.address import to_checksum_address
|
from chainlib.eth.address import to_checksum_address
|
||||||
from hexathon import strip_0x
|
from hexathon import strip_0x
|
||||||
|
from eth_accounts_index import AccountsIndex
|
||||||
|
from eth_faucet import EthFaucet
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from gas3.error import InvalidInput
|
from gas3.error import InvalidInput
|
||||||
@ -13,10 +15,31 @@ from gas3.base import check
|
|||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def register_address(a):
|
def register_address(settings, address):
|
||||||
pass
|
c = AccountsIndex(
|
||||||
|
settings.get('CHAIN_SPEC'),
|
||||||
|
signer=settings.get('SIGNER'),
|
||||||
|
gas_oracle=settings.get('FEE_ORACLE'),
|
||||||
|
nonce_oracle=settings.get('NONCE_ORACLE'),
|
||||||
|
)
|
||||||
|
(tx_hash, o) = c.add(settings.get('ACCOUNTS_CONTRACT'), settings.get('SENDER_ADDRESS'), address)
|
||||||
|
r = settings.get('CONN').do(o)
|
||||||
|
logg.debug('registry tx for {}: {}'.format(address, tx_hash))
|
||||||
|
|
||||||
def do_register(req, env, data_dir):
|
c = EthFaucet(
|
||||||
|
settings.get('CHAIN_SPEC'),
|
||||||
|
signer=settings.get('SIGNER'),
|
||||||
|
gas_oracle=settings.get('FEE_ORACLE'),
|
||||||
|
nonce_oracle=settings.get('NONCE_ORACLE'),
|
||||||
|
)
|
||||||
|
(tx_hash, o) = c.give_to(settings.get('FAUCET_CONTRACT'), settings.get('SENDER_ADDRESS'), address)
|
||||||
|
r = settings.get('CONN').do(o)
|
||||||
|
logg.debug('faucet tx for {}: {}'.format(address, tx_hash))
|
||||||
|
|
||||||
|
return tx_hash
|
||||||
|
|
||||||
|
|
||||||
|
def do_register(req, env, data_dir, settings):
|
||||||
i = req.path.find('/', 1)
|
i = req.path.find('/', 1)
|
||||||
if i == -1:
|
if i == -1:
|
||||||
raise InvalidInput(env.path)
|
raise InvalidInput(env.path)
|
||||||
@ -36,4 +59,5 @@ def do_register(req, env, data_dir):
|
|||||||
raise InvalidInput('invalid address: ' + str(v))
|
raise InvalidInput('invalid address: ' + str(v))
|
||||||
|
|
||||||
data_dir.add(p, bytes.fromhex(v))
|
data_dir.add(p, bytes.fromhex(v))
|
||||||
return v
|
tx_hash = register_address(settings, v)
|
||||||
|
return tx_hash
|
||||||
|
@ -1,2 +1,5 @@
|
|||||||
leveldir~=0.3.3rc1
|
leveldir~=0.3.3rc1
|
||||||
chainlib-eth~=0.5.2
|
chainlib-eth~=0.5.2
|
||||||
|
eth-contract-registry~=0.12.0rc1
|
||||||
|
eth-accounts-index~=0.5.4rc1
|
||||||
|
eth-faucet~=0.5.0rc1
|
||||||
|
@ -54,6 +54,5 @@ class TestRegister(EthTesterCase):
|
|||||||
self.assertTrue(is_same_hex(r.hex(), self.accounts[0]))
|
self.assertTrue(is_same_hex(r.hex(), self.accounts[0]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user