From 8c9317a91db2f31c8f167a5e21899c9d5abc7a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= <thoralf.mue@gmail.com> Date: Tue, 9 Jan 2024 10:47:42 +0100 Subject: [PATCH] Add GetUtxoChangesFull routes --- bindings/core/src/method/client.rs | 6 +-- bindings/core/src/method_handler/client.rs | 12 ++--- bindings/nodejs/lib/client/client.ts | 51 ++++++++++++++++--- .../nodejs/lib/types/client/bridge/client.ts | 18 ++++++- .../nodejs/lib/types/client/bridge/index.ts | 4 ++ .../types/models/api/utxo-changes-response.ts | 37 ++++++++++++++ bindings/nodejs/lib/types/models/state.ts | 6 +-- 7 files changed, 112 insertions(+), 22 deletions(-) diff --git a/bindings/core/src/method/client.rs b/bindings/core/src/method/client.rs index 02e829a698..7ce48daf54 100644 --- a/bindings/core/src/method/client.rs +++ b/bindings/core/src/method/client.rs @@ -285,17 +285,17 @@ pub enum ClientMethod { /// Look up a commitment by a given commitment index. GetCommitmentByIndex { /// Index of the commitment to look up. - index: SlotIndex, + slot: SlotIndex, }, /// Get all UTXO changes of a given slot by commitment index. GetUtxoChangesByIndex { /// Index of the commitment to look up. - index: SlotIndex, + slot: SlotIndex, }, /// Get all full UTXO changes of a given slot by commitment index. GetUtxoChangesFullByIndex { /// Index of the commitment to look up. - index: SlotIndex, + slot: SlotIndex, }, ////////////////////////////////////////////////////////////////////// diff --git a/bindings/core/src/method_handler/client.rs b/bindings/core/src/method_handler/client.rs index b5f2ae738f..0560e15afb 100644 --- a/bindings/core/src/method_handler/client.rs +++ b/bindings/core/src/method_handler/client.rs @@ -241,14 +241,14 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM .get_utxo_changes_full_by_slot_commitment_id(&commitment_id) .await?, ), - ClientMethod::GetCommitmentByIndex { index } => { - Response::SlotCommitment(client.get_slot_commitment_by_slot(index).await?) + ClientMethod::GetCommitmentByIndex { slot } => { + Response::SlotCommitment(client.get_slot_commitment_by_slot(slot).await?) } - ClientMethod::GetUtxoChangesByIndex { index } => { - Response::UtxoChanges(client.get_utxo_changes_by_slot(index).await?) + ClientMethod::GetUtxoChangesByIndex { slot } => { + Response::UtxoChanges(client.get_utxo_changes_by_slot(slot).await?) } - ClientMethod::GetUtxoChangesFullByIndex { index } => { - Response::UtxoChangesFull(client.get_utxo_changes_full_by_slot(index).await?) + ClientMethod::GetUtxoChangesFullByIndex { slot } => { + Response::UtxoChangesFull(client.get_utxo_changes_full_by_slot(slot).await?) } ClientMethod::OutputIds { query_parameters } => { Response::OutputIdsResponse(client.output_ids(query_parameters).await?) diff --git a/bindings/nodejs/lib/client/client.ts b/bindings/nodejs/lib/client/client.ts index d3ecf0fc70..082c52bbfa 100644 --- a/bindings/nodejs/lib/client/client.ts +++ b/bindings/nodejs/lib/client/client.ts @@ -67,6 +67,7 @@ import { IOutputsResponse, CongestionResponse, UtxoChangesResponse, + UtxoChangesFullResponse, } from '../types/models/api'; import { plainToInstance } from 'class-transformer'; @@ -594,17 +595,35 @@ export class Client { return JSON.parse(response).payload; } + /** + * Get all full UTXO changes of a given slot by Commitment ID. + * + * @param commitmentId Commitment ID of the commitment to look up. + * @returns The UTXO changes. + */ + async getUtxoChangesFull( + commitmentId: SlotCommitmentId, + ): Promise<UtxoChangesFullResponse> { + const response = await this.methodHandler.callMethod({ + name: 'getUtxoChangesFull', + data: { + commitmentId, + }, + }); + return JSON.parse(response).payload; + } + /** * Look up a commitment by a given commitment index. * - * @param index Index of the commitment to look up. + * @param slot Index of the commitment to look up. * @returns The commitment. */ - async getCommitmentByIndex(index: SlotIndex): Promise<SlotCommitment> { + async getCommitmentByIndex(slot: SlotIndex): Promise<SlotCommitment> { const response = await this.methodHandler.callMethod({ name: 'getCommitmentByIndex', data: { - index, + slot, }, }); return JSON.parse(response).payload; @@ -613,16 +632,32 @@ export class Client { /** * Get all UTXO changes of a given slot by commitment index. * - * @param index Index of the commitment to look up. + * @param slot Index of the commitment to look up. * @returns The UTXO changes. */ - async getUtxoChangesByIndex( - index: SlotIndex, - ): Promise<UtxoChangesResponse> { + async getUtxoChangesByIndex(slot: SlotIndex): Promise<UtxoChangesResponse> { const response = await this.methodHandler.callMethod({ name: 'getUtxoChangesByIndex', data: { - index, + slot, + }, + }); + return JSON.parse(response).payload; + } + + /** + * Get all full UTXO changes of a given slot by commitment index. + * + * @param slot Index of the commitment to look up. + * @returns The UTXO changes. + */ + async getUtxoChangesFullByIndex( + slot: SlotIndex, + ): Promise<UtxoChangesFullResponse> { + const response = await this.methodHandler.callMethod({ + name: 'getUtxoChangesFullByIndex', + data: { + slot, }, }); return JSON.parse(response).payload; diff --git a/bindings/nodejs/lib/types/client/bridge/client.ts b/bindings/nodejs/lib/types/client/bridge/client.ts index f07b9c7428..2919d75f52 100644 --- a/bindings/nodejs/lib/types/client/bridge/client.ts +++ b/bindings/nodejs/lib/types/client/bridge/client.ts @@ -233,17 +233,31 @@ export interface __GetUtxoChangesMethod__ { }; } +export interface __GetUtxoChangesFullMethod__ { + name: 'getUtxoChangesFull'; + data: { + commitmentId: HexEncodedString; + }; +} + export interface __GetCommitmentByIndexMethod__ { name: 'getCommitmentByIndex'; data: { - index: SlotIndex; + slot: SlotIndex; }; } export interface __GetUtxoChangesByIndexMethod__ { name: 'getUtxoChangesByIndex'; data: { - index: SlotIndex; + slot: SlotIndex; + }; +} + +export interface __GetUtxoChangesFullByIndexMethod__ { + name: 'getUtxoChangesFullByIndex'; + data: { + slot: SlotIndex; }; } diff --git a/bindings/nodejs/lib/types/client/bridge/index.ts b/bindings/nodejs/lib/types/client/bridge/index.ts index 57bee666a3..743c428eda 100644 --- a/bindings/nodejs/lib/types/client/bridge/index.ts +++ b/bindings/nodejs/lib/types/client/bridge/index.ts @@ -33,8 +33,10 @@ import type { __GetTransactionMetadataMethod__, __GetCommitmentMethod__, __GetUtxoChangesMethod__, + __GetUtxoChangesFullMethod__, __GetCommitmentByIndexMethod__, __GetUtxoChangesByIndexMethod__, + __GetUtxoChangesFullByIndexMethod__, __HexToBech32Method__, __AccountIdToBech32Method__, __NftIdToBech32Method__, @@ -97,8 +99,10 @@ export type __ClientMethods__ = | __GetTransactionMetadataMethod__ | __GetCommitmentMethod__ | __GetUtxoChangesMethod__ + | __GetUtxoChangesFullMethod__ | __GetCommitmentByIndexMethod__ | __GetUtxoChangesByIndexMethod__ + | __GetUtxoChangesFullByIndexMethod__ | __HexToBech32Method__ | __AccountIdToBech32Method__ | __NftIdToBech32Method__ diff --git a/bindings/nodejs/lib/types/models/api/utxo-changes-response.ts b/bindings/nodejs/lib/types/models/api/utxo-changes-response.ts index 2c9f332c0f..23051c54ac 100644 --- a/bindings/nodejs/lib/types/models/api/utxo-changes-response.ts +++ b/bindings/nodejs/lib/types/models/api/utxo-changes-response.ts @@ -3,6 +3,8 @@ import { OutputId } from '../../block/output'; import { SlotCommitmentId } from '../../block'; +import { Output, OutputDiscriminator } from '../../block/output'; +import { Type } from 'class-transformer'; /** * Returns all UTXO changes that happened at a specific slot. @@ -21,3 +23,38 @@ export class UtxoChangesResponse { */ consumedOutputs!: OutputId[]; } + +/** + * An output with its id. + */ +export class OutputWithId { + /** + * The output id. + */ + outputId!: OutputId; + /** + * The output. + */ + @Type(() => Output, { + discriminator: OutputDiscriminator, + }) + output!: Output; +} + +/** + * Returns all full UTXO changes that happened at a specific slot. + */ +export class UtxoChangesFullResponse { + /** + * The commitment ID of the requested slot that contains the changes. + */ + commitmentId!: SlotCommitmentId; + /** + * The created outputs of the given slot. + */ + createdOutputs!: OutputWithId[]; + /** + * The consumed outputs of the given slot. + */ + consumedOutputs!: OutputWithId[]; +} diff --git a/bindings/nodejs/lib/types/models/state.ts b/bindings/nodejs/lib/types/models/state.ts index c59107bbaf..3a71a756f6 100644 --- a/bindings/nodejs/lib/types/models/state.ts +++ b/bindings/nodejs/lib/types/models/state.ts @@ -15,9 +15,9 @@ export declare type BlockState = * The different states of a transaction. * If 'pending', the transaction is not included yet. * If 'accepted', the transaction is included. - * If 'confirmed' means transaction is included and its included block is confirmed. - * If 'finalized' means transaction is included, its included block is finalized and cannot be reverted anymore. - * If 'failed' means transaction is not successfully issued due to failure reason. + * If 'confirmed' the transaction is included and its included block is confirmed. + * If 'finalized' the transaction is included, its included block is finalized and cannot be reverted anymore. + * If 'failed' the transaction is not successfully issued due to failure reason. */ export declare type TransactionState = | 'pending'