Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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": "15.3.2",
"version": "15.4.0",
"description": "MultiversX SDK for JavaScript and TypeScript",
"author": "MultiversX",
"homepage": "https://multiversx.com",
Expand Down
5 changes: 5 additions & 0 deletions src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ export const UNKNOWN_SIGNER = "unknown";
export const EGLD_IDENTIFIER_FOR_MULTI_ESDTNFT_TRANSFER = "EGLD-000000";
export const EXTRA_GAS_LIMIT_FOR_GUARDED_TRANSACTIONS = 50_000;
export const EXTRA_GAS_LIMIT_FOR_RELAYED_TRANSACTIONS = 50_000;

export const DEFAULT_TRANSACTION_AWAITING_POLLING_TIMEOUT_IN_MILLISECONDS = 600;
export const DEFAULT_TRANSACTION_AWAITING_TIMEOUT_IN_MILLISECONDS =
15 * DEFAULT_TRANSACTION_AWAITING_POLLING_TIMEOUT_IN_MILLISECONDS;
Comment thread
popenta marked this conversation as resolved.
export const DEFAULT_TRANSACTION_AWAITING_PATIENCE_IN_MILLISECONDS = 0;
8 changes: 7 additions & 1 deletion src/core/transactionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ export class TransactionStatus {
* Returns whether the transaction has been executed, but with a failure.
*/
isFailed(): boolean {
return this.status == "fail" || this.status == "failed" || this.status == "unsuccessful" || this.isInvalid();
return (
this.status == "fail" ||
this.status == "failed" ||
this.status == "unsuccessful" ||
this.isInvalid() ||
this.status == "not-executable-in-block"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this correct for the unexecutable to be reported as failed?

this was not executed, similar to higher nonce or lower nonce in transaction.
It may be executed in a different block afterwards (for higher nonce for example, if the gap is filled)

);
}

/**
Expand Down
28 changes: 28 additions & 0 deletions src/core/transactionWatcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,32 @@ describe("test transactionWatcher", () => {

assert.isTrue((await provider.getTransactionStatus(hash)).isCompleted());
});

it("should await status == not-executable-in-block using transaction", async () => {
let hash = "abbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba";
let provider = new MockNetworkProvider();
let watcher = new TransactionWatcher(provider, {
pollingIntervalMilliseconds: 42,
timeoutMilliseconds: 42 * 42,
});

provider.mockPutTransaction(
hash,
new TransactionOnNetwork({
status: new TransactionStatus("unknown"),
}),
);

await Promise.all([
provider.mockTransactionTimelineByHash(hash, [
new Wait(40),
new TransactionStatus("pending"),
new Wait(40),
new TransactionStatus("not-executable-in-block"),
]),
watcher.awaitCompleted(hash),
]);

assert.isTrue((await provider.getTransactionStatus(hash)).isFailed());
});
});
11 changes: 8 additions & 3 deletions src/core/transactionWatcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { AsyncTimer } from "./asyncTimer";
import {
DEFAULT_TRANSACTION_AWAITING_PATIENCE_IN_MILLISECONDS,
DEFAULT_TRANSACTION_AWAITING_POLLING_TIMEOUT_IN_MILLISECONDS,
DEFAULT_TRANSACTION_AWAITING_TIMEOUT_IN_MILLISECONDS,
} from "./constants";
import {
Err,
ErrExpectedTransactionEventsNotFound,
Expand All @@ -17,9 +22,9 @@ export type PredicateIsAwaitedStatus = (status: TransactionStatus) => boolean;
* TransactionWatcher allows one to continuously watch (monitor), by means of polling, the status of a given transaction.
*/
export class TransactionWatcher {
private static DefaultPollingInterval: number = 6000;
private static DefaultTimeout: number = TransactionWatcher.DefaultPollingInterval * 15;
private static DefaultPatience: number = 0;
private static DefaultPollingInterval: number = DEFAULT_TRANSACTION_AWAITING_POLLING_TIMEOUT_IN_MILLISECONDS;
private static DefaultTimeout: number = DEFAULT_TRANSACTION_AWAITING_TIMEOUT_IN_MILLISECONDS;
private static DefaultPatience: number = DEFAULT_TRANSACTION_AWAITING_PATIENCE_IN_MILLISECONDS;

static NoopOnStatusReceived = (_: TransactionStatus) => {};

Expand Down
2 changes: 1 addition & 1 deletion src/networkProviders/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const EsdtContractAddress = new Address("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqq
export const BaseUserAgent = "multiversx-sdk";
export const UnknownClientName = "unknown";

export const DEFAULT_ACCOUNT_AWAITING_POLLING_TIMEOUT_IN_MILLISECONDS = 6000;
export const DEFAULT_ACCOUNT_AWAITING_POLLING_TIMEOUT_IN_MILLISECONDS = 600;
Comment thread
popenta marked this conversation as resolved.
export const DEFAULT_ACCOUNT_AWAITING_TIMEOUT_IN_MILLISECONDS =
15 * DEFAULT_ACCOUNT_AWAITING_POLLING_TIMEOUT_IN_MILLISECONDS;
export const DEFAULT_ACCOUNT_AWAITING_PATIENCE_IN_MILLISECONDS = 0;
7 changes: 7 additions & 0 deletions src/networkProviders/networkStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ export class NetworkStatus {
*/
public blockTimestamp: number;

/**
* The block timestamp in milliseconds.
*/
public blockTimestampMs: number;

/**
* The block nonce.
*/
Expand All @@ -35,6 +40,7 @@ export class NetworkStatus {
this.highestFinalNonce = 0n;
this.blockNonce = 0n;
this.blockTimestamp = 0;
this.blockTimestampMs = 0;
}

/**
Expand All @@ -49,6 +55,7 @@ export class NetworkStatus {
networkStatus.highestFinalNonce = BigInt(payload["erd_highest_final_nonce"]);
networkStatus.blockNonce = BigInt(payload["erd_nonce"]);
networkStatus.blockTimestamp = Number(payload["erd_block_timestamp"]);
networkStatus.blockTimestampMs = Number(payload["erd_block_timestamp_ms"]);

return networkStatus;
}
Expand Down
Loading