Skip to content

Commit

Permalink
fix transaction signing
Browse files Browse the repository at this point in the history
  • Loading branch information
popenta committed Apr 19, 2024
1 parent c8b95fc commit 9fe2302
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
5 changes: 4 additions & 1 deletion multiversx_sdk_cli/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ def sign_transaction(self, transaction: ITransaction) -> str:
assert self.signer is not None

transaction_computer = TransactionComputer()
if transaction.options & TX_HASH_SIGN_OPTIONS == TX_HASH_SIGN_OPTIONS:
return self.signer.sign(transaction_computer.compute_hash_for_signing(transaction)).hex()

return self.signer.sign(transaction_computer.compute_bytes_for_signing(transaction)).hex()

def sign_message(self, data: bytes) -> str:
Expand All @@ -96,7 +99,7 @@ def sign_transaction(self, transaction: ITransaction) -> str:
should_use_hash_signing = compare_versions(ledger_version, SIGN_USING_HASH_VERSION) >= 0
if should_use_hash_signing:
transaction.version = TX_HASH_SIGN_VERSION
transaction.options = TX_HASH_SIGN_OPTIONS
transaction.options = transaction.options | TX_HASH_SIGN_OPTIONS

transaction_computer = TransactionComputer()

Expand Down
2 changes: 1 addition & 1 deletion multiversx_sdk_cli/cli_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def should_sign_with_guardian_key(args: Any) -> bool:

def check_options_for_guarded_tx(options: int):
if not options & TRANSACTION_OPTIONS_TX_GUARDED == TRANSACTION_OPTIONS_TX_GUARDED:
raise errors.BadUsage("Invalid guarded transaction's options. The second least significant bit must be set.")
raise errors.BadUsage("Invalid guarded transaction's options. The second least significant bit must be set")


def send_or_simulate(tx: ITransaction, args: Any, dump_output: bool = True) -> CLIOutputBuilder:
Expand Down
2 changes: 1 addition & 1 deletion multiversx_sdk_cli/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ITransaction(Protocol):
gas_limit: int
chain_id: str
nonce: int
amount: int
value: int
sender_username: str
receiver_username: str
gas_price: int
Expand Down
6 changes: 3 additions & 3 deletions multiversx_sdk_cli/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def do_prepare_transaction(args: Any) -> Transaction:
gas_price=int(args.gas_price),
data=str(args.data).encode(),
nonce=int(args.nonce),
amount=int(args.value),
value=int(args.value),
version=int(args.version),
options=int(args.options)
)
Expand Down Expand Up @@ -150,7 +150,7 @@ def tx_to_dictionary_as_inner_for_relayed_V1(tx: Transaction) -> Dict[str, Any]:
dictionary["nonce"] = tx.nonce
dictionary["sender"] = base64.b64encode(Address.new_from_bech32(tx.sender).get_public_key()).decode()
dictionary["receiver"] = base64.b64encode(Address.new_from_bech32(tx.receiver).get_public_key()).decode()
dictionary["value"] = tx.amount
dictionary["value"] = tx.value
dictionary["gasPrice"] = tx.gas_price
dictionary["gasLimit"] = tx.gas_limit
dictionary["data"] = base64.b64encode(tx.data).decode()
Expand Down Expand Up @@ -204,7 +204,7 @@ def load_transaction_from_file(f: TextIO) -> Transaction:
receiver_username=decode_field_value(instance.receiverUsername),
gas_limit=instance.gasLimit,
gas_price=instance.gasPrice,
amount=int(instance.value),
value=int(instance.value),
data=TransactionPayload.from_encoded_str(instance.data).data,
version=instance.version,
options=instance.options,
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ semver
requests-cache
rich==13.3.4

multiversx-sdk-core>=0.7.0,<0.8.0
multiversx-sdk-network-providers>=0.12.0,<0.13.0
multiversx-sdk-wallet>=0.8.0,<0.9.0
multiversx-sdk-core>=0.8.0,<0.9.0
multiversx-sdk-network-providers>=0.13.0,<0.14.0
multiversx-sdk-wallet>=0.9.0,<0.10.0

0 comments on commit 9fe2302

Please sign in to comment.