Skip to content

Commit

Permalink
Merge branch '2.0' into isa-allotments
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex6323 authored Jan 10, 2024
2 parents 8bc979d + 2576174 commit 550c8a0
Show file tree
Hide file tree
Showing 21 changed files with 571 additions and 198 deletions.
17 changes: 10 additions & 7 deletions bindings/core/src/method/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,18 @@ pub enum ClientMethod {
/// The Account ID of the account.
account_id: AccountId,
},
/// Returns the totally available Mana rewards of an account or delegation output decayed up to endEpoch index
/// provided in the response.
/// Returns all the available Mana rewards of an account or delegation output in the returned range of epochs.
#[serde(rename_all = "camelCase")]
GetRewards {
/// Output ID of an account or delegation output.
output_id: OutputId,
/// A client can specify a slot index explicitly, which should be equal to the slot it uses as the commitment
/// input for the claiming transaction. This parameter is only recommended to be provided when requesting
/// rewards for a Delegation Output in delegating state (i.e. when Delegation ID is zeroed).
/// input for the claiming transaction to ensure the node calculates the rewards identically as during
/// transaction execution. Rewards are decayed up to the epoch corresponding to the given slotIndex +
/// MinCommittableAge. For a Delegation Output in delegating state (i.e. when Delegation ID is zeroed), that
/// epoch - 1 is also used as the last epoch for which rewards are fetched. Callers that do not build
/// transactions with the returned values may omit this value in which case it defaults to the latest committed
/// slot, which is good enough to, e.g. display estimated rewards to users.
slot_index: Option<SlotIndex>,
},
/// Returns information of all registered validators and if they are active, ordered by their holding stake.
Expand Down Expand Up @@ -282,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 @@ -251,14 +251,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
221 changes: 205 additions & 16 deletions bindings/nodejs/lib/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ import {
DelegationId,
UnsignedBlock,
parseUnsignedBlock,
SlotIndex,
SlotCommitmentId,
SlotCommitment,
} from '../types/block';
import { HexEncodedString } from '../utils';
import {
IBlockMetadata,
INodeInfo,
IPeer,
UTXOInput,
Response,
OutputId,
Expand All @@ -58,10 +60,19 @@ import {
TransactionId,
Bech32Address,
IBlockWithMetadata,
TransactionMetadata,
} from '../types';
import { OutputResponse, IOutputsResponse } from '../types/models/api';
import {
OutputResponse,
IOutputsResponse,
CongestionResponse,
UtxoChangesResponse,
UtxoChangesFullResponse,
} from '../types/models/api';

import { plainToInstance } from 'class-transformer';
import { ManaRewardsResponse } from '../types/models/api/mana-rewards-response';
import { ValidatorsResponse } from '../types/models/api/validators-response';

/** The Client to interact with nodes. */
export class Client {
Expand Down Expand Up @@ -106,6 +117,74 @@ export class Client {
return JSON.parse(response).payload;
}

/**
* Check the readiness of the node to issue a new block, the reference mana cost based on the rate setter and
* current network congestion, and the block issuance credits of the requested account.
*/
async getAccountCongestion(
accountId: AccountId,
): Promise<CongestionResponse> {
const response = await this.methodHandler.callMethod({
name: 'getAccountCongestion',
data: {
accountId,
},
});

return JSON.parse(response).payload;
}

/**
* Returns the totally available Mana rewards of an account or delegation output decayed up to endEpoch index
* provided in the response.
*/
async getRewards(
outputId: OutputId,
slotIndex?: SlotIndex,
): Promise<ManaRewardsResponse> {
const response = await this.methodHandler.callMethod({
name: 'getRewards',
data: {
outputId,
slotIndex,
},
});

return JSON.parse(response).payload;
}

/**
* Returns information of all registered validators and if they are active, ordered by their holding stake.
*/
async getValidators(
pageSize?: number,
cursor?: string,
): Promise<ValidatorsResponse> {
const response = await this.methodHandler.callMethod({
name: 'getValidators',
data: {
pageSize,
cursor,
},
});

return JSON.parse(response).payload;
}

/**
* Return information about a validator.
*/
async getValidator(accountId: AccountId): Promise<ValidatorsResponse> {
const response = await this.methodHandler.callMethod({
name: 'getValidator',
data: {
accountId,
},
});

return JSON.parse(response).payload;
}

/**
* Get output from a given output ID.
*/
Expand Down Expand Up @@ -393,17 +472,6 @@ export class Client {
return JSON.parse(response).payload;
}

/**
* Get the peers of the node.
*/
async getPeers(): Promise<IPeer[]> {
const response = await this.methodHandler.callMethod({
name: 'getPeers',
});

return JSON.parse(response).payload;
}

/**
* Post block as raw bytes, returns the block ID.
*
Expand Down Expand Up @@ -463,15 +531,136 @@ export class Client {
*/
async getIncludedBlockMetadata(
transactionId: TransactionId,
): Promise<Block> {
): Promise<IBlockMetadata> {
const response = await this.methodHandler.callMethod({
name: 'getIncludedBlockMetadata',
data: {
transactionId,
},
});
const parsed = JSON.parse(response) as Response<Block>;
return parseBlock(parsed.payload);
return JSON.parse(response).payload;
}

/**
* Find the metadata of a transaction.
*
* @param transactionId The ID of the transaction.
* @returns The transaction metadata.
*/
async getTransactionMetadata(
transactionId: TransactionId,
): Promise<TransactionMetadata> {
const response = await this.methodHandler.callMethod({
name: 'getTransactionMetadata',
data: {
transactionId,
},
});
return JSON.parse(response).payload;
}

/**
* Look up a commitment by a given commitment ID.
*
* @param commitmentId Commitment ID of the commitment to look up.
* @returns The commitment.
*/
async getCommitment(
commitmentId: SlotCommitmentId,
): Promise<SlotCommitment> {
const response = await this.methodHandler.callMethod({
name: 'getCommitment',
data: {
commitmentId,
},
});
return JSON.parse(response).payload;
}

/**
* Get all UTXO changes of a given slot by Commitment ID.
*
* @param commitmentId Commitment ID of the commitment to look up.
* @returns The UTXO changes.
*/
async getUtxoChanges(
commitmentId: SlotCommitmentId,
): Promise<UtxoChangesResponse> {
const response = await this.methodHandler.callMethod({
name: 'getUtxoChanges',
data: {
commitmentId,
},
});
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 slot Index of the commitment to look up.
* @returns The commitment.
*/
async getCommitmentByIndex(slot: SlotIndex): Promise<SlotCommitment> {
const response = await this.methodHandler.callMethod({
name: 'getCommitmentByIndex',
data: {
slot,
},
});
return JSON.parse(response).payload;
}

/**
* Get all UTXO changes of a given slot by commitment index.
*
* @param slot Index of the commitment to look up.
* @returns The UTXO changes.
*/
async getUtxoChangesByIndex(slot: SlotIndex): Promise<UtxoChangesResponse> {
const response = await this.methodHandler.callMethod({
name: 'getUtxoChangesByIndex',
data: {
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
Loading

0 comments on commit 550c8a0

Please sign in to comment.