From 3645a29b7c1fa36364baa743d0ad5cd0221efda8 Mon Sep 17 00:00:00 2001 From: danielailie Date: Thu, 19 Dec 2024 15:32:08 +0200 Subject: [PATCH 1/7] Update TransactionOnNetwork to follow specs --- .../providers.dev.net.spec.ts | 14 +++++-- ...tContractTransactionsOutcomeParser.spec.ts | 10 ++--- src/transactionEvents.ts | 3 +- src/transactionOnNetwork.ts | 41 +++++++++++-------- .../transactionEventsParser.spec.ts | 4 +- 5 files changed, 42 insertions(+), 30 deletions(-) diff --git a/src/networkProviders/providers.dev.net.spec.ts b/src/networkProviders/providers.dev.net.spec.ts index 3c5a09e7..4a7760d1 100644 --- a/src/networkProviders/providers.dev.net.spec.ts +++ b/src/networkProviders/providers.dev.net.spec.ts @@ -274,12 +274,18 @@ describe("test network providers on devnet: Proxy and API", function () { ) { // Proxy and API exhibit differences in the "function" field, in case of move-balance transactions. apiResponse.function = proxyResponse.function; - + apiResponse.raw = {}; + apiResponse.smartContractResults.map((x) => (x.raw = {})); + apiResponse.smartContractResults.map((x) => x.logs.events.map((e) => (e.raw = {}))); + apiResponse.logs.events.map((e) => (e.raw = {})); // Ignore fields which are not present on API response: proxyResponse.epoch = 0; - proxyResponse.blockNonce = 0; - proxyResponse.hyperblockNonce = 0; - proxyResponse.hyperblockHash = ""; + proxyResponse.blockHash = ""; + proxyResponse.miniblockHash = ""; + proxyResponse.raw = {}; + proxyResponse.smartContractResults.map((x) => (x.raw = {})); + proxyResponse.smartContractResults.map((x) => x.logs.events.map((e) => (e.raw = {}))); + proxyResponse.logs.events.map((e) => (e.raw = {})); } it("should have the same response for transactions with events", async function () { diff --git a/src/smartContracts/smartContractTransactionsOutcomeParser.spec.ts b/src/smartContracts/smartContractTransactionsOutcomeParser.spec.ts index 1f1b151d..b835dbf6 100644 --- a/src/smartContracts/smartContractTransactionsOutcomeParser.spec.ts +++ b/src/smartContracts/smartContractTransactionsOutcomeParser.spec.ts @@ -17,7 +17,7 @@ describe("test smart contract transactions outcome parser", () => { const parser = new SmartContractTransactionsOutcomeParser(); const transactionOnNetwork = new TransactionOnNetwork({ - nonce: 7, + nonce: 7n, logs: new TransactionLogs({ events: [ new TransactionEvent({ @@ -52,7 +52,7 @@ describe("test smart contract transactions outcome parser", () => { const parser = new SmartContractTransactionsOutcomeParser(); const transactionOnNetwork = new TransactionOnNetwork({ - nonce: 7, + nonce: 7n, logs: new TransactionLogs({ events: [ new TransactionEvent({ @@ -77,7 +77,7 @@ describe("test smart contract transactions outcome parser", () => { it("parses execute outcome, without ABI", function () { const parser = new SmartContractTransactionsOutcomeParser(); const transactionOnNetwork = new TransactionOnNetwork({ - nonce: 7, + nonce: 7n, smartContractResults: [new SmartContractResult({ data: Buffer.from("@6f6b@2a") })], }); @@ -94,7 +94,7 @@ describe("test smart contract transactions outcome parser", () => { }); const transactionOnNetwork = new TransactionOnNetwork({ - nonce: 7, + nonce: 7n, function: "getUltimateAnswer", smartContractResults: [new SmartContractResult({ data: Buffer.from("@6f6b@2a") })], }); @@ -113,7 +113,7 @@ describe("test smart contract transactions outcome parser", () => { }); const transactionOnNetwork = new TransactionOnNetwork({ - nonce: 7, + nonce: 7n, smartContractResults: [new SmartContractResult({ data: Buffer.from("@6f6b@2a") })], }); diff --git a/src/transactionEvents.ts b/src/transactionEvents.ts index 5aadce52..48df23cc 100644 --- a/src/transactionEvents.ts +++ b/src/transactionEvents.ts @@ -1,6 +1,7 @@ import { Address } from "./address"; export class TransactionEvent { + raw: Record = {}; address: Address = Address.empty(); identifier: string = ""; topics: Uint8Array[] = []; @@ -25,8 +26,8 @@ export class TransactionEvent { result.topics = (responsePart.topics || []).map((topic) => Buffer.from(topic, "base64")); result.data = Buffer.from(responsePart.data ?? "", "base64"); - result.additionalData = (responsePart.additionalData || []).map((data) => Buffer.from(data, "base64")); + result.raw = responsePart; return result; } diff --git a/src/transactionOnNetwork.ts b/src/transactionOnNetwork.ts index 0e7b4f49..ebb81f2c 100644 --- a/src/transactionOnNetwork.ts +++ b/src/transactionOnNetwork.ts @@ -32,26 +32,29 @@ export function prepareTransactionForBroadcasting(transaction: Transaction): any } export class TransactionOnNetwork { + raw: Record = {}; isCompleted?: boolean; hash: string = ""; type: string = ""; - nonce: number = 0; - round: number = 0; + nonce: bigint = 0n; + round: bigint = 0n; epoch: number = 0; - value: string = ""; + value: bigint = 0n; receiver: Address = Address.empty(); sender: Address = Address.empty(); - gasLimit: number = 0; - gasPrice: number = 0; + senderShard: number = 0; + receiverShard: number = 0; + gasLimit: bigint = 0n; + gasPrice: bigint = 0n; function: string = ""; data: Buffer = Buffer.from([]); + version: number = 0; + options: number = 0; signature: string = ""; status: TransactionStatus = TransactionStatus.createUnknown(); timestamp: number = 0; - - blockNonce: number = 0; - hyperblockNonce: number = 0; - hyperblockHash: string = ""; + miniblockHash: string = ""; + blockHash: string = ""; smartContractResults: SmartContractResult[] = []; logs: TransactionLogs = new TransactionLogs(); @@ -105,23 +108,25 @@ export class TransactionOnNetwork { let result = new TransactionOnNetwork(); result.hash = txHash; result.type = response.type || ""; - result.nonce = response.nonce || 0; - result.round = response.round; + result.nonce = BigInt(response.nonce || 0); + result.round = BigInt(response.round || 0); result.epoch = response.epoch || 0; - result.value = (response.value || 0).toString(); + result.value = BigInt((response.value || 0).toString()); result.sender = new Address(response.sender); result.receiver = new Address(response.receiver); - result.gasPrice = response.gasPrice || 0; - result.gasLimit = response.gasLimit || 0; + result.gasPrice = BigInt(response.gasPrice) || 0n; + result.gasLimit = BigInt(response.gasLimit) || 0n; result.function = response.function || ""; result.data = Buffer.from(response.data || "", "base64"); + result.version = response.version || 1; + result.options = response.options || 0; + result.data = Buffer.from(response.data || "", "base64"); result.status = new TransactionStatus(response.status); result.timestamp = response.timestamp || 0; - - result.blockNonce = response.blockNonce || 0; - result.hyperblockNonce = response.hyperblockNonce || 0; - result.hyperblockHash = response.hyperblockHash || ""; + result.miniblockHash = response.miniblockHash || ""; + result.blockHash = response.blockHash || ""; result.logs = TransactionLogs.fromHttpResponse(response.logs || {}); + // result.raw = response; return result; } diff --git a/src/transactionsOutcomeParsers/transactionEventsParser.spec.ts b/src/transactionsOutcomeParsers/transactionEventsParser.spec.ts index d5fb21d2..5770853a 100644 --- a/src/transactionsOutcomeParsers/transactionEventsParser.spec.ts +++ b/src/transactionsOutcomeParsers/transactionEventsParser.spec.ts @@ -42,7 +42,7 @@ describe("test transaction events parser", () => { }); const transactionOnNetwork = new TransactionOnNetwork({ - nonce: 7, + nonce: 7n, smartContractResults: [ new SmartContractResult({ data: Buffer.from("@6f6b"), @@ -92,7 +92,7 @@ describe("test transaction events parser", () => { }); const transactionOnNetwork = new TransactionOnNetwork({ - nonce: 7, + nonce: 7n, smartContractResults: [new SmartContractResult({ data: Buffer.from("@6f6b") })], logs: new TransactionLogs({ events: [ From cd90c4e6b00fd23207fcd781d1919f53a40ba282 Mon Sep 17 00:00:00 2001 From: danielailie Date: Tue, 14 Jan 2025 11:11:35 +0200 Subject: [PATCH 2/7] Update isCompleted --- src/testutils/mockNetworkProvider.ts | 5 ++--- src/transactionOnNetwork.ts | 2 +- src/transactionWatcher.ts | 5 +---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/testutils/mockNetworkProvider.ts b/src/testutils/mockNetworkProvider.ts index ea560da9..6083900e 100644 --- a/src/testutils/mockNetworkProvider.ts +++ b/src/testutils/mockNetworkProvider.ts @@ -121,7 +121,7 @@ export class MockNetworkProvider implements INetworkProvider { } mockPutTransaction(hash: TransactionHash, item: TransactionOnNetwork) { - item.isCompleted = false; + item.status = TransactionStatus.createUnknown(); this.transactions.set(hash.toString(), item); } @@ -137,7 +137,6 @@ export class MockNetworkProvider implements INetworkProvider { let response = new TransactionOnNetwork({ status: new TransactionStatus("executed"), smartContractResults: [contractResult], - isCompleted: true, function: functionName, }); @@ -164,7 +163,7 @@ export class MockNetworkProvider implements INetworkProvider { }); } else if (point instanceof MarkCompleted) { this.mockUpdateTransaction(hash, (transaction) => { - transaction.isCompleted = true; + transaction.status = new TransactionStatus("success"); }); } else if (point instanceof Wait) { await timeline.start(point.milliseconds); diff --git a/src/transactionOnNetwork.ts b/src/transactionOnNetwork.ts index ebb81f2c..36fb4f07 100644 --- a/src/transactionOnNetwork.ts +++ b/src/transactionOnNetwork.ts @@ -82,7 +82,7 @@ export class TransactionOnNetwork { if (processStatus) { result.status = processStatus; - result.isCompleted = result.status.isSuccessful() || result.status.isFailed(); + result.isCompleted = result.status.isExecuted(); } return result; diff --git a/src/transactionWatcher.ts b/src/transactionWatcher.ts index d0483105..4b2179a2 100644 --- a/src/transactionWatcher.ts +++ b/src/transactionWatcher.ts @@ -81,10 +81,7 @@ export class TransactionWatcher { */ public async awaitCompleted(transactionOrTxHash: ITransaction | string): Promise { const isCompleted = (transactionOnNetwork: TransactionOnNetwork) => { - if (transactionOnNetwork.isCompleted === undefined) { - throw new ErrIsCompletedFieldIsMissingOnTransaction(); - } - return transactionOnNetwork.isCompleted; + return transactionOnNetwork.status.isExecuted(); }; const doFetch = async () => { From 8501e03bb4bed5b49632bbba9f0748987eefdf0c Mon Sep 17 00:00:00 2001 From: danielailie Date: Tue, 14 Jan 2025 11:13:24 +0200 Subject: [PATCH 3/7] remove comment --- src/transactionOnNetwork.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transactionOnNetwork.ts b/src/transactionOnNetwork.ts index 36fb4f07..f7a692f0 100644 --- a/src/transactionOnNetwork.ts +++ b/src/transactionOnNetwork.ts @@ -126,7 +126,7 @@ export class TransactionOnNetwork { result.miniblockHash = response.miniblockHash || ""; result.blockHash = response.blockHash || ""; result.logs = TransactionLogs.fromHttpResponse(response.logs || {}); - // result.raw = response; + result.raw = response; return result; } From 7df8980bff7f1e178deb16d2abbf8dd49a43743a Mon Sep 17 00:00:00 2001 From: danielailie Date: Tue, 14 Jan 2025 12:19:16 +0200 Subject: [PATCH 4/7] Add isCompleted on TranactionStatus and mark as deprecated isExecuted --- src/transactionOnNetwork.ts | 2 +- src/transactionStatus.ts | 26 +++++++++++--------------- src/transactionWatcher.ts | 2 +- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/transactionOnNetwork.ts b/src/transactionOnNetwork.ts index f7a692f0..c884a689 100644 --- a/src/transactionOnNetwork.ts +++ b/src/transactionOnNetwork.ts @@ -82,7 +82,7 @@ export class TransactionOnNetwork { if (processStatus) { result.status = processStatus; - result.isCompleted = result.status.isExecuted(); + result.isCompleted = result.status.isCompleted(); } return result; diff --git a/src/transactionStatus.ts b/src/transactionStatus.ts index bb509cbc..e13ee7b8 100644 --- a/src/transactionStatus.ts +++ b/src/transactionStatus.ts @@ -25,40 +25,36 @@ export class TransactionStatus { * Returns whether the transaction is pending (e.g. in mempool). */ isPending(): boolean { - return ( - this.status == "received" || - this.status == "pending" - ); + return this.status == "received" || this.status == "pending"; } /** * Returns whether the transaction has been executed (not necessarily with success). + * @deprecated This will be remove next version, please use {@link isCompleted} instead. */ isExecuted(): boolean { return this.isSuccessful() || this.isFailed() || this.isInvalid(); } + /** + * Returns whether the transaction has been conpleted (not necessarily with success). + */ + isCompleted(): boolean { + return this.isSuccessful() || this.isFailed() || this.isInvalid(); + } + /** * Returns whether the transaction has been executed successfully. */ isSuccessful(): boolean { - return ( - this.status == "executed" || - this.status == "success" || - this.status == "successful" - ); + return this.status == "executed" || this.status == "success" || this.status == "successful"; } /** * 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(); } /** diff --git a/src/transactionWatcher.ts b/src/transactionWatcher.ts index 4b2179a2..98bf2073 100644 --- a/src/transactionWatcher.ts +++ b/src/transactionWatcher.ts @@ -81,7 +81,7 @@ export class TransactionWatcher { */ public async awaitCompleted(transactionOrTxHash: ITransaction | string): Promise { const isCompleted = (transactionOnNetwork: TransactionOnNetwork) => { - return transactionOnNetwork.status.isExecuted(); + return transactionOnNetwork.status.isCompleted(); }; const doFetch = async () => { From 00144afd91a3b6f87e3ae63e6ceb75dd81f3bfa0 Mon Sep 17 00:00:00 2001 From: danielailie Date: Tue, 14 Jan 2025 14:24:00 +0200 Subject: [PATCH 5/7] Add isCompleted and IsSuccessfull falg on transaction status --- src/transactionOnNetwork.ts | 4 ++-- src/transactionStatus.ts | 16 +++++++++++----- src/transactionWatcher.ts | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/transactionOnNetwork.ts b/src/transactionOnNetwork.ts index c884a689..42bfa624 100644 --- a/src/transactionOnNetwork.ts +++ b/src/transactionOnNetwork.ts @@ -50,7 +50,7 @@ export class TransactionOnNetwork { data: Buffer = Buffer.from([]); version: number = 0; options: number = 0; - signature: string = ""; + signature?: Uint8Array; status: TransactionStatus = TransactionStatus.createUnknown(); timestamp: number = 0; miniblockHash: string = ""; @@ -82,7 +82,7 @@ export class TransactionOnNetwork { if (processStatus) { result.status = processStatus; - result.isCompleted = result.status.isCompleted(); + result.isCompleted = result.status.isStatusCompleted(); } return result; diff --git a/src/transactionStatus.ts b/src/transactionStatus.ts index e13ee7b8..e5848681 100644 --- a/src/transactionStatus.ts +++ b/src/transactionStatus.ts @@ -7,11 +7,17 @@ export class TransactionStatus { */ readonly status: string; + readonly isCompleted: boolean; + + readonly isSuccessfull: boolean; + /** * Creates a new TransactionStatus object. */ constructor(status: string) { this.status = (status || "").toLowerCase(); + this.isCompleted = this.isStatusCompleted(); + this.isSuccessfull = this.isStatusSuccessful(); } /** @@ -30,23 +36,23 @@ export class TransactionStatus { /** * Returns whether the transaction has been executed (not necessarily with success). - * @deprecated This will be remove next version, please use {@link isCompleted} instead. + * @deprecated This will be remove next version, please use {@link isStatusCompleted} instead. */ isExecuted(): boolean { - return this.isSuccessful() || this.isFailed() || this.isInvalid(); + return this.isStatusSuccessful() || this.isFailed() || this.isInvalid(); } /** * Returns whether the transaction has been conpleted (not necessarily with success). */ - isCompleted(): boolean { - return this.isSuccessful() || this.isFailed() || this.isInvalid(); + isStatusCompleted(): boolean { + return this.isStatusSuccessful() || this.isFailed() || this.isInvalid(); } /** * Returns whether the transaction has been executed successfully. */ - isSuccessful(): boolean { + isStatusSuccessful(): boolean { return this.status == "executed" || this.status == "success" || this.status == "successful"; } diff --git a/src/transactionWatcher.ts b/src/transactionWatcher.ts index 98bf2073..d3e4fa4c 100644 --- a/src/transactionWatcher.ts +++ b/src/transactionWatcher.ts @@ -81,7 +81,7 @@ export class TransactionWatcher { */ public async awaitCompleted(transactionOrTxHash: ITransaction | string): Promise { const isCompleted = (transactionOnNetwork: TransactionOnNetwork) => { - return transactionOnNetwork.status.isCompleted(); + return transactionOnNetwork.status.isStatusCompleted(); }; const doFetch = async () => { From a3ba1c8aca7752b99bec9a3236b112de63437540 Mon Sep 17 00:00:00 2001 From: danielailie Date: Tue, 14 Jan 2025 14:41:36 +0200 Subject: [PATCH 6/7] Revert IsCompleted and IsSuccessfull methods --- src/transactionOnNetwork.ts | 6 +++--- src/transactionStatus.ts | 16 +++++----------- src/transactionWatcher.ts | 2 +- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/transactionOnNetwork.ts b/src/transactionOnNetwork.ts index 42bfa624..a5db991e 100644 --- a/src/transactionOnNetwork.ts +++ b/src/transactionOnNetwork.ts @@ -50,7 +50,7 @@ export class TransactionOnNetwork { data: Buffer = Buffer.from([]); version: number = 0; options: number = 0; - signature?: Uint8Array; + signature: Uint8Array = new Uint8Array(); status: TransactionStatus = TransactionStatus.createUnknown(); timestamp: number = 0; miniblockHash: string = ""; @@ -82,7 +82,7 @@ export class TransactionOnNetwork { if (processStatus) { result.status = processStatus; - result.isCompleted = result.status.isStatusCompleted(); + result.isCompleted = result.status.isSuccessful() || result.status.isFailed(); } return result; @@ -126,7 +126,7 @@ export class TransactionOnNetwork { result.miniblockHash = response.miniblockHash || ""; result.blockHash = response.blockHash || ""; result.logs = TransactionLogs.fromHttpResponse(response.logs || {}); - result.raw = response; + // result.raw = response; return result; } diff --git a/src/transactionStatus.ts b/src/transactionStatus.ts index e5848681..e13ee7b8 100644 --- a/src/transactionStatus.ts +++ b/src/transactionStatus.ts @@ -7,17 +7,11 @@ export class TransactionStatus { */ readonly status: string; - readonly isCompleted: boolean; - - readonly isSuccessfull: boolean; - /** * Creates a new TransactionStatus object. */ constructor(status: string) { this.status = (status || "").toLowerCase(); - this.isCompleted = this.isStatusCompleted(); - this.isSuccessfull = this.isStatusSuccessful(); } /** @@ -36,23 +30,23 @@ export class TransactionStatus { /** * Returns whether the transaction has been executed (not necessarily with success). - * @deprecated This will be remove next version, please use {@link isStatusCompleted} instead. + * @deprecated This will be remove next version, please use {@link isCompleted} instead. */ isExecuted(): boolean { - return this.isStatusSuccessful() || this.isFailed() || this.isInvalid(); + return this.isSuccessful() || this.isFailed() || this.isInvalid(); } /** * Returns whether the transaction has been conpleted (not necessarily with success). */ - isStatusCompleted(): boolean { - return this.isStatusSuccessful() || this.isFailed() || this.isInvalid(); + isCompleted(): boolean { + return this.isSuccessful() || this.isFailed() || this.isInvalid(); } /** * Returns whether the transaction has been executed successfully. */ - isStatusSuccessful(): boolean { + isSuccessful(): boolean { return this.status == "executed" || this.status == "success" || this.status == "successful"; } diff --git a/src/transactionWatcher.ts b/src/transactionWatcher.ts index d3e4fa4c..98bf2073 100644 --- a/src/transactionWatcher.ts +++ b/src/transactionWatcher.ts @@ -81,7 +81,7 @@ export class TransactionWatcher { */ public async awaitCompleted(transactionOrTxHash: ITransaction | string): Promise { const isCompleted = (transactionOnNetwork: TransactionOnNetwork) => { - return transactionOnNetwork.status.isStatusCompleted(); + return transactionOnNetwork.status.isCompleted(); }; const doFetch = async () => { From 279eb8d87b0c366f46d56d3bbf03ebdcb0c30301 Mon Sep 17 00:00:00 2001 From: danielailie Date: Tue, 14 Jan 2025 14:44:14 +0200 Subject: [PATCH 7/7] Remove commented code --- src/transactionOnNetwork.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transactionOnNetwork.ts b/src/transactionOnNetwork.ts index a5db991e..2b4746a4 100644 --- a/src/transactionOnNetwork.ts +++ b/src/transactionOnNetwork.ts @@ -126,7 +126,7 @@ export class TransactionOnNetwork { result.miniblockHash = response.miniblockHash || ""; result.blockHash = response.blockHash || ""; result.logs = TransactionLogs.fromHttpResponse(response.logs || {}); - // result.raw = response; + result.raw = response; return result; }