Skip to content

Commit

Permalink
feat: clean-up AccountIdentifier string
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Feb 12, 2024
1 parent de9835b commit ad49e16
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
9 changes: 6 additions & 3 deletions packages/nns/src/canisters/governance/request.converters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { AccountIdentifier as AccountIdentifierClass } from "@dfinity/ledger-icp";
import type {
AccountIdentifier as AccountIdentifierClass,
AccountIdentifierHex,
} from "@dfinity/ledger-icp";
import { accountIdentifierToBytes } from "@dfinity/ledger-icp";
import { Principal } from "@dfinity/principal";
import { arrayBufferToUint8Array, toNullable } from "@dfinity/utils";
Expand Down Expand Up @@ -37,7 +40,7 @@ import type {
} from "../../../candid/governance";
import type { Vote } from "../../enums/governance.enums";
import { UnsupportedValueError } from "../../errors/governance.errors";
import type { AccountIdentifier, E8s, NeuronId } from "../../types/common";
import type { E8s, NeuronId } from "../../types/common";
import type {
Action,
By,
Expand Down Expand Up @@ -845,7 +848,7 @@ const fromAmount = (amount: E8s): Amount => ({
});

const fromAccountIdentifier = (
accountIdentifier: AccountIdentifier,
accountIdentifier: AccountIdentifierHex,
): RawAccountIdentifier => ({
hash: accountIdentifierToBytes(accountIdentifier),
});
Expand Down
10 changes: 3 additions & 7 deletions packages/nns/src/canisters/governance/response.converters.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { AccountIdentifierHex } from "@dfinity/ledger-icp";
import {
AccountIdentifier,
accountIdentifierFromBytes,
Expand Down Expand Up @@ -64,12 +65,7 @@ import type {
} from "../../../candid/governance";
import { NeuronState, type NeuronType } from "../../enums/governance.enums";
import { UnsupportedValueError } from "../../errors/governance.errors";
import type {
AccountIdentifier as AccountIdentifierString,
CanisterIdString,
E8s,
NeuronId,
} from "../../types/common";
import type { CanisterIdString, E8s, NeuronId } from "../../types/common";
import type {
Action,
Ballot,
Expand Down Expand Up @@ -760,7 +756,7 @@ const toAmount = (amount: RawAmount): E8s => {

const toAccountIdentifier = (
accountIdentifier: RawAccountIdentifier,
): AccountIdentifierString =>
): AccountIdentifierHex =>
accountIdentifierFromBytes(new Uint8Array(accountIdentifier.hash));

const toRewardMode = (rewardMode: RawRewardMode): RewardMode => {
Expand Down
12 changes: 6 additions & 6 deletions packages/nns/src/types/governance_converters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { DerEncodedPublicKey } from "@dfinity/agent";
import type { AccountIdentifierHex } from "@dfinity/ledger-icp";
import type { Principal } from "@dfinity/principal";
import type {
NeuronState,
Expand All @@ -9,7 +10,6 @@ import type {
Vote,
} from "../enums/governance.enums";
import type {
AccountIdentifier,
CanisterIdString,
E8s,
NeuronId,
Expand Down Expand Up @@ -88,7 +88,7 @@ export interface Configure {
operation: Option<Operation>;
}
export interface Disburse {
toAccountId: Option<AccountIdentifier>;
toAccountId: Option<AccountIdentifierHex>;
amount: Option<E8s>;
}
export interface DisburseResponse {
Expand Down Expand Up @@ -273,7 +273,7 @@ export interface Neuron {
spawnAtTimesSeconds: Option<bigint>;
neuronFees: E8s;
hotKeys: Array<PrincipalString>;
accountIdentifier: AccountIdentifier;
accountIdentifier: AccountIdentifierHex;
joinedCommunityFundTimestampSeconds: Option<bigint>;
dissolveState: Option<DissolveState>;
followees: Array<Followees>;
Expand All @@ -297,7 +297,7 @@ export interface NeuronInfo {

export interface NodeProvider {
id: Option<PrincipalString>;
rewardAccount: Option<AccountIdentifier>;
rewardAccount: Option<AccountIdentifierHex>;
}
export type Operation =
| { RemoveHotKey: RemoveHotKey }
Expand Down Expand Up @@ -350,7 +350,7 @@ export type RewardNodeProviders = {
rewards: Array<RewardNodeProvider>;
};
export interface RewardToAccount {
toAccount: Option<AccountIdentifier>;
toAccount: Option<AccountIdentifierHex>;
}
export interface RewardToNeuron {
dissolveDelaySeconds: bigint;
Expand Down Expand Up @@ -433,7 +433,7 @@ export interface SplitRequest {

export interface DisburseRequest {
neuronId: NeuronId;
toAccountId?: AccountIdentifier;
toAccountId?: AccountIdentifierHex;
amount?: E8s;
}

Expand Down

0 comments on commit ad49e16

Please sign in to comment.