Skip to content

Commit

Permalink
feat: add .getL1Validator() to P-Chain api
Browse files Browse the repository at this point in the history
  • Loading branch information
meeh0w committed Nov 21, 2024
1 parent ac7e0d7 commit cc4574c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/vms/pvm/api.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -266,4 +269,29 @@ export class PVMApi extends AvaxApi {
timestamp: resp.timestamp,
};
}

async getL1Validator(validationID: string): Promise<L1ValidatorDetails> {
const resp = await this.callRpc<GetL1ValidatorResponse>('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,
};
}
}
32 changes: 32 additions & 0 deletions src/vms/pvm/models.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
}

0 comments on commit cc4574c

Please sign in to comment.