From cc4574c878f24a9581b966ce59ffa5a3fe973d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Leszczyk?= Date: Mon, 18 Nov 2024 10:41:45 +0100 Subject: [PATCH] feat: add .getL1Validator() to P-Chain api --- src/vms/pvm/api.ts | 30 +++++++++++++++++++++++++++++- src/vms/pvm/models.ts | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/vms/pvm/api.ts b/src/vms/pvm/api.ts index 2aff4cfb9..f2e9e8cc3 100644 --- a/src/vms/pvm/api.ts +++ b/src/vms/pvm/api.ts @@ -1,11 +1,14 @@ +import { PChainOwner } from '../../serializable'; import { TransferableOutput } from '../../serializable/avax'; import { Utxo } from '../../serializable/avax/utxo'; import { getPVMManager } from '../../serializable/pvm/codec'; -import { hexToBuffer } from '../../utils'; +import { hexToBuffer, parse } from '../../utils'; import type { GetAssetDescriptionResponse } from '../common/apiModels'; import { AvaxApi } from '../common/avaxApi'; import { createDimensions } from '../common/fees/dimensions'; import type { + GetL1ValidatorResponse, + L1ValidatorDetails, FeeConfig, FeeConfigResponse, FeeState, @@ -266,4 +269,29 @@ export class PVMApi extends AvaxApi { timestamp: resp.timestamp, }; } + + async getL1Validator(validationID: string): Promise { + const resp = await this.callRpc('getL1Validator', { + validationID, + }); + + const deactivationOwner = PChainOwner.fromNative( + resp.deactivationOwner.addresses.map((a) => parse(a)[2]), + Number(resp.deactivationOwner.threshold), + ); + const remainingBalanceOwner = PChainOwner.fromNative( + resp.remainingBalanceOwner.addresses.map((a) => parse(a)[2]), + Number(resp.remainingBalanceOwner.threshold), + ); + + return { + balance: BigInt(resp.balance), + nodeID: resp.nodeID, + publicKey: resp.publicKey, + subnetID: resp.subnetID, + weight: BigInt(resp.weight), + deactivationOwner, + remainingBalanceOwner, + }; + } } diff --git a/src/vms/pvm/models.ts b/src/vms/pvm/models.ts index be919bc80..2790a07ba 100644 --- a/src/vms/pvm/models.ts +++ b/src/vms/pvm/models.ts @@ -1,3 +1,4 @@ +import type { PChainOwner } from '../../serializable'; import type { TransferableOutput } from '../../serializable/avax'; import type { Utxo } from '../../serializable/avax/utxo'; import type { Dimensions } from '../common/fees/dimensions'; @@ -305,3 +306,34 @@ export interface FeeState { /** ISO8601 DateTime */ timestamp: string; } + +export interface GetL1ValidatorResponse { + subnetID: string; + nodeID: string; + publicKey: string; + remainingBalanceOwner: { + addresses: string[]; + locktime: string; + threshold: string; + }; + deactivationOwner: { + addresses: string[]; + locktime: string; + threshold: string; + }; + startTime: string; + weight: string; + minNonce: string; + balance: string; + height: string; +} + +export interface L1ValidatorDetails { + subnetID: string; + nodeID: string; + publicKey: string; + remainingBalanceOwner: PChainOwner; + deactivationOwner: PChainOwner; + weight: bigint; + balance: bigint; +}