@helium/spl-utils
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -120,3 +120,3 @@ "use strict"; | ||
try { | ||
console.log(`Batching account fetch of ${currentBatch.size}`); | ||
console.log("accountFetchCache", `Batching account fetch of ${currentBatch.size}`); | ||
const keys = Array.from(currentBatch); | ||
@@ -249,5 +249,11 @@ const array = yield this.connection.getMultipleAccountsInfo(keys.map(b => new web3_js_1.PublicKey(b)), this.commitment); | ||
onAccountChange(key, parser, account) { | ||
const parsed = this.getParsed(key, account, parser); | ||
const address = key.toBase58(); | ||
this.updateCache(address, parsed || null); | ||
try { | ||
const parsed = this.getParsed(key, account, parser); | ||
const address = key.toBase58(); | ||
console.log("accountFetchCache", `Received account change ${key}`, parsed); | ||
this.updateCache(address, parsed || null); | ||
} | ||
catch (e) { | ||
console.error("accountFetchCache", "Failed to update account", e); | ||
} | ||
} | ||
@@ -300,3 +306,11 @@ watch(id, parser, exists = true) { | ||
this.accountChangeListeners.delete(address); | ||
this.connection.removeAccountChangeListener(subscriptionId); | ||
try { | ||
this.connection.removeAccountChangeListener(subscriptionId); | ||
} | ||
catch (e) { | ||
if (e.toString().includes("not implemented")) { | ||
// @ts-ignore | ||
this.usableConnection.removeAccountChangeListener(subscriptionId); | ||
} | ||
} | ||
} | ||
@@ -303,0 +317,0 @@ this.missingAccounts.delete(address); |
@@ -5,5 +5,5 @@ "use strict"; | ||
const web3_js_1 = require("@solana/web3.js"); | ||
exports.DC_MINT = new web3_js_1.PublicKey("2SyDxfawpkdg2EojMv1ZTUiqCefYFksNXjsBZivu5dpG"); | ||
exports.HNT_MINT = new web3_js_1.PublicKey("9PT9Um19m1JKc1sbWETxD9NySjinnNoxv7xYmvBXUqyx"); | ||
exports.MOBILE_MINT = new web3_js_1.PublicKey("CKuwd2oB8be14g9Y94NuM87nZZzq9HXDBeEe6N3QXZdN"); | ||
exports.DC_MINT = new web3_js_1.PublicKey("CnU1ySY7q5qgYowLACz23d515wwakiEt5ujx8k1f6E34"); | ||
exports.HNT_MINT = new web3_js_1.PublicKey("Fd1ceDiVgfRQw3j9HAn3aarrkqUqTgHRBbHStRp1u2ck"); | ||
exports.MOBILE_MINT = new web3_js_1.PublicKey("783c5RUqWpoioXZujWmas97hVVom5BpMncsBcbnPVfyR"); | ||
//# sourceMappingURL=constants.js.map |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.humanReadable = exports.roundToDecimals = exports.numberWithCommas = exports.supplyAsNum = exports.toBN = exports.amountAsNum = exports.toNumber = exports.truthy = void 0; | ||
exports.humanReadable = exports.humanReadableBigint = exports.roundToDecimals = exports.numberWithCommas = exports.supplyAsNum = exports.toBN = exports.amountAsNum = exports.toNumber = exports.truthy = void 0; | ||
const bn_js_1 = __importDefault(require("bn.js")); | ||
@@ -12,3 +12,3 @@ const truthy = (value) => !!value; | ||
function toNumber(numberOrBn, mintOrDecimals) { | ||
if (bn_js_1.default.isBN(numberOrBn)) { | ||
if (bn_js_1.default.isBN(numberOrBn) || typeof numberOrBn == "bigint") { | ||
return amountAsNum(numberOrBn, mintOrDecimals); | ||
@@ -26,4 +26,4 @@ } | ||
const factor = new bn_js_1.default(Math.pow(10, decimals).toString()); | ||
const decimal = amount.mod(factor).toNumber() / factor.toNumber(); | ||
return amount.div(factor).toNumber() + decimal; | ||
const decimal = new bn_js_1.default(amount.toString()).mod(factor).toNumber() / factor.toNumber(); | ||
return new bn_js_1.default(amount.toString()).div(factor).toNumber() + decimal; | ||
} | ||
@@ -57,2 +57,6 @@ exports.amountAsNum = amountAsNum; | ||
exports.roundToDecimals = roundToDecimals; | ||
function humanReadableBigint(bigint, decimals, round = decimals) { | ||
return numberWithCommas(roundToDecimals(toNumber(bigint, decimals), round)); | ||
} | ||
exports.humanReadableBigint = humanReadableBigint; | ||
function humanReadable(bn, mint) { | ||
@@ -59,0 +63,0 @@ return numberWithCommas(roundToDecimals(toNumber(bn, mint), mint.decimals)); |
@@ -107,3 +107,3 @@ import { Connection, PublicKey, Transaction } from "@solana/web3.js"; | ||
try { | ||
console.log(`Batching account fetch of ${currentBatch.size}`); | ||
console.log("accountFetchCache", `Batching account fetch of ${currentBatch.size}`); | ||
const keys = Array.from(currentBatch); | ||
@@ -229,5 +229,11 @@ const array = await this.connection.getMultipleAccountsInfo(keys.map(b => new PublicKey(b)), this.commitment); | ||
onAccountChange(key, parser, account) { | ||
const parsed = this.getParsed(key, account, parser); | ||
const address = key.toBase58(); | ||
this.updateCache(address, parsed || null); | ||
try { | ||
const parsed = this.getParsed(key, account, parser); | ||
const address = key.toBase58(); | ||
console.log("accountFetchCache", `Received account change ${key}`, parsed); | ||
this.updateCache(address, parsed || null); | ||
} | ||
catch (e) { | ||
console.error("accountFetchCache", "Failed to update account", e); | ||
} | ||
} | ||
@@ -280,3 +286,11 @@ watch(id, parser, exists = true) { | ||
this.accountChangeListeners.delete(address); | ||
this.connection.removeAccountChangeListener(subscriptionId); | ||
try { | ||
this.connection.removeAccountChangeListener(subscriptionId); | ||
} | ||
catch (e) { | ||
if (e.toString().includes("not implemented")) { | ||
// @ts-ignore | ||
this.usableConnection.removeAccountChangeListener(subscriptionId); | ||
} | ||
} | ||
} | ||
@@ -283,0 +297,0 @@ this.missingAccounts.delete(address); |
import { PublicKey } from "@solana/web3.js"; | ||
export const DC_MINT = new PublicKey("2SyDxfawpkdg2EojMv1ZTUiqCefYFksNXjsBZivu5dpG"); | ||
export const HNT_MINT = new PublicKey("9PT9Um19m1JKc1sbWETxD9NySjinnNoxv7xYmvBXUqyx"); | ||
export const MOBILE_MINT = new PublicKey("CKuwd2oB8be14g9Y94NuM87nZZzq9HXDBeEe6N3QXZdN"); | ||
export const DC_MINT = new PublicKey("CnU1ySY7q5qgYowLACz23d515wwakiEt5ujx8k1f6E34"); | ||
export const HNT_MINT = new PublicKey("Fd1ceDiVgfRQw3j9HAn3aarrkqUqTgHRBbHStRp1u2ck"); | ||
export const MOBILE_MINT = new PublicKey("783c5RUqWpoioXZujWmas97hVVom5BpMncsBcbnPVfyR"); | ||
//# sourceMappingURL=constants.js.map |
import BN from "bn.js"; | ||
export const truthy = (value) => !!value; | ||
export function toNumber(numberOrBn, mintOrDecimals) { | ||
if (BN.isBN(numberOrBn)) { | ||
if (BN.isBN(numberOrBn) || typeof numberOrBn == "bigint") { | ||
return amountAsNum(numberOrBn, mintOrDecimals); | ||
@@ -16,4 +16,4 @@ } | ||
const factor = new BN(Math.pow(10, decimals).toString()); | ||
const decimal = amount.mod(factor).toNumber() / factor.toNumber(); | ||
return amount.div(factor).toNumber() + decimal; | ||
const decimal = new BN(amount.toString()).mod(factor).toNumber() / factor.toNumber(); | ||
return new BN(amount.toString()).div(factor).toNumber() + decimal; | ||
} | ||
@@ -42,2 +42,5 @@ export function toBN(numberOrBn, mintOrDecimals) { | ||
} | ||
export function humanReadableBigint(bigint, decimals, round = decimals) { | ||
return numberWithCommas(roundToDecimals(toNumber(bigint, decimals), round)); | ||
} | ||
export function humanReadable(bn, mint) { | ||
@@ -44,0 +47,0 @@ return numberWithCommas(roundToDecimals(toNumber(bn, mint), mint.decimals)); |
@@ -5,4 +5,4 @@ import BN from "bn.js"; | ||
export declare const truthy: <T>(value: T) => value is Truthy<T>; | ||
export declare function toNumber(numberOrBn: BN | number, mintOrDecimals: Mint | number): number; | ||
export declare function amountAsNum(amount: BN, mintOrDecimals: Mint | number): number; | ||
export declare function toNumber(numberOrBn: bigint | BN | number, mintOrDecimals: Mint | number): number; | ||
export declare function amountAsNum(amount: BN | bigint, mintOrDecimals: Mint | number): number; | ||
export declare function toBN(numberOrBn: BN | number, mintOrDecimals: Mint | number): BN; | ||
@@ -12,3 +12,4 @@ export declare function supplyAsNum(mint: Mint): number; | ||
export declare function roundToDecimals(num: number, decimals: number): number; | ||
export declare function humanReadableBigint(bigint: bigint, decimals: number, round?: number): string; | ||
export declare function humanReadable(bn: BN, mint: Mint): string; | ||
//# sourceMappingURL=utils.d.ts.map |
{ | ||
"name": "@helium/spl-utils", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Utils shared across spl suite", | ||
@@ -44,3 +44,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "714ad551d3d6efe4be1ddd8c89a13357d105ffd3" | ||
"gitHead": "3e271beef8444e8c48bb3722bcbccfba6276a081" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
355716
3373