From 4e22ce0049fd4d7cc298bd06414e80be51ffe7d6 Mon Sep 17 00:00:00 2001 From: lucanicoladebiasi Date: Wed, 1 Jan 2025 12:37:48 +0100 Subject: [PATCH] feat: 1484 node documented --- .../v2/net/thor/transactions/transactions.md | 4 +-- packages/net/src/thor/transactions/Clause.ts | 12 ++++++--- .../src/thor/transactions/GetTxResponse.ts | 26 +++++++++++-------- .../RetrieveTransactionReceipt.ts | 2 +- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/docs/diagrams/v2/net/thor/transactions/transactions.md b/docs/diagrams/v2/net/thor/transactions/transactions.md index 78cba088f..8d9a1c6a0 100644 --- a/docs/diagrams/v2/net/thor/transactions/transactions.md +++ b/docs/diagrams/v2/net/thor/transactions/transactions.md @@ -67,7 +67,7 @@ classDiagram class GetTxResponse { id: TxId origin: Address - delegator?: Address + delegator: Address | null size: UInt chainTag: UInt blockRef: BlockId @@ -84,7 +84,7 @@ classDiagram class GetTxResponseJSON { id: string origin: string - delegator?: string + delegator: string | null size: number chainTag: number blockRef: string diff --git a/packages/net/src/thor/transactions/Clause.ts b/packages/net/src/thor/transactions/Clause.ts index e3f95c030..936115770 100644 --- a/packages/net/src/thor/transactions/Clause.ts +++ b/packages/net/src/thor/transactions/Clause.ts @@ -6,14 +6,20 @@ class Clause { readonly data: HexUInt; constructor(json: ClauseJSON) { - this.to = json.to !== undefined ? Address.of(json.to) : undefined; + this.to = + json.to !== undefined && json.to != null + ? Address.of(json.to) + : undefined; this.value = VET.of(json.value); this.data = HexUInt.of(json.data); } toJSON(): ClauseJSON { return { - to: this.to?.toString(), + to: + this.to !== undefined && this.to !== null + ? this.to.toString() + : undefined, value: HexUInt.of(this.value.wei).toString(), data: this.data.toString() } satisfies ClauseJSON; @@ -21,7 +27,7 @@ class Clause { } interface ClauseJSON { - to?: string; + to?: string | null; value: string; data: string; } diff --git a/packages/net/src/thor/transactions/GetTxResponse.ts b/packages/net/src/thor/transactions/GetTxResponse.ts index 903548f0b..2c3eba646 100644 --- a/packages/net/src/thor/transactions/GetTxResponse.ts +++ b/packages/net/src/thor/transactions/GetTxResponse.ts @@ -9,7 +9,7 @@ import { UInt } from '../../../../core/src/vcdm/UInt'; class GetTxResponse { readonly id: TxId; readonly origin: Address; - readonly delegator?: Address; + readonly delegator: Address | null; readonly size: UInt; readonly chainTag: UInt; readonly blockRef: BlockId; @@ -17,7 +17,7 @@ class GetTxResponse { readonly clauses: Clause[]; readonly gasPriceCoef: UInt; readonly gas: VTHO; - readonly dependsOn?: TxId; + readonly dependsOn?: TxId | null; readonly nonce: Nonce; readonly meta: TxMeta; @@ -25,9 +25,7 @@ class GetTxResponse { this.id = TxId.of(json.id); this.origin = Address.of(json.origin); this.delegator = - json.delegator !== undefined - ? Address.of(json.delegator) - : undefined; + json.delegator !== null ? Address.of(json.delegator) : null; this.size = UInt.of(json.size); this.chainTag = UInt.of(json.chainTag); this.blockRef = BlockId.of(json.blockRef); @@ -38,7 +36,9 @@ class GetTxResponse { this.gasPriceCoef = UInt.of(json.gasPriceCoef); this.gas = VTHO.of(json.gas); this.dependsOn = - json.dependsOn !== undefined ? TxId.of(json.dependsOn) : undefined; + json.dependsOn !== undefined && json.dependsOn !== null + ? TxId.of(json.dependsOn) + : undefined; this.nonce = Nonce.of(json.nonce); this.meta = new TxMeta(json.meta); } @@ -47,15 +47,19 @@ class GetTxResponse { return { id: this.id.toString(), origin: this.origin.toString(), - delegator: this.delegator?.toString(), + delegator: + this.delegator != null ? this.delegator.toString() : null, size: this.size.valueOf(), chainTag: this.chainTag.valueOf(), blockRef: this.blockRef.toString(), expiration: this.expiration.valueOf(), - clauses: this.clauses.map((clause) => clause.toJSON()), + clauses: this.clauses?.map((clause) => clause.toJSON()), gasPriceCoef: this.gasPriceCoef.valueOf(), gas: Number(this.gas.wei), - dependsOn: this.dependsOn?.toString(), + dependsOn: + this.dependsOn !== undefined && this.dependsOn !== null + ? this.dependsOn.toString() + : undefined, nonce: this.nonce.toString(), meta: this.meta.toJSON() } satisfies GetTxResponseJSON; @@ -65,7 +69,7 @@ class GetTxResponse { interface GetTxResponseJSON { id: string; origin: string; - delegator?: string; + delegator: string | null; // The end point at https://mainnet.vechain.org/doc/stoplight-ui/#/schemas/GetTxResponse specifically returns `null`. size: number; chainTag: number; blockRef: string; @@ -73,7 +77,7 @@ interface GetTxResponseJSON { clauses: ClauseJSON[]; gasPriceCoef: number; gas: number; - dependsOn?: string; + dependsOn?: string | null; nonce: string; meta: TxMetaJSON; } diff --git a/packages/net/src/thor/transactions/RetrieveTransactionReceipt.ts b/packages/net/src/thor/transactions/RetrieveTransactionReceipt.ts index d1e9acad3..a89792b66 100644 --- a/packages/net/src/thor/transactions/RetrieveTransactionReceipt.ts +++ b/packages/net/src/thor/transactions/RetrieveTransactionReceipt.ts @@ -74,7 +74,7 @@ class RetrieveTransactionReceiptQuery implements HttpQuery { } get query(): string { - return this.head === null ? '' : `${this.head}&`; + return this.head === undefined ? '' : `${this.head}&`; } }