Skip to content

Commit

Permalink
Add GetUtxoChangesFull routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M committed Jan 9, 2024
1 parent 0cfb83d commit 8c9317a
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 22 deletions.
6 changes: 3 additions & 3 deletions bindings/core/src/method/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},

//////////////////////////////////////////////////////////////////////
Expand Down
12 changes: 6 additions & 6 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand Down
51 changes: 43 additions & 8 deletions bindings/nodejs/lib/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import {
IOutputsResponse,
CongestionResponse,
UtxoChangesResponse,
UtxoChangesFullResponse,
} from '../types/models/api';

import { plainToInstance } from 'class-transformer';
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
18 changes: 16 additions & 2 deletions bindings/nodejs/lib/types/client/bridge/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

Expand Down
4 changes: 4 additions & 0 deletions bindings/nodejs/lib/types/client/bridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ import type {
__GetTransactionMetadataMethod__,
__GetCommitmentMethod__,
__GetUtxoChangesMethod__,
__GetUtxoChangesFullMethod__,
__GetCommitmentByIndexMethod__,
__GetUtxoChangesByIndexMethod__,
__GetUtxoChangesFullByIndexMethod__,
__HexToBech32Method__,
__AccountIdToBech32Method__,
__NftIdToBech32Method__,
Expand Down Expand Up @@ -97,8 +99,10 @@ export type __ClientMethods__ =
| __GetTransactionMetadataMethod__
| __GetCommitmentMethod__
| __GetUtxoChangesMethod__
| __GetUtxoChangesFullMethod__
| __GetCommitmentByIndexMethod__
| __GetUtxoChangesByIndexMethod__
| __GetUtxoChangesFullByIndexMethod__
| __HexToBech32Method__
| __AccountIdToBech32Method__
| __NftIdToBech32Method__
Expand Down
37 changes: 37 additions & 0 deletions bindings/nodejs/lib/types/models/api/utxo-changes-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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[];
}
6 changes: 3 additions & 3 deletions bindings/nodejs/lib/types/models/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 8c9317a

Please sign in to comment.