-
Notifications
You must be signed in to change notification settings - Fork 37
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,14 +49,19 @@ interface IGasEstimator { | |
|
||
/** | ||
* Use this class to create transactions for native token transfers (EGLD) or custom tokens transfers (ESDT/NTF/MetaESDT). | ||
* This name is only temporary, the class will be renamed to `TransferTransactionsFactory`. | ||
*/ | ||
export class TransferTransactionsFactory { | ||
private readonly config?: IConfig; | ||
private readonly dataArgsBuilder?: TokenTransfersDataBuilder; | ||
private readonly tokenComputer?: ITokenComputer; | ||
private readonly gasEstimator?: IGasEstimator; | ||
|
||
/** | ||
* Should be instantiated using `Config` and `TokenComputer`. | ||
* 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorporated it in the above comment |
||
constructor(options: IGasEstimator | { config: IConfig; tokenComputer: ITokenComputer }) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
if (this.isGasEstimator(options)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we drop the check here, does ES lint complain? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's typescript that complains. Or perhaps I misunderstood your question. |
||
this.gasEstimator = options; | ||
|
@@ -81,7 +86,7 @@ export class TransferTransactionsFactory { | |
if (this.gasEstimator === undefined) { | ||
return false; | ||
} | ||
return this.isGasEstimator(this.gasEstimator); | ||
return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function can also be implemented with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. Changed! |
||
} | ||
|
||
private ensureMembersAreDefined() { | ||
|
@@ -133,7 +138,7 @@ export class TransferTransactionsFactory { | |
} | ||
|
||
if (numberOfTransfers === 1) { | ||
return this.createSingleESDTTransferDraft(options); | ||
return this.createSingleESDTTransferTransaction(options); | ||
} | ||
|
||
const transferArgs = this.dataArgsBuilder!.buildArgsForMultiESDTNFTTransfer( | ||
|
@@ -155,6 +160,10 @@ export class TransferTransactionsFactory { | |
}).build(); | ||
} | ||
|
||
/** | ||
* This is a legacy method. Can only be used if the class was instantiated using `GasEstimator`. | ||
* Use {@link createTransactionForNativeTokenTransfer} instead. | ||
*/ | ||
createEGLDTransfer(args: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
nonce?: INonce; | ||
value: ITransactionValue; | ||
|
@@ -166,7 +175,9 @@ export class TransferTransactionsFactory { | |
chainID: IChainID; | ||
}) { | ||
if (!this.isGasEstimatorDefined()) { | ||
throw new Err("`gasEstimator` is not defined. Instantiate the factory using the gasEstimator."); | ||
throw new Err( | ||
"You are calling a legacy function to create an EGLD transfer transaction. If this is your intent, then instantiate the class using a `GasEstimator`. Or, instead, use the new, recommended `createTransactionForNativeTokenTransfer` method.", | ||
); | ||
} | ||
|
||
const dataLength = args.data?.length() || 0; | ||
|
@@ -184,6 +195,10 @@ export class TransferTransactionsFactory { | |
}); | ||
} | ||
|
||
/** | ||
* This is a legacy method. Can only be used if the class was instantiated using `GasEstimator`. | ||
* Use {@link createTransactionForESDTTokenTransfer} instead. | ||
*/ | ||
createESDTTransfer(args: { | ||
tokenTransfer: ITokenTransfer; | ||
nonce?: INonce; | ||
|
@@ -194,7 +209,9 @@ export class TransferTransactionsFactory { | |
chainID: IChainID; | ||
}) { | ||
if (!this.isGasEstimatorDefined()) { | ||
throw new Err("`gasEstimator` is not defined. Instantiate the factory using the gasEstimator."); | ||
throw new Err( | ||
"You are calling a legacy function to create an ESDT transfer transaction. If this is your intent, then instantiate the class using a `GasEstimator`. Or, instead, use the new, recommended `createTransactionForESDTTokenTransfer` method.", | ||
); | ||
} | ||
|
||
const { argumentsString } = new ArgSerializer().valuesToString([ | ||
|
@@ -220,6 +237,10 @@ export class TransferTransactionsFactory { | |
}); | ||
} | ||
|
||
/** | ||
* This is a legacy method. Can only be used if the class was instantiated using `GasEstimator`. | ||
* Use {@link createTransactionForESDTTokenTransfer} instead. | ||
*/ | ||
createESDTNFTTransfer(args: { | ||
tokenTransfer: ITokenTransfer; | ||
nonce?: INonce; | ||
|
@@ -230,7 +251,9 @@ export class TransferTransactionsFactory { | |
chainID: IChainID; | ||
}) { | ||
if (!this.isGasEstimatorDefined()) { | ||
throw new Err("`gasEstimator` is not defined. Instantiate the factory using the gasEstimator."); | ||
throw new Err( | ||
"You are calling a legacy function to create an ESDTNFT transfer transaction. If this is your intent, then instantiate the class using a `GasEstimator`. Or, instead, use the new, recommended `createTransactionForESDTTokenTransfer` method.", | ||
); | ||
} | ||
|
||
const { argumentsString } = new ArgSerializer().valuesToString([ | ||
|
@@ -260,6 +283,10 @@ export class TransferTransactionsFactory { | |
}); | ||
} | ||
|
||
/** | ||
* This is a legacy method. Can only be used if the class was instantiated using `GasEstimator`. | ||
* Use {@link createTransactionForESDTTokenTransfer} instead. | ||
*/ | ||
createMultiESDTNFTTransfer(args: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add comments (as above). |
||
tokenTransfers: ITokenTransfer[]; | ||
nonce?: INonce; | ||
|
@@ -270,7 +297,9 @@ export class TransferTransactionsFactory { | |
chainID: IChainID; | ||
}) { | ||
if (!this.isGasEstimatorDefined()) { | ||
throw new Err("`gasEstimator` is not defined. Instantiate the factory using the gasEstimator."); | ||
throw new Err( | ||
"You are calling a legacy function to create a MultiESDTNFT transfer transaction. If this is your intent, then instantiate the class using a `GasEstimator`. Or, instead, use the new, recommended `createTransactionForESDTTokenTransfer` method.", | ||
); | ||
} | ||
|
||
const parts: TypedValue[] = [ | ||
|
@@ -310,7 +339,7 @@ export class TransferTransactionsFactory { | |
}); | ||
} | ||
|
||
private createSingleESDTTransferDraft(options: { | ||
private createSingleESDTTransferTransaction(options: { | ||
sender: IAddress; | ||
receiver: IAddress; | ||
tokenTransfers: NextTokenTransfer[]; | ||
|
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.
Comment (above) should be updated.
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.
Done