Skip to content

Commit

Permalink
Merge pull request #73 from multiversx/TOOL-278-remove-code-for-relay…
Browse files Browse the repository at this point in the history
…ed-v-3-transactions

Tool 278 remove code for relayed v 3 transactions
  • Loading branch information
danielailie authored Oct 21, 2024
2 parents 158da78 + cf4fdd8 commit 8a6264b
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 136 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-network-providers",
"version": "2.8.0",
"version": "2.9.0",
"lockfileVersion": 2,
"requires": true,
"author": "MultiversX",
Expand Down
4 changes: 1 addition & 3 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,4 @@ export interface ITransactionNext {
guardian: string;
signature: Uint8Array;
guardianSignature: Uint8Array;
relayer?: string;
innerTransactions?: ITransactionNext[];
}
}
105 changes: 1 addition & 104 deletions src/providers.dev.net.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("test network providers on devnet: Proxy and API", function () {

const apiResponse = await apiProviderWithoutConfig.getNetworkConfig();
const proxyResponse = await proxyProviderWithoutConfig.getNetworkConfig();

assert.equal(apiResponse.ChainID, "D");
assert.equal(proxyResponse.ChainID, "D");
});
Expand Down Expand Up @@ -232,49 +232,6 @@ describe("test network providers on devnet: Proxy and API", function () {
}
});

it("should have same response for getTransaction() (relayed V3)", async function () {
this.timeout(20000);

// Transaction was sent using mxpy, as follows:
// mxpy tx new --pem=~/multiversx-sdk/testwallets/latest/users/alice.pem --receiver=erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx --value=1000000000000000000 --gas-limit=50000 --recall-nonce --relayer=erd1r69gk66fmedhhcg24g2c5kn2f2a5k4kvpr6jfw67dn2lyydd8cfswy6ede --inner-transactions-outfile=inner.json --proxy=https://devnet-gateway.multiversx.com
// mxpy tx new --pem=~/multiversx-sdk/testwallets/latest/users/grace.pem --receiver=erd1r69gk66fmedhhcg24g2c5kn2f2a5k4kvpr6jfw67dn2lyydd8cfswy6ede --gas-limit=100000 --recall-nonce --chain=D --inner-transactions=inner.json --proxy=https://devnet-gateway.multiversx.com --send

const txHash = "8cdfb790be8cd4b331da486ba014ed56d0dbac70c1cfbadf11db2edd48d0e437";
const apiResponse = await apiProvider.getTransaction(txHash);
const proxyResponse = await proxyProvider.getTransaction(txHash, true);

assert.deepEqual(proxyResponse.innerTransactions, [
{
nonce: BigInt(9340),
value: BigInt("1000000000000000000"),
receiver: "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx",
sender: "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th",
data: Buffer.from([]),
gasPrice: BigInt(1000000000),
gasLimit: BigInt(50000),
chainID: "D",
version: 2,
signature: Buffer.from(
"0993c2f3a47c01cf8330e54571ea9340aae481d0d5212af31b62eb7194e199231f105134aae28a75bb48b53a3dff09d6c6208843c8e0376617cf62d3bfb60204",
"hex",
),
senderUsername: "",
receiverUsername: "",
guardian: "",
guardianSignature: Buffer.from([]),
options: 0,
relayer: "erd1r69gk66fmedhhcg24g2c5kn2f2a5k4kvpr6jfw67dn2lyydd8cfswy6ede",
},
]);

ignoreKnownTransactionDifferencesBetweenProviders(apiResponse, proxyResponse);
assert.deepEqual(apiResponse, proxyResponse);

// Also assert completion
assert.isTrue(apiResponse.isCompleted);
assert.isTrue(proxyResponse.isCompleted);
});

// TODO: Strive to have as little differences as possible between Proxy and API.
function ignoreKnownTransactionDifferencesBetweenProviders(
apiResponse: TransactionOnNetwork,
Expand All @@ -288,9 +245,6 @@ describe("test network providers on devnet: Proxy and API", function () {
proxyResponse.blockNonce = 0;
proxyResponse.hyperblockNonce = 0;
proxyResponse.hyperblockHash = "";

// API does not provide "innerTransactions" (Spica), for the moment.
proxyResponse.innerTransactions = [];
}

it("should have the same response for transactions with events", async function () {
Expand Down Expand Up @@ -457,61 +411,4 @@ describe("test network providers on devnet: Proxy and API", function () {
assert.equal(apiLegacyTxHash, proxyLegacyTxHash);
assert.equal(apiTxNextHash, proxyTxNextHash);
});

it("should send `TransactionNext` (as relayed V3)", async function () {
this.timeout(50000);

// Transaction was created using mxpy, as follows:
// mxpy tx new --pem=~/multiversx-sdk/testwallets/latest/users/alice.pem --receiver=erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx --value=1000000000000000000 --gas-limit=50000 --nonce=7 --chain=D --relayer=erd1r69gk66fmedhhcg24g2c5kn2f2a5k4kvpr6jfw67dn2lyydd8cfswy6ede --inner-transactions-outfile=inner.json
// mxpy tx new --pem=~/multiversx-sdk/testwallets/latest/users/grace.pem --receiver=erd1r69gk66fmedhhcg24g2c5kn2f2a5k4kvpr6jfw67dn2lyydd8cfswy6ede --gas-limit=100000 --nonce=42 --chain=D --inner-transactions=inner.json

const transactionNext: ITransactionNext = {
nonce: BigInt(42),
value: BigInt(0),
receiver: "erd1r69gk66fmedhhcg24g2c5kn2f2a5k4kvpr6jfw67dn2lyydd8cfswy6ede",
sender: "erd1r69gk66fmedhhcg24g2c5kn2f2a5k4kvpr6jfw67dn2lyydd8cfswy6ede",
data: new Uint8Array(),
gasPrice: BigInt(1000000000),
gasLimit: BigInt(100000),
chainID: "D",
version: 2,
signature: Buffer.from(
"c623854967c954d13681035d5b24be68a5a58d25e7efdc75c7d59b5c389e1ad6c9d21a6f41149ec6e8bd051d74f3636a60ce047062f05c748600c36348238e0b",
"hex",
),
senderUsername: "",
receiverUsername: "",
guardian: "",
guardianSignature: new Uint8Array(),
options: 0,
innerTransactions: [
{
nonce: BigInt(7),
value: BigInt("1000000000000000000"),
receiver: "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx",
sender: "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th",
data: new Uint8Array(),
gasPrice: BigInt(1000000000),
gasLimit: BigInt(50000),
chainID: "D",
version: 2,
signature: Buffer.from(
"40808231154b9924c0d5f885d320f4ab666308f7443ea128ac26029b1de07abfcee6412e1249a9c0fcf79638d9691be3c9fe75dd7c85462082f9b86c4008b30e",
"hex",
),
senderUsername: "",
receiverUsername: "",
guardian: "",
guardianSignature: new Uint8Array(),
options: 0,
relayer: "erd1r69gk66fmedhhcg24g2c5kn2f2a5k4kvpr6jfw67dn2lyydd8cfswy6ede",
},
],
};

const apiTxNextHash = await apiProvider.sendTransaction(transactionNext);
const proxyTxNextHash = await proxyProvider.sendTransaction(transactionNext);

assert.equal(apiTxNextHash, proxyTxNextHash);
});
});
26 changes: 0 additions & 26 deletions src/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export function prepareTransactionForBroadcasting(transaction: ITransaction | IT
guardian: transaction.guardian || undefined,
signature: Buffer.from(transaction.signature).toString("hex"),
guardianSignature: transaction.guardianSignature.length === 0 ? undefined : Buffer.from(transaction.guardianSignature).toString("hex"),
relayer: transaction.relayer ? transaction.relayer : undefined,
innerTransactions: transaction.innerTransactions ? transaction.innerTransactions.map((tx) => prepareTransactionForBroadcasting(tx)) : undefined,
};
}

Expand Down Expand Up @@ -56,7 +54,6 @@ export class TransactionOnNetwork {
receipt: TransactionReceipt = new TransactionReceipt();
contractResults: ContractResults = new ContractResults([]);
logs: TransactionLogs = new TransactionLogs();
innerTransactions: ITransactionNext[] = [];

constructor(init?: Partial<TransactionOnNetwork>) {
Object.assign(this, init);
Expand Down Expand Up @@ -105,33 +102,10 @@ export class TransactionOnNetwork {

result.receipt = TransactionReceipt.fromHttpResponse(response.receipt || {});
result.logs = TransactionLogs.fromHttpResponse(response.logs || {});
result.innerTransactions = (response.innerTransactions || []).map(this.innerTransactionFromHttpResource);

return result;
}

private static innerTransactionFromHttpResource(resource: any): ITransactionNext {
return {
nonce: BigInt(resource.nonce || 0),
value: BigInt(resource.value || 0),
receiver: resource.receiver,
sender: resource.sender,
// We discard "senderUsername" and "receiverUsername" (to avoid future discrepancies between Proxy and API):
senderUsername: "",
receiverUsername: "",
gasPrice: BigInt(resource.gasPrice),
gasLimit: BigInt(resource.gasLimit),
data: Buffer.from(resource.data || "", "base64"),
chainID: resource.chainID,
version: resource.version,
options: resource.options || 0,
guardian: resource.guardian || "",
signature: Buffer.from(resource.signature, "hex"),
guardianSignature: resource.guardianSignature ? Buffer.from(resource.guardianSignature, "hex") : Buffer.from([]),
relayer: resource.relayer,
};
}

getDateTime(): Date {
return new Date(this.timestamp * 1000);
}
Expand Down

0 comments on commit 8a6264b

Please sign in to comment.