Skip to content

Commit

Permalink
feat: 1484 node documented
Browse files Browse the repository at this point in the history
  • Loading branch information
lucanicoladebiasi committed Jan 1, 2025
1 parent 320173d commit 4e22ce0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
4 changes: 2 additions & 2 deletions docs/diagrams/v2/net/thor/transactions/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ classDiagram
class GetTxResponse {
id: TxId
origin: Address
delegator?: Address
delegator: Address | null
size: UInt
chainTag: UInt
blockRef: BlockId
Expand All @@ -84,7 +84,7 @@ classDiagram
class GetTxResponseJSON {
id: string
origin: string
delegator?: string
delegator: string | null
size: number
chainTag: number
blockRef: string
Expand Down
12 changes: 9 additions & 3 deletions packages/net/src/thor/transactions/Clause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,28 @@ 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;
}
}

interface ClauseJSON {
to?: string;
to?: string | null;
value: string;
data: string;
}
Expand Down
26 changes: 15 additions & 11 deletions packages/net/src/thor/transactions/GetTxResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,23 @@ 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;
readonly expiration: UInt;
readonly clauses: Clause[];
readonly gasPriceCoef: UInt;
readonly gas: VTHO;
readonly dependsOn?: TxId;
readonly dependsOn?: TxId | null;
readonly nonce: Nonce;
readonly meta: TxMeta;

constructor(json: GetTxResponseJSON) {
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);
Expand All @@ -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);
}
Expand All @@ -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;
Expand All @@ -65,15 +69,15 @@ 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;
expiration: number;
clauses: ClauseJSON[];
gasPriceCoef: number;
gas: number;
dependsOn?: string;
dependsOn?: string | null;
nonce: string;
meta: TxMetaJSON;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class RetrieveTransactionReceiptQuery implements HttpQuery {
}

get query(): string {
return this.head === null ? '' : `${this.head}&`;
return this.head === undefined ? '' : `${this.head}&`;
}
}

Expand Down

0 comments on commit 4e22ce0

Please sign in to comment.