示例#1
0
    def _sign_transaction(self, prepared_tx):
        acct = self._w3.eth.account.from_key(self._private_key)

        try:
            signed_tx = acct.sign_transaction(prepared_tx)
            return signed_tx
        except Exception:
            raise UnableToSignTxError(
                'You are trying to sign a non transaction type')
示例#2
0
 def sign_transaction(self, wif, transaction_to_sign):
     secret_exponent = wif_to_secret_exponent(wif, self.allowable_wif_prefixes)
     lookup = build_hash160_lookup([secret_exponent])
     signed_transaction = transaction_to_sign.sign(lookup)
     # Because signing failures silently continue, first check that the inputs are signed
     for input in signed_transaction.txs_in:
         if len(input.script) == 0:
             logging.error('Unable to sign transaction. hextx=%s', signed_transaction.as_hex())
             raise UnableToSignTxError('Unable to sign transaction')
     return signed_transaction
示例#3
0
    def sign_transaction(self, wif, transaction_to_sign):
        # try to sign the transaction.

        self.w3 = Web3(HTTPProvider())
        acct = self.w3.eth.account.from_key(wif)

        try:
            signed_tx = acct.sign_transaction(transaction_to_sign)
            return signed_tx
        except Exception as msg:
            raise UnableToSignTxError(
                'You are trying to sign a non transaction type')
示例#4
0
    def sign_transaction(self, wif, transaction_to_sign):
        ##try to sign the transaction.

        if isinstance(transaction_to_sign, transactions.Transaction):
            try:
                raw_tx = rlp.encode(transaction_to_sign.sign(wif, self.netcode))
                raw_tx_hex = encode_hex(raw_tx)
                return raw_tx_hex
            except Exception as msg:
                return {'error': True, 'message': msg}
        else:
            raise UnableToSignTxError('You are trying to sign a non transaction type')
示例#5
0
    def transact(self, method, *argv):
        """
        Sends a signed transaction on the blockchain and waits for a response.
        If initialized with private key this class can sign the transaction.
        In general, an external signer should be used in conjunction with
        create_transaction() and broadcast_tx.
        """
        if self._private_key is None:
            raise UnableToSignTxError(
                "This method is only available if a private key was passed upon initialization"
            )

        prepared_tx = self.create_transaction(method, *argv)
        signed_tx = self._sign_transaction(prepared_tx)
        txid = self.broadcast_transaction(signed_tx)
        return txid