Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add GET_PROTOCOL_PARAMETERS #272

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"cbor",
"cbors",
"compat",
"decentralisation",
"drep",
"dreps",
"emurgo",
Expand All @@ -19,6 +20,8 @@
"memoizee",
"nixify",
"preprod",
"pvtpp",
"tada",
"tailwindcss",
"timelock",
"txid",
Expand Down
95 changes: 90 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ using the same encoding.

Each command message requires:

- `id`: an identifier which is mirrored by the server in the output message; This identifier, while unused by the server, is useful for the client to reconcile output messages to relative input message.
- `command`: Command to execute (`ESTIMATE_FEE` | `GET_ACCOUNT_INFO` | `GET_ACCOUNT_UTXO` | `GET_BALANCE_HISTORY` | `GET_BLOCK` | `GET_SERVER_INFO` | `GET_TRANSACTION` | `PUSH_TRANSACTION` | `SUBSCRIBE_ADDRESS` | `SUBSCRIBE_BLOCK` | `UNSUBSCRIBE_ADDRESS` | `UNSUBSCRIBE_BLOCK`
)
- `params`: optionally a set of parameters, depending on
the command.
- `id`: an identifier which is mirrored by the server in the output message; This identifier, while unused by the server, is useful for the client to
reconcile output messages to relative input message.
- `command`: Command to execute (`ESTIMATE_FEE` | `GET_ACCOUNT_INFO` | `GET_ACCOUNT_UTXO` | `GET_BALANCE_HISTORY` | `GET_BLOCK` |
`GET_PROTOCOL_PARAMETERS` | `GET_SERVER_INFO` | `GET_TRANSACTION` | `PUSH_TRANSACTION` |
`SUBSCRIBE_ADDRESS` | `SUBSCRIBE_BLOCK` | `UNSUBSCRIBE_ADDRESS` | `UNSUBSCRIBE_BLOCK`).
- `params`: optionally a set of parameters, depending on the command.

**The structure of an input message is:**

Expand Down Expand Up @@ -159,6 +160,7 @@ For each of these commands the client receives an immediate response
- [`GET_ADA_HANDLE`](#get_ada_handle) - resolves an Ada Handle
- [`GET_BALANCE_HISTORY`](#get_balance_history) - get balance history of an account
- [`GET_BLOCK`](#get_block) - get details of a block
- [`GET_PROTOCOL_PARAMETERS`](#get_protocol_parameters) - get latest epoch protocol parameters
- [`GET_TRANSACTION`](#get_transaction) - get details of a transaction
- [`GET_SERVER_INFO`](#get_server_info) - get information about the server
- [`PUSH_TRANSACTION`](#push_transaction) - submits a transaction to the network
Expand All @@ -176,6 +178,8 @@ When an unsubscribe command is sent, the client receives an immediate response c

### ESTIMATE_FEE

**Note: DEPRECATED** - use `min_fee_a` from [`GET_PROTOCOL_PARAMETERS`](#get_protocol_parameters) instead.

Estimates the minimum fee required for transaction submission based on the linear fee parameters for the current epoch.

Input message:
Expand Down Expand Up @@ -549,6 +553,87 @@ Payload contains [block data](https://docs.blockfrost.io/#tag/cardano--blocks/GE
}
```

### GET_PROTOCOL_PARAMETERS

Gets the protocol parameters relative to the latest epochs.

Input message:

```ts
{
id: number | string;
"command": "GET_PROTOCOL_PARAMETERS"
}
```

Response:
Payload contains [protocol parameters](https://docs.blockfrost.io/#tag/cardano--epochs/GET/epochs/latest/parameters).

```TypeScript
{
id: number | string;
type: "message";
data: { // https://docs.blockfrost.io/#tag/cardano--epochs/GET/epochs/latest/parameters
epoch: number;
min_fee_a: number;
min_fee_b: number;
max_block_size: number;
max_tx_size: number;
max_block_header_size: number;
key_deposit: string;
pool_deposit: string;
e_max: number;
n_opt: number;
a0: number;
rho: number;
tau: number;
decentralisation_param: number;
extra_entropy: string | null;
protocol_major_ver: number;
protocol_minor_ver: number;
min_utxo: string;
min_pool_cost: string;
nonce: string;
cost_models: { [key: string]: unknown } | null;
cost_models_raw?: { [key: string]: unknown } | null;
price_mem: number | null;
price_step: number | null;
max_tx_ex_mem: string | null;
max_tx_ex_steps: string | null;
max_block_ex_mem: string | null;
max_block_ex_steps: string | null;
max_val_size: string | null;
collateral_percent: number | null;
max_collateral_inputs: number | null;
coins_per_utxo_size: string | null;
coins_per_utxo_word: string | null;
pvt_motion_no_confidence: number | null;
pvt_committee_normal: number | null;
pvt_committee_no_confidence: number | null;
pvt_hard_fork_initiation: number | null;
dvt_motion_no_confidence: number | null;
dvt_committee_normal: number | null;
dvt_committee_no_confidence: number | null;
dvt_update_to_constitution: number | null;
dvt_hard_fork_initiation: number | null;
dvt_p_p_network_group: number | null;
dvt_p_p_economic_group: number | null;
dvt_p_p_technical_group: number | null;
dvt_p_p_gov_group: number | null;
dvt_treasury_withdrawal: number | null;
committee_min_size: string | null;
committee_max_term_length: string | null;
gov_action_lifetime: string | null;
gov_action_deposit: string | null;
drep_deposit: string | null;
drep_activity: string | null;
pvtpp_security_group: number | null;
pvt_p_p_security_group: number | null;
min_fee_ref_script_cost_per_byte: number | null;
}
}
```

### GET_TRANSACTION

Returns information about a specified transaction.
Expand Down
11 changes: 11 additions & 0 deletions src/methods/get-protocols-parameters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { prepareMessage } from '../utils/message.js';
import { blockfrostAPI } from '../utils/blockfrost-api.js';
import { MessageId } from '../types/message.js';
import { limiter } from '../utils/limiter.js';

export default async (id: MessageId, clientId: string) =>
prepareMessage({
id,
clientId,
data: await limiter(() => blockfrostAPI.epochsLatestParameters()),
});
47 changes: 27 additions & 20 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import getAccountInfo from './methods/get-account-info.js';
import getAccountUtxo from './methods/get-account-utxo.js';
import getAdaHandle from './methods/get-ada-handle.js';
import getBlock from './methods/get-block.js';
import getProtocolParameters from './methods/get-protocols-parameters.js';
import getTransaction from './methods/get-transaction.js';
import submitTransaction from './methods/push-transaction.js';
import estimateFee from './methods/estimate-fee.js';
Expand Down Expand Up @@ -200,19 +201,6 @@ wss.on('connection', async (ws: Server.Ws) => {
);

switch (command) {
case 'GET_SERVER_INFO': {
response = await getServerInfo(id, clientId);

break;
}

case 'GET_TRANSACTION': {
validators.GET_TRANSACTION(params);
response = await getTransaction(id, clientId, params.txId);

break;
}

case 'GET_BLOCK': {
validators.GET_BLOCK(params);
response = await getBlock(id, clientId, params.hashOrNumber);
Expand Down Expand Up @@ -268,6 +256,32 @@ wss.on('connection', async (ws: Server.Ws) => {
break;
}

case 'GET_PROTOCOL_PARAMETERS': {
response = await getProtocolParameters(id, clientId);

break;
}

case 'GET_SERVER_INFO': {
response = await getServerInfo(id, clientId);

break;
}

case 'GET_TRANSACTION': {
validators.GET_TRANSACTION(params);
response = await getTransaction(id, clientId, params.txId);

break;
}

case 'PUSH_TRANSACTION': {
validators.PUSH_TRANSACTION(params);
response = await submitTransaction(id, clientId, params.txData);

break;
}

case 'SUBSCRIBE_BLOCK': {
const activeBlockSubIndex = activeSubscriptions[clientId].findIndex(
index => index.type === 'block',
Expand Down Expand Up @@ -350,13 +364,6 @@ wss.on('connection', async (ws: Server.Ws) => {
break;
}

case 'PUSH_TRANSACTION': {
validators.PUSH_TRANSACTION(params);
response = await submitTransaction(id, clientId, params.txData);

break;
}

default: {
response = prepareErrorMessage(id, clientId, `Unknown command: ${command}`);
}
Expand Down
4 changes: 4 additions & 0 deletions src/types/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export type Messages = BaseMessage &
txId: string;
};
}
| {
command: 'GET_PROTOCOL_PARAMETERS';
params: null;
}
| {
command: 'GET_SERVER_INFO';
params: null;
Expand Down
1 change: 1 addition & 0 deletions src/types/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export type Responses = {
| { address: string }
| null
| Schemas['block_content']
| Schemas['epoch_param_content']
| BalanceHistoryData[]
| TxIdsToTransactionsResponse[]
| TransformedTransaction
Expand Down
Loading