@autonomys/auto-consensus 0.5.3 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ import type { Api } from '@autonomys/auto-utils';
2
+ import type { AccountData } from './types/account';
3
+ export declare const account: (api: Api, address: string) => Promise<AccountData>;
4
+ //# sourceMappingURL=account.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,iBAAiB,CAAA;AAGlE,eAAO,MAAM,OAAO,QAAe,GAAG,WAAW,MAAM,KAAG,OAAO,CAAC,WAAW,CAc5E,CAAA"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ // file: src/account.ts
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.account = void 0;
14
+ const utils_1 = require("./utils");
15
+ const account = (api, address) => __awaiter(void 0, void 0, void 0, function* () {
16
+ try {
17
+ const rawAccount = yield api.query.system.account(address);
18
+ const { nonce, data } = rawAccount.toPrimitive();
19
+ return {
20
+ nonce,
21
+ data: (0, utils_1.parseBalance)(data),
22
+ };
23
+ }
24
+ catch (error) {
25
+ console.log('error', error);
26
+ throw new Error('Error getting account' + error);
27
+ }
28
+ });
29
+ exports.account = account;
@@ -1,10 +1,5 @@
1
1
  import type { Api } from '@autonomys/auto-utils';
2
- type BalanceData = {
3
- free: bigint;
4
- reserved: bigint;
5
- frozen: bigint;
6
- };
2
+ import type { BalanceData } from './types/balance';
7
3
  export declare const totalIssuance: (networkId?: string) => Promise<import("@autonomys/auto-utils").Codec>;
8
4
  export declare const balance: (api: Api, address: string) => Promise<BalanceData>;
9
- export {};
10
5
  //# sourceMappingURL=balances.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"balances.d.ts","sourceRoot":"","sources":["../src/balances.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAM,MAAM,uBAAuB,CAAA;AASpD,KAAK,WAAW,GAAG;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,eAAO,MAAM,aAAa,eAAsB,MAAM,mDAQrD,CAAA;AAED,eAAO,MAAM,OAAO,QAAe,GAAG,WAAW,MAAM,KAAG,OAAO,CAAC,WAAW,CAgB5E,CAAA"}
1
+ {"version":3,"file":"balances.d.ts","sourceRoot":"","sources":["../src/balances.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAM,MAAM,uBAAuB,CAAA;AAGpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAElD,eAAO,MAAM,aAAa,eAAsB,MAAM,mDAQrD,CAAA;AAED,eAAO,MAAM,OAAO,QAAe,GAAG,WAAW,MAAM,KAAG,OAAO,CAAC,WAAW,CAY5E,CAAA"}
package/dist/balances.js CHANGED
@@ -12,6 +12,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.balance = exports.totalIssuance = void 0;
14
14
  const auto_utils_1 = require("@autonomys/auto-utils");
15
+ const account_1 = require("./account");
15
16
  const totalIssuance = (networkId) => __awaiter(void 0, void 0, void 0, function* () {
16
17
  // Get the api instance for the network
17
18
  const api = yield (0, auto_utils_1.activate)({ networkId });
@@ -23,13 +24,9 @@ exports.totalIssuance = totalIssuance;
23
24
  const balance = (api, address) => __awaiter(void 0, void 0, void 0, function* () {
24
25
  // Query the balance of the address and parse the data
25
26
  try {
26
- const rawBalance = yield api.query.system.account(address);
27
- const { data } = rawBalance;
28
- return {
29
- free: BigInt(data.free.toString()),
30
- reserved: BigInt(data.reserved.toString()),
31
- frozen: BigInt(data.frozen.toString()),
32
- };
27
+ const rawAccount = yield (0, account_1.account)(api, address);
28
+ const { data } = rawAccount;
29
+ return data;
33
30
  }
34
31
  catch (error) {
35
32
  console.log('error', error);
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './account';
1
2
  export * from './balances';
2
3
  export * from './batch';
3
4
  export * from './domain';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAE1B,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAE1B,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./account"), exports);
18
19
  __exportStar(require("./balances"), exports);
19
20
  __exportStar(require("./batch"), exports);
20
21
  __exportStar(require("./domain"), exports);
package/dist/info.d.ts CHANGED
@@ -1,7 +1,21 @@
1
- export declare const rpc: (methodPath: string, params?: any[], networkId?: string) => Promise<any>;
2
- export declare const query: (methodPath: string, params?: any[], networkId?: string) => Promise<any>;
3
- export declare const block: (networkId?: string) => Promise<any>;
4
- export declare const blockNumber: (networkId?: string) => Promise<number>;
5
- export declare const blockHash: (networkId?: string) => Promise<any>;
6
- export declare const networkTimestamp: (networkId?: string) => Promise<any>;
1
+ import { AnyTuple, Api, Codec, StorageKey } from '@autonomys/auto-utils';
2
+ export declare const rpc: <T>(api: Api, methodPath: string, params?: any[]) => Promise<T>;
3
+ export declare const query: <T>(api: Api, methodPath: string, params?: any[]) => Promise<T>;
4
+ export declare const block: <RawBlock>(api: Api) => Promise<RawBlock>;
5
+ export declare const blockNumber: (api: Api) => Promise<number>;
6
+ export declare const blockHash: (api: Api) => Promise<string>;
7
+ export declare const networkTimestamp: (api: Api) => Promise<Codec>;
8
+ export declare const solutionRanges: (api: Api) => Promise<{
9
+ current: bigint | null;
10
+ next: bigint | null;
11
+ votingCurrent: bigint | null;
12
+ votingNext: bigint | null;
13
+ }>;
14
+ export declare const shouldAdjustSolutionRange: (api: Api) => Promise<boolean>;
15
+ export declare const segmentCommitment: (api: Api) => Promise<[StorageKey<AnyTuple>, Codec][]>;
16
+ export declare const slotProbability: (api: Api) => [number, number];
17
+ export declare const maxPiecesInSector: (api: Api) => bigint;
18
+ export declare function solutionRangeToSectors(solutionRange: bigint, slotProbability: [bigint, bigint], piecesInSector: bigint): bigint;
19
+ export declare const spacePledge: (api: Api) => Promise<bigint | 0>;
20
+ export declare const blockchainSize: (api: Api) => Promise<bigint>;
7
21
  //# sourceMappingURL=info.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../src/info.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,GAAG,eAAsB,MAAM,WAAU,GAAG,EAAE,cAAmB,MAAM,iBACrB,CAAA;AAE/D,eAAO,MAAM,KAAK,eAAsB,MAAM,WAAU,GAAG,EAAE,cAAmB,MAAM,iBACrB,CAAA;AAEjE,eAAO,MAAM,KAAK,eAAsB,MAAM,iBAA+C,CAAA;AAE7F,eAAO,MAAM,WAAW,eAAsB,MAAM,KAAG,OAAO,CAAC,MAAM,CAKpE,CAAA;AAED,eAAO,MAAM,SAAS,eAAsB,MAAM,iBAKjD,CAAA;AAED,eAAO,MAAM,gBAAgB,eAAsB,MAAM,iBACZ,CAAA"}
1
+ {"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../src/info.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAMxE,eAAO,MAAM,GAAG,GAAU,CAAC,OAAO,GAAG,cAAc,MAAM,WAAU,GAAG,EAAE,KAAQ,OAAO,CAAC,CAAC,CAC7B,CAAA;AAE5D,eAAO,MAAM,KAAK,GAAU,CAAC,OAAO,GAAG,cAAc,MAAM,WAAU,GAAG,EAAE,KAAQ,OAAO,CAAC,CAAC,CAC7B,CAAA;AAE9D,eAAO,MAAM,KAAK,GAAU,QAAQ,OAAO,GAAG,sBAAmD,CAAA;AAEjG,eAAO,MAAM,WAAW,QAAe,GAAG,KAAG,OAAO,CAAC,MAAM,CAK1D,CAAA;AAED,eAAO,MAAM,SAAS,QAAe,GAAG,oBAGvC,CAAA;AAED,eAAO,MAAM,gBAAgB,QAAe,GAAG,mBAAiD,CAAA;AAEhG,eAAO,MAAM,cAAc,QAAe,GAAG;;;;;EAc5C,CAAA;AAED,eAAO,MAAM,yBAAyB,QAAe,GAAG,qBACa,CAAA;AAErE,eAAO,MAAM,iBAAiB,QAAe,GAAG,6CACqC,CAAA;AAErF,eAAO,MAAM,eAAe,QAAS,GAAG,KAAG,CAAC,MAAM,EAAE,MAAM,CACa,CAAA;AAEvE,eAAO,MAAM,iBAAiB,QAAS,GAAG,WAC6B,CAAA;AAEvE,wBAAgB,sBAAsB,CACpC,aAAa,EAAE,MAAM,EACrB,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EACjC,cAAc,EAAE,MAAM,GACrB,MAAM,CAUR;AAED,eAAO,MAAM,WAAW,QAAe,GAAG,wBAezC,CAAA;AAED,eAAO,MAAM,cAAc,QAAe,GAAG,oBAM5C,CAAA"}
package/dist/info.js CHANGED
@@ -10,25 +10,71 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  });
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.networkTimestamp = exports.blockHash = exports.blockNumber = exports.block = exports.query = exports.rpc = void 0;
13
+ exports.blockchainSize = exports.spacePledge = exports.maxPiecesInSector = exports.slotProbability = exports.segmentCommitment = exports.shouldAdjustSolutionRange = exports.solutionRanges = exports.networkTimestamp = exports.blockHash = exports.blockNumber = exports.block = exports.query = exports.rpc = void 0;
14
+ exports.solutionRangeToSectors = solutionRangeToSectors;
14
15
  const query_1 = require("./utils/query");
15
- const rpc = (methodPath_1, ...args_1) => __awaiter(void 0, [methodPath_1, ...args_1], void 0, function* (methodPath, params = [], networkId) { return yield (0, query_1.queryMethodPath)(`rpc.${methodPath}`, params, networkId); });
16
+ const PIECE_SIZE = BigInt(1048576);
17
+ const rpc = (api_1, methodPath_1, ...args_1) => __awaiter(void 0, [api_1, methodPath_1, ...args_1], void 0, function* (api, methodPath, params = []) { return yield (0, query_1.queryMethodPath)(api, `rpc.${methodPath}`, params); });
16
18
  exports.rpc = rpc;
17
- const query = (methodPath_1, ...args_1) => __awaiter(void 0, [methodPath_1, ...args_1], void 0, function* (methodPath, params = [], networkId) { return yield (0, query_1.queryMethodPath)(`query.${methodPath}`, params, networkId); });
19
+ const query = (api_1, methodPath_1, ...args_1) => __awaiter(void 0, [api_1, methodPath_1, ...args_1], void 0, function* (api, methodPath, params = []) { return yield (0, query_1.queryMethodPath)(api, `query.${methodPath}`, params); });
18
20
  exports.query = query;
19
- const block = (networkId) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, exports.rpc)('chain.getBlock', [], networkId); });
21
+ const block = (api) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, exports.rpc)(api, 'chain.getBlock', []); });
20
22
  exports.block = block;
21
- const blockNumber = (networkId) => __awaiter(void 0, void 0, void 0, function* () {
23
+ const blockNumber = (api) => __awaiter(void 0, void 0, void 0, function* () {
22
24
  // Get the block
23
- const _block = yield (0, exports.block)(networkId);
25
+ const _block = yield (0, exports.block)(api);
24
26
  return _block.block.header.number.toNumber();
25
27
  });
26
28
  exports.blockNumber = blockNumber;
27
- const blockHash = (networkId) => __awaiter(void 0, void 0, void 0, function* () {
28
- // Get the block
29
- const _block = yield (0, exports.block)(networkId);
30
- return _block.block.header.hash.toString();
29
+ const blockHash = (api) => __awaiter(void 0, void 0, void 0, function* () {
30
+ const _blockHash = yield (0, exports.rpc)(api, 'chain.getBlockHash', []);
31
+ return _blockHash.toString();
31
32
  });
32
33
  exports.blockHash = blockHash;
33
- const networkTimestamp = (networkId) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, exports.query)('timestamp.now', [], networkId); });
34
+ const networkTimestamp = (api) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, exports.query)(api, 'timestamp.now', []); });
34
35
  exports.networkTimestamp = networkTimestamp;
36
+ const solutionRanges = (api) => __awaiter(void 0, void 0, void 0, function* () {
37
+ const _solutionRanges = yield (0, exports.query)(api, 'subspace.solutionRanges', []);
38
+ const solution = _solutionRanges.toPrimitive();
39
+ return {
40
+ current: solution.current ? BigInt(solution.current) : null,
41
+ next: solution.next ? BigInt(solution.next) : null,
42
+ votingCurrent: solution.votingCurrent ? BigInt(solution.votingCurrent) : null,
43
+ votingNext: solution.votingNext ? BigInt(solution.votingNext) : null,
44
+ };
45
+ });
46
+ exports.solutionRanges = solutionRanges;
47
+ const shouldAdjustSolutionRange = (api) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, exports.query)(api, 'subspace.shouldAdjustSolutionRange', []); });
48
+ exports.shouldAdjustSolutionRange = shouldAdjustSolutionRange;
49
+ const segmentCommitment = (api) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, exports.query)(api, 'subspace.segmentCommitment', []); });
50
+ exports.segmentCommitment = segmentCommitment;
51
+ const slotProbability = (api) => api.consts.subspace.slotProbability.toPrimitive();
52
+ exports.slotProbability = slotProbability;
53
+ const maxPiecesInSector = (api) => BigInt(api.consts.subspace.maxPiecesInSector.toPrimitive());
54
+ exports.maxPiecesInSector = maxPiecesInSector;
55
+ function solutionRangeToSectors(solutionRange, slotProbability, piecesInSector) {
56
+ const MAX_U64 = BigInt(Math.pow(2, 64) - 1);
57
+ const RECORD_NUM_CHUNKS = BigInt(32768);
58
+ const RECORD_NUM_S_BUCKETS = BigInt(65536);
59
+ const sectors = ((MAX_U64 / slotProbability[1]) * slotProbability[0]) /
60
+ ((piecesInSector * RECORD_NUM_CHUNKS) / RECORD_NUM_S_BUCKETS);
61
+ return sectors / solutionRange;
62
+ }
63
+ const spacePledge = (api) => __awaiter(void 0, void 0, void 0, function* () {
64
+ const _solutionRanges = yield (0, exports.solutionRanges)(api);
65
+ const _slotProbability = (0, exports.slotProbability)(api);
66
+ const _maxPiecesInSector = (0, exports.maxPiecesInSector)(api);
67
+ if (!_solutionRanges.current || !_slotProbability || !_maxPiecesInSector)
68
+ return 0;
69
+ const sectors = solutionRangeToSectors(_solutionRanges.current, [BigInt(_slotProbability[0]), BigInt(_slotProbability[1])], _maxPiecesInSector);
70
+ const totalSpacePledged = sectors * _maxPiecesInSector * PIECE_SIZE;
71
+ return totalSpacePledged;
72
+ });
73
+ exports.spacePledge = spacePledge;
74
+ const blockchainSize = (api) => __awaiter(void 0, void 0, void 0, function* () {
75
+ const _segmentCommitment = yield (0, exports.segmentCommitment)(api);
76
+ const segmentsCount = BigInt(_segmentCommitment.length);
77
+ const blockchainSize = PIECE_SIZE * BigInt(256) * segmentsCount;
78
+ return blockchainSize;
79
+ });
80
+ exports.blockchainSize = blockchainSize;
@@ -0,0 +1,11 @@
1
+ import type { BN } from '@autonomys/auto-utils';
2
+ import type { BalanceData, RawBalanceData } from './balance';
3
+ export type RawAccountData = {
4
+ nonce: BN;
5
+ data: RawBalanceData;
6
+ };
7
+ export type AccountData = {
8
+ nonce: BN;
9
+ data: BalanceData;
10
+ };
11
+ //# sourceMappingURL=account.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../src/types/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAA;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE5D,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,EAAE,CAAA;IACT,IAAI,EAAE,cAAc,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,EAAE,CAAA;IACT,IAAI,EAAE,WAAW,CAAA;CAClB,CAAA"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ import type { BN } from '@autonomys/auto-utils';
2
+ export type RawBalanceData = {
3
+ free: BN;
4
+ reserved: BN;
5
+ frozen: BN;
6
+ flags: BN;
7
+ };
8
+ export type BalanceData = {
9
+ free: bigint;
10
+ reserved: bigint;
11
+ frozen: bigint;
12
+ flags: bigint;
13
+ };
14
+ //# sourceMappingURL=balance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"balance.d.ts","sourceRoot":"","sources":["../../src/types/balance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAA;AAE/C,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,EAAE,CAAA;IACR,QAAQ,EAAE,EAAE,CAAA;IACZ,MAAM,EAAE,EAAE,CAAA;IACV,KAAK,EAAE,EAAE,CAAA;CACV,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;CACd,CAAA"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,28 @@
1
+ import type { BN } from '@autonomys/auto-utils';
2
+ export type RawBlock = {
3
+ block: {
4
+ header: {
5
+ parentHash: string;
6
+ number: BN;
7
+ stateRoot: string;
8
+ extrinsicsRoot: string;
9
+ digest: {
10
+ logs: string[];
11
+ };
12
+ };
13
+ };
14
+ };
15
+ export type Block = {
16
+ block: {
17
+ header: {
18
+ parentHash: string;
19
+ number: number;
20
+ stateRoot: string;
21
+ extrinsicsRoot: string;
22
+ digest: {
23
+ logs: string[];
24
+ };
25
+ };
26
+ };
27
+ };
28
+ //# sourceMappingURL=block.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../src/types/block.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAA;AAE/C,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE;QACL,MAAM,EAAE;YACN,UAAU,EAAE,MAAM,CAAA;YAClB,MAAM,EAAE,EAAE,CAAA;YACV,SAAS,EAAE,MAAM,CAAA;YACjB,cAAc,EAAE,MAAM,CAAA;YACtB,MAAM,EAAE;gBACN,IAAI,EAAE,MAAM,EAAE,CAAA;aACf,CAAA;SACF,CAAA;KACF,CAAA;CACF,CAAA;AAED,MAAM,MAAM,KAAK,GAAG;IAClB,KAAK,EAAE;QACL,MAAM,EAAE;YACN,UAAU,EAAE,MAAM,CAAA;YAClB,MAAM,EAAE,MAAM,CAAA;YACd,SAAS,EAAE,MAAM,CAAA;YACjB,cAAc,EAAE,MAAM,CAAA;YACtB,MAAM,EAAE;gBACN,IAAI,EAAE,MAAM,EAAE,CAAA;aACf,CAAA;SACF,CAAA;KACF,CAAA;CACF,CAAA"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,4 @@
1
+ export * from './balance';
1
2
  export * from './domain';
2
3
  export * from './events';
3
4
  export * from './staking';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA"}
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./balance"), exports);
18
19
  __exportStar(require("./domain"), exports);
19
20
  __exportStar(require("./events"), exports);
20
21
  __exportStar(require("./staking"), exports);
@@ -1,6 +1,8 @@
1
1
  import type { AnyTuple, Codec, StorageKey } from '@autonomys/auto-utils';
2
+ import type { BalanceData, RawBalanceData } from '../types/balance';
2
3
  import { DomainRegistry } from '../types/domain';
3
4
  import { Deposit, Operator, OperatorDetails, StringNumberOrBigInt, Withdrawal } from '../types/staking';
5
+ export declare const parseBalance: (data: RawBalanceData) => BalanceData;
4
6
  export declare const parseDomain: (domain: [StorageKey<AnyTuple>, Codec]) => DomainRegistry;
5
7
  export declare const parseOperatorDetails: (operatorDetails: Codec) => OperatorDetails;
6
8
  export declare const parseOperator: (operator: [StorageKey<AnyTuple>, Codec]) => Operator;
@@ -1 +1 @@
1
- {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/utils/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EACL,OAAO,EACP,QAAQ,EACR,eAAe,EAOf,oBAAoB,EACpB,UAAU,EACX,MAAM,kBAAkB,CAAA;AAEzB,eAAO,MAAM,WAAW,WAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAG,cAMnE,CAAA;AAED,eAAO,MAAM,oBAAoB,oBAAqB,KAAK,KAAG,eAgB7D,CAAA;AAED,eAAO,MAAM,aAAa,aAAc,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAG,QAKvE,CAAA;AAED,eAAO,MAAM,YAAY,YAAa,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAG,OAuBrE,CAAA;AAED,eAAO,MAAM,eAAe,eAAgB,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAG,UAwB3E,CAAA;AAED,eAAO,MAAM,WAAW,eAAgB,oBAAoB,KAAG,MACM,CAAA"}
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/utils/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EACL,OAAO,EACP,QAAQ,EACR,eAAe,EAOf,oBAAoB,EACpB,UAAU,EACX,MAAM,kBAAkB,CAAA;AAEzB,eAAO,MAAM,YAAY,SAAU,cAAc,KAAG,WAYnD,CAAA;AAED,eAAO,MAAM,WAAW,WAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAG,cAMnE,CAAA;AAED,eAAO,MAAM,oBAAoB,oBAAqB,KAAK,KAAG,eAgB7D,CAAA;AAED,eAAO,MAAM,aAAa,aAAc,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAG,QAKvE,CAAA;AAED,eAAO,MAAM,YAAY,YAAa,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAG,OAuBrE,CAAA;AAED,eAAO,MAAM,eAAe,eAAgB,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAG,UAwB3E,CAAA;AAED,eAAO,MAAM,WAAW,eAAgB,oBAAoB,KAAG,MACM,CAAA"}
@@ -1,6 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseString = exports.parseWithdrawal = exports.parseDeposit = exports.parseOperator = exports.parseOperatorDetails = exports.parseDomain = void 0;
3
+ exports.parseString = exports.parseWithdrawal = exports.parseDeposit = exports.parseOperator = exports.parseOperatorDetails = exports.parseDomain = exports.parseBalance = void 0;
4
+ const parseBalance = (data) => {
5
+ try {
6
+ return {
7
+ free: BigInt(data.free.toString()),
8
+ reserved: BigInt(data.reserved.toString()),
9
+ frozen: BigInt(data.frozen.toString()),
10
+ flags: BigInt(data.flags.toString()),
11
+ };
12
+ }
13
+ catch (error) {
14
+ console.error('Error parsing balance:', error);
15
+ throw new Error('Failed to parse balance');
16
+ }
17
+ };
18
+ exports.parseBalance = parseBalance;
4
19
  const parseDomain = (domain) => {
5
20
  const header = domain[0].toHuman();
6
21
  return Object.assign({ domainId: header[0] }, domain[1].toJSON());
@@ -1,2 +1,3 @@
1
- export declare const queryMethodPath: (methodPath: string, params?: any[], networkId?: string) => Promise<any>;
1
+ import { Api } from '@autonomys/auto-utils';
2
+ export declare const queryMethodPath: <T>(api: Api, methodPath: string, params?: any[]) => Promise<T>;
2
3
  //# sourceMappingURL=query.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/utils/query.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,eACd,MAAM,WACV,GAAG,EAAE,cACD,MAAM,iBAuBnB,CAAA"}
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/utils/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAE3C,eAAO,MAAM,eAAe,GAAU,CAAC,OAChC,GAAG,cACI,MAAM,WACV,GAAG,EAAE,KACZ,OAAO,CAAC,CAAC,CAgBX,CAAA"}
@@ -10,10 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.queryMethodPath = void 0;
13
- const auto_utils_1 = require("@autonomys/auto-utils");
14
- const queryMethodPath = (methodPath_1, ...args_1) => __awaiter(void 0, [methodPath_1, ...args_1], void 0, function* (methodPath, params = [], networkId) {
13
+ const queryMethodPath = (api_1, methodPath_1, ...args_1) => __awaiter(void 0, [api_1, methodPath_1, ...args_1], void 0, function* (api, methodPath, params = []) {
15
14
  try {
16
- const api = yield (0, auto_utils_1.activate)({ networkId });
17
15
  // Split the method path to traverse the api object
18
16
  const methodParts = methodPath.split('.');
19
17
  let method = api;
@@ -22,9 +20,7 @@ const queryMethodPath = (methodPath_1, ...args_1) => __awaiter(void 0, [methodPa
22
20
  }
23
21
  if (typeof method !== 'function')
24
22
  throw new Error(`Invalid method path: ${methodPath}`);
25
- const result = yield method(...params);
26
- yield (0, auto_utils_1.disconnect)(api);
27
- return result;
23
+ return (yield method(...params));
28
24
  }
29
25
  catch (error) {
30
26
  console.error(error);
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@autonomys/auto-consensus",
3
- "version": "0.5.3",
3
+ "version": "0.6.1",
4
+ "license": "MIT",
4
5
  "main": "dist/index.js",
5
6
  "scripts": {
6
7
  "build": "tsc",
@@ -21,7 +22,7 @@
21
22
  "url": "https://www.autonomys.net"
22
23
  },
23
24
  "dependencies": {
24
- "@autonomys/auto-utils": "^0.5.3"
25
+ "@autonomys/auto-utils": "^0.6.1"
25
26
  },
26
27
  "devDependencies": {
27
28
  "@types/jest": "^29.5.12",
@@ -31,5 +32,5 @@
31
32
  "ts-jest": "^29.1.4",
32
33
  "typescript": "^5.4.5"
33
34
  },
34
- "gitHead": "6562d96024a64cb8c9cf9c15ec7ee795fdb52318"
35
+ "gitHead": "95bcddae352dc40801bbcea12c6489bd78014f32"
35
36
  }