コード例 #1
0
ファイル: __init__.py プロジェクト: todicus/hmt-escrow
def _setup_sol(contract: WContract,
               reputation_oracle: str,
               recording_oracle: str,
               reputation_oracle_stake: int,
               recording_oracle_stake: int,
               amount: int,
               manifest_url: str,
               manifest_hash: str,
               gas=DEFAULT_GAS) -> bool:

    W3 = get_w3()
    nonce = W3.eth.getTransactionCount(GAS_PAYER)

    tx_dict = contract.functions.setup(reputation_oracle, recording_oracle,
                                       reputation_oracle_stake,
                                       recording_oracle_stake, amount,
                                       manifest_url,
                                       manifest_hash).buildTransaction({
                                           'from':
                                           GAS_PAYER,
                                           'gas':
                                           gas,
                                           'nonce':
                                           nonce
                                       })
    tx_hash = sign_and_send_transaction(tx_dict, GAS_PAYER_PRIV)
    wait_on_transaction(tx_hash)

    return contract.functions.getStatus().call({
        'from': GAS_PAYER,
        'gas': gas
    }) == 1  # 1 Is pending 5 is Launched
コード例 #2
0
ファイル: __init__.py プロジェクト: todicus/hmt-escrow
def get_job(gas=DEFAULT_GAS) -> WContract:
    """ Get a new job and launch it without funds on the blockchain.

        This is the first step of putting a new job on the blockchain.
        After this function is called the user can add funds, abort, or set the job up for pending.

        Args:
            gas (int): How much gas to get on the contract.
        Returns:
            WContract: The contract launched on the blockchain
            """

    global ESCROW_FACTORY
    factory = None
    if not ESCROW_FACTORY:
        factory = get_factory(gas)
        ESCROW_FACTORY = factory.address
        if not ESCROW_FACTORY:
            raise Exception("Unable to get address from factory")

    if factory is None:
        contract_interface = get_contract_interface('<stdin>:EscrowFactory')
        factory = get_w3().eth.contract(address=ESCROW_FACTORY,
                                        abi=contract_interface['abi'])
        counter = factory.functions.getCounter().call({
            'from': GAS_PAYER,
            'gas': gas
        })
        LOG.debug("Factory counter is at:{}".format(counter))

    W3 = get_w3()
    nonce = W3.eth.getTransactionCount(GAS_PAYER)
    tx_dict = factory.functions.createEscrow().buildTransaction({
        'from': GAS_PAYER,
        'gas': gas,
        'nonce': nonce
    })
    tx_hash = sign_and_send_transaction(tx_dict, GAS_PAYER_PRIV)
    wait_on_transaction(tx_hash)

    escrow_address = factory.functions.getLastAddress().call({
        'from': GAS_PAYER,
        'gas': gas
    })

    LOG.info("New pokemon!:{}".format(escrow_address))
    contract_interface = get_contract_interface('<stdin>:Escrow')
    escrow = get_w3().eth.contract(address=escrow_address,
                                   abi=contract_interface['abi'])
    return escrow
コード例 #3
0
ファイル: __init__.py プロジェクト: todicus/hmt-escrow
def _abort_sol(contract: WContract, gas: int) -> bool:
    W3 = get_w3()
    nonce = W3.eth.getTransactionCount(GAS_PAYER)

    tx_dict = contract.functions.abort().buildTransaction({
        'from': GAS_PAYER,
        'gas': gas,
        'nonce': nonce
    })
    tx_hash = sign_and_send_transaction(tx_dict, GAS_PAYER_PRIV)
    wait_on_transaction(tx_hash)

    return contract.functions.getStatus().call({
        'from': GAS_PAYER,
        'gas': gas
    }) == 5  # 1 Is pending 5 is Launched
コード例 #4
0
ファイル: __init__.py プロジェクト: todicus/hmt-escrow
def _complete(contract: WContract, gas=DEFAULT_GAS) -> bool:
    W3 = get_w3()
    nonce = W3.eth.getTransactionCount(GAS_PAYER)

    tx_dict = contract.functions.complete().buildTransaction({
        'from': GAS_PAYER,
        'gas': gas,
        'nonce': nonce
    })
    tx_hash = sign_and_send_transaction(tx_dict, GAS_PAYER_PRIV)
    wait_on_transaction(tx_hash)

    return bool(contract.functions.complete().call({
        'from': GAS_PAYER,
        'gas': gas
    }))
コード例 #5
0
ファイル: __init__.py プロジェクト: todicus/hmt-escrow
def _partial_payout_sol(contract: WContract,
                        amount: int,
                        to_account: str,
                        uri: str,
                        hash_: str,
                        gas=DEFAULT_GAS):
    W3 = get_w3()
    nonce = W3.eth.getTransactionCount(GAS_PAYER)

    tx_dict = contract.functions.payOut(amount, to_account, uri,
                                        hash_).buildTransaction({
                                            'from': GAS_PAYER,
                                            'gas': gas,
                                            'nonce': nonce
                                        })
    tx_hash = sign_and_send_transaction(tx_dict, GAS_PAYER_PRIV)
    wait_on_transaction(tx_hash)
コード例 #6
0
ファイル: __init__.py プロジェクト: todicus/hmt-escrow
def _bulk_payout_sol(contract: WContract,
                     addresses: list,
                     amounts: list,
                     uri: str,
                     hash_: str,
                     gas=DEFAULT_GAS):
    W3 = get_w3()
    nonce = W3.eth.getTransactionCount(GAS_PAYER)

    tx_dict = contract.functions.bulkPayOut(addresses, amounts, uri, hash_,
                                            1).buildTransaction({
                                                'from': GAS_PAYER,
                                                'gas': gas,
                                                'nonce': nonce
                                            })
    tx_hash = sign_and_send_transaction(tx_dict, GAS_PAYER_PRIV)
    wait_on_transaction(tx_hash)
コード例 #7
0
ファイル: __init__.py プロジェクト: todicus/hmt-escrow
def _transfer_to_address(address: str, amount: int, gas=DEFAULT_GAS) -> bool:
    W3 = get_w3()
    nonce = W3.eth.getTransactionCount(GAS_PAYER)
    eip20_contract = get_eip20()

    tx_dict = eip20_contract.functions.transfer(address,
                                                amount).buildTransaction({
                                                    'from':
                                                    GAS_PAYER,
                                                    'gas':
                                                    gas,
                                                    'nonce':
                                                    nonce
                                                })
    tx_hash = sign_and_send_transaction(tx_dict, GAS_PAYER_PRIV)

    # Smart contract returns True if transaction completes successfully
    return wait_on_transaction(tx_hash)
コード例 #8
0
ファイル: __init__.py プロジェクト: todicus/hmt-escrow
def _store_results(contract: WContract,
                   uri: str,
                   hash_: str,
                   gas=DEFAULT_GAS) -> bool:
    W3 = get_w3()
    nonce = W3.eth.getTransactionCount(GAS_PAYER)

    tx_dict = contract.functions.storeResults(uri, hash_).buildTransaction({
        'from':
        GAS_PAYER,
        'gas':
        gas,
        'nonce':
        nonce
    })
    tx_hash = sign_and_send_transaction(tx_dict, GAS_PAYER_PRIV)
    wait_on_transaction(tx_hash)

    contract.functions.storeResults(uri, hash_).call({
        'from': GAS_PAYER,
        'gas': gas
    })
    return True