コード例 #1
0
ファイル: core.py プロジェクト: weilbith/blockchain
def deploy_home_bridge_contract(
    *,
    validator_proxy_contract_address: str,
    validators_required_percent: int,
    web3: Web3,
    transaction_options: Dict = None,
    private_key=None,
) -> Contract:

    if transaction_options is None:
        transaction_options = {}

    home_bridge_src = load_contract("HomeBridge")

    return deploy_compiled_contract(
        abi=home_bridge_src["abi"],
        bytecode=home_bridge_src["bytecode"],
        constructor_args=(
            validator_proxy_contract_address,
            validators_required_percent,
        ),
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )
コード例 #2
0
def token_contract(ether_owning_whitelist):
    contract_assets = load_contracts_json("auction_deploy")
    abi = contract_assets["TrustlinesNetworkToken"]["abi"]
    bytecode = contract_assets["TrustlinesNetworkToken"]["bytecode"]
    token_name = "Trustlines Network Token"
    token_symbol = "TLN"
    token_decimal = 18
    number_to_mint = 10 * 10**18
    premint_address = ether_owning_whitelist[0]
    constructor_args = (
        token_name,
        token_symbol,
        token_decimal,
        premint_address,
        number_to_mint,
    )

    token_contract = deploy_compiled_contract(
        abi=abi,
        bytecode=bytecode,
        web3=test_json_rpc,
        constructor_args=constructor_args,
    )
    token_contract.functions.transfer(ether_owning_whitelist[1],
                                      int(number_to_mint / 2)).transact(
                                          {"from": ether_owning_whitelist[0]})

    return token_contract
コード例 #3
0
def test_deploy_st_petersburg(web3, contract_assets_st_petersburg):
    contract_interface = contract_assets_st_petersburg["TestContract"]
    contract = deploy_compiled_contract(
        abi=contract_interface["abi"],
        bytecode=contract_interface["bytecode"],
        web3=web3,
        constructor_args=(1,),
    )

    assert is_address(contract.address)
コード例 #4
0
def test_deploy_from_private_key(web3, contract_assets, account_keys):
    contract_interface = contract_assets["TestContract"]
    contract = deploy_compiled_contract(
        abi=contract_interface["abi"],
        bytecode=contract_interface["bytecode"],
        web3=web3,
        constructor_args=(1,),
        private_key=account_keys[1],
    )

    assert is_address(contract.address)
コード例 #5
0
def token_contract(premint_token_value):
    web3 = connect_to_json_rpc("test")
    compiled_contracts = load_contracts_json("merkle_drop")

    token_contract: Contract = deploy_compiled_contract(
        abi=compiled_contracts["DroppedToken"]["abi"],
        bytecode=compiled_contracts["DroppedToken"]["bytecode"],
        constructor_args=(
            "Test Token",
            "TT",
            18,
            web3.eth.accounts[0],
            premint_token_value,
        ),
        web3=web3,
    )

    return token_contract
コード例 #6
0
def unfunded_merkle_drop_contract(
    premint_token_value, root_hash_for_tree_data, token_contract
):
    web3 = connect_to_json_rpc("test")
    compiled_contracts = load_contracts_json("merkle_drop")

    merkle_drop_contract: Contract = deploy_compiled_contract(
        abi=compiled_contracts["MerkleDrop"]["abi"],
        bytecode=compiled_contracts["MerkleDrop"]["bytecode"],
        constructor_args=(
            token_contract.address,
            premint_token_value,
            root_hash_for_tree_data,
            pendulum.now().int_timestamp + 10,
            60 * 60 * 24 * 4,
        ),
        web3=web3,
    )

    return merkle_drop_contract
コード例 #7
0
ファイル: core.py プロジェクト: weilbith/blockchain
def deploy_foreign_bridge_contract(
    *,
    token_contract_address: str,
    web3: Web3,
    transaction_options: Dict = None,
    private_key=None,
) -> Contract:

    if transaction_options is None:
        transaction_options = {}

    foreign_bridge_src = load_contract("ForeignBridge")

    return deploy_compiled_contract(
        abi=foreign_bridge_src["abi"],
        bytecode=foreign_bridge_src["bytecode"],
        constructor_args=(token_contract_address,),
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )
コード例 #8
0
def deploy_validator_set_contract(
    *, web3, transaction_options: Dict = None, private_key=None
):

    if transaction_options is None:
        transaction_options = {}

    compiled_contracts = load_contracts_json(__name__)

    validator_set_abi = compiled_contracts["ValidatorSet"]["abi"]
    validator_set_bin = compiled_contracts["ValidatorSet"]["bytecode"]

    validator_set_contract: Contract = deploy_compiled_contract(
        abi=validator_set_abi,
        bytecode=validator_set_bin,
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )

    return validator_set_contract
コード例 #9
0
def deploy_validator_proxy_contract(
    *, web3, transaction_options: Dict = None, private_key=None, validators
):

    if transaction_options is None:
        transaction_options = {}

    compiled_contracts = load_contracts_json(__name__)

    validator_proxy_abi = compiled_contracts["ValidatorProxy"]["abi"]
    validator_proxy_bin = compiled_contracts["ValidatorProxy"]["bytecode"]

    validator_proxy_contract: Contract = deploy_compiled_contract(
        abi=validator_proxy_abi,
        bytecode=validator_proxy_bin,
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
        constructor_args=(validators,),
    )

    return validator_proxy_contract
コード例 #10
0
def deploy_merkle_drop(
    *, web3, transaction_options: Dict = None, private_key=None, constructor_args
):

    if transaction_options is None:
        transaction_options = {}

    compiled_contracts = load_contracts_json(__name__)

    merkle_drop_abi = compiled_contracts["MerkleDrop"]["abi"]
    merkle_drop_bin = compiled_contracts["MerkleDrop"]["bytecode"]

    merkle_drop_contract: Contract = deploy_compiled_contract(
        abi=merkle_drop_abi,
        bytecode=merkle_drop_bin,
        constructor_args=constructor_args,
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )

    return merkle_drop_contract
コード例 #11
0
def deploy_auction_contracts(
    *,
    web3,
    transaction_options: Dict = None,
    private_key=None,
    auction_options: AuctionOptions,
    already_deployed_contracts:
    DeployedContractsAddresses = DeployedContractsAddresses(),
) -> DeployedAuctionContracts:

    use_token = auction_options.token_address is not None

    if transaction_options is None:
        transaction_options = {}

    if (already_deployed_contracts.auction is not None
            and already_deployed_contracts.locker is None):
        raise ValueError(
            "Cannot deploy new locker if auction already deployed due to constructor of auction."
        )

    compiled_contracts = load_contracts_json(__name__)

    deposit_locker_abi = (compiled_contracts["TokenDepositLocker"]["abi"]
                          if use_token else
                          compiled_contracts["ETHDepositLocker"]["abi"])
    deposit_locker_bin = (compiled_contracts["TokenDepositLocker"]["bytecode"]
                          if use_token else
                          compiled_contracts["ETHDepositLocker"]["bytecode"])

    validator_slasher_abi = compiled_contracts["ValidatorSlasher"]["abi"]
    validator_slasher_bin = compiled_contracts["ValidatorSlasher"]["bytecode"]

    auction_abi = (compiled_contracts["TokenValidatorAuction"]["abi"]
                   if use_token else
                   compiled_contracts["ETHValidatorAuction"]["abi"])
    auction_bin = (compiled_contracts["TokenValidatorAuction"]["bytecode"]
                   if use_token else
                   compiled_contracts["ETHValidatorAuction"]["bytecode"])

    if already_deployed_contracts.locker is not None:
        deposit_locker_contract: Contract = web3.eth.contract(
            abi=deposit_locker_abi,
            bytecode=deposit_locker_bin,
            address=already_deployed_contracts.locker,
        )
    else:
        deposit_locker_contract = deploy_compiled_contract(
            abi=deposit_locker_abi,
            bytecode=deposit_locker_bin,
            web3=web3,
            transaction_options=transaction_options,
            private_key=private_key,
        )
        increase_transaction_options_nonce(transaction_options)

    if already_deployed_contracts.slasher is not None:
        validator_slasher_contract = web3.eth.contract(
            abi=validator_slasher_abi,
            bytecode=validator_slasher_bin,
            address=already_deployed_contracts.slasher,
        )
    else:
        validator_slasher_contract = deploy_compiled_contract(
            abi=validator_slasher_abi,
            bytecode=validator_slasher_bin,
            web3=web3,
            transaction_options=transaction_options,
            private_key=private_key,
        )
        increase_transaction_options_nonce(transaction_options)

    if already_deployed_contracts.auction is not None:
        auction_contract: Contract = web3.eth.contract(
            abi=auction_abi,
            bytecode=auction_bin,
            address=already_deployed_contracts.auction,
        )
    else:
        auction_constructor_args: Tuple = (
            auction_options.start_price,
            auction_options.auction_duration,
            auction_options.minimal_number_of_participants,
            auction_options.maximal_number_of_participants,
            deposit_locker_contract.address,
        )
        if use_token:
            auction_constructor_args += (auction_options.token_address, )

        auction_contract = deploy_compiled_contract(
            abi=auction_abi,
            bytecode=auction_bin,
            web3=web3,
            constructor_args=auction_constructor_args,
            transaction_options=transaction_options,
            private_key=private_key,
        )
        increase_transaction_options_nonce(transaction_options)

    contracts = DeployedAuctionContracts(deposit_locker_contract,
                                         validator_slasher_contract,
                                         auction_contract)

    return contracts
コード例 #12
0
ファイル: core.py プロジェクト: weilbith/blockchain
def deploy_auction_contracts(
    *,
    web3,
    transaction_options: Dict = None,
    private_key=None,
    auction_options: AuctionOptions,
) -> DeployedAuctionContracts:

    if transaction_options is None:
        transaction_options = {}

    compiled_contracts = load_contracts_json(__name__)

    deposit_locker_abi = compiled_contracts["DepositLocker"]["abi"]
    deposit_locker_bin = compiled_contracts["DepositLocker"]["bytecode"]

    validator_slasher_abi = compiled_contracts["ValidatorSlasher"]["abi"]
    validator_slasher_bin = compiled_contracts["ValidatorSlasher"]["bytecode"]

    auction_abi = compiled_contracts["ValidatorAuction"]["abi"]
    auction_bin = compiled_contracts["ValidatorAuction"]["bytecode"]

    deposit_locker_contract: Contract = deploy_compiled_contract(
        abi=deposit_locker_abi,
        bytecode=deposit_locker_bin,
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )
    increase_transaction_options_nonce(transaction_options)

    validator_slasher_contract = deploy_compiled_contract(
        abi=validator_slasher_abi,
        bytecode=validator_slasher_bin,
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
    )
    increase_transaction_options_nonce(transaction_options)

    auction_constructor_args = (
        auction_options.start_price,
        auction_options.auction_duration,
        auction_options.minimal_number_of_participants,
        auction_options.maximal_number_of_participants,
        deposit_locker_contract.address,
    )
    auction_contract: Contract = deploy_compiled_contract(
        abi=auction_abi,
        bytecode=auction_bin,
        web3=web3,
        constructor_args=auction_constructor_args,
        transaction_options=transaction_options,
        private_key=private_key,
    )
    increase_transaction_options_nonce(transaction_options)

    contracts = DeployedAuctionContracts(deposit_locker_contract,
                                         validator_slasher_contract,
                                         auction_contract)

    return contracts