Skip to content

Commit

Permalink
refactors canisterStatus to use shared util
Browse files Browse the repository at this point in the history
  • Loading branch information
krpeacock committed Sep 8, 2023
1 parent b448227 commit cb89597
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions packages/agent/src/canisterStatus/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/** @module CanisterStatus */

import { lebDecode, PipeArrayBuffer } from '@dfinity/candid';
import { Principal } from '@dfinity/principal';
import { AgentError } from '../errors';
import { HttpAgent } from '../agent/http';
import { Certificate, CreateCertificateOptions } from '../certificate';
import { toHex } from '../utils/buffer';
import * as Cbor from '../cbor';
import { decodeLeb128, decodeTime } from '../utils/leb';

/**
* Types of an entry on the canisterStatus map.
Expand Down Expand Up @@ -220,10 +220,6 @@ const decodeHex = (buf: ArrayBuffer): string => {
return toHex(buf);
};

const decodeLeb128 = (buf: ArrayBuffer): bigint => {
return lebDecode(new PipeArrayBuffer(buf));
};

const decodeCbor = (buf: ArrayBuffer): ArrayBuffer[] => {
return Cbor.decode(buf);
};
Expand All @@ -232,12 +228,6 @@ const decodeUtf8 = (buf: ArrayBuffer): string => {
return new TextDecoder().decode(buf);
};

// time is a LEB128-encoded Nat
const decodeTime = (buf: ArrayBuffer): Date => {
const decoded = decodeLeb128(buf);
return new Date(Number(decoded / BigInt(1_000_000)));
};

// Controllers are CBOR-encoded buffers, starting with a Tag we don't need
const decodeControllers = (buf: ArrayBuffer): Principal[] => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down

0 comments on commit cb89597

Please sign in to comment.