Skip to content
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

Merge "legacy" transfer transactions factory in NextTransferTransactionsFactory #405

Merged
merged 3 commits into from
Mar 21, 2024

Conversation

popenta
Copy link
Contributor

@popenta popenta commented Mar 19, 2024

Merged "legacy" transfer transactions factory in NextTransferTransactionsFactory and renamed NextTransferTransactionsFactory to TransferTransactionsFactory.

@popenta popenta self-assigned this Mar 19, 2024
@@ -3,7 +3,7 @@ import { Address } from "./address";
import { GasEstimator } from "./gasEstimator";
import { TokenTransfer } from "./tokenTransfer";
import { TransactionPayload } from "./transactionPayload";
import { TransferTransactionsFactory } from "./transferTransactionsFactory";
import { TransferTransactionsFactory } from "./transactionsFactories/transferTransactionsFactory";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would lead to an eventual, small, breaking change (depending on how import statement is written in client code).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed

this.config = options.config;
this.tokenComputer = options.tokenComputer;
this.dataArgsBuilder = new TokenTransfersDataBuilder();
export class TransferTransactionsFactory {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment (above) should be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

private readonly tokenComputer?: ITokenComputer;
private readonly gasEstimator?: IGasEstimator;

constructor(options: IGasEstimator | { config: IConfig; tokenComputer: ITokenComputer }) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can add extra comment (documentation comment) to mention that the variant with gas estimator is legacy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

private readonly gasEstimator?: IGasEstimator;

constructor(options: IGasEstimator | { config: IConfig; tokenComputer: ITokenComputer }) {
if (this.isGasEstimator(options)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we drop the check here, does ES lint complain?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's typescript that complains. Or perhaps I misunderstood your question.

}
}

private isGasEstimator(options: any): options is IGasEstimator {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting (hard-core TypeScript).

if (this.gasEstimator === undefined) {
return false;
}
return this.isGasEstimator(this.gasEstimator);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this.gasEstimator === undefined is a "sufficient" check (covers the flow where the user called the constructor with gas estimator)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be enough. Removed.

@@ -89,27 +155,184 @@ export class NextTransferTransactionsFactory {
}).build();
}

createEGLDTransfer(args: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comments that they are legacy functions? Since old constructor is not deprecated, it's OK not to deprecate these, as well, but at least mark them with "This is a legacy function, use ... instead".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

chainID: IChainID;
}) {
if (!this.isGasEstimatorDefined()) {
throw new Err("`gasEstimator` is not defined. Instantiate the factory using the gasEstimator.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alter the message perhaps to recommend the new functions, instead.

"It seems that you are calling the legacy functions to create a transfer transaction. If this is your intent, then pass a gas estimator in the constructor. Or, instead, use the new, recommended ...".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added for all legacy methods.

});
}

createMultiESDTNFTTransfer(args: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comments (as above).

chainID: IChainID;
}) {
if (!this.isGasEstimatorDefined()) {
throw new Err("`gasEstimator` is not defined. Instantiate the factory using the gasEstimator.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjust message, as above (to point user to the new way).

* Instantiating this class using GasEstimator represents the legacy version of this class.
* The legacy version contains methods like `createEGLDTransfer`, `createESDTTransfer`, `createESDTNFTTransfer` and `createMultiESDTNFTTransfer`.
*/
// this was done to minimize breaking changes in client code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow rogue comment. Can be incorporated into the above one (to avoid any negative impact in some IDEs).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorporated it in the above comment

@@ -81,7 +86,7 @@ export class TransferTransactionsFactory {
if (this.gasEstimator === undefined) {
return false;
}
return this.isGasEstimator(this.gasEstimator);
return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function can also be implemented with return this.gasEstimator !== undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Changed!

@popenta popenta merged commit fbbf0fb into feat/next Mar 21, 2024
1 check passed
@popenta popenta deleted the merge-transfer-txs-factories branch March 21, 2024 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants