Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add necessary APIs to facilitate DisableL1ValidatorTx signing #921

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}