Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-core",
"version": "14.1.0-beta.6",
"version": "14.2.0",
"description": "MultiversX SDK for JavaScript and TypeScript",
"author": "MultiversX",
"homepage": "https://multiversx.com",
Expand Down
3 changes: 3 additions & 0 deletions src/accountManagement/accountController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class AccountController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -42,6 +43,7 @@ export class AccountController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand Down Expand Up @@ -72,6 +74,7 @@ export class AccountController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand Down
56 changes: 56 additions & 0 deletions src/core/baseController.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { assert } from "chai";
import { Address } from "./address";
import { BaseController } from "./baseController";
import { Transaction } from "./transaction";

class TestableBaseController extends BaseController {
public exposeSetTransactionGasOptions(
transaction: Transaction,
options: { gasLimit?: bigint; gasPrice?: bigint },
): void {
this.setTransactionGasOptions(transaction, options);
}

public exposeSetVersionAndOptionsForGuardian(transaction: Transaction): void {
this.setVersionAndOptionsForGuardian(transaction);
}
}

describe("BaseController Tests", function () {
it("set correct gasLimit", function () {
const controller = new TestableBaseController();

const transaction = new Transaction({
sender: Address.newFromBech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"),
receiver: Address.newFromBech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"),
gasLimit: 0n,
chainID: "D",
});

controller.exposeSetTransactionGasOptions(transaction, { gasLimit: 50000n });
assert.equal(transaction.gasLimit, 50000n);

transaction.guardian = Address.newFromBech32("erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8");
transaction.relayer = Address.newFromBech32("erd1kyaqzaprcdnv4luvanah0gfxzzsnpaygsy6pytrexll2urtd05ts9vegu7");
controller.exposeSetTransactionGasOptions(transaction, {});
assert.equal(transaction.gasLimit, 150000n);
});

it("set correct version and options for guarded transactions", function () {
const controller = new TestableBaseController();

const transaction = new Transaction({
sender: Address.newFromBech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"),
receiver: Address.newFromBech32("erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"),
gasLimit: 0n,
chainID: "D",
version: 0,
options: 0,
guardian: Address.newFromBech32("erd1k2s324ww2g0yj38qn2ch2jwctdy8mnfxep94q9arncc6xecg3xaq6mjse8"),
});

controller.exposeSetVersionAndOptionsForGuardian(transaction);
assert.equal(transaction.version, 2);
assert.equal(transaction.options, 2);
});
});
8 changes: 8 additions & 0 deletions src/core/baseController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Address } from "./address";
import { EXTRA_GAS_LIMIT_FOR_GUARDED_TRANSACTIONS, EXTRA_GAS_LIMIT_FOR_RELAYED_TRANSACTIONS } from "./constants";
import { Transaction } from "./transaction";
import { TransactionComputer } from "./transactionComputer";

export type BaseControllerInput = {
guardian?: Address;
Expand Down Expand Up @@ -30,4 +31,11 @@ export class BaseController {
transaction.gasLimit += BigInt(EXTRA_GAS_LIMIT_FOR_RELAYED_TRANSACTIONS);
}
}

protected setVersionAndOptionsForGuardian(transaction: Transaction): void {
if (transaction.guardian && !transaction.guardian.isEmpty()) {
const txComputer = new TransactionComputer();
txComputer.applyGuardian(transaction, transaction.guardian);
}
}
}
19 changes: 19 additions & 0 deletions src/delegation/delegationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -63,6 +64,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -79,6 +81,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -95,6 +98,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -111,6 +115,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -127,6 +132,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -143,6 +149,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -159,6 +166,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -175,6 +183,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -191,6 +200,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -207,6 +217,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -226,6 +237,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -245,6 +257,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -261,6 +274,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -277,6 +291,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -293,6 +308,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -309,6 +325,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -325,6 +342,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -342,6 +360,7 @@ export class DelegationController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();

this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand Down
7 changes: 7 additions & 0 deletions src/networkProviders/apiNetworkProvider.dev.net.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,4 +396,11 @@ describe("ApiNetworkProvider Tests", function () {
const result = await apiProvider.queryContract(query);
assert.equal(result.returnDataParts.length, 0);
});

it("should fetch transactions for an account", async () => {
const transactions = await apiProvider.getTransactions(
Address.newFromBech32("erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"),
);
assert.isTrue(transactions.length > 0);
});
});
6 changes: 6 additions & 0 deletions src/networkProviders/apiNetworkProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ export class ApiNetworkProvider implements INetworkProvider {
return transaction;
}

async getTransactions(address: Address): Promise<TransactionOnNetwork[]> {
const response = await this.doGetGeneric(`accounts/${address.toBech32()}/transactions`);
const transactions = response.map((item: any) => TransactionOnNetwork.fromApiHttpResponse(item.txHash, item));
return transactions;
}

async getTransactionStatus(txHash: string): Promise<TransactionStatus> {
const response = await this.doGetGeneric(`transactions/${txHash}?fields=status`);
const status = new TransactionStatus(response.status);
Expand Down
3 changes: 3 additions & 0 deletions src/smartContracts/smartContractController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class SmartContractController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -74,6 +75,7 @@ export class SmartContractController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand All @@ -90,6 +92,7 @@ export class SmartContractController extends BaseController {
transaction.relayer = options.relayer ?? Address.empty();
transaction.nonce = nonce;
this.setTransactionGasOptions(transaction, options);
this.setVersionAndOptionsForGuardian(transaction);
transaction.signature = await sender.signTransaction(transaction);

return transaction;
Expand Down
Loading
Loading