2020-12-29 19:44:14 +01:00
|
|
|
# Author: Louis Holbrook <dev@holbrook.no> 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
# File-version: 1
|
|
|
|
# Description: Python interface to abi and bin files for faucet contracts
|
|
|
|
|
|
|
|
# standard imports
|
|
|
|
import logging
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import hashlib
|
|
|
|
|
2021-03-21 13:27:42 +01:00
|
|
|
# external imports
|
|
|
|
from hexathon import (
|
|
|
|
strip_0x,
|
|
|
|
add_0x,
|
|
|
|
)
|
|
|
|
from chainlib.eth.tx import (
|
|
|
|
TxFormat,
|
|
|
|
TxFactory,
|
|
|
|
)
|
|
|
|
from chainlib.eth.contract import (
|
|
|
|
ABIContractEncoder,
|
|
|
|
ABIContractType,
|
|
|
|
abi_decode_single,
|
|
|
|
)
|
|
|
|
from chainlib.eth.constant import ZERO_ADDRESS
|
|
|
|
|
2021-04-30 17:13:58 +02:00
|
|
|
# local imports
|
|
|
|
from eth_address_declarator import Declarator
|
|
|
|
|
2020-12-29 19:44:14 +01:00
|
|
|
logg = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
moddir = os.path.dirname(__file__)
|
|
|
|
datadir = os.path.join(moddir, 'data')
|
|
|
|
|
|
|
|
|
2021-03-21 13:27:42 +01:00
|
|
|
def to_declarator_key(declarator_address_hex, declaration_address_hex):
|
|
|
|
h = hashlib.new('sha256')
|
|
|
|
h.update(bytes.fromhex(strip_0x(declaration_address_hex)))
|
|
|
|
h.update(bytes.fromhex(strip_0x(declarator_address_hex)))
|
|
|
|
return h.digest()
|
|
|
|
|
|
|
|
|
2021-04-30 17:13:58 +02:00
|
|
|
class AddressDeclarator(Declarator):
|
2020-12-29 19:44:14 +01:00
|
|
|
|
|
|
|
__abi = None
|
|
|
|
__bytecode = None
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def abi():
|
2020-12-29 21:19:12 +01:00
|
|
|
if AddressDeclarator.__abi == None:
|
2021-02-19 13:50:13 +01:00
|
|
|
f = open(os.path.join(datadir, 'AddressDeclarator.json'), 'r')
|
|
|
|
AddressDeclarator.__abi = json.load(f)
|
2020-12-29 19:44:14 +01:00
|
|
|
f.close()
|
2020-12-29 21:19:12 +01:00
|
|
|
return AddressDeclarator.__abi
|
2020-12-29 19:44:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def bytecode():
|
2020-12-29 21:19:12 +01:00
|
|
|
if AddressDeclarator.__bytecode == None:
|
2021-02-19 13:50:13 +01:00
|
|
|
f = open(os.path.join(datadir, 'AddressDeclarator.bin'))
|
|
|
|
AddressDeclarator.__bytecode = f.read()
|
2020-12-29 19:44:14 +01:00
|
|
|
f.close()
|
2020-12-29 21:19:12 +01:00
|
|
|
return AddressDeclarator.__bytecode
|
2020-12-29 19:44:14 +01:00
|
|
|
|
|
|
|
|
2021-03-22 17:23:57 +01:00
|
|
|
@staticmethod
|
|
|
|
def gas(code=None):
|
|
|
|
return 2000000
|
|
|
|
|
|
|
|
|
2023-03-24 09:55:59 +01:00
|
|
|
def constructor(self, sender_address, description):
|
2021-03-21 13:27:42 +01:00
|
|
|
code = AddressDeclarator.bytecode()
|
|
|
|
enc = ABIContractEncoder()
|
2023-03-24 09:55:59 +01:00
|
|
|
enc.bytes32(description)
|
2021-03-21 13:27:42 +01:00
|
|
|
code += enc.get()
|
|
|
|
tx = self.template(sender_address, None, use_nonce=True)
|
|
|
|
tx = self.set_code(tx, code)
|
|
|
|
return self.build(tx)
|