Example #1
0
    def get(self, receiver, coins):

        w3 = Web3(HTTPProvider())
        if int(w3.version.network) == 4:
            txn_wait = 500
            size_extraData_for_poa = 200  # can change
            pythonic_middleware.__closure__[2].cell_contents[
                'eth_getBlockByNumber'].args[1].args[0][
                    'extraData'] = to_hexbytes(size_extraData_for_poa,
                                               variable_length=True)
            pythonic_middleware.__closure__[2].cell_contents[
                'eth_getBlockByHash'].args[1].args[0][
                    'extraData'] = to_hexbytes(size_extraData_for_poa,
                                               variable_length=True)
        contract_instance = w3.eth.contract(
            address=contract_address,
            abi=abi,
            ContractFactoryClass=ConciseContract)
        owner = "0x09226F56C5699E2d87700179507cf25FA2F79F6b"
        res = contract_instance.transfer(receiver,
                                         coins * (10**18),
                                         transact={'from': owner})

        return res.hex()
Example #2
0
def main(
    ctx,
    channel_manager_address,
    ssl_key,
    ssl_cert,
    gas_price,
    state_file,
    private_key,
    private_key_password_file,
    paywall_info,
    rpc_provider,
):
    private_key = utils.get_private_key(private_key, private_key_password_file)
    if private_key is None:
        sys.exit(1)

    receiver_address = privkey_to_addr(private_key)

    constants.paywall_html_dir = paywall_info
    while True:
        try:
            web3 = Web3(
                HTTPProvider(rpc_provider, request_kwargs={'timeout': 60}))
            size_extraData_for_poa = 200  # can change
            pythonic_middleware.__closure__[2].cell_contents[
                'eth_getBlockByNumber'].args[1].args[0][
                    'extraData'] = to_hexbytes(size_extraData_for_poa,
                                               variable_length=True)
            pythonic_middleware.__closure__[2].cell_contents[
                'eth_getBlockByHash'].args[1].args[0][
                    'extraData'] = to_hexbytes(size_extraData_for_poa,
                                               variable_length=True)
            NETWORK_CFG.set_defaults(int(web3.version.network))
            channel_manager_address = to_checksum_address(
                channel_manager_address or NETWORK_CFG.CHANNEL_MANAGER_ADDRESS)
            if gas_price is not None:
                NETWORK_CFG.gas_price = gas_price
            if not state_file:
                state_file_name = "%s_%s.db" % (channel_manager_address[:10],
                                                receiver_address[:10])
                app_dir = click.get_app_dir('microraiden')
                if not os.path.exists(app_dir):
                    os.makedirs(app_dir)
                state_file = os.path.join(app_dir, state_file_name)
            app = make_paywalled_proxy(
                private_key,
                state_file,
                contract_address=channel_manager_address,
                web3=web3)
        except StateFileLocked as ex:
            log.warning('Another uRaiden process is already running (%s)!' %
                        str(ex))
        except InsecureStateFile as ex:
            msg = (
                'The permission bits of the state file (%s) are set incorrectly (others can '
                'read or write) or you are not the owner. For reasons of security, '
                'startup is aborted.' % state_file)
            log.fatal(msg)
            raise
        except NetworkIdMismatch as ex:
            log.fatal(str(ex))
            raise
        except requests.exceptions.ConnectionError as ex:
            log.warning("Ethereum node refused connection: %s" % str(ex))
        else:
            break
        sleep(constants.SLEEP_RELOAD)
    ctx.obj = app
Example #3
0
from Modules import Listener
from time import sleep
from web3.middleware.pythonic import (
    pythonic_middleware,
    to_hexbytes,
)
from web3 import Web3
from getpass import getpass
import json
import yaml

size_extraData_for_poa = 200  # can change

pythonic_middleware.__closure__[2].cell_contents['eth_getBlockByNumber'].args[
    1].args[0]['extraData'] = to_hexbytes(size_extraData_for_poa,
                                          variable_length=True)

pythonic_middleware.__closure__[2].cell_contents['eth_getBlockByHash'].args[
    1].args[0]['extraData'] = to_hexbytes(size_extraData_for_poa,
                                          variable_length=True)

config = 'configs/settings_test.yml'

with open(config, 'r') as ymlFile:
    cfg = yaml.load(ymlFile)

pDataBridgeAddress = cfg['private']['dataBridgeAddress']

pDataBridgeAbiFile = cfg['private']['dataBridgeAbi']

pConnectionMethod = cfg['private']['connectionMethod']
Example #4
0
log = logging.getLogger(__name__)

#w3 = chain.web3
w3 = Web3(HTTPProvider("http://localhost:8545", request_kwargs={'timeout':
                                                                60}))
print('Web3 provider is', w3.providers[0])

# Temporary fix for Rinkeby; PoA adds bytes to extraData, which is not yellow-paper-compliant
# https://github.com/ethereum/web3.py/issues/549
if int(w3.version.network) == 4:
    txn_wait = 500
    size_extraData_for_poa = 200  # can change

    pythonic_middleware.__closure__[2].cell_contents[
        'eth_getBlockByNumber'].args[1].args[0]['extraData'] = to_hexbytes(
            size_extraData_for_poa, variable_length=True)
    pythonic_middleware.__closure__[2].cell_contents[
        'eth_getBlockByHash'].args[1].args[0]['extraData'] = to_hexbytes(
            size_extraData_for_poa, variable_length=True)


def wait_for_blocks(n):
    while w3.eth.blockNumber < n:
        gevent.sleep()


def open_channel(
    channel_manager: ChannelManager,
    client: Client,
    receiver_address: str,
):
Example #5
0
def main(**kwargs):
    project = Project()

    chain_name = kwargs['chain']
    owner = kwargs['owner']
    challenge_period = kwargs['challenge_period']
    supply = kwargs['supply']
    token_name = kwargs['token_name']
    token_decimals = kwargs['token_decimals']
    token_symbol = kwargs['token_symbol']
    token_address = kwargs['token_address']
    supply *= 10**(token_decimals)
    txn_wait = 250

    assert challenge_period >= 500, 'Challenge period should be >= 500 blocks'

    if chain_name == 'rinkeby':
        txn_wait = 500

    print(
        '''Make sure {} chain is running, you can connect to it and it is synced,
          or you'll get timeout'''.format(chain_name))

    with project.get_chain(chain_name) as chain:
        web3 = chain.web3
        print('Web3 provider is', web3.providers[0])

        # Temporary fix for Rinkeby; PoA adds bytes to extraData, which is not yellow-paper-compliant
        # https://github.com/ethereum/web3.py/issues/549
        if int(web3.version.network) == 4:
            txn_wait = 500
            size_extraData_for_poa = 200  # can change

            pythonic_middleware.__closure__[2].cell_contents[
                'eth_getBlockByNumber'].args[1].args[0][
                    'extraData'] = to_hexbytes(size_extraData_for_poa,
                                               variable_length=True)
            pythonic_middleware.__closure__[2].cell_contents[
                'eth_getBlockByHash'].args[1].args[0][
                    'extraData'] = to_hexbytes(size_extraData_for_poa,
                                               variable_length=True)

        owner = owner or web3.eth.accounts[0]
        assert owner and is_address(owner), 'Invalid owner provided.'
        owner = to_checksum_address(owner)
        print('Owner is', owner)
        assert web3.eth.getBalance(
            owner) > 0, 'Account with insuficient funds.'

        token = chain.provider.get_contract_factory('TestMOS')

        if not token_address:
            txhash = token.deploy(
                args=[supply, token_name, token_symbol, token_decimals],
                transaction={'from': owner})
            time.sleep(180)
            receipt = check_succesful_tx(chain.web3, txhash, txn_wait)
            token_address = receipt['contractAddress']

        assert token_address and is_address(token_address)
        token_address = to_checksum_address(token_address)
        print(token_name, 'address is', token_address)

        microraiden_contract = chain.provider.get_contract_factory(
            'RaidenMicroTransferChannels')
        txhash = microraiden_contract.deploy(
            args=[token_address, challenge_period, []],
            transaction={'from': owner})
        time.sleep(180)
        receipt = check_succesful_tx(chain.web3, txhash, txn_wait)
        microraiden_address = receipt['contractAddress']

        print('RaidenMicroTransferChannels address is', microraiden_address)
Example #6
0
def main(**kwargs):
    project = Project()

    chain_name = kwargs['chain']
    owner = kwargs['owner']
    challenge_period = kwargs['challenge_period']
    supply = kwargs['supply']
    token_name = kwargs['token_name']
    token_decimals = kwargs['token_decimals']
    token_symbol = kwargs['token_symbol']
    token_address = kwargs['token_address']
    output_json = kwargs['output_json']
    delta_settle = kwargs['delta_settle']
    delta_withdraw = kwargs['delta_withdraw']
    supply *= 10**(token_decimals)
    txn_wait = 250

    #assert challenge_period >= 500, 'Challenge period should be >= 500 blocks'

    # PART OF TEMP FIX TO ISSUE 414 IN PULL REQUEST: https://github.com/raiden-network/microraiden/pull/416
    #    if chain_name == 'rinkeby':
    #        txn_wait = 500
    # end

    print(
        '''Make sure {} chain is running, you can connect to it and it is synced,
          or you'll get timeout'''.format(chain_name))

    with project.get_chain(chain_name) as chain:
        web3 = chain.web3
        print('Web3 provider is', web3.providers[0])

        # Temporary fix for Rinkeby; PoA adds bytes to extraData, which is not yellow-paper-compliant
        # https://github.com/ethereum/web3.py/issues/549
        if int(web3.version.network) == 4:
            txn_wait = 500
            size_extraData_for_poa = 200
            pythonic_middleware.__closure__[2].cell_contents[
                'eth_getBlockByNumber'].args[1].args[0][
                    'extraData'] = to_hexbytes(size_extraData_for_poa,
                                               variable_length=True)
            pythonic_middleware.__closure__[2].cell_contents[
                'eth_getBlockByHash'].args[1].args[0][
                    'extraData'] = to_hexbytes(size_extraData_for_poa,
                                               variable_length=True)
        # end

        owner = web3.eth.accounts[0]
        assert owner and is_address(owner), 'Invalid owner provided.'
        owner = to_checksum_address(owner)
        print('Owner is', owner)
        assert web3.eth.getBalance(
            owner) > 0, 'Account with insuficient funds.'

        token = chain.provider.get_contract_factory('CustomToken')

        if not token_address:
            print("Trying to deploy token.")
            txhash = token.deploy(
                args=[supply, token_name, token_symbol, token_decimals],
                transaction={'from': owner})
            receipt = check_succesful_tx(chain.web3, txhash, txn_wait)
            token_address = receipt['contractAddress']

        assert token_address and is_address(token_address)
        token_address = to_checksum_address(token_address)
        print(token_name, 'address is', token_address)
        print(token_name, 'tx is', encode_hex(txhash))

        print('Giving address %s some tokens.' % web3.eth.accounts[1])
        txid = token.transact({
            'from': web3.eth.accounts[1],
            'value': web3.toWei(100, 'finney'),
            'to': token_address
        }).mint()
        print('Minting transaction: %s' % txid)
        receipt = check_succesful_tx(web3, txid, txn_wait)

        print('Minting transaction finished')

        microraiden_contract = chain.provider.get_contract_factory(
            'RaidenMicroTransferChannels')
        txhash = microraiden_contract.deploy(
            args=[token_address, challenge_period, []],
            transaction={'from': owner})
        receipt = check_succesful_tx(chain.web3, txhash, txn_wait)
        microraiden_address = receipt['contractAddress']

        print('RaidenMicroTransferChannels txid is', encode_hex(txhash))
        print('RaidenMicroTransferChannels address is', microraiden_address)

        owner = web3.eth.accounts[1]
        assert owner and is_address(owner), 'Invalid owner provided.'
        owner = to_checksum_address(owner)
        print('Owner is', owner)
        assert web3.eth.getBalance(
            owner) > 0, 'Account with insuficient funds.'

        guardian_contract = chain.provider.get_contract_factory(
            'StateGuardian')
        txhash = guardian_contract.deploy(args=[delta_withdraw, delta_settle],
                                          transaction={
                                              'from': owner,
                                              'value': 10000
                                          })
        receipt = check_succesful_tx(chain.web3, txhash, txn_wait)
        guardian_address = receipt['contractAddress']

        print('StateGuardian tx is', encode_hex(txhash))
        print('StateGuardian address is', guardian_address)

        if output_json:
            d = json.load(open(output_json))
            d['token'] = token_address
            d['manager'] = microraiden_address
            d['monitor'] = guardian_address

            json.dump(d, open(output_json, 'w'))
Example #7
0
from Modules import IpfsModule
from web3 import Web3,IPCProvider
import datetime
import json
import yaml

from web3.middleware.pythonic import (
    pythonic_middleware,
    to_hexbytes,
)

size_extraData_for_poa = 200   # can change

web3 = Web3(IPCProvider('/home/solidity/.ethereum/geth.ipc'))

pythonic_middleware.__closure__[2].cell_contents['eth_getBlockByNumber'].args[1].args[0]['extraData'] = to_hexbytes(size_extraData_for_poa, variable_length=True)

pythonic_middleware.__closure__[2].cell_contents['eth_getBlockByHash'].args[1].args[0]['extraData'] = to_hexbytes(size_extraData_for_poa, variable_length=True)

# lets load the configuration file
configFile = 'configs/settings_test.yml'

with open(configFile, 'r') as ymlFile:
	cfg = yaml.load(ymlFile)

pDataBridgeAddress = cfg['private']['dataBridgeAddress']

pDataBridgeAbiFile = cfg['private']['dataBridgeAbi']

pSealerAddress = cfg['private']['sealerAddress']