Skip to content

Commit

Permalink
Merge pull request #921 from ava-labs/feat/etna-updates
Browse files Browse the repository at this point in the history
feat: add necessary APIs to facilitate DisableL1ValidatorTx signing
  • Loading branch information
meeh0w authored Nov 21, 2024
2 parents 0b4eb57 + b31f376 commit f647166
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/serializable/pvm/disableL1ValidatorTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@ export class DisableL1ValidatorTx extends PVMTx {
getDisableAuth() {
return this.disableAuth as Input;
}

getSigIndices(): number[][] {
return [
...this.getInputs().map((input) => {
return input.sigIndicies();
}),
this.getDisableAuth().values(),
].filter((indicies): indicies is number[] => indicies !== undefined);
}
}
33 changes: 32 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,32 @@ 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,
startTime: BigInt(resp.startTime),
height: BigInt(resp.height),
minNonce: BigInt(resp.minNonce),
};
}
}
35 changes: 35 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,37 @@ 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;
startTime: bigint;
minNonce: bigint;
height: bigint;
}

0 comments on commit f647166

Please sign in to comment.