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

EN-13168: added relayed v1 tx builder #235

Merged
merged 11 commits into from
Sep 22, 2022

Conversation

bogdan-rosianu
Copy link
Contributor

@bogdan-rosianu bogdan-rosianu commented Sep 20, 2022

Added a buidler for relayed v1 tx builder + some fixes for relayed v2

@bogdan-rosianu bogdan-rosianu marked this pull request as ready for review September 21, 2022 13:19
@bogdan-rosianu bogdan-rosianu self-assigned this Sep 21, 2022
@schimih schimih self-requested a review September 21, 2022 13:30
schimih
schimih previously approved these changes Sep 21, 2022
Copy link
Contributor

@schimih schimih left a comment

Choose a reason for hiding this comment

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

Approve: I don't see any issue, only small beautifiers. I may do the changes when support for frozen account will be needed for relayed transactions as well.

import BigNumber from "bignumber.js";

export class RelayedTransactionV1Builder {

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

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

}

/**
* Sets the network config to be used for building the relayed v2 transaction
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Sets the network config to be used for building the relayed v2 transaction
* Sets the network config to be used for building the relayed v1 transaction

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}

/**
* Sets the address of the relayer (the one that will actually pay the fee
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Sets the address of the relayer (the one that will actually pay the fee
* Sets the address of the relayer (the one that will actually pay the fee)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

.setFunction(new ContractFunction("relayedTx"))
.setArgs([
new StringValue(serializedTransaction),
//new StringValue(serializedTransaction.toString("hex"))
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see why this should stay here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true, removed

Comment on lines +39 to +43
builder = builder
.setNetworkConfig(networkConfig)
.setInnerTransactionGasLimit(10)
.setInnerTransaction(innerTx)
.setRelayerAddress(alice.address);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -68,6 +76,7 @@ describe("test relayed v2 transaction builder", function () {
.setInnerTransaction(innerTx)
.setInnerTransactionGasLimit(60_000_000)
.setNetworkConfig(networkConfig)
.setRelayerAddress(alice.getAddress())
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

this.netConfig = netConfig;
return this;
}

/**
* Tries to build the relayed v2 transaction based on the previously set fields
* Sets the address of the relayer (the one that will actually pay the fee
Copy link
Contributor

Choose a reason for hiding this comment

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

Like the one before

Suggested change
* Sets the address of the relayer (the one that will actually pay the fee
* Sets the address of the relayer (the one that will actually pay the fee)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

vladbucur1
vladbucur1 previously approved these changes Sep 22, 2022
schimih
schimih previously approved these changes Sep 22, 2022
andreibancioiu
andreibancioiu previously approved these changes Sep 22, 2022
@@ -0,0 +1,81 @@
import {loadTestWallets, TestWallet} from "./testutils";
Copy link
Contributor

Choose a reason for hiding this comment

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

Imports formatting is inconsistent with other files (optional).

nonce: 15,
sender: alice.address,
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.

Can use a more real-world value her (optional).

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

const relayedTxV1 = builder
.setInnerTransaction(innerTx)
.setRelayerNonce({
valueOf: function () {
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 passing the number directly should work (since Number implements valueOf).

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

netConfig: INetworkConfig | undefined;

/**
* Sets the inner transaction to be used. It has to be already signed.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

*
* @param {Transaction} transaction The inner transaction to be used
*/
setInnerTransaction(transaction: Transaction): RelayedTransactionV1Builder {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we have received an ITransaction here? Please leave as it is otherwise :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, we cannot use that

const payload = TransactionPayload.contractCall()
.setFunction(new ContractFunction("relayedTx"))
.setArgs([
new StringValue(serializedTransaction),
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

receiver: this.innerTransaction.getSender(),
value: 0,
gasLimit:
this.netConfig.MinGasLimit + this.netConfig.GasPerDataByte * payload.length() + this.innerTransaction.getGasLimit().valueOf(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Optionally, this could have been a separate variable.

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


const txObject = {
"nonce": this.innerTransaction.getNonce().valueOf(),
"sender": new Address(this.innerTransaction.getSender().bech32()).pubkey().toString("base64"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I've forgot about this 👍

@@ -67,10 +75,17 @@ describe("test relayed v2 transaction builder", function () {
const relayedTxV2 = builder
.setInnerTransaction(innerTx)
.setInnerTransactionGasLimit(60_000_000)
.setRelayerNonce({
Copy link
Contributor

Choose a reason for hiding this comment

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

Could have been setRelayerNonce(37) (I think).

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

innerTransaction: Transaction | undefined;
innerTransactionGasLimit: IGasLimit | undefined;
relayerAddress: IAddress | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

All right, they don't seem to be breaking changes.

andreibancioiu
andreibancioiu previously approved these changes Sep 22, 2022
schimih
schimih previously approved these changes Sep 22, 2022
@bogdan-rosianu bogdan-rosianu merged commit 150613a into main Sep 22, 2022
@andreibancioiu andreibancioiu deleted the EN-13168-relayed-v1-tx-builder branch October 31, 2023 10:16
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