|
|
@ -44,6 +44,7 @@ class UnsignedHarmonyTxData( HashableRLP ): |
|
|
|
Includes `shardID` and `toShardID` |
|
|
|
Includes `shardID` and `toShardID` |
|
|
|
as the difference against Eth |
|
|
|
as the difference against Eth |
|
|
|
""" |
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
fields = ( |
|
|
|
fields = ( |
|
|
|
( "nonce", |
|
|
|
( "nonce", |
|
|
|
big_endian_int ), |
|
|
|
big_endian_int ), |
|
|
@ -71,6 +72,7 @@ class SignedHarmonyTxData( HashableRLP ): |
|
|
|
Includes `shardID` and `toShardID` |
|
|
|
Includes `shardID` and `toShardID` |
|
|
|
as the difference against Eth |
|
|
|
as the difference against Eth |
|
|
|
""" |
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
fields = UnsignedHarmonyTxData._meta.fields + ( |
|
|
|
fields = UnsignedHarmonyTxData._meta.fields + ( |
|
|
|
("v", big_endian_int), # Recovery value + 27 |
|
|
|
("v", big_endian_int), # Recovery value + 27 |
|
|
|
("r", big_endian_int), # First 32 bytes |
|
|
|
("r", big_endian_int), # First 32 bytes |
|
|
@ -107,8 +109,12 @@ def encode_transaction( unsigned_transaction, vrs ): |
|
|
|
|
|
|
|
|
|
|
|
def serialize_transaction( filled_transaction ): |
|
|
|
def serialize_transaction( filled_transaction ): |
|
|
|
"""serialize a signed/unsigned transaction.""" |
|
|
|
"""serialize a signed/unsigned transaction.""" |
|
|
|
|
|
|
|
# although this will always be present for this module |
|
|
|
|
|
|
|
# keep this check anyway |
|
|
|
if "v" in filled_transaction: |
|
|
|
if "v" in filled_transaction: |
|
|
|
if "shardID" in filled_transaction: |
|
|
|
# https://github.com/harmony-one/harmony/blob/f8879f5e0288157bf95ae2898a9a27f0c85ff9ad/core/types/transaction_signing.go#L173 |
|
|
|
|
|
|
|
if "shardID" in filled_transaction and filled_transaction[ |
|
|
|
|
|
|
|
"v" ] < 1666600000: |
|
|
|
serializer = SignedHarmonyTxData |
|
|
|
serializer = SignedHarmonyTxData |
|
|
|
else: |
|
|
|
else: |
|
|
|
serializer = SignedEthereumTxData |
|
|
|
serializer = SignedEthereumTxData |
|
|
@ -132,10 +138,9 @@ def serialize_transaction( filled_transaction ): |
|
|
|
def sanitize_transaction( transaction_dict, private_key ): |
|
|
|
def sanitize_transaction( transaction_dict, private_key ): |
|
|
|
"""remove the originating address from the dict and convert chainId to |
|
|
|
"""remove the originating address from the dict and convert chainId to |
|
|
|
int.""" |
|
|
|
int.""" |
|
|
|
account = Account.from_key( # pylint: disable=no-value-for-parameter |
|
|
|
account = Account.from_key( private_key ) # pylint: disable=no-value-for-parameter |
|
|
|
private_key |
|
|
|
sanitized_transaction = ( |
|
|
|
) |
|
|
|
transaction_dict.copy() |
|
|
|
sanitized_transaction = transaction_dict.copy( |
|
|
|
|
|
|
|
) # do not alter the original dictionary |
|
|
|
) # do not alter the original dictionary |
|
|
|
if "from" in sanitized_transaction: |
|
|
|
if "from" in sanitized_transaction: |
|
|
|
sanitized_transaction[ "from" ] = convert_one_to_hex( |
|
|
|
sanitized_transaction[ "from" ] = convert_one_to_hex( |
|
|
@ -227,12 +232,12 @@ def sign_transaction( transaction_dict, private_key ) -> SignedTransaction: |
|
|
|
chain_id = None |
|
|
|
chain_id = None |
|
|
|
else: |
|
|
|
else: |
|
|
|
chain_id = unsigned_transaction.v |
|
|
|
chain_id = unsigned_transaction.v |
|
|
|
( v, # pylint: disable=invalid-name |
|
|
|
( |
|
|
|
|
|
|
|
v, # pylint: disable=invalid-name |
|
|
|
r, # pylint: disable=invalid-name |
|
|
|
r, # pylint: disable=invalid-name |
|
|
|
s ) = sign_transaction_hash( # pylint: disable=invalid-name |
|
|
|
s, # pylint: disable=invalid-name |
|
|
|
account._key_obj, |
|
|
|
) = sign_transaction_hash( |
|
|
|
transaction_hash, |
|
|
|
account._key_obj, transaction_hash, chain_id |
|
|
|
chain_id |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
encoded_transaction = encode_transaction( |
|
|
|
encoded_transaction = encode_transaction( |
|
|
|
unsigned_transaction, |
|
|
|
unsigned_transaction, |
|
|
|