Skip to content
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
19 changes: 19 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
subaccountToHexString,
nowInBigIntNanoSeconds,
isCurrentVersionSmallerThanFullCandidParser,
jsonStringifyWithBigInt,
} from "./utils";
import { CANDID_PARSER_VERSION, HOTKEY_PERMISSIONS } from "./constants";
import { AnonymousIdentity, Identity } from "@dfinity/agent";
Expand Down Expand Up @@ -794,6 +795,18 @@ async function claimNeurons() {
ok(`Successfully claimed the following neurons: ${claimedNeuronIds}`);
}

async function getNeuron(neuronId: bigint) {
const identity = await getIdentity();
const governance = GovernanceCanister.create({
agent: await getCurrentAgent(identity),
});
const neuron = await governance.getNeuron({
certified: true,
neuronId,
});
ok(`Neuron: ${jsonStringifyWithBigInt(neuron)}`);
}

/**
* Runs a function with a try/catch block.
*/
Expand Down Expand Up @@ -1288,6 +1301,12 @@ async function main() {
new Command("claim")
.description("Claim the caller's GTC neurons.")
.action((args) => run(() => claimNeurons()))
)
.addCommand(
new Command("info")
.description("Show full information about a neuron.")
.requiredOption("--neuron-id <neuron-id>", "Neuron ID", tryParseBigInt)
.action((args) => run(() => getNeuron(args.neuronId)))
);

const icp = new Command("icp")
Expand Down
11 changes: 11 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,14 @@ export const hexToSnsNeuronId = (hex: string): SnsNeuronId => ({

export const nowInBigIntNanoSeconds = (): bigint =>
BigInt(Date.now()) * BigInt(1e6);

/**
* JSON.stringify with bigint support.
* Converts bigint values to strings since JSON doesn't support bigint natively.
*/
export const jsonStringifyWithBigInt = (obj: unknown, indent = 2): string =>
Comment thread
mducroux marked this conversation as resolved.
JSON.stringify(
obj,
(_, value) => (typeof value === "bigint" ? value.toString() : value),
indent
);