-
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
Refactoring DraftTransaction to TransactionNext #376
Conversation
@@ -32,6 +32,7 @@ export class SmartContractTransactionsFactory { | |||
private readonly abiRegistry?: Abi; | |||
private readonly tokenComputer: TokenComputer; | |||
private readonly dataArgsBuilder: TokenTransfersDataBuilder; | |||
//private dataParts!: string[]; |
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.
remove this comment
dataParts: parts, | ||
return new TransactionNext({ | ||
sender: options.sender.bech32(), | ||
receiver: Address.fromBech32(CONTRACT_DEPLOY_ADDRESS).bech32(), |
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.
can be simply CONTRACT_DEPLOY_ADDRESS
. There's no need to make it an Address
just to convert it back to a str
.
@@ -152,16 +149,17 @@ export class SmartContractTransactionsFactory { | |||
|
|||
const preparedArgs = this.argsToDataParts(args, this.abiRegistry?.constructorDefinition); | |||
parts = parts.concat(preparedArgs); | |||
let dataParts: string[] = parts.concat(preparedArgs); |
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.
dataParts
can be const
@@ -185,4 +183,9 @@ export class SmartContractTransactionsFactory { | |||
} | |||
return true; | |||
} | |||
|
|||
private buildTransactionPayload(dataParts: string[]): TransactionPayload { |
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.
I think we don't need to use TransactionPayload
anymore, the method can return UInt8Array
, but it's not wrong as it is now.
const d = options.data || ""; | ||
let dataParts: string[] = [d]; |
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.
This can be:
const dataParts = [options.data || ""];
|
||
return new TransactionNext({ | ||
sender: options.sender.bech32(), | ||
receiver: Address.fromBech32(DELEGATION_MANAGER_SC_ADDRESS).bech32(), |
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.
DELEGATION_MANAGER_SC_ADDRESS
is already string
, does not need to be converted to Address
and then back to string
.
if (options.publicKeys.length !== options.signedMessages.length) { | ||
throw new Err("The number of public keys should match the number of signed messages"); | ||
} | ||
|
||
const numNodes = options.publicKeys.length; | ||
|
||
const dataParts = ["addNodes"]; | ||
let dataParts: string[] = ["addNodes"]; |
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.
can be const
and I think the type is inferred, but maybe this is because of the linter?
@@ -603,4 +672,19 @@ IMPORTANT! | |||
You are about to issue (register) a new token. This will set the role "ESDTRoleBurnForAll" (globally). | |||
Once the token is registered, you can unset this role by calling "unsetBurnRoleGlobally" (in a separate transaction).`); | |||
} | |||
|
|||
private buildTransactionPayload(dataParts: string[]): TransactionPayload { |
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.
can also return UInt8Array
but this is not wrong either.
amount: this.config.issueCost, | ||
}).build(); | ||
const data = this.buildTransactionPayload(dataParts); | ||
const addDataMovementGas: boolean = true; |
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 this is always true
, it can be removed, and the computeGasLimit()
method can be implemented without this parameter.
}).build(); | ||
const data = this.buildTransactionPayload(dataParts); | ||
const addDataMovementGas: boolean = true; | ||
const providedGasLimit: BigNumber = new BigNumber(this.config.gasLimitIssue); |
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.
can be renamed to extraGasLimit
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.
Now I see, we should have not removed the transaction builder. Sorry for incorrectly describing the steps. They should have been:
- adjust (add chain ID) and rename the transaction builder with respect to: https://github.com/multiversx/mx-sdk-py-core/blob/main/multiversx_sdk_core/transaction_factories/transaction_builder.py
- use
TransactionNext
insteadDraftTransaction
- remove
DraftTransaction
- rename remaining variables (e.g. to not contain "draft" anymore).
That is, no other code movement should happen - the gas computation logic and so on should stay as they were.
For reference: https://github.com/multiversx/mx-sdk-py-core/tree/main/multiversx_sdk_core/transaction_factories
}) | ||
} | ||
} | ||
} |
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.
add empty line at end of file
@@ -69,13 +71,11 @@ export class NextTransferTransactionsFactory { | |||
const transferArgs = this.dataArgsBuilder.buildArgsForMultiESDTNFTTransfer( | |||
options.receiver, | |||
options.tokenTransfers | |||
); | |||
) |
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.
add ;
after calling the method.
@@ -603,4 +623,4 @@ IMPORTANT! | |||
You are about to issue (register) a new token. This will set the role "ESDTRoleBurnForAll" (globally). | |||
Once the token is registered, you can unset this role by calling "unsetBurnRoleGlobally" (in a separate transaction).`); | |||
} | |||
} | |||
} |
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.
add empty line at end of file
@@ -120,7 +122,8 @@ export class TokenManagementTransactionsFactory { | |||
options.canAddSpecialRoles ? this.trueAsHex : this.falseAsHex, | |||
]; | |||
|
|||
return new DraftTransactionBuilder({ | |||
|
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.
Remove one empty line unless the formatter added it, then you can ignore the comments. Applies to all methods.
const sender = Address.fromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"); | ||
const delagationCap = "5000000000000000000000"; | ||
const serviceFee = 10; | ||
const value = new BigNumber("1250000000000000000000"); | ||
|
||
const draft = delegationFactory.createTransactionForNewDelegationContract({ | ||
const next = delegationFactory.createTransactionForNewDelegationContract({ |
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.
Could be renamed to transaction
. (optional) Same for the other tests.
@@ -19,33 +18,27 @@ interface Config { | |||
additionalGasLimitPerValidatorNode: BigNumber.Value; | |||
additionalGasLimitForDelegationOperations: BigNumber.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.
unless the formatter removed the empty lines they can be added back.
private computeExecutionGasLimitForNodesManagement(numNodes: number): BigNumber.Value { | ||
const additionalGasForAllNodes = new BigNumber(this.config.additionalGasLimitPerValidatorNode).multipliedBy(numNodes); | ||
return new BigNumber(this.config.gasLimitDelegationOperations).plus(additionalGasForAllNodes); | ||
} | ||
} | ||
} |
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.
add empty line
@@ -185,4 +183,4 @@ export class SmartContractTransactionsFactory { | |||
} | |||
return true; | |||
} | |||
} | |||
} |
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.
add empty new line
No description provided.