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

Refactoring DraftTransaction to TransactionNext #376

Merged
merged 10 commits into from
Feb 13, 2024

Conversation

ramonalobont
Copy link
Contributor

No description provided.

@@ -32,6 +32,7 @@ export class SmartContractTransactionsFactory {
private readonly abiRegistry?: Abi;
private readonly tokenComputer: TokenComputer;
private readonly dataArgsBuilder: TokenTransfersDataBuilder;
//private dataParts!: string[];
Copy link
Contributor

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(),
Copy link
Contributor

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);
Copy link
Contributor

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 {
Copy link
Contributor

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.

Comment on lines 43 to 44
const d = options.data || "";
let dataParts: string[] = [d];
Copy link
Contributor

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(),
Copy link
Contributor

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"];
Copy link
Contributor

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 {
Copy link
Contributor

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;
Copy link
Contributor

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);
Copy link
Contributor

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

Copy link
Contributor

@andreibancioiu andreibancioiu left a 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:

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

})
}
}
}
Copy link
Contributor

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
);
)
Copy link
Contributor

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).`);
}
}
}
Copy link
Contributor

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({

Copy link
Contributor

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({
Copy link
Contributor

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;
}

Copy link
Contributor

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);
}
}
}
Copy link
Contributor

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;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

add empty new line

@popenta popenta merged commit 38d12f1 into feat/next Feb 13, 2024
1 check passed
@popenta popenta deleted the refactoring-DraftTransaction branch February 13, 2024 08:33
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.

3 participants