Rehabilitate cic-eth-create step

This commit is contained in:
nolash 2021-03-24 15:52:52 +01:00
parent 585ad07c6e
commit e64b1bf984
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
20 changed files with 34 additions and 296 deletions

View File

@ -1,9 +1,10 @@
# standard imports
import logging
# third-party imports
# external imports
import celery
from cic_registry.chain import ChainSpec
from chainlib.chain import ChainSpec
from chainlib.eth.tx import unpack
# local imports
from cic_eth.db.models.base import SessionBase
@ -21,7 +22,6 @@ from cic_eth.queue.tx import (
set_cancel,
)
from cic_eth.queue.tx import create as queue_create
from cic_eth.eth.util import unpack_signed_raw_tx
from cic_eth.eth.gas import (
create_check_gas_task,
)
@ -51,7 +51,7 @@ def shift_nonce(self, chain_str, tx_hash_orig_hex, delta=1):
chain_spec = ChainSpec.from_chain_str(chain_str)
tx_brief = get_tx(tx_hash_orig_hex)
tx_raw = bytes.fromhex(tx_brief['signed_tx'][2:])
tx = unpack_signed_raw_tx(tx_raw, chain_spec.chain_id())
tx = unpack(tx_raw, chain_spec.chain_id())
nonce = tx_brief['nonce']
address = tx['from']
@ -72,7 +72,7 @@ def shift_nonce(self, chain_str, tx_hash_orig_hex, delta=1):
txs = []
for otx in otxs:
tx_raw = bytes.fromhex(otx.signed_tx[2:])
tx_new = unpack_signed_raw_tx(tx_raw, chain_spec.chain_id())
tx_new = unpack(tx_raw, chain_spec.chain_id())
tx_previous_hash_hex = tx_new['hash']
tx_previous_nonce = tx_new['nonce']

View File

@ -2,14 +2,13 @@
import logging
import sys
# third-party imports
# external imports
import celery
import web3
from cic_registry import zero_address
from cic_registry import zero_content
from cic_registry import CICRegistry
from crypto_dev_signer.eth.web3ext import Web3 as Web3Ext
from cic_registry.error import UnknownContractError
from chainlib.eth.constant import (
ZERO_ADDRESS,
ZERO_CONTENT,
)
from cic_eth_registry.error import UnknownContractError
from chainlib.eth.address import to_checksum_address
# local imports
@ -24,9 +23,7 @@ from cic_eth.db.enum import (
)
from cic_eth.error import InitializationError
from cic_eth.db.error import TxStateChangeError
from cic_eth.eth.rpc import RpcClient
from cic_eth.queue.tx import get_tx
from cic_eth.eth.util import unpack_signed_raw_tx
app = celery.current_app

View File

@ -8,7 +8,7 @@ import logging
# external imports
import celery
from cic_registry import CICRegistry
from cic_eth_registry import CICRegistry
from chainlib.chain import ChainSpec
# local imports

View File

@ -4,7 +4,7 @@ import logging
# third-party imports
from sqlalchemy import Column, String, Integer, DateTime, ForeignKey
from cic_registry import zero_address
from chainlib.eth.constant import ZERO_ADDRESS
# local imports
from cic_eth.db.models.base import SessionBase
@ -35,7 +35,7 @@ class Lock(SessionBase):
@staticmethod
def set(chain_str, flags, address=zero_address, session=None, tx_hash=None):
def set(chain_str, flags, address=ZERO_ADDRESS, session=None, tx_hash=None):
"""Sets flags associated with the given address and chain.
If a flags entry does not exist it is created.
@ -88,7 +88,7 @@ class Lock(SessionBase):
@staticmethod
def reset(chain_str, flags, address=zero_address, session=None):
def reset(chain_str, flags, address=ZERO_ADDRESS, session=None):
"""Resets flags associated with the given address and chain.
If the resulting flags entry value is 0, the entry will be deleted.
@ -132,7 +132,7 @@ class Lock(SessionBase):
@staticmethod
def check(chain_str, flags, address=zero_address, session=None):
def check(chain_str, flags, address=ZERO_ADDRESS, session=None):
"""Checks whether all given flags are set for given address and chain.
Does not validate the address against any other tables or components.

View File

@ -15,7 +15,6 @@ from cic_eth.db.enum import (
is_error_status,
)
from cic_eth.db.error import TxStateChangeError
#from cic_eth.eth.util import address_hex_from_signed_tx
logg = logging.getLogger()

View File

@ -1,9 +1,9 @@
# standard imports
import logging
# third-party imports
# external imports
from sqlalchemy import Column, String, Text
from cic_registry import zero_address
from chainlib.eth.constant import ZERO_ADDRESS
# local imports
from .base import SessionBase
@ -42,7 +42,7 @@ class AccountRole(SessionBase):
role = AccountRole.__get_role(tag, session)
r = zero_address
r = ZERO_ADDRESS
if role != None:
r = role.address_hex
@ -133,4 +133,4 @@ class AccountRole(SessionBase):
def __init__(self, tag):
self.tag = tag
self.address_hex = zero_address
self.address_hex = ZERO_ADDRESS

View File

@ -1,16 +0,0 @@
"""Ethereum batch functions and utilities
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
"""
# standard imports
import os
# local imports
from .rpc import RpcClient
registry_extra_identifiers = {
'Faucet': '0x{:0<64s}'.format(b'Faucet'.hex()),
'TransferApproval': '0x{:0<64s}'.format(b'TransferApproval'.hex()),
}

View File

@ -23,10 +23,7 @@ from eth_accounts_index import AccountRegistry
from sarafu_faucet import MinterFaucet as Faucet
# local import
#from cic_eth.registry import safe_registry
#from cic_eth.eth import RpcClient
from cic_eth_registry import CICRegistry
from cic_eth.eth import registry_extra_identifiers
from cic_eth.eth.gas import (
create_check_gas_task,
)
@ -35,7 +32,6 @@ from cic_eth.db.models.nonce import Nonce
from cic_eth.db.models.base import SessionBase
from cic_eth.db.models.role import AccountRole
from cic_eth.db.models.tx import TxCache
from cic_eth.eth.util import unpack_signed_raw_tx
from cic_eth.error import (
RoleMissingError,
SignerError,

View File

@ -3,8 +3,6 @@ import logging
# external imports
import celery
import requests
import web3
from chainlib.eth.constant import ZERO_ADDRESS
from chainlib.chain import ChainSpec
from chainlib.connection import RPCConnection
@ -18,11 +16,9 @@ from cic_eth_registry.erc20 import ERC20Token
from hexathon import strip_0x
# local imports
from cic_eth.registry import safe_registry
from cic_eth.db.models.tx import TxCache
from cic_eth.db.models.base import SessionBase
from cic_eth.db.models.role import AccountRole
from cic_eth.eth import RpcClient
from cic_eth.error import TokenCountError, PermanentTxError, OutOfGasError, NotLocalTxError
from cic_eth.queue.tx import register_tx
from cic_eth.eth.gas import (

View File

@ -1,39 +0,0 @@
# standard imports
import logging
logg = logging.getLogger()
class RpcClient:
pass
#class RpcClient(GasOracle):
# """RPC wrapper for web3 enabling gas calculation helpers and signer middleware.
#
# :param chain_spec: Chain spec
# :type chain_spec: cic_registry.chain.ChainSpec
# :param holder_address: DEPRECATED Address of subject of the session.
# :type holder_address: str, 0x-hex
# """
#
# signer_ipc_path = None
# """Unix socket path to JSONRPC signer and keystore"""
#
# web3_constructor = None
# """Custom function to build a web3 object with middleware plugins"""
#
#
# def __init__(self, chain_spec, holder_address=None):
# (self.provider, w3) = RpcClient.web3_constructor()
# super(RpcClient, self).__init__(w3)
# self.chain_spec = chain_spec
# if holder_address != None:
# self.holder_address = holder_address
# logg.info('gasprice {}'.format(self.gas_price()))
#
#
# @staticmethod
# def set_constructor(web3_constructor):
# """Sets the constructor to use for building the web3 object.
# """
# RpcClient.web3_constructor = web3_constructor

View File

@ -32,7 +32,6 @@ from hexathon import (
)
# local imports
from .rpc import RpcClient
from cic_eth.db import (
Otx,
SessionBase,
@ -64,7 +63,6 @@ from cic_eth.error import (
AlreadyFillingGasError,
EthError,
)
from cic_eth.eth.util import tx_hex_string
from cic_eth.admin.ctrl import lock_send
from cic_eth.task import (
CriticalSQLAlchemyTask,
@ -269,7 +267,6 @@ def send(self, txs, chain_spec_dict):
queue = self.request.delivery_info.get('routing_key')
#c = RpcClient(chain_spec)
r = None
s_set_sent = celery.signature(
'cic_eth.queue.tx.set_sent_status',
@ -399,7 +396,7 @@ def resend_with_higher_gas(self, txold_hash_hex, chain_str, gas=None, default_fa
c = RpcClient(chain_spec)
tx_signed_raw_bytes = bytes.fromhex(otx.signed_tx[2:])
tx = unpack_signed_raw_tx(tx_signed_raw_bytes, chain_spec.chain_id())
tx = unpack(tx_signed_raw_bytes, chain_spec.chain_id())
logg.debug('resend otx {} {}'.format(tx, otx.signed_tx))
queue = self.request.delivery_info['routing_key']
@ -489,9 +486,7 @@ def sync_tx(self, tx_hash_hex, chain_str):
queue = self.request.delivery_info['routing_key']
chain_spec = ChainSpec.from_chain_str(chain_str)
#c = RpcClient(chain_spec)
#tx = c.w3.eth.getTransaction(tx_hash_hex)
conn = RPCConnection.connect()
o = transaction(tx_hash_hex)
tx = conn.do(o)

View File

@ -1,110 +0,0 @@
# standard imports
import logging
import sha3
import web3
# external imports
from rlp import decode as rlp_decode
from rlp import encode as rlp_encode
from eth_keys import KeyAPI
from chainlib.eth.tx import unpack
logg = logging.getLogger()
field_debugs = [
'nonce',
'gasPrice',
'gas',
'to',
'value',
'data',
'v',
'r',
's',
]
unpack_signed_raw_tx = unpack
#def unpack_signed_raw_tx(tx_raw_bytes, chain_id):
# d = rlp_decode(tx_raw_bytes)
#
# logg.debug('decoding {} using chain id {}'.format(tx_raw_bytes.hex(), chain_id))
# j = 0
# for i in d:
# logg.debug('decoded {}: {}'.format(field_debugs[j], i.hex()))
# j += 1
# vb = chain_id
# if chain_id != 0:
# v = int.from_bytes(d[6], 'big')
# vb = v - (chain_id * 2) - 35
# while len(d[7]) < 32:
# d[7] = b'\x00' + d[7]
# while len(d[8]) < 32:
# d[8] = b'\x00' + d[8]
# s = b''.join([d[7], d[8], bytes([vb])])
# so = KeyAPI.Signature(signature_bytes=s)
#
# h = sha3.keccak_256()
# h.update(rlp_encode(d))
# signed_hash = h.digest()
#
# d[6] = chain_id
# d[7] = b''
# d[8] = b''
#
# h = sha3.keccak_256()
# h.update(rlp_encode(d))
# unsigned_hash = h.digest()
#
# p = so.recover_public_key_from_msg_hash(unsigned_hash)
# a = p.to_checksum_address()
# logg.debug('decoded recovery byte {}'.format(vb))
# logg.debug('decoded address {}'.format(a))
# logg.debug('decoded signed hash {}'.format(signed_hash.hex()))
# logg.debug('decoded unsigned hash {}'.format(unsigned_hash.hex()))
#
# to = d[3].hex() or None
# if to != None:
# to = web3.Web3.toChecksumAddress('0x' + to)
#
# return {
# 'from': a,
# 'nonce': int.from_bytes(d[0], 'big'),
# 'gasPrice': int.from_bytes(d[1], 'big'),
# 'gas': int.from_bytes(d[2], 'big'),
# 'to': to,
# 'value': int.from_bytes(d[4], 'big'),
# 'data': '0x' + d[5].hex(),
# 'v': chain_id,
# 'r': '0x' + s[:32].hex(),
# 's': '0x' + s[32:64].hex(),
# 'chainId': chain_id,
# 'hash': '0x' + signed_hash.hex(),
# 'hash_unsigned': '0x' + unsigned_hash.hex(),
# }
def unpack_signed_raw_tx_hex(tx_raw_hex, chain_id):
return unpack_signed_raw_tx(bytes.fromhex(tx_raw_hex[2:]), chain_id)
# TODO: consider moving tx string representation generation from api_admin to here
def tx_string(tx_raw_bytes, chain_id):
tx_unpacked = unpack_signed_raw_tx(tx_raw_bytes, chain_id)
return 'tx nonce {} from {} to {} hash {}'.format(
tx_unpacked['nonce'],
tx_unpacked['from'],
tx_unpacked['to'],
tx_unpacked['hash'],
)
def tx_hex_string(tx_hex, chain_id):
if len(tx_hex) < 2:
raise ValueError('invalid data length')
elif tx_hex[:2] == '0x':
tx_hex = tx_hex[2:]
tx_raw_bytes = bytes.fromhex(tx_hex)
return tx_string(tx_raw_bytes, chain_id)

View File

@ -10,8 +10,6 @@ from cic_eth_registry import CICRegistry
from eth_address_declarator import AddressDeclarator
# local imports
from cic_eth.eth import RpcClient
from cic_eth.registry import safe_registry
from cic_eth.task import BaseTask
celery_app = celery.current_app

View File

@ -26,7 +26,6 @@ from cic_eth.db.enum import (
dead,
)
from cic_eth.task import CriticalSQLAlchemyTask
from cic_eth.eth.util import unpack_signed_raw_tx # TODO: should not be in same sub-path as package that imports queue.tx
from cic_eth.error import NotLocalTxError
from cic_eth.error import LockedError
from cic_eth.db.enum import status_str

View File

@ -1,80 +0,0 @@
# standard imports
import logging
# external imports
from cic_registry import CICRegistry
from cic_registry.registry import from_identifier
from chainlib.chain import ChainSpec
from cic_registry.chain import ChainRegistry
from cic_registry.helper.declarator import DeclaratorOracleAdapter
logg = logging.getLogger(__name__)
def safe_registry(w3):
"""Temporary workaround for enabling thread-safe usage of the CICRegistry.
"""
CICRegistry.w3 = w3
return CICRegistry
def init_registry(config, w3, auto_populate=True):
chain_spec = ChainSpec.from_chain_str(config.get('CIC_CHAIN_SPEC'))
CICRegistry.init(w3, config.get('CIC_REGISTRY_ADDRESS'), chain_spec)
CICRegistry.add_path(config.get('ETH_ABI_DIR'))
chain_registry = ChainRegistry(chain_spec)
CICRegistry.add_chain_registry(chain_registry, True)
declarator = CICRegistry.get_contract(chain_spec, 'AddressDeclarator', interface='Declarator')
trusted_addresses_src = config.get('CIC_TRUST_ADDRESS')
if trusted_addresses_src == None:
raise ValueError('At least one trusted address must be declared in CIC_TRUST_ADDRESS')
trusted_addresses = trusted_addresses_src.split(',')
for address in trusted_addresses:
logg.info('using trusted address {}'.format(address))
oracle = DeclaratorOracleAdapter(declarator.contract, trusted_addresses)
chain_registry.add_oracle(oracle, 'naive_erc20_oracle')
if auto_populate:
populate(chain_spec, w3)
return CICRegistry
def populate(chain_spec, w3):
registry = CICRegistry.get_contract(chain_spec, 'CICRegistry')
fn = registry.function('identifiers')
i = 0
token_registry_contract = None
while True:
identifier_hex = None
try:
identifier_hex = fn(i).call()
except ValueError:
break
identifier = from_identifier(identifier_hex)
i += 1
try:
if identifier == 'TokenRegistry':
c = CICRegistry.get_contract(chain_spec, identifier, interface='RegistryClient')
token_registry_contract = c
else:
c = CICRegistry.get_contract(chain_spec, identifier)
logg.info('found token registry contract {}'.format(c.address()))
except ValueError:
logg.error('contract for identifier {} not found'.format(identifier))
continue
fn = token_registry_contract.function('entry')
i = 0
while True:
token_address = None
try:
token_address = fn(i).call()
except ValueError:
break
CICRegistry.get_address(chain_spec, token_address)
i += 1

View File

@ -1,17 +1,19 @@
#!/usr/bin/python
#import socket
import sys
import os
import logging
import uuid
import json
import argparse
# external imports
import confini
import redis
import celery
from xdg.BaseDirectory import xdg_config_home
import celery
# local imports
from cic_eth.api import Api
import confini
import argparse
import redis
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger('create_account_script')

View File

@ -145,7 +145,7 @@ def main():
rpc = RPCConnection.connect(chain_spec, 'default')
registry = CICRegistry(chain_spec, rpc)
registry_address = registry.by_name('CICRegistry')
registry_address = registry.by_name('ContractRegistry')
trusted_addresses_src = config.get('CIC_TRUST_ADDRESS')
if trusted_addresses_src == None:

View File

@ -1,7 +1,7 @@
cic-base~=0.1.2a5
cic-base~=0.1.2a18
web3==5.12.2
celery==4.4.7
crypto-dev-signer~=0.4.14a5
crypto-dev-signer~=0.4.14a6
confini~=0.3.6rc3
cic-eth-registry~=0.5.4a3
#cic-bancor~=0.0.6
@ -18,8 +18,9 @@ semver==2.13.0
websocket-client==0.57.0
moolb~=0.1.1b2
eth-address-index~=0.1.1a2
chainlib~=0.0.1a29
chainlib~=0.0.1a30
hexathon~=0.0.1a5
chainsyncer~=0.0.1a20
pysha3==1.0.2
coincurve==15.0.0
sarafu-faucet==0.0.2a6

View File

@ -236,7 +236,7 @@ services:
BANCOR_DIR: ${BANCOR_DIR:-/usr/local/share/cic/bancor}
CELERY_BROKER_URL: ${CELERY_BROKER_URL:-redis://redis}
CELERY_RESULT_URL: ${CELERY_RESULT_URL:-redis://redis}
SIGNER_SOCKET_PATH: ${SIGNER_SOCKET_PATH:-ipc:///tmp/cic/signer/jsonrpc.ipc}
SIGNER_SOCKET_PATH: ${SIGNER_SOCKET_PATH:-ipc:///run/crypto-dev-signer/jsonrpc.ipc}
SIGNER_SECRET: ${SIGNER_SECRET:-deadbeef}
ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER: ${DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER:-0xACB0BC74E1686D62dE7DC6414C999EA60C09F0eA}
TASKS_TRACE_QUEUE_STATUS: ${TASKS_TRACE_QUEUE_STATUS:-1}