Skip to content

Commit cc4574c

Browse files
committed
feat: add .getL1Validator() to P-Chain api
1 parent ac7e0d7 commit cc4574c

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

src/vms/pvm/api.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
import { PChainOwner } from '../../serializable';
12
import { TransferableOutput } from '../../serializable/avax';
23
import { Utxo } from '../../serializable/avax/utxo';
34
import { getPVMManager } from '../../serializable/pvm/codec';
4-
import { hexToBuffer } from '../../utils';
5+
import { hexToBuffer, parse } from '../../utils';
56
import type { GetAssetDescriptionResponse } from '../common/apiModels';
67
import { AvaxApi } from '../common/avaxApi';
78
import { createDimensions } from '../common/fees/dimensions';
89
import type {
10+
GetL1ValidatorResponse,
11+
L1ValidatorDetails,
912
FeeConfig,
1013
FeeConfigResponse,
1114
FeeState,
@@ -266,4 +269,29 @@ export class PVMApi extends AvaxApi {
266269
timestamp: resp.timestamp,
267270
};
268271
}
272+
273+
async getL1Validator(validationID: string): Promise<L1ValidatorDetails> {
274+
const resp = await this.callRpc<GetL1ValidatorResponse>('getL1Validator', {
275+
validationID,
276+
});
277+
278+
const deactivationOwner = PChainOwner.fromNative(
279+
resp.deactivationOwner.addresses.map((a) => parse(a)[2]),
280+
Number(resp.deactivationOwner.threshold),
281+
);
282+
const remainingBalanceOwner = PChainOwner.fromNative(
283+
resp.remainingBalanceOwner.addresses.map((a) => parse(a)[2]),
284+
Number(resp.remainingBalanceOwner.threshold),
285+
);
286+
287+
return {
288+
balance: BigInt(resp.balance),
289+
nodeID: resp.nodeID,
290+
publicKey: resp.publicKey,
291+
subnetID: resp.subnetID,
292+
weight: BigInt(resp.weight),
293+
deactivationOwner,
294+
remainingBalanceOwner,
295+
};
296+
}
269297
}

src/vms/pvm/models.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { PChainOwner } from '../../serializable';
12
import type { TransferableOutput } from '../../serializable/avax';
23
import type { Utxo } from '../../serializable/avax/utxo';
34
import type { Dimensions } from '../common/fees/dimensions';
@@ -305,3 +306,34 @@ export interface FeeState {
305306
/** ISO8601 DateTime */
306307
timestamp: string;
307308
}
309+
310+
export interface GetL1ValidatorResponse {
311+
subnetID: string;
312+
nodeID: string;
313+
publicKey: string;
314+
remainingBalanceOwner: {
315+
addresses: string[];
316+
locktime: string;
317+
threshold: string;
318+
};
319+
deactivationOwner: {
320+
addresses: string[];
321+
locktime: string;
322+
threshold: string;
323+
};
324+
startTime: string;
325+
weight: string;
326+
minNonce: string;
327+
balance: string;
328+
height: string;
329+
}
330+
331+
export interface L1ValidatorDetails {
332+
subnetID: string;
333+
nodeID: string;
334+
publicKey: string;
335+
remainingBalanceOwner: PChainOwner;
336+
deactivationOwner: PChainOwner;
337+
weight: bigint;
338+
balance: bigint;
339+
}

0 commit comments

Comments
 (0)