40 lines
840 B
Python
40 lines
840 B
Python
# standard imports
|
|
import logging
|
|
|
|
# external imports
|
|
from chainlib.eth.address import to_checksum_address
|
|
from hexathon import strip_0x
|
|
|
|
# local imports
|
|
from gas3.error import InvalidInput
|
|
from gas3.error import Used
|
|
from gas3.base import check
|
|
|
|
logg = logging.getLogger(__name__)
|
|
|
|
|
|
def register_address(a):
|
|
pass
|
|
|
|
def do_register(req, env, data_dir):
|
|
i = req.path.find('/', 1)
|
|
if i == -1:
|
|
raise InvalidInput(env.path)
|
|
p = req.path[i+1:]
|
|
r = None
|
|
r = check(p, data_dir)
|
|
if not r:
|
|
raise Used('already used: ' + p)
|
|
|
|
v = env['wsgi.input'].read(42)
|
|
if type(v) == bytes:
|
|
v = v.decode('utf-8')
|
|
try:
|
|
v = strip_0x(v)
|
|
v = to_checksum_address(v)
|
|
except:
|
|
raise InvalidInput('invalid address: ' + str(v))
|
|
|
|
data_dir.add(p, bytes.fromhex(v))
|
|
return v
|