-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transaction Converter & refactoring and reorganizing #17
Conversation
@@ -314,7 +314,7 @@ | |||
], | |||
"source": [ | |||
"from multiversx_sdk.core import TokenComputer\n", | |||
"from multiversx_sdk.core.transaction_factories import \\\n", | |||
"from multiversx_sdk.core.transactions_factories import \\\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, easy to welcome breaking change.
examples/Cookbook.ipynb
Outdated
"\n", | ||
"provider = ProxyNetworkProvider(\"https://devnet-gateway.multiversx.com\")\n", | ||
"provider = ProxyNetworkProvider(\"https://devnet-gateway.multiversx.com\", TransactionConverter())\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional breaking change. Very good from a design point of view. Perhaps less welcomed by some developers.
Let's brainstorm an eventual facade
package - first, in the specs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we can provide also the default value?
def __init__( | ||
self, | ||
url: str, | ||
transaction_converter: ITransactionConverter, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned above, it's a breaking change.
In the specs, we use the plural variant: https://github.com/multiversx/mx-sdk-specs/blob/main/converters/transactionsConverter.md.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to ITransactionsConverter
.
ITransaction, TransactionOnNetwork) | ||
|
||
|
||
class ITransactionConverter(Protocol): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be plural, I think.
transaction.options = transaction.options | TRANSACTION_OPTIONS_TX_GUARDED | ||
transaction.guardian = guardian | ||
|
||
def _to_dictionary(self, transaction: ITransaction) -> Dict[str, Any]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, this should not use the new converter 👍
(it has other reasons for change / wrt. SRP).
def __init__( | ||
self, | ||
url: str, | ||
transaction_converter: ITransactionConverter, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a breaking change (we can postpone it via some workarounds, but perhaps we should not).
Also, can use plural variant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the plural variant
def __init__(self, transaction: Transaction) -> None: | ||
self.expected = transaction | ||
|
||
def __eq__(self, actual: object) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Maybe we can also promote this as a core functionality (just a question)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I think this is more for testing purposes, but we can think about it.
return Transaction( | ||
nonce=dictionary.get("nonce", None), | ||
value=int(dictionary.get("value", None)), | ||
receiver=dictionary["receiver"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, sender, receiver, gas limit, chain ID are required - but if the input dictionary is missing them, the resulting exception will not be very intelligible (JS implementation would suffer from the same thing, but there we have the legacy IPlainTransaction
interface).
Maybe validate the input dictionary around the required fields and throw exceptions with explicit messages?
Maybe can also stay as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a method to validate that the fields sender, receiver, chainID and gasLimit are not missing
def _value_to_b64_or_empty(self, value: str | bytes) -> str: | ||
value_as_bytes = value.encode() if isinstance(value, str) else value | ||
|
||
if value and len(value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using len(value)
only would be all right? Below as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. Changed.
return b"" | ||
|
||
def _bytes_from_hex(self, value: str) -> bytes: | ||
print(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rogue print statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deleted
…ncy from network providers constructors
from multiversx_sdk.core.transaction import Transaction | ||
|
||
|
||
class TransactionsConverter: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the specs there is also transaction_on_network_to_outcome(transaction: TransactionOnNetwork): TransactionOutcome;
do we implement this one also? or not yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That has been added later. Will be implemented in a future PR.
Implemented the
TransactionConverter
class according to the sdk-specs. Also moved theadapters
package outside of thecore
package and theTransactionComputer
class out of thetransaction
module in thetransaction_computer
module.