Skip to content

Commit f647166

Browse files
authored
Merge pull request #921 from ava-labs/feat/etna-updates
feat: add necessary APIs to facilitate DisableL1ValidatorTx signing
2 parents 0b4eb57 + b31f376 commit f647166

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

src/serializable/pvm/disableL1ValidatorTx.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,13 @@ export class DisableL1ValidatorTx extends PVMTx {
4242
getDisableAuth() {
4343
return this.disableAuth as Input;
4444
}
45+
46+
getSigIndices(): number[][] {
47+
return [
48+
...this.getInputs().map((input) => {
49+
return input.sigIndicies();
50+
}),
51+
this.getDisableAuth().values(),
52+
].filter((indicies): indicies is number[] => indicies !== undefined);
53+
}
4554
}

src/vms/pvm/api.ts

Lines changed: 32 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,32 @@ 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+
startTime: BigInt(resp.startTime),
296+
height: BigInt(resp.height),
297+
minNonce: BigInt(resp.minNonce),
298+
};
299+
}
269300
}

src/vms/pvm/models.ts

Lines changed: 35 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,37 @@ 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+
startTime: bigint;
340+
minNonce: bigint;
341+
height: bigint;
342+
}

0 commit comments

Comments
 (0)