mirror of https://github.com/nucypher/nucypher.git
Fix inconsistent return from `sign_transaction`; either a SignedTransaction is returned or HexBytes. Reverting to lowest common denominator which is HexBytes (bytes). This issue was noticed while running the nucypher_dkg script which failed - it uses a keystore signer.
parent
532745632b
commit
2500fe1507
|
@ -6,7 +6,6 @@ from typing import Union
|
|||
from constant_sorrow.constants import UNKNOWN_DEVELOPMENT_CHAIN_ID
|
||||
from cytoolz.dicttoolz import dissoc
|
||||
from eth_account import Account
|
||||
from eth_account.datastructures import SignedTransaction
|
||||
from eth_account.messages import encode_defunct
|
||||
from eth_typing.evm import BlockNumber, ChecksumAddress
|
||||
from eth_utils import to_canonical_address, to_checksum_address
|
||||
|
@ -558,12 +557,14 @@ class EthereumTesterClient(EthereumClient):
|
|||
raise self.UnknownAccount(account)
|
||||
return signing_key
|
||||
|
||||
def sign_transaction(self, transaction_dict: dict) -> SignedTransaction:
|
||||
def sign_transaction(self, transaction_dict: dict) -> bytes:
|
||||
# Sign using a local private key
|
||||
address = to_canonical_address(transaction_dict['from'])
|
||||
signing_key = self.__get_signing_key(account=address)
|
||||
signed_transaction = self.w3.eth.account.sign_transaction(transaction_dict, private_key=signing_key)
|
||||
return signed_transaction
|
||||
raw_transaction = self.w3.eth.account.sign_transaction(
|
||||
transaction_dict, private_key=signing_key
|
||||
).rawTransaction
|
||||
return raw_transaction
|
||||
|
||||
def sign_message(self, account: str, message: bytes) -> str:
|
||||
"""Sign, EIP-191 (Geth) Style"""
|
||||
|
|
|
@ -617,7 +617,7 @@ class BlockchainInterface:
|
|||
f"({max_cost} @ {max_price_gwei} gwei)",
|
||||
color="yellow",
|
||||
)
|
||||
signed_transaction = transacting_power.sign_transaction(transaction_dict)
|
||||
raw_transaction = transacting_power.sign_transaction(transaction_dict)
|
||||
|
||||
#
|
||||
# Broadcast
|
||||
|
@ -627,9 +627,7 @@ class BlockchainInterface:
|
|||
color="yellow",
|
||||
)
|
||||
try:
|
||||
txhash = self.client.send_raw_transaction(
|
||||
signed_transaction.rawTransaction
|
||||
) # <--- BROADCAST
|
||||
txhash = self.client.send_raw_transaction(raw_transaction) # <--- BROADCAST
|
||||
emitter.message(f"TXHASH {txhash.hex()}", color="yellow")
|
||||
except ValueError:
|
||||
raise # TODO: Unify with Transaction failed handling -- Entry point for _handle_failed_transaction
|
||||
|
|
|
@ -2,7 +2,6 @@ from abc import ABC, abstractmethod
|
|||
from typing import List
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from eth_account.datastructures import SignedTransaction
|
||||
from eth_typing.evm import ChecksumAddress
|
||||
from hexbytes.main import HexBytes
|
||||
|
||||
|
@ -78,7 +77,7 @@ class Signer(ABC):
|
|||
return NotImplemented
|
||||
|
||||
@abstractmethod
|
||||
def sign_transaction(self, transaction_dict: dict) -> SignedTransaction:
|
||||
def sign_transaction(self, transaction_dict: dict) -> bytes:
|
||||
return NotImplemented
|
||||
|
||||
@abstractmethod
|
||||
|
|
|
@ -6,7 +6,6 @@ from urllib.parse import urlparse
|
|||
|
||||
from cytoolz.dicttoolz import dissoc
|
||||
from eth_account.account import Account
|
||||
from eth_account.datastructures import SignedTransaction
|
||||
from eth_account.messages import encode_defunct
|
||||
from eth_account.signers.local import LocalAccount
|
||||
from eth_utils.address import is_address, to_canonical_address, to_checksum_address
|
||||
|
@ -99,11 +98,11 @@ class Web3Signer(Signer):
|
|||
signature = self.__client.sign_message(account=account, message=message)
|
||||
return HexBytes(signature)
|
||||
|
||||
def sign_transaction(self, transaction_dict: dict) -> SignedTransaction:
|
||||
signed_transaction = self.__client.sign_transaction(
|
||||
def sign_transaction(self, transaction_dict: dict) -> bytes:
|
||||
raw_transaction = self.__client.sign_transaction(
|
||||
transaction_dict=transaction_dict
|
||||
)
|
||||
return signed_transaction
|
||||
return raw_transaction
|
||||
|
||||
|
||||
class KeystoreSigner(Signer):
|
||||
|
@ -275,7 +274,7 @@ class KeystoreSigner(Signer):
|
|||
return account not in self.__signers
|
||||
|
||||
@validate_checksum_address
|
||||
def sign_transaction(self, transaction_dict: dict) -> SignedTransaction:
|
||||
def sign_transaction(self, transaction_dict: dict) -> bytes:
|
||||
"""
|
||||
Produce a raw signed ethereum transaction signed by the account specified
|
||||
in the 'from' field of the transaction dictionary.
|
||||
|
@ -355,15 +354,15 @@ class InMemorySigner(Signer):
|
|||
raise self.AccountLocked(account=account)
|
||||
|
||||
@validate_checksum_address
|
||||
def sign_transaction(self, transaction_dict: dict) -> SignedTransaction:
|
||||
def sign_transaction(self, transaction_dict: dict) -> bytes:
|
||||
sender = transaction_dict["from"]
|
||||
signer = self.__get_signer(account=sender)
|
||||
if not transaction_dict["to"]:
|
||||
transaction_dict = dissoc(transaction_dict, "to")
|
||||
signed_transaction = signer.sign_transaction(
|
||||
raw_transaction = signer.sign_transaction(
|
||||
transaction_dict=transaction_dict
|
||||
).rawTransaction
|
||||
return signed_transaction
|
||||
return raw_transaction
|
||||
|
||||
@validate_checksum_address
|
||||
def sign_message(self, account: str, message: bytes, **kwargs) -> HexBytes:
|
||||
|
|
|
@ -2,7 +2,6 @@ import inspect
|
|||
from typing import List, Optional, Tuple, Union
|
||||
|
||||
from eth_account._utils.signing import to_standard_signature_bytes
|
||||
from eth_account.datastructures import SignedTransaction
|
||||
from eth_typing.evm import ChecksumAddress
|
||||
from nucypher_core import (
|
||||
EncryptedThresholdDecryptionRequest,
|
||||
|
@ -201,7 +200,7 @@ class TransactingPower(CryptoPowerUp):
|
|||
# from the recovery byte, bringing it to the standard choice of {0, 1}.
|
||||
return to_standard_signature_bytes(signature)
|
||||
|
||||
def sign_transaction(self, transaction_dict: dict) -> SignedTransaction:
|
||||
def sign_transaction(self, transaction_dict: dict) -> bytes:
|
||||
"""Signs the transaction with the private key of the TransactingPower."""
|
||||
return self._signer.sign_transaction(transaction_dict=transaction_dict)
|
||||
|
||||
|
|
Loading…
Reference in New Issue