コード例 #1
0
def sign_execute_deposit(deposit_params, private_key, infura_url):
    """
    Function to execute the deposit request by signing the transaction generated from the create deposit function.
    Execution of this function is as follows::

        sign_execute_deposit(deposit_params=create_deposit, private_key=eth_private_key)

    The expected return result for this function is as follows::

        {
            'transaction_hash': '0xcf3ea5d1821544e1686fbcb1f49d423b9ea9f42772ff9ecdaf615616d780fa75'
        }

    :param deposit_params: The parameters generated by the create function that now requires a signature.
    :type deposit_params: dict
    :param private_key: The Ethereum private key to sign the deposit parameters.
    :type private_key: str
    :param infura_url: The URL used to broadcast the deposit transaction to the Ethereum network.
    :type infura_url: str
    :return: Dictionary of the signed transaction to initiate the deposit of ETH via the Switcheo API.
    """
    create_deposit_upper = deposit_params.copy()
    create_deposit_upper['transaction']['from'] = to_checksum_address(create_deposit_upper['transaction']['from'])
    create_deposit_upper['transaction']['to'] = to_checksum_address(create_deposit_upper['transaction']['to'])
    create_deposit_upper['transaction'].pop('sha256')
    signed_create_txn = Account.signTransaction(create_deposit_upper['transaction'], private_key=private_key)
    execute_signed_txn = binascii.hexlify(signed_create_txn['hash']).decode()

    # Broadcast transaction to Ethereum Network.
    Web3(HTTPProvider(infura_url)).eth.sendRawTransaction(signed_create_txn.rawTransaction)

    return {'transaction_hash': '0x' + execute_signed_txn}
コード例 #2
0
ファイル: hdaccount.py プロジェクト: sea212/eth-account
    def signTransaction(self, transaction_dict):
        '''
        Sign the hash provided.

        .. WARNING:: *Never* sign a hash that you didn't generate,
            it can be an arbitrary transaction. For example, it might
            send all of your account's ether to an attacker.

        If you would like compatibility with
        :meth:`w3.eth.sign() <web3.eth.Eth.sign>`
        you can use :meth:`~eth_account.messages.defunct_hash_message`.

        Several other message standards are proposed, but none have a clear
        consensus. You'll need to manually comply with any of those message standards manually.

        :param message_hash: the 32-byte message hash to be signed
        :type message_hash: hex str, bytes or int
        :param private_key: the key to sign the message with
        :type private_key: hex str, bytes, int or :class:`eth_keys.datatypes.PrivateKey`
        :returns: Various details about the signature - most
          importantly the fields: v, r, and s
        :rtype: ~eth_account.datastructures.AttributeDict
        '''

        rawtuple = bip32_deserialize(self.__key)

        if rawtuple[0] in PRIVATE:
            # slice the last byte, since it is the WIF-Compressed information
            return Account.signTransaction(transaction_dict, rawtuple[5][:-1])

        if bip32_deserialize(self.__key)[0] not in PRIVATE:
            raise RuntimeError("Cannot sign, only the public key is available")