Skip to content

Conversation

@bogdan-rosianu
Copy link
Contributor

added a builder for relayed v2 txs.
tested on testnet by using the resulted transaction from the unit test:
https://testnet-explorer.elrond.com/transactions/c02398ab9f02e564539ef1d8acd0c36cb4b8720d4c3397ef2e2ed656177471ff

@bogdan-rosianu bogdan-rosianu added the enhancement New feature or request label Jun 28, 2022
@bogdan-rosianu bogdan-rosianu self-assigned this Jun 28, 2022
@mariusmihaic mariusmihaic self-requested a review June 29, 2022 07:59
receiver: innerTransaction.getSender(),
value: 0,
gasLimit:
innerTransactionGasLimit.valueOf() + networkConfig.MinGasLimit + networkConfig.GasPerDataByte * payload.length(),

Choose a reason for hiding this comment

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

Could we move this logic in https://github.com/ElrondNetwork/elrond-sdk-erdjs/blob/main/src/gasEstimator.ts ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wouldn't add an extra dependency to this class. Also, it is pretty specific to this use-case

Choose a reason for hiding this comment

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

That's exactly what gasEstimator does. Computes gas for every specific use-case.
I would keep the consistency, we could also ask @andreibancioiu 's opinion on this

Copy link
Contributor

Choose a reason for hiding this comment

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

(added a separate comment)

Both options are valid and both are backed by good arguments ⚖️

import {ISigner} from "@elrondnetwork/erdjs-walletcore/out/interface";
import {INetworkConfig} from "./interfaceOfNetwork";

export class RelayedTransactionV2Builder {

Choose a reason for hiding this comment

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

Allt tx builders in this repo are defined here: https://github.com/ElrondNetwork/elrond-sdk-erdjs/blob/main/src/transactionFactory.ts. Could we move the logic here to keep consistency?

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 is rather more similar to tokenTransferBuilders.ts so I will leave it as it is

Choose a reason for hiding this comment

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

tokenTransferBuilders builds the payLoad. transactionFactory builds the txs. You could've split relayedTransactionV2Builder in 3 to keep consistency:

  • gasEstimator for relayed tx
  • payloadBuilder for relayed tx
  • txFactory to create the relayed tx.

Again, let's also hear @andreibancioiu 's opinion

Copy link
Contributor

@andreibancioiu andreibancioiu Jun 29, 2022

Choose a reason for hiding this comment

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

The need for consistency is indeed a very good argument. On the other hand, this new component is self-contained, which is also good.

If we were to move gasEstimator.ts, tokenTransferBuilders.ts and transactionFactory.ts to a new package called transfers (in the future), then this design is a good choice. It's possible that in the future we might even extract the following logic outside of erdjs (and move it to separate packages):

  • transfers (EGLD and all kinds of ESDT)
  • relayed transactions (V1 & V2)
  • staking & delegation SC calls (actually, missing here now)
  • esdt management calls (actually, missing here now)

So, no strong opinion at this moment (can stay as it is if we desire to further split erdjs functionality to separate NPM packages).

chainID: networkConfig.ChainID,
data: new TransactionPayload("getContractConfig"),
});
builder = builder.setNetworkConfig(networkConfig).setInnerTransactionGasLimit(10).setInnerTransaction(innerTx);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

await bob.signer.sign(innerTx);

const builder = new RelayedTransactionV2Builder();
const relayedTxV2 = builder
Copy link
Contributor

Choose a reason for hiding this comment

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

🚀

import {ISigner} from "@elrondnetwork/erdjs-walletcore/out/interface";
import {INetworkConfig} from "./interfaceOfNetwork";

export class RelayedTransactionV2Builder {
Copy link
Contributor

@andreibancioiu andreibancioiu Jun 29, 2022

Choose a reason for hiding this comment

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

The need for consistency is indeed a very good argument. On the other hand, this new component is self-contained, which is also good.

If we were to move gasEstimator.ts, tokenTransferBuilders.ts and transactionFactory.ts to a new package called transfers (in the future), then this design is a good choice. It's possible that in the future we might even extract the following logic outside of erdjs (and move it to separate packages):

  • transfers (EGLD and all kinds of ESDT)
  • relayed transactions (V1 & V2)
  • staking & delegation SC calls (actually, missing here now)
  • esdt management calls (actually, missing here now)

So, no strong opinion at this moment (can stay as it is if we desire to further split erdjs functionality to separate NPM packages).

if(!this.innerTransaction || !this.innerTransactionGasLimit || !this.netConfig || !this.innerTransaction.getSignature()) {
throw new ErrInvalidRelayedV2BuilderArguments();
}
if(this.innerTransaction.getGasLimit() !== 0){
Copy link
Contributor

Choose a reason for hiding this comment

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

Comparison might fail if getGasLimit returns an object that implements IGasLimit. Perhaps allow type coercion to happen? != / or add a test with both numbers and objects if this works as it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

used !=

const innerTx = new Transaction({
nonce: 15,
receiver: Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"),
gasLimit: 10,
Copy link
Contributor

Choose a reason for hiding this comment

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

Using some implementation of IGasLimit, such as { valueOf: function() { return 10; } } might fail the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

extended the test to include this as well

@bogdan-rosianu bogdan-rosianu merged commit 5a6b98d into main Jun 29, 2022
@andreibancioiu andreibancioiu deleted the add-relayed-tx-v2-builder branch October 31, 2023 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants