@polkadot-api/substrate-client 0.3.0 → 0.4.0
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.
- package/dist/esm/archive/archive.mjs +52 -0
- package/dist/esm/archive/archive.mjs.map +1 -0
- package/dist/esm/archive/errors.mjs +21 -0
- package/dist/esm/archive/errors.mjs.map +1 -0
- package/dist/esm/archive/storage-subscription.mjs +55 -0
- package/dist/esm/archive/storage-subscription.mjs.map +1 -0
- package/dist/esm/archive/storage.mjs +26 -0
- package/dist/esm/archive/storage.mjs.map +1 -0
- package/dist/esm/chainhead/chainhead.mjs.map +1 -1
- package/dist/esm/index.mjs +5 -40
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/internal-utils/abortablePromiseFn.mjs +1 -1
- package/dist/esm/substrate-client.mjs +41 -0
- package/dist/esm/substrate-client.mjs.map +1 -0
- package/dist/index.d.ts +44 -13
- package/dist/index.js +267 -127
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { abortablePromiseFn } from '../internal-utils/abortablePromiseFn.mjs';
|
|
2
|
+
import { createStorageCb } from './storage-subscription.mjs';
|
|
3
|
+
import { createStorageFn } from './storage.mjs';
|
|
4
|
+
import { BlockHashNotFoundError, CallError } from './errors.mjs';
|
|
5
|
+
|
|
6
|
+
const identity = () => (x) => x;
|
|
7
|
+
const handleInvalidBlockHash = () => (result, hash) => {
|
|
8
|
+
if (result === null) throw new BlockHashNotFoundError(hash);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
const getArchive = (request) => {
|
|
12
|
+
const archiveRequest = (method, ...rest) => request(`archive_v1_${method}`, ...rest);
|
|
13
|
+
const fnCreator = (method) => (mapper) => abortablePromiseFn(
|
|
14
|
+
(res, rej, ...args) => archiveRequest(method, args, {
|
|
15
|
+
onSuccess: (x) => {
|
|
16
|
+
try {
|
|
17
|
+
res(mapper(x, ...args));
|
|
18
|
+
} catch (e) {
|
|
19
|
+
rej(e);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
onError: rej
|
|
23
|
+
})
|
|
24
|
+
);
|
|
25
|
+
const header = fnCreator("header")(
|
|
26
|
+
handleInvalidBlockHash()
|
|
27
|
+
);
|
|
28
|
+
const body = fnCreator("body")(
|
|
29
|
+
handleInvalidBlockHash()
|
|
30
|
+
);
|
|
31
|
+
const storageSubscription = createStorageCb(archiveRequest);
|
|
32
|
+
const storage = createStorageFn(storageSubscription);
|
|
33
|
+
const call = fnCreator("call")((x, hash) => {
|
|
34
|
+
if (!x) throw new BlockHashNotFoundError(hash);
|
|
35
|
+
if (!x.success) throw new CallError(x.error);
|
|
36
|
+
return x.value;
|
|
37
|
+
});
|
|
38
|
+
const finalizedHeight = fnCreator("finalizedHeight")(identity());
|
|
39
|
+
const hashByHeight = fnCreator("hashByHeight")(identity());
|
|
40
|
+
return {
|
|
41
|
+
header,
|
|
42
|
+
body,
|
|
43
|
+
storageSubscription,
|
|
44
|
+
storage,
|
|
45
|
+
call,
|
|
46
|
+
finalizedHeight,
|
|
47
|
+
hashByHeight
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { getArchive };
|
|
52
|
+
//# sourceMappingURL=archive.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"archive.mjs","sources":["../../../src/archive/archive.ts"],"sourcesContent":["import { abortablePromiseFn } from \"@/internal-utils\"\nimport { type ClientRequest } from \"../client\"\nimport { createStorageCb } from \"./storage-subscription\"\nimport { createStorageFn } from \"./storage\"\nimport { Archive } from \"./public-types\"\nimport { CallError, BlockHashNotFoundError } from \"./errors\"\n\nconst identity =\n <T>() =>\n (x: T): T =>\n x\n\nconst handleInvalidBlockHash =\n <T>() =>\n (result: T | null, hash: string): T => {\n if (result === null) throw new BlockHashNotFoundError(hash)\n return result\n }\n\nexport const getArchive = (request: ClientRequest<any, any>): Archive => {\n const archiveRequest: ClientRequest<any, any> = (method: string, ...rest) =>\n request(`archive_v1_${method}`, ...rest)\n\n const fnCreator =\n <A extends Array<any>>(method: string) =>\n <I, O>(mapper: (input: I, ...args: A) => O) =>\n abortablePromiseFn<O, A>((res, rej, ...args) =>\n archiveRequest(method, args, {\n onSuccess: (x: I) => {\n try {\n res(mapper(x, ...args))\n } catch (e) {\n rej(e)\n }\n },\n onError: rej,\n }),\n )\n\n const header = fnCreator<[hash: string]>(\"header\")(\n handleInvalidBlockHash<string>(),\n )\n\n const body = fnCreator<[hash: string]>(\"body\")(\n handleInvalidBlockHash<string[]>(),\n )\n\n const storageSubscription = createStorageCb(archiveRequest)\n const storage = createStorageFn(storageSubscription)\n\n const call = fnCreator<\n [hash: string, function: string, callParameters: string]\n >(\"call\")((\n x:\n | { success: true; value: string }\n | { success: false; error: string }\n | null,\n hash,\n ) => {\n if (!x) throw new BlockHashNotFoundError(hash)\n if (!x.success) throw new CallError(x.error)\n return x.value\n })\n\n const finalizedHeight = fnCreator<[]>(\"finalizedHeight\")(identity<number>())\n const hashByHeight =\n fnCreator<[height: number]>(\"hashByHeight\")(identity<string[]>())\n\n return {\n header,\n body,\n storageSubscription,\n storage,\n call,\n finalizedHeight,\n hashByHeight,\n }\n}\n"],"names":[],"mappings":";;;;;AAOA,MAAM,QAAA,GACJ,MACA,CAAC,CACC,KAAA,CAAA;AAEJ,MAAM,sBACJ,GAAA,MACA,CAAC,MAAA,EAAkB,IAAoB,KAAA;AACrC,EAAA,IAAI,MAAW,KAAA,IAAA,EAAY,MAAA,IAAI,uBAAuB,IAAI,CAAA;AAC1D,EAAO,OAAA,MAAA;AACT,CAAA;AAEW,MAAA,UAAA,GAAa,CAAC,OAA8C,KAAA;AACvE,EAAM,MAAA,cAAA,GAA0C,CAAC,MAAmB,EAAA,GAAA,IAAA,KAClE,QAAQ,CAAc,WAAA,EAAA,MAAM,CAAI,CAAA,EAAA,GAAG,IAAI,CAAA;AAEzC,EAAA,MAAM,SACJ,GAAA,CA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A,GACF;AACF;;;;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class BlockHashNotFoundError extends Error {
|
|
2
|
+
constructor(hash) {
|
|
3
|
+
super(`Invalid BlockHash: ${hash}`);
|
|
4
|
+
this.name = "BlockHashNotFoundError";
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
class StorageError extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(`Storage Error: ${message}`);
|
|
10
|
+
this.name = "StorageError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
class CallError extends Error {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(`Call Error: ${message}`);
|
|
16
|
+
this.name = "CallError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { BlockHashNotFoundError, CallError, StorageError };
|
|
21
|
+
//# sourceMappingURL=errors.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.mjs","sources":["../../../src/archive/errors.ts"],"sourcesContent":["export class BlockHashNotFoundError extends Error {\n constructor(hash: string) {\n super(`Invalid BlockHash: ${hash}`)\n this.name = \"BlockHashNotFoundError\"\n }\n}\n\nexport class StorageError extends Error {\n constructor(message: string) {\n super(`Storage Error: ${message}`)\n this.name = \"StorageError\"\n }\n}\n\nexport class CallError extends Error {\n constructor(message: string) {\n super(`Call Error: ${message}`)\n this.name = \"CallError\"\n }\n}\n"],"names":[],"mappings":"AAAO,MAAM,+BAA+B,KAAM,CAAA;AAAA,EAChD,YAAY,IAAc,EAAA;AACxB,IAAM,KAAA,CAAA,CAAA,mBAAA,EAAsB,IAAI,CAAE,CAAA,CAAA;AAClC,IAAA,IAAA,CAAK,IAAO,GAAA,wBAAA;AAAA;AAEhB;AAEO,MAAM,qBAAqB,KAAM,CAAA;AAAA,EACtC,YAAY,OAAiB,EAAA;AAC3B,IAAM,KAAA,CAAA,CAAA,eAAA,EAAkB,OAAO,CAAE,CAAA,CAAA;AACjC,IAAA,IAAA,CAAK,IAAO,GAAA,cAAA;AAAA;AAEhB;AAEO,MAAM,kBAAkB,KAAM,CAAA;AAAA,EACnC,YAAY,OAAiB,EAAA;AAC3B,IAAM,KAAA,CAAA,CAAA,YAAA,EAAe,OAAO,CAAE,CAAA,CAAA;AAC9B,IAAA,IAAA,CAAK,IAAO,GAAA,WAAA;AAAA;AAEhB;;;;"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { noop } from '@polkadot-api/utils';
|
|
2
|
+
import { StorageError } from './errors.mjs';
|
|
3
|
+
|
|
4
|
+
const createStorageCb = (archiveRequest) => (hash, inputs, childTrie, onItem, onError, onDone) => {
|
|
5
|
+
if (inputs.length === 0) {
|
|
6
|
+
onDone();
|
|
7
|
+
return noop;
|
|
8
|
+
}
|
|
9
|
+
let isRunning = true;
|
|
10
|
+
let cancel = () => {
|
|
11
|
+
isRunning = false;
|
|
12
|
+
};
|
|
13
|
+
archiveRequest("storage", [hash, inputs, childTrie], {
|
|
14
|
+
onSuccess: (operationId, followSubscription) => {
|
|
15
|
+
const stopOperation = () => {
|
|
16
|
+
archiveRequest("stopStorage", [operationId]);
|
|
17
|
+
};
|
|
18
|
+
if (!isRunning) return stopOperation();
|
|
19
|
+
const doneListening = followSubscription(operationId, {
|
|
20
|
+
next: (event) => {
|
|
21
|
+
const { event: type } = event;
|
|
22
|
+
if (type === "storage") {
|
|
23
|
+
const { event: _, ...item } = event;
|
|
24
|
+
onItem(item);
|
|
25
|
+
} else if (type === "storageDone") _onDone();
|
|
26
|
+
else _onError(new StorageError(event.error));
|
|
27
|
+
},
|
|
28
|
+
error: onError
|
|
29
|
+
});
|
|
30
|
+
const tearDown = () => {
|
|
31
|
+
cancel = noop;
|
|
32
|
+
doneListening();
|
|
33
|
+
};
|
|
34
|
+
cancel = () => {
|
|
35
|
+
tearDown();
|
|
36
|
+
stopOperation();
|
|
37
|
+
};
|
|
38
|
+
const _onError = (e) => {
|
|
39
|
+
tearDown();
|
|
40
|
+
onError(e);
|
|
41
|
+
};
|
|
42
|
+
const _onDone = () => {
|
|
43
|
+
tearDown();
|
|
44
|
+
onDone();
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
onError
|
|
48
|
+
});
|
|
49
|
+
return () => {
|
|
50
|
+
cancel();
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { createStorageCb };
|
|
55
|
+
//# sourceMappingURL=storage-subscription.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-subscription.mjs","sources":["../../../src/archive/storage-subscription.ts"],"sourcesContent":["import type { ClientRequest } from \"@/client\"\nimport { noop } from \"@polkadot-api/utils\"\nimport { Archive } from \"./public-types\"\nimport { StorageItemResponse } from \"@/chainhead\"\nimport { StorageError } from \"./errors\"\n\ntype StorageEvent = {\n event: \"storage\"\n} & StorageItemResponse\n\ntype StorageDone = {\n event: \"storageDone\"\n}\n\ntype StorageErrorEvent = {\n event: \"storageError\"\n error: string\n}\n\nexport const createStorageCb =\n (\n archiveRequest: ClientRequest<\n string,\n StorageEvent | StorageDone | StorageErrorEvent\n >,\n ): Archive[\"storageSubscription\"] =>\n (hash, inputs, childTrie, onItem, onError, onDone) => {\n if (inputs.length === 0) {\n onDone()\n return noop\n }\n\n let isRunning = true\n let cancel = () => {\n isRunning = false\n }\n\n archiveRequest(\"storage\", [hash, inputs, childTrie], {\n onSuccess: (operationId, followSubscription) => {\n const stopOperation = () => {\n archiveRequest(\"stopStorage\", [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n const doneListening = followSubscription(operationId, {\n next: (event) => {\n const { event: type } = event\n if (type === \"storage\") {\n const { event: _, ...item } = event\n onItem(item)\n } else if (type === \"storageDone\") _onDone()\n else _onError(new StorageError(event.error))\n },\n error: onError,\n })\n\n const tearDown = () => {\n cancel = noop\n doneListening()\n }\n\n cancel = () => {\n tearDown()\n stopOperation()\n }\n\n const _onError = (e: Error) => {\n tearDown()\n onError(e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,MAAM;AACrB,QAAS,MAAA,GAAA,IAAA;AACT,QAAc,aAAA,EAAA;AAAA,OAChB;AAEA,MAAA,MAAA,GAAS,MAAM;AACb,QAAS,QAAA,EAAA;AACT,QAAc,aAAA,EAAA;AAAA,OAChB;AAEA,MAAM,MAAA,QAAA,GAAW,CAAC,CAAa,KAAA;AAC7B,QAAS,QAAA,EAAA;AACT,QAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,OACX;AAEA,MAAA,MAAM,UAAU,MAAM;AACpB,QAAS,QAAA,EAAA;AACT,QAAO,MAAA,EAAA;AAAA,OACT;AAAA,KACF;AAAA,IACA;AAAA,GACD,CAAA;AAED,EAAA,OAAO,MAAM;AACX,IAAO,MAAA,EAAA;AAAA,GACT;AACF;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { abortablePromiseFn } from '../internal-utils/abortablePromiseFn.mjs';
|
|
2
|
+
|
|
3
|
+
const createStorageFn = (cbStore) => abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => {
|
|
4
|
+
const isDescendants = type.startsWith("descendants");
|
|
5
|
+
let result = isDescendants ? [] : null;
|
|
6
|
+
const onItem = isDescendants ? result.push.bind(result) : ({ [type]: res }) => {
|
|
7
|
+
result = res;
|
|
8
|
+
};
|
|
9
|
+
return cbStore(
|
|
10
|
+
hash,
|
|
11
|
+
[{ key, type }],
|
|
12
|
+
childTrie,
|
|
13
|
+
onItem,
|
|
14
|
+
(e) => {
|
|
15
|
+
reject(e);
|
|
16
|
+
result = null;
|
|
17
|
+
},
|
|
18
|
+
() => {
|
|
19
|
+
resolve(result);
|
|
20
|
+
result = null;
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export { createStorageFn };
|
|
26
|
+
//# sourceMappingURL=storage.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.mjs","sources":["../../../src/archive/storage.ts"],"sourcesContent":["import { abortablePromiseFn } from \"@/internal-utils\"\nimport type { Archive } from \"./public-types\"\n\nexport const createStorageFn = (\n cbStore: Archive[\"storageSubscription\"],\n): Archive[\"storage\"] =>\n abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => {\n const isDescendants = type.startsWith(\"descendants\")\n\n let result: any = isDescendants ? [] : null\n const onItem: Parameters<typeof cbStore>[3] = isDescendants\n ? result.push.bind(result)\n : ({ [type]: res }) => {\n result = res\n }\n\n return cbStore(\n hash,\n [{ key, type }],\n childTrie,\n onItem,\n (e) => {\n reject(e)\n result = null\n },\n () => {\n resolve(result)\n result = null\n },\n )\n })\n"],"names":[],"mappings":";;AAGa,MAAA,eAAA,GAAkB,CAC7B,OAAA,KAEA,kBAAmB,CAAA,CAAC,SAAS,MAAQ,EAAA,IAAA,EAAM,IAAM,EAAA,GAAA,EAAK,SAAc,KAAA;AAClE,EAAM,MAAA,aAAA,GAAgB,IAAK,CAAA,UAAA,CAAW,aAAa,CAAA;AAEnD,EAAI,IAAA,MAAA,GAAc,aAAgB,GAAA,EAAK,GAAA,IAAA;AACvC,EAAA,MAAM,MAAwC,GAAA,aAAA,GAC1C,MAAO,CAAA,IAAA,CAAK,IAAK,CAAA,MAAM,CACvB,GAAA,CAAC,EAAE,CAAC,IAAO,GAAA,GAAA,EAAU,KAAA;AACnB,IAAS,MAAA,GAAA,GAAA;AAAA,GACX;AAEJ,EAAO,OAAA,OAAA;AAAA,IACL,IAAA;AAAA,IACA,CAAC,EAAE,GAAK,EAAA,IAAA,EAAM,CAAA;AAAA,IACd,SAAA;AAAA,IACA,MAAA;AAAA,IACA,CAAC,CAAM,KAAA;AACL,MAAA,MAAA,CAAO,CAAC,CAAA;AACR,MAAS,MAAA,GAAA,IAAA;AAAA,KACX;AAAA,IACA,MAAM;AACJ,MAAA,OAAA,CAAQ,MAAM,CAAA;AACd,MAAS,MAAA,GAAA,IAAA;AAAA;AACX,GACF;AACF,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chainhead.mjs","sources":["../../../src/chainhead/chainhead.ts"],"sourcesContent":["import type { ClientRequest, FollowSubscriptionCb } from \"@/client\"\nimport type {\n FollowEventWithRuntimeRpc,\n FollowEventWithoutRuntimeRpc,\n OperationEventsRpc,\n StopRpc,\n} from \"./json-rpc-types\"\nimport type {\n ChainHead,\n ClientInnerRequest,\n FollowEventWithoutRuntime,\n FollowEventWithRuntime,\n FollowResponse,\n} from \"./public-types\"\nimport {\n Subscriber,\n getSubscriptionsManager,\n noop,\n deferred,\n} from \"@/internal-utils\"\nimport { createBodyFn } from \"./body\"\nimport { createCallFn } from \"./call\"\nimport { createHeaderFn } from \"./header\"\nimport { createStorageFn } from \"./storage\"\nimport { createUnpinFn } from \"./unpin\"\nimport { DisjointError, StopError } from \"./errors\"\nimport { createStorageCb } from \"./storage-subscription\"\nimport { DestroyedError } from \"@/client/DestroyedError\"\nimport { chainHead } from \"@/methods\"\n\ntype FollowEventRpc =\n | FollowEventWithRuntimeRpc\n | FollowEventWithoutRuntimeRpc\n | OperationEventsRpc\n | StopRpc\n\nfunction isOperationEvent(event: FollowEventRpc): event is OperationEventsRpc {\n return (event as OperationEventsRpc).operationId !== undefined\n}\n\nexport function getChainHead(\n request: ClientRequest<string, FollowEventRpc>,\n): ChainHead {\n return (\n withRuntime: boolean,\n onFollowEvent:\n | ((event: FollowEventWithoutRuntime) => void)\n | ((event: FollowEventWithRuntime) => void),\n onFollowError: (e: Error) => void,\n ): FollowResponse => {\n const subscriptions = getSubscriptionsManager<OperationEventsRpc>()\n\n const ongoingRequests = new Set<() => void>()\n const deferredFollow = deferred<string | Error>()\n let followSubscription: Promise<string | Error> | string | null =\n deferredFollow.promise\n\n const onAllFollowEventsNext = (event: FollowEventRpc) => {\n if (isOperationEvent(event)) {\n if (!subscriptions.has(event.operationId))\n console.warn(\"Uknown operationId on\", event)\n\n return subscriptions.next(event.operationId, event)\n }\n\n if (event.event !== \"stop\") {\n if (event.event === \"initialized\") {\n return onFollowEvent({\n type: event.event,\n finalizedBlockHashes: event.finalizedBlockHashes,\n finalizedBlockRuntime: (event as any).finalizedBlockRuntime,\n })\n }\n\n const { event: type, ...rest } = event\n // This is kinda dangerous, but YOLO\n return onFollowEvent({ type, ...rest } as any)\n }\n\n onFollowError(new StopError())\n unfollow(false)\n }\n\n const onAllFollowEventsError = (error: Error) => {\n onFollowError(error)\n unfollow(!(error instanceof DestroyedError))\n }\n\n const onFollowRequestSuccess = (\n subscriptionId: string,\n follow: FollowSubscriptionCb<FollowEventRpc>,\n ) => {\n const done = follow(subscriptionId, {\n next: onAllFollowEventsNext,\n error: onAllFollowEventsError,\n })\n\n unfollow = (sendUnfollow = true) => {\n followSubscription = null\n unfollow = noop\n done()\n sendUnfollow && request(chainHead.unfollow, [subscriptionId])\n subscriptions.errorAll(new DisjointError())\n ongoingRequests.forEach((cb) => {\n cb()\n })\n ongoingRequests.clear()\n }\n\n followSubscription = subscriptionId\n deferredFollow.res(subscriptionId)\n }\n\n const onFollowRequestError = (e: Error) => {\n if (e instanceof DestroyedError) {\n unfollow(false)\n } else {\n onFollowError(e)\n }\n followSubscription = null\n deferredFollow.res(e)\n }\n\n let unfollow: (internal?: boolean) => void = request(\n chainHead.follow,\n [withRuntime],\n { onSuccess: onFollowRequestSuccess, onError: onFollowRequestError },\n )\n\n const fRequest: ClientInnerRequest<any, any> = (method, params, cb) => {\n const disjoint = () => {\n cb?.onError(new DisjointError())\n }\n\n if (followSubscription === null) {\n disjoint()\n return noop\n }\n\n const onSubscription = (subscription: string) => {\n if (!cb) return request(method, [subscription, ...params])\n\n ongoingRequests.add(disjoint)\n\n const onSubscribeOperation = (\n operationId: string,\n subscriber: Subscriber<any>,\n ) => {\n if (followSubscription === null) {\n subscriber.error(new DisjointError())\n return noop\n }\n\n subscriptions.subscribe(operationId, subscriber)\n\n return () => {\n subscriptions.unsubscribe(operationId)\n }\n }\n\n const cleanup = request(method, [subscription, ...params], {\n onSuccess: (response) => {\n ongoingRequests.delete(disjoint)\n cb.onSuccess(response, onSubscribeOperation)\n },\n onError: (e) => {\n ongoingRequests.delete(disjoint)\n cb.onError(e)\n },\n })\n\n return () => {\n ongoingRequests.delete(disjoint)\n cleanup()\n }\n }\n\n if (typeof followSubscription === \"string\")\n return onSubscription(followSubscription)\n\n let onCancel = noop\n followSubscription.then((x) => {\n if (x instanceof Error) return disjoint()\n if (followSubscription) onCancel = onSubscription(x)\n })\n\n return () => {\n onCancel()\n }\n }\n\n return {\n unfollow() {\n unfollow()\n followSubscription = null\n },\n body: createBodyFn(fRequest),\n call: createCallFn(fRequest),\n header: createHeaderFn(fRequest),\n storage: createStorageFn(fRequest),\n storageSubscription: createStorageCb(fRequest),\n unpin: createUnpinFn(fRequest),\n _request: fRequest,\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAoCA,SAAS,iBAAiB,KAAoD,EAAA;AAC5E,EAAA,OAAQ,MAA6B,WAAgB,KAAA,KAAA,CAAA;AACvD;AAEO,SAAS,aACd,OACW,EAAA;AACX,EAAO,OAAA,CACL,WACA,EAAA,aAAA,EAGA,aACmB,KAAA;AACnB,IAAA,MAAM,gBAAgB,uBAA4C,EAAA;AAElE,IAAM,MAAA,eAAA,uBAAsB,GAAgB,EAAA;AAC5C,IAAA,MAAM,iBAAiB,QAAyB,EAAA;AAChD,IAAA,IAAI,qBACF,cAAe,CAAA,OAAA;AAEjB,IAAM,MAAA,qBAAA,GAAwB,CAAC,KAA0B,KAAA;AACvD,MAAI,IAAA,gBAAA,CAAiB,KAAK,CAAG,EAAA;AAC3B,QAAA,IAAI,CAAC,aAAA,CAAc,GAAI,CAAA,KAAA,CAAM,WAAW,CAAA;AACtC,UAAQ,OAAA,CAAA,IAAA,CAAK,yBAAyB,KAAK,CAAA;AAE7C,QAAA,OAAO,aAAc,CAAA,IAAA,CAAK,KAAM,CAAA,WAAA,EAAa,KAAK,CAAA;AAAA;AAGpD,MAAI,IAAA,KAAA,CAAM,UAAU,MAAQ,EAAA;AAC1B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A,MAC/B,OAAA,EAAS,gBAAgB,QAAQ,CAAA;AAAA,MACjC,mBAAA,EAAqB,gBAAgB,QAAQ,CAAA;AAAA,MAC7C,KAAA,EAAO,cAAc,QAAQ,CAAA;AAAA,MAC7B,QAAU,EAAA;AAAA,KACZ;AAAA,GACF;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"chainhead.mjs","sources":["../../../src/chainhead/chainhead.ts"],"sourcesContent":["import type { ClientRequest, FollowSubscriptionCb } from \"@/client\"\nimport type {\n FollowEventWithRuntimeRpc,\n FollowEventWithoutRuntimeRpc,\n OperationEventsRpc,\n StopRpc,\n} from \"./json-rpc-types\"\nimport type {\n ChainHead,\n ClientInnerRequest,\n FollowEventWithoutRuntime,\n FollowEventWithRuntime,\n FollowResponse,\n} from \"./public-types\"\nimport {\n Subscriber,\n getSubscriptionsManager,\n noop,\n deferred,\n} from \"@/internal-utils\"\nimport { createBodyFn } from \"./body\"\nimport { createCallFn } from \"./call\"\nimport { createHeaderFn } from \"./header\"\nimport { createStorageFn } from \"./storage\"\nimport { createUnpinFn } from \"./unpin\"\nimport { DisjointError, StopError } from \"./errors\"\nimport { createStorageCb } from \"./storage-subscription\"\nimport { DestroyedError } from \"@/client/DestroyedError\"\nimport { chainHead } from \"@/methods\"\n\ntype FollowEventRpc =\n | FollowEventWithRuntimeRpc\n | FollowEventWithoutRuntimeRpc\n | OperationEventsRpc\n | StopRpc\n\nfunction isOperationEvent(event: FollowEventRpc): event is OperationEventsRpc {\n return (event as OperationEventsRpc).operationId !== undefined\n}\n\nexport function getChainHead(\n request: ClientRequest<string, FollowEventRpc>,\n): ChainHead {\n return (\n withRuntime: boolean,\n onFollowEvent:\n | ((event: FollowEventWithoutRuntime) => void)\n | ((event: FollowEventWithRuntime) => void),\n onFollowError: (e: Error) => void,\n ): FollowResponse => {\n const subscriptions = getSubscriptionsManager<OperationEventsRpc>()\n\n const ongoingRequests = new Set<() => void>()\n const deferredFollow = deferred<string | Error>()\n let followSubscription: Promise<string | Error> | string | null =\n deferredFollow.promise\n\n const onAllFollowEventsNext = (event: FollowEventRpc) => {\n if (isOperationEvent(event)) {\n if (!subscriptions.has(event.operationId))\n console.warn(\"Uknown operationId on\", event)\n\n return subscriptions.next(event.operationId, event)\n }\n\n if (event.event !== \"stop\") {\n if (event.event === \"initialized\") {\n return onFollowEvent({\n type: event.event,\n finalizedBlockHashes: event.finalizedBlockHashes,\n finalizedBlockRuntime: (event as any).finalizedBlockRuntime,\n })\n }\n\n const { event: type, ...rest } = event\n // This is kinda dangerous, but YOLO\n return onFollowEvent({ type, ...rest } as any)\n }\n\n onFollowError(new StopError())\n unfollow(false)\n }\n\n const onAllFollowEventsError = (error: Error) => {\n onFollowError(error)\n unfollow(!(error instanceof DestroyedError))\n }\n\n const onFollowRequestSuccess = (\n subscriptionId: string,\n follow: FollowSubscriptionCb<FollowEventRpc>,\n ) => {\n const done = follow(subscriptionId, {\n next: onAllFollowEventsNext,\n error: onAllFollowEventsError,\n })\n\n unfollow = (sendUnfollow = true) => {\n followSubscription = null\n unfollow = noop\n done()\n sendUnfollow && request(chainHead.unfollow, [subscriptionId])\n subscriptions.errorAll(new DisjointError())\n ongoingRequests.forEach((cb) => {\n cb()\n })\n ongoingRequests.clear()\n }\n\n followSubscription = subscriptionId\n deferredFollow.res(subscriptionId)\n }\n\n const onFollowRequestError = (e: Error) => {\n if (e instanceof DestroyedError) {\n unfollow(false)\n } else {\n onFollowError(e)\n }\n followSubscription = null\n deferredFollow.res(e)\n }\n\n let unfollow: (internal?: boolean) => void = request(\n chainHead.follow,\n [withRuntime],\n { onSuccess: onFollowRequestSuccess, onError: onFollowRequestError },\n )\n\n const fRequest: ClientInnerRequest<any, any> = (method, params, cb) => {\n const disjoint = () => {\n cb?.onError(new DisjointError())\n }\n\n if (followSubscription === null) {\n disjoint()\n return noop\n }\n\n const onSubscription = (subscription: string) => {\n if (!cb) return request(method, [subscription, ...params])\n\n ongoingRequests.add(disjoint)\n\n const onSubscribeOperation = (\n operationId: string,\n subscriber: Subscriber<any>,\n ) => {\n if (followSubscription === null) {\n subscriber.error(new DisjointError())\n return noop\n }\n\n subscriptions.subscribe(operationId, subscriber)\n\n return () => {\n subscriptions.unsubscribe(operationId)\n }\n }\n\n const cleanup = request(method, [subscription, ...params], {\n onSuccess: (response) => {\n ongoingRequests.delete(disjoint)\n cb.onSuccess(response, onSubscribeOperation)\n },\n onError: (e) => {\n ongoingRequests.delete(disjoint)\n cb.onError(e)\n },\n })\n\n return () => {\n ongoingRequests.delete(disjoint)\n cleanup()\n }\n }\n\n if (typeof followSubscription === \"string\")\n return onSubscription(followSubscription)\n\n let onCancel = noop\n followSubscription.then((x) => {\n if (x instanceof Error) return disjoint()\n if (followSubscription) onCancel = onSubscription(x)\n })\n\n return () => {\n onCancel()\n }\n }\n\n return {\n unfollow() {\n unfollow()\n followSubscription = null\n },\n body: createBodyFn(fRequest),\n call: createCallFn(fRequest),\n header: createHeaderFn(fRequest),\n storage: createStorageFn(fRequest),\n storageSubscription: createStorageCb(fRequest),\n unpin: createUnpinFn(fRequest),\n _request: fRequest,\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAoCA,SAAS,iBAAiB,KAAoD,EAAA;AAC5E,EAAA,OAAQ,MAA6B,WAAgB,KAAA,MAAA;AACvD;AAEO,SAAS,aACd,OACW,EAAA;AACX,EAAO,OAAA,CACL,WACA,EAAA,aAAA,EAGA,aACmB,KAAA;AACnB,IAAA,MAAM,gBAAgB,uBAA4C,EAAA;AAElE,IAAM,MAAA,eAAA,uBAAsB,GAAgB,EAAA;AAC5C,IAAA,MAAM,iBAAiB,QAAyB,EAAA;AAChD,IAAA,IAAI,qBACF,cAAe,CAAA,OAAA;AAEjB,IAAM,MAAA,qBAAA,GAAwB,CAAC,KAA0B,KAAA;AACvD,MAAI,IAAA,gBAAA,CAAiB,KAAK,CAAG,EAAA;AAC3B,QAAA,IAAI,CAAC,aAAA,CAAc,GAAI,CAAA,KAAA,CAAM,WAAW,C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A;AACT,QAAS,QAAA,EAAA;AACT,QAAqB,kBAAA,GAAA,IAAA;AAAA,OACvB;AAAA,MACA,IAAA,EAAM,aAAa,QAAQ,CAAA;AAAA,MAC3B,IAAA,EAAM,aAAa,QAAQ,CAAA;AAAA,MAC3B,MAAA,EAAQ,eAAe,QAAQ,CAAA;AAAA,MAC/B,OAAA,EAAS,gBAAgB,QAAQ,CAAA;AAAA,MACjC,mBAAA,EAAqB,gBAAgB,QAAQ,CAAA;AAAA,MAC7C,KAAA,EAAO,cAAc,QAAQ,CAAA;AAAA,MAC7B,QAAU,EAAA;AAAA,KACZ;AAAA,GACF;AACF;;;;"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,43 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
export { DisjointError, OperationError, OperationInaccessibleError, OperationLimitError, StopError } from './chainhead/errors.mjs';
|
|
3
|
-
import { getChainHead } from './chainhead/chainhead.mjs';
|
|
1
|
+
export { AbortError } from '@polkadot-api/utils';
|
|
4
2
|
export { RpcError } from './client/RpcError.mjs';
|
|
5
|
-
import { createClient as createClient$1 } from './client/createClient.mjs';
|
|
6
3
|
export { DestroyedError } from './client/DestroyedError.mjs';
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
export {
|
|
10
|
-
|
|
11
|
-
const clientCache = /* @__PURE__ */ new Map();
|
|
12
|
-
const createClient = (provider) => {
|
|
13
|
-
const cached = clientCache.get(provider);
|
|
14
|
-
if (cached) {
|
|
15
|
-
cached.refCount++;
|
|
16
|
-
return cached.client;
|
|
17
|
-
}
|
|
18
|
-
const { request, disconnect } = createClient$1(provider);
|
|
19
|
-
const destroy = () => {
|
|
20
|
-
const cached2 = clientCache.get(provider);
|
|
21
|
-
if (!cached2 || cached2.refCount <= 1) {
|
|
22
|
-
clientCache.delete(provider);
|
|
23
|
-
disconnect();
|
|
24
|
-
} else {
|
|
25
|
-
cached2.refCount--;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
const client = {
|
|
29
|
-
chainHead: getChainHead(request),
|
|
30
|
-
transaction: getTransaction(request),
|
|
31
|
-
getChainSpecData: createGetChainSpec(request),
|
|
32
|
-
destroy,
|
|
33
|
-
request: abortablePromiseFn(
|
|
34
|
-
(onSuccess, onError, method, params) => request(method, params, { onSuccess, onError })
|
|
35
|
-
),
|
|
36
|
-
_request: request
|
|
37
|
-
};
|
|
38
|
-
clientCache.set(provider, { client, refCount: 1 });
|
|
39
|
-
return client;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export { createClient };
|
|
4
|
+
export { DisjointError, OperationError, OperationInaccessibleError, OperationLimitError, StopError } from './chainhead/errors.mjs';
|
|
5
|
+
import './methods.mjs';
|
|
6
|
+
export { BlockHashNotFoundError, CallError, StorageError } from './archive/errors.mjs';
|
|
7
|
+
export { createClient } from './substrate-client.mjs';
|
|
43
8
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getTransaction } from './transaction/transaction.mjs';
|
|
2
|
+
import { getChainHead } from './chainhead/chainhead.mjs';
|
|
3
|
+
import { createClient as createClient$1 } from './client/createClient.mjs';
|
|
4
|
+
import { abortablePromiseFn } from './internal-utils/abortablePromiseFn.mjs';
|
|
5
|
+
import { createGetChainSpec } from './chainspec.mjs';
|
|
6
|
+
import { getArchive } from './archive/archive.mjs';
|
|
7
|
+
|
|
8
|
+
const clientCache = /* @__PURE__ */ new Map();
|
|
9
|
+
const createClient = (provider) => {
|
|
10
|
+
const cached = clientCache.get(provider);
|
|
11
|
+
if (cached) {
|
|
12
|
+
cached.refCount++;
|
|
13
|
+
return cached.client;
|
|
14
|
+
}
|
|
15
|
+
const { request, disconnect } = createClient$1(provider);
|
|
16
|
+
const destroy = () => {
|
|
17
|
+
const cached2 = clientCache.get(provider);
|
|
18
|
+
if (!cached2 || cached2.refCount <= 1) {
|
|
19
|
+
clientCache.delete(provider);
|
|
20
|
+
disconnect();
|
|
21
|
+
} else {
|
|
22
|
+
cached2.refCount--;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const client = {
|
|
26
|
+
archive: getArchive(request),
|
|
27
|
+
chainHead: getChainHead(request),
|
|
28
|
+
transaction: getTransaction(request),
|
|
29
|
+
getChainSpecData: createGetChainSpec(request),
|
|
30
|
+
destroy,
|
|
31
|
+
request: abortablePromiseFn(
|
|
32
|
+
(onSuccess, onError, method, params) => request(method, params, { onSuccess, onError })
|
|
33
|
+
),
|
|
34
|
+
_request: request
|
|
35
|
+
};
|
|
36
|
+
clientCache.set(provider, { client, refCount: 1 });
|
|
37
|
+
return client;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { createClient };
|
|
41
|
+
//# sourceMappingURL=substrate-client.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"substrate-client.mjs","sources":["../../src/substrate-client.ts"],"sourcesContent":["import type { JsonRpcProvider } from \"@polkadot-api/json-rpc-provider\"\nimport { getTransaction } from \"./transaction/transaction\"\nimport { getChainHead } from \"./chainhead\"\nimport { ClientRequestCb, createClient as createRawClient } from \"./client\"\nimport type { ChainHead } from \"./chainhead\"\nimport type { Transaction } from \"./transaction\"\nimport { UnsubscribeFn } from \"./common-types\"\nimport { abortablePromiseFn } from \"./internal-utils\"\nimport { ChainSpecData, createGetChainSpec } from \"./chainspec\"\nimport { Archive, getArchive } from \"./archive\"\n\nexport interface SubstrateClient {\n archive: Archive\n chainHead: ChainHead\n transaction: Transaction\n destroy: UnsubscribeFn\n getChainSpecData: () => Promise<ChainSpecData>\n request: <T>(\n method: string,\n params: any[],\n abortSignal?: AbortSignal,\n ) => Promise<T>\n _request: <Reply, Notification>(\n method: string,\n params: any[],\n cb?: ClientRequestCb<Reply, Notification>,\n ) => UnsubscribeFn\n}\n\nconst clientCache = new Map<\n JsonRpcProvider,\n { client: SubstrateClient; refCount: number }\n>()\n\nexport const createClient = (provider: JsonRpcProvider): SubstrateClient => {\n const cached = clientCache.get(provider)\n if (cached) {\n cached.refCount++\n return cached.client\n }\n\n const { request, disconnect } = createRawClient(provider)\n const destroy = () => {\n const cached = clientCache.get(provider)\n if (!cached || cached.refCount <= 1) {\n clientCache.delete(provider)\n disconnect()\n } else {\n cached.refCount--\n }\n }\n const client: SubstrateClient = {\n archive: getArchive(request),\n chainHead: getChainHead(request),\n transaction: getTransaction(request),\n getChainSpecData: createGetChainSpec(request),\n destroy,\n request: abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => request(method, params, { onSuccess, onError }),\n ),\n _request: request,\n }\n clientCache.set(provider, { client, refCount: 1 })\n return client\n}\n"],"names":["createRawClient","cached"],"mappings":";;;;;;;AA6BA,MAAM,WAAA,uBAAkB,GAGtB,EAAA;AAEW,MAAA,YAAA,GAAe,CAAC,QAA+C,KAAA;AAC1E,EAAM,MAAA,MAAA,GAAS,WAAY,CAAA,GAAA,CAAI,QAAQ,CAAA;AACvC,EAAA,IAAI,MAAQ,EAAA;AACV,IAAO,MAAA,CAAA,QAAA,EAAA;AACP,IAAA,OAAO,MAAO,CAAA,MAAA;AAAA;AAGhB,EAAA,MAAM,EAAE,OAAA,EAAS,UAAW,EAAA,GAAIA,eAAgB,QAAQ,CAAA;AACxD,EAAA,MAAM,UAAU,MAAM;AACpB,IAAMC,MAAAA,OAAAA,GAAS,WAAY,CAAA,GAAA,CAAI,QAAQ,CAAA;AACvC,IAAA,IAAI,CAACA,OAAAA,IAAUA,OAAO,CAAA,QAAA,IAAY,CAAG,EAAA;AACnC,MAAA,WAAA,CAAY,OAAO,QAAQ,CAAA;AAC3B,MAAW,UAAA,EAAA;AAAA,KACN,MAAA;AACL,MAAAA,OAAO,CAAA,QAAA,EAAA;AAAA;AACT,GACF;AACA,EAAA,MAAM,MAA0B,GAAA;AAAA,IAC9B,OAAA,EAAS,WAAW,OAAO,CAAA;AAAA,IAC3B,SAAA,EAAW,aAAa,OAAO,CAAA;AAAA,IAC/B,WAAA,EAAa,eAAe,OAAO,CAAA;AAAA,IACnC,gBAAA,EAAkB,mBAAmB,OAAO,CAAA;AAAA,IAC5C,OAAA;AAAA,IACA,OAAS,EAAA,kBAAA;AAAA,MACP,CACE,SACA,EAAA,OAAA,EACA,MACA,EAAA,MAAA,KACG,OAAQ,CAAA,MAAA,EAAQ,MAAQ,EAAA,EAAE,SAAW,EAAA,OAAA,EAAS;AAAA,KACrD;AAAA,IACA,QAAU,EAAA;AAAA,GACZ;AACA,EAAA,WAAA,CAAY,IAAI,QAAU,EAAA,EAAE,MAAQ,EAAA,QAAA,EAAU,GAAG,CAAA;AACjD,EAAO,OAAA,MAAA;AACT;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
export { AbortError } from '@polkadot-api/utils';
|
|
1
2
|
import { JsonRpcProvider } from '@polkadot-api/json-rpc-provider';
|
|
2
3
|
export * from '@polkadot-api/json-rpc-provider';
|
|
3
|
-
|
|
4
|
+
|
|
5
|
+
type UnsubscribeFn = () => void;
|
|
6
|
+
type WithAbortSignal<T extends Array<any>> = [
|
|
7
|
+
...args: T,
|
|
8
|
+
abortSignal?: AbortSignal
|
|
9
|
+
];
|
|
10
|
+
type AbortablePromiseFn<A extends Array<any>, T> = (...args: WithAbortSignal<A>) => Promise<T>;
|
|
4
11
|
|
|
5
12
|
interface IRpcError {
|
|
6
13
|
code: number;
|
|
@@ -13,13 +20,6 @@ declare class RpcError extends Error implements IRpcError {
|
|
|
13
20
|
constructor(e: IRpcError);
|
|
14
21
|
}
|
|
15
22
|
|
|
16
|
-
type UnsubscribeFn = () => void;
|
|
17
|
-
type WithAbortSignal<T extends Array<any>> = [
|
|
18
|
-
...args: T,
|
|
19
|
-
abortSignal?: AbortSignal
|
|
20
|
-
];
|
|
21
|
-
type AbortablePromiseFn<A extends Array<any>, T> = (...args: WithAbortSignal<A>) => Promise<T>;
|
|
22
|
-
|
|
23
23
|
interface Subscriber<T> {
|
|
24
24
|
next: (data: T) => void;
|
|
25
25
|
error: (e: Error) => void;
|
|
@@ -40,6 +40,10 @@ declare class DestroyedError extends Error {
|
|
|
40
40
|
constructor();
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
type Transaction = (tx: string, error: (e: Error) => void) => UnsubscribeFn;
|
|
44
|
+
|
|
45
|
+
declare const getTransaction: (request: ClientRequest<string, any>) => (tx: string, error: (e: Error) => void) => () => void;
|
|
46
|
+
|
|
43
47
|
type FollowInnerSubscriptionCb<T> = (subscriptionId: string, cb: Subscriber<T>) => UnsubscribeFn;
|
|
44
48
|
type ClientInnerRequestCb<T, TT> = {
|
|
45
49
|
onSuccess: (result: T, followSubscription: FollowInnerSubscriptionCb<TT>) => void;
|
|
@@ -212,10 +216,6 @@ type OperationEventsRpc = OperationBodyDoneRpc | OperationCallDoneRpc | Operatio
|
|
|
212
216
|
type FollowEventRpc = FollowEventWithRuntimeRpc | FollowEventWithoutRuntimeRpc | OperationEventsRpc | StopRpc;
|
|
213
217
|
declare function getChainHead(request: ClientRequest<string, FollowEventRpc>): ChainHead;
|
|
214
218
|
|
|
215
|
-
type Transaction = (tx: string, error: (e: Error) => void) => UnsubscribeFn;
|
|
216
|
-
|
|
217
|
-
declare const getTransaction: (request: ClientRequest<string, any>) => (tx: string, error: (e: Error) => void) => () => void;
|
|
218
|
-
|
|
219
219
|
interface ChainSpecData {
|
|
220
220
|
name: string;
|
|
221
221
|
genesisHash: string;
|
|
@@ -223,7 +223,37 @@ interface ChainSpecData {
|
|
|
223
223
|
}
|
|
224
224
|
declare const createGetChainSpec: (clientRequest: ClientRequest<any, any>) => () => Promise<ChainSpecData>;
|
|
225
225
|
|
|
226
|
+
type ArchiveStorageItemInput = StorageItemInput & {
|
|
227
|
+
paginationStartKey?: string;
|
|
228
|
+
};
|
|
229
|
+
interface Archive {
|
|
230
|
+
body: AbortablePromiseFn<[hash: string], Array<string>>;
|
|
231
|
+
call: AbortablePromiseFn<[
|
|
232
|
+
hash: string,
|
|
233
|
+
fnName: string,
|
|
234
|
+
callParameters: string
|
|
235
|
+
], string>;
|
|
236
|
+
header: AbortablePromiseFn<[hash: string], string>;
|
|
237
|
+
finalizedHeight: AbortablePromiseFn<[], number>;
|
|
238
|
+
hashByHeight: AbortablePromiseFn<[height: number], string[]>;
|
|
239
|
+
storage: <Type extends StorageItemInput["type"]>(hash: string, type: Type, key: string, childTrie: string | null, abortSignal?: AbortSignal | undefined) => Promise<StorageResult<Type>>;
|
|
240
|
+
storageSubscription: (hash: string, inputs: Array<ArchiveStorageItemInput>, childTrie: string | null, onItem: (item: StorageItemResponse) => void, onError: (e: Error) => void, onDone: () => void) => () => void;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
declare class BlockHashNotFoundError extends Error {
|
|
244
|
+
constructor(hash: string);
|
|
245
|
+
}
|
|
246
|
+
declare class StorageError extends Error {
|
|
247
|
+
constructor(message: string);
|
|
248
|
+
}
|
|
249
|
+
declare class CallError extends Error {
|
|
250
|
+
constructor(message: string);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
declare const getArchive: (request: ClientRequest<any, any>) => Archive;
|
|
254
|
+
|
|
226
255
|
interface SubstrateClient {
|
|
256
|
+
archive: Archive;
|
|
227
257
|
chainHead: ChainHead;
|
|
228
258
|
transaction: Transaction;
|
|
229
259
|
destroy: UnsubscribeFn;
|
|
@@ -233,4 +263,5 @@ interface SubstrateClient {
|
|
|
233
263
|
}
|
|
234
264
|
declare const createClient: (provider: JsonRpcProvider) => SubstrateClient;
|
|
235
265
|
|
|
236
|
-
export {
|
|
266
|
+
export { BlockHashNotFoundError, CallError, DestroyedError, DisjointError, OperationError, OperationInaccessibleError, OperationLimitError, RpcError, StopError, StorageError, createClient, createGetChainSpec, getArchive, getChainHead, getTransaction };
|
|
267
|
+
export type { AbortablePromiseFn, Archive, ArchiveStorageItemInput, BestBlockChanged, ChainHead, ChainSpecData, Client, ClientInnerRequest, ClientInnerRequestCb, ClientRequest, ClientRequestCb, Finalized, FollowEventWithRuntime, FollowEventWithoutRuntime, FollowInnerSubscriptionCb, FollowResponse, FollowSubscriptionCb, IRpcError, Initialized, InitializedWithRuntime$1 as InitializedWithRuntime, NewBlock, NewBlockWithRuntime$1 as NewBlockWithRuntime, Runtime, StorageItemInput, StorageItemResponse, StorageResult, SubstrateClient, Transaction, UnsubscribeFn };
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
var utils = require('@polkadot-api/utils');
|
|
4
4
|
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
|
+
class RpcError extends Error {
|
|
9
|
+
constructor(e) {
|
|
10
|
+
super(e.message);
|
|
11
|
+
__publicField(this, "code");
|
|
12
|
+
__publicField(this, "data");
|
|
13
|
+
this.code = e.code;
|
|
14
|
+
this.data = e.data;
|
|
15
|
+
this.name = "RpcError";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
5
19
|
const abortablePromiseFn = (fn) => (...args) => new Promise((res, rej) => {
|
|
6
20
|
let cancel = utils.noop;
|
|
7
21
|
const [actualArgs, abortSignal] = args[args.length - 1] instanceof AbortSignal ? [args.slice(0, args.length - 1), args[args.length - 1]] : [args];
|
|
@@ -63,49 +77,81 @@ const getSubscriptionsManager = () => {
|
|
|
63
77
|
};
|
|
64
78
|
};
|
|
65
79
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
follow: "",
|
|
71
|
-
header: "",
|
|
72
|
-
stopOperation: "",
|
|
73
|
-
storage: "",
|
|
74
|
-
unfollow: "",
|
|
75
|
-
unpin: "",
|
|
76
|
-
followEvent: ""
|
|
77
|
-
};
|
|
78
|
-
const chainSpec = {
|
|
79
|
-
chainName: "",
|
|
80
|
-
genesisHash: "",
|
|
81
|
-
properties: ""
|
|
82
|
-
};
|
|
83
|
-
const transaction = {
|
|
84
|
-
broadcast: "",
|
|
85
|
-
stop: ""
|
|
86
|
-
};
|
|
87
|
-
Object.entries({ chainHead, chainSpec, transaction }).forEach(
|
|
88
|
-
([fnGroupName, methods]) => {
|
|
89
|
-
Object.keys(methods).forEach((methodName) => {
|
|
90
|
-
methods[methodName] = `${fnGroupName}_v1_${methodName}`;
|
|
91
|
-
});
|
|
80
|
+
class DestroyedError extends Error {
|
|
81
|
+
constructor() {
|
|
82
|
+
super("Client destroyed");
|
|
83
|
+
this.name = "DestroyedError";
|
|
92
84
|
}
|
|
93
|
-
|
|
85
|
+
}
|
|
94
86
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
87
|
+
let nextClientId = 1;
|
|
88
|
+
const createClient$1 = (gProvider) => {
|
|
89
|
+
let clientId = nextClientId++;
|
|
90
|
+
const responses = /* @__PURE__ */ new Map();
|
|
91
|
+
const subscriptions = getSubscriptionsManager();
|
|
92
|
+
let connection = null;
|
|
93
|
+
const send = (id, method, params) => {
|
|
94
|
+
connection.send(
|
|
95
|
+
JSON.stringify({
|
|
96
|
+
jsonrpc: "2.0",
|
|
97
|
+
id,
|
|
98
|
+
method,
|
|
99
|
+
params
|
|
100
|
+
})
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
function onMessage(message) {
|
|
104
|
+
try {
|
|
105
|
+
let id, result, error, params, subscription;
|
|
106
|
+
const parsed = JSON.parse(message);
|
|
107
|
+
({ id, result, error, params } = parsed);
|
|
108
|
+
if (id) {
|
|
109
|
+
const cb = responses.get(id);
|
|
110
|
+
if (!cb) return;
|
|
111
|
+
responses.delete(id);
|
|
112
|
+
return error ? cb.onError(new RpcError(error)) : cb.onSuccess(result, (opaqueId, subscriber) => {
|
|
113
|
+
const subscriptionId2 = opaqueId;
|
|
114
|
+
subscriptions.subscribe(subscriptionId2, subscriber);
|
|
115
|
+
return () => {
|
|
116
|
+
subscriptions.unsubscribe(subscriptionId2);
|
|
117
|
+
};
|
|
118
|
+
});
|
|
103
119
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
120
|
+
;
|
|
121
|
+
({ subscription, result, error } = params);
|
|
122
|
+
if (!subscription || !error && !Object.hasOwn(params, "result")) throw 0;
|
|
123
|
+
const subscriptionId = subscription;
|
|
124
|
+
if (error) {
|
|
125
|
+
subscriptions.error(subscriptionId, new RpcError(error));
|
|
126
|
+
} else {
|
|
127
|
+
subscriptions.next(subscriptionId, result);
|
|
128
|
+
}
|
|
129
|
+
} catch (e) {
|
|
130
|
+
console.warn("Error parsing incomming message: " + message);
|
|
131
|
+
console.error(e);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
connection = gProvider(onMessage);
|
|
135
|
+
const disconnect = () => {
|
|
136
|
+
connection?.disconnect();
|
|
137
|
+
connection = null;
|
|
138
|
+
subscriptions.errorAll(new DestroyedError());
|
|
139
|
+
responses.forEach((r) => r.onError(new DestroyedError()));
|
|
140
|
+
responses.clear();
|
|
141
|
+
};
|
|
142
|
+
let nextId = 1;
|
|
143
|
+
const request = (method, params, cb) => {
|
|
144
|
+
if (!connection) throw new Error("Not connected");
|
|
145
|
+
const id = `${clientId}-${nextId++}`;
|
|
146
|
+
if (cb) responses.set(id, cb);
|
|
147
|
+
send(id, method, params);
|
|
148
|
+
return () => {
|
|
149
|
+
responses.delete(id);
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
return {
|
|
153
|
+
request,
|
|
154
|
+
disconnect
|
|
109
155
|
};
|
|
110
156
|
};
|
|
111
157
|
|
|
@@ -140,6 +186,35 @@ class OperationInaccessibleError extends Error {
|
|
|
140
186
|
}
|
|
141
187
|
}
|
|
142
188
|
|
|
189
|
+
const chainHead = {
|
|
190
|
+
body: "",
|
|
191
|
+
call: "",
|
|
192
|
+
continue: "",
|
|
193
|
+
follow: "",
|
|
194
|
+
header: "",
|
|
195
|
+
stopOperation: "",
|
|
196
|
+
storage: "",
|
|
197
|
+
unfollow: "",
|
|
198
|
+
unpin: "",
|
|
199
|
+
followEvent: ""
|
|
200
|
+
};
|
|
201
|
+
const chainSpec = {
|
|
202
|
+
chainName: "",
|
|
203
|
+
genesisHash: "",
|
|
204
|
+
properties: ""
|
|
205
|
+
};
|
|
206
|
+
const transaction = {
|
|
207
|
+
broadcast: "",
|
|
208
|
+
stop: ""
|
|
209
|
+
};
|
|
210
|
+
Object.entries({ chainHead, chainSpec, transaction }).forEach(
|
|
211
|
+
([fnGroupName, methods]) => {
|
|
212
|
+
Object.keys(methods).forEach((methodName) => {
|
|
213
|
+
methods[methodName] = `${fnGroupName}_v1_${methodName}`;
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
|
|
143
218
|
const createOperationPromise = (operationName, factory) => (request) => abortablePromiseFn((res, rej, ...args) => {
|
|
144
219
|
let isRunning = true;
|
|
145
220
|
let cancel = () => {
|
|
@@ -218,7 +293,7 @@ const createHeaderFn = (request) => (hash) => new Promise((res, rej) => {
|
|
|
218
293
|
});
|
|
219
294
|
});
|
|
220
295
|
|
|
221
|
-
const createStorageCb = (request) => (hash, inputs, childTrie, onItems, onError, onDone, onDiscardedItems) => {
|
|
296
|
+
const createStorageCb$1 = (request) => (hash, inputs, childTrie, onItems, onError, onDone, onDiscardedItems) => {
|
|
222
297
|
if (inputs.length === 0) {
|
|
223
298
|
onDone();
|
|
224
299
|
return utils.noop;
|
|
@@ -284,8 +359,8 @@ const createStorageCb = (request) => (hash, inputs, childTrie, onItems, onError,
|
|
|
284
359
|
};
|
|
285
360
|
};
|
|
286
361
|
|
|
287
|
-
const createStorageFn = (request) => {
|
|
288
|
-
const cbStore = createStorageCb(request);
|
|
362
|
+
const createStorageFn$1 = (request) => {
|
|
363
|
+
const cbStore = createStorageCb$1(request);
|
|
289
364
|
return abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => {
|
|
290
365
|
const isDescendants = type.startsWith("descendants");
|
|
291
366
|
let result = isDescendants ? [] : null;
|
|
@@ -327,13 +402,6 @@ const createUnpinFn = (request) => (hashes) => hashes.length > 0 ? new Promise((
|
|
|
327
402
|
});
|
|
328
403
|
}) : Promise.resolve();
|
|
329
404
|
|
|
330
|
-
class DestroyedError extends Error {
|
|
331
|
-
constructor() {
|
|
332
|
-
super("Client destroyed");
|
|
333
|
-
this.name = "DestroyedError";
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
405
|
function isOperationEvent(event) {
|
|
338
406
|
return event.operationId !== void 0;
|
|
339
407
|
}
|
|
@@ -455,96 +523,164 @@ function getChainHead(request) {
|
|
|
455
523
|
body: createBodyFn(fRequest),
|
|
456
524
|
call: createCallFn(fRequest),
|
|
457
525
|
header: createHeaderFn(fRequest),
|
|
458
|
-
storage: createStorageFn(fRequest),
|
|
459
|
-
storageSubscription: createStorageCb(fRequest),
|
|
526
|
+
storage: createStorageFn$1(fRequest),
|
|
527
|
+
storageSubscription: createStorageCb$1(fRequest),
|
|
460
528
|
unpin: createUnpinFn(fRequest),
|
|
461
529
|
_request: fRequest
|
|
462
530
|
};
|
|
463
531
|
};
|
|
464
532
|
}
|
|
465
533
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
this.
|
|
476
|
-
|
|
534
|
+
class BlockHashNotFoundError extends Error {
|
|
535
|
+
constructor(hash) {
|
|
536
|
+
super(`Invalid BlockHash: ${hash}`);
|
|
537
|
+
this.name = "BlockHashNotFoundError";
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
class StorageError extends Error {
|
|
541
|
+
constructor(message) {
|
|
542
|
+
super(`Storage Error: ${message}`);
|
|
543
|
+
this.name = "StorageError";
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
class CallError extends Error {
|
|
547
|
+
constructor(message) {
|
|
548
|
+
super(`Call Error: ${message}`);
|
|
549
|
+
this.name = "CallError";
|
|
477
550
|
}
|
|
478
551
|
}
|
|
479
552
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
const subscriptions = getSubscriptionsManager();
|
|
485
|
-
let connection = null;
|
|
486
|
-
const send = (id, method, params) => {
|
|
487
|
-
connection.send(
|
|
488
|
-
JSON.stringify({
|
|
489
|
-
jsonrpc: "2.0",
|
|
490
|
-
id,
|
|
491
|
-
method,
|
|
492
|
-
params
|
|
493
|
-
})
|
|
494
|
-
);
|
|
495
|
-
};
|
|
496
|
-
function onMessage(message) {
|
|
497
|
-
try {
|
|
498
|
-
let id, result, error, params, subscription;
|
|
499
|
-
const parsed = JSON.parse(message);
|
|
500
|
-
({ id, result, error, params } = parsed);
|
|
501
|
-
if (id) {
|
|
502
|
-
const cb = responses.get(id);
|
|
503
|
-
if (!cb) return;
|
|
504
|
-
responses.delete(id);
|
|
505
|
-
return error ? cb.onError(new RpcError(error)) : cb.onSuccess(result, (opaqueId, subscriber) => {
|
|
506
|
-
const subscriptionId2 = opaqueId;
|
|
507
|
-
subscriptions.subscribe(subscriptionId2, subscriber);
|
|
508
|
-
return () => {
|
|
509
|
-
subscriptions.unsubscribe(subscriptionId2);
|
|
510
|
-
};
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
;
|
|
514
|
-
({ subscription, result, error } = params);
|
|
515
|
-
if (!subscription || !error && !Object.hasOwn(params, "result")) throw 0;
|
|
516
|
-
const subscriptionId = subscription;
|
|
517
|
-
if (error) {
|
|
518
|
-
subscriptions.error(subscriptionId, new RpcError(error));
|
|
519
|
-
} else {
|
|
520
|
-
subscriptions.next(subscriptionId, result);
|
|
521
|
-
}
|
|
522
|
-
} catch (e) {
|
|
523
|
-
console.warn("Error parsing incomming message: " + message);
|
|
524
|
-
console.error(e);
|
|
525
|
-
}
|
|
553
|
+
const createStorageCb = (archiveRequest) => (hash, inputs, childTrie, onItem, onError, onDone) => {
|
|
554
|
+
if (inputs.length === 0) {
|
|
555
|
+
onDone();
|
|
556
|
+
return utils.noop;
|
|
526
557
|
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
connection = null;
|
|
531
|
-
subscriptions.errorAll(new DestroyedError());
|
|
532
|
-
responses.forEach((r) => r.onError(new DestroyedError()));
|
|
533
|
-
responses.clear();
|
|
558
|
+
let isRunning = true;
|
|
559
|
+
let cancel = () => {
|
|
560
|
+
isRunning = false;
|
|
534
561
|
};
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
562
|
+
archiveRequest("storage", [hash, inputs, childTrie], {
|
|
563
|
+
onSuccess: (operationId, followSubscription) => {
|
|
564
|
+
const stopOperation = () => {
|
|
565
|
+
archiveRequest("stopStorage", [operationId]);
|
|
566
|
+
};
|
|
567
|
+
if (!isRunning) return stopOperation();
|
|
568
|
+
const doneListening = followSubscription(operationId, {
|
|
569
|
+
next: (event) => {
|
|
570
|
+
const { event: type } = event;
|
|
571
|
+
if (type === "storage") {
|
|
572
|
+
const { event: _, ...item } = event;
|
|
573
|
+
onItem(item);
|
|
574
|
+
} else if (type === "storageDone") _onDone();
|
|
575
|
+
else _onError(new StorageError(event.error));
|
|
576
|
+
},
|
|
577
|
+
error: onError
|
|
578
|
+
});
|
|
579
|
+
const tearDown = () => {
|
|
580
|
+
cancel = utils.noop;
|
|
581
|
+
doneListening();
|
|
582
|
+
};
|
|
583
|
+
cancel = () => {
|
|
584
|
+
tearDown();
|
|
585
|
+
stopOperation();
|
|
586
|
+
};
|
|
587
|
+
const _onError = (e) => {
|
|
588
|
+
tearDown();
|
|
589
|
+
onError(e);
|
|
590
|
+
};
|
|
591
|
+
const _onDone = () => {
|
|
592
|
+
tearDown();
|
|
593
|
+
onDone();
|
|
594
|
+
};
|
|
595
|
+
},
|
|
596
|
+
onError
|
|
597
|
+
});
|
|
598
|
+
return () => {
|
|
599
|
+
cancel();
|
|
600
|
+
};
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
const createStorageFn = (cbStore) => abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => {
|
|
604
|
+
const isDescendants = type.startsWith("descendants");
|
|
605
|
+
let result = isDescendants ? [] : null;
|
|
606
|
+
const onItem = isDescendants ? result.push.bind(result) : ({ [type]: res }) => {
|
|
607
|
+
result = res;
|
|
544
608
|
};
|
|
609
|
+
return cbStore(
|
|
610
|
+
hash,
|
|
611
|
+
[{ key, type }],
|
|
612
|
+
childTrie,
|
|
613
|
+
onItem,
|
|
614
|
+
(e) => {
|
|
615
|
+
reject(e);
|
|
616
|
+
result = null;
|
|
617
|
+
},
|
|
618
|
+
() => {
|
|
619
|
+
resolve(result);
|
|
620
|
+
result = null;
|
|
621
|
+
}
|
|
622
|
+
);
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
const identity = () => (x) => x;
|
|
626
|
+
const handleInvalidBlockHash = () => (result, hash) => {
|
|
627
|
+
if (result === null) throw new BlockHashNotFoundError(hash);
|
|
628
|
+
return result;
|
|
629
|
+
};
|
|
630
|
+
const getArchive = (request) => {
|
|
631
|
+
const archiveRequest = (method, ...rest) => request(`archive_v1_${method}`, ...rest);
|
|
632
|
+
const fnCreator = (method) => (mapper) => abortablePromiseFn(
|
|
633
|
+
(res, rej, ...args) => archiveRequest(method, args, {
|
|
634
|
+
onSuccess: (x) => {
|
|
635
|
+
try {
|
|
636
|
+
res(mapper(x, ...args));
|
|
637
|
+
} catch (e) {
|
|
638
|
+
rej(e);
|
|
639
|
+
}
|
|
640
|
+
},
|
|
641
|
+
onError: rej
|
|
642
|
+
})
|
|
643
|
+
);
|
|
644
|
+
const header = fnCreator("header")(
|
|
645
|
+
handleInvalidBlockHash()
|
|
646
|
+
);
|
|
647
|
+
const body = fnCreator("body")(
|
|
648
|
+
handleInvalidBlockHash()
|
|
649
|
+
);
|
|
650
|
+
const storageSubscription = createStorageCb(archiveRequest);
|
|
651
|
+
const storage = createStorageFn(storageSubscription);
|
|
652
|
+
const call = fnCreator("call")((x, hash) => {
|
|
653
|
+
if (!x) throw new BlockHashNotFoundError(hash);
|
|
654
|
+
if (!x.success) throw new CallError(x.error);
|
|
655
|
+
return x.value;
|
|
656
|
+
});
|
|
657
|
+
const finalizedHeight = fnCreator("finalizedHeight")(identity());
|
|
658
|
+
const hashByHeight = fnCreator("hashByHeight")(identity());
|
|
545
659
|
return {
|
|
546
|
-
|
|
547
|
-
|
|
660
|
+
header,
|
|
661
|
+
body,
|
|
662
|
+
storageSubscription,
|
|
663
|
+
storage,
|
|
664
|
+
call,
|
|
665
|
+
finalizedHeight,
|
|
666
|
+
hashByHeight
|
|
667
|
+
};
|
|
668
|
+
};
|
|
669
|
+
|
|
670
|
+
const getTransaction = (request) => (tx, error) => {
|
|
671
|
+
let cancel = request(transaction.broadcast, [tx], {
|
|
672
|
+
onSuccess: (subscriptionId) => {
|
|
673
|
+
cancel = subscriptionId === null ? noop : () => {
|
|
674
|
+
request(transaction.stop, [subscriptionId]);
|
|
675
|
+
};
|
|
676
|
+
if (subscriptionId === null) {
|
|
677
|
+
error(new Error("Max # of broadcasted transactions has been reached"));
|
|
678
|
+
}
|
|
679
|
+
},
|
|
680
|
+
onError: error
|
|
681
|
+
});
|
|
682
|
+
return () => {
|
|
683
|
+
cancel();
|
|
548
684
|
};
|
|
549
685
|
};
|
|
550
686
|
|
|
@@ -585,6 +721,7 @@ const createClient = (provider) => {
|
|
|
585
721
|
}
|
|
586
722
|
};
|
|
587
723
|
const client = {
|
|
724
|
+
archive: getArchive(request),
|
|
588
725
|
chainHead: getChainHead(request),
|
|
589
726
|
transaction: getTransaction(request),
|
|
590
727
|
getChainSpecData: createGetChainSpec(request),
|
|
@@ -602,6 +739,8 @@ Object.defineProperty(exports, "AbortError", {
|
|
|
602
739
|
enumerable: true,
|
|
603
740
|
get: function () { return utils.AbortError; }
|
|
604
741
|
});
|
|
742
|
+
exports.BlockHashNotFoundError = BlockHashNotFoundError;
|
|
743
|
+
exports.CallError = CallError;
|
|
605
744
|
exports.DestroyedError = DestroyedError;
|
|
606
745
|
exports.DisjointError = DisjointError;
|
|
607
746
|
exports.OperationError = OperationError;
|
|
@@ -609,5 +748,6 @@ exports.OperationInaccessibleError = OperationInaccessibleError;
|
|
|
609
748
|
exports.OperationLimitError = OperationLimitError;
|
|
610
749
|
exports.RpcError = RpcError;
|
|
611
750
|
exports.StopError = StopError;
|
|
751
|
+
exports.StorageError = StorageError;
|
|
612
752
|
exports.createClient = createClient;
|
|
613
753
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/internal-utils/abortablePromiseFn.ts","../src/internal-utils/deferred-promise.ts","../src/internal-utils/noop.ts","../src/internal-utils/subscriptions-manager.ts","../src/methods.ts","../src/transaction/transaction.ts","../src/chainhead/errors.ts","../src/chainhead/operation-promise.ts","../src/chainhead/body.ts","../src/chainhead/call.ts","../src/chainhead/header.ts","../src/chainhead/storage-subscription.ts","../src/chainhead/storage.ts","../src/chainhead/unpin.ts","../src/client/DestroyedError.ts","../src/chainhead/chainhead.ts","../src/client/RpcError.ts","../src/client/createClient.ts","../src/chainspec.ts","../src/index.ts"],"sourcesContent":["import { AbortError, noop } from \"@polkadot-api/utils\"\nimport { AbortablePromiseFn } from \"../common-types\"\n\nexport const abortablePromiseFn =\n <T, A extends Array<any>>(\n fn: (\n ...args: [...[res: (x: T) => void, rej: (e: any) => void], ...A]\n ) => () => void,\n ): AbortablePromiseFn<A, T> =>\n (...args): Promise<T> =>\n new Promise((res, rej) => {\n let cancel = noop\n\n const [actualArgs, abortSignal] =\n args[args.length - 1] instanceof AbortSignal\n ? ([args.slice(0, args.length - 1), args[args.length - 1]] as [\n A,\n AbortSignal,\n ])\n : ([args] as unknown as [A])\n\n const onAbort = () => {\n cancel()\n rej(new AbortError())\n }\n\n abortSignal?.addEventListener(\"abort\", onAbort, { once: true })\n\n const withCleanup =\n <T>(fn: (x: T) => void): ((x: T) => void) =>\n (x) => {\n cancel = noop\n abortSignal?.removeEventListener(\"abort\", onAbort)\n fn(x)\n }\n\n cancel = fn(...[withCleanup(res), withCleanup(rej), ...actualArgs])\n })\n","export interface DeferredPromise<T> {\n promise: Promise<T>\n res: (value: T) => void\n rej: (err: Error) => void\n}\n\nexport function deferred<T>(): DeferredPromise<T> {\n let res: (value: T) => void = () => {}\n let rej: (err: Error) => void = () => {}\n\n const promise = new Promise<T>((_res, _rej) => {\n res = _res\n rej = _rej\n })\n\n return { promise, res, rej }\n}\n","export const noop = (): void => {}\n","export interface Subscriber<T> {\n next: (data: T) => void\n error: (e: Error) => void\n}\n\nexport const getSubscriptionsManager = <T>() => {\n const subscriptions = new Map<string, Subscriber<T>>()\n\n return {\n has: subscriptions.has.bind(subscriptions),\n subscribe(id: string, subscriber: Subscriber<T>) {\n subscriptions.set(id, subscriber)\n },\n unsubscribe(id: string) {\n subscriptions.delete(id)\n },\n next(id: string, data: T) {\n subscriptions.get(id)?.next(data)\n },\n error(id: string, e: Error) {\n const subscriber = subscriptions.get(id)\n if (subscriber) {\n subscriptions.delete(id)\n subscriber.error(e)\n }\n },\n errorAll(e: Error) {\n const subscribers = [...subscriptions.values()]\n subscriptions.clear()\n subscribers.forEach((s) => {\n s.error(e)\n })\n },\n }\n}\n\nexport type SubscriptionManager<T> = ReturnType<\n typeof getSubscriptionsManager<T>\n>\n","const chainHead = {\n body: \"\",\n call: \"\",\n continue: \"\",\n follow: \"\",\n header: \"\",\n stopOperation: \"\",\n storage: \"\",\n unfollow: \"\",\n unpin: \"\",\n followEvent: \"\",\n}\n\nconst chainSpec = {\n chainName: \"\",\n genesisHash: \"\",\n properties: \"\",\n}\n\nconst transaction = {\n broadcast: \"\",\n stop: \"\",\n}\n\nObject.entries({ chainHead, chainSpec, transaction }).forEach(\n ([fnGroupName, methods]) => {\n Object.keys(methods).forEach((methodName) => {\n ;(methods as any)[methodName] = `${fnGroupName}_v1_${methodName}`\n })\n },\n)\n\nexport { chainHead, transaction, chainSpec }\n","import { noop } from \"@/internal-utils\"\nimport { type ClientRequest } from \"../client\"\nimport { transaction } from \"@/methods\"\n\nexport const getTransaction =\n (request: ClientRequest<string, any>) =>\n (tx: string, error: (e: Error) => void) => {\n let cancel = request(transaction.broadcast, [tx], {\n onSuccess: (subscriptionId) => {\n cancel =\n subscriptionId === null\n ? noop\n : () => {\n request(transaction.stop, [subscriptionId])\n }\n\n if (subscriptionId === null) {\n error(new Error(\"Max # of broadcasted transactions has been reached\"))\n }\n },\n onError: error,\n })\n\n return () => {\n cancel()\n }\n }\n","export class StopError extends Error {\n constructor() {\n super(\"ChainHead stopped\")\n this.name = \"StopError\"\n }\n}\n\nexport class DisjointError extends Error {\n constructor() {\n super(\"ChainHead disjointed\")\n this.name = \"DisjointError\"\n }\n}\n\nexport class OperationLimitError extends Error {\n constructor() {\n super(\"ChainHead operations limit reached\")\n this.name = \"OperationLimitError\"\n }\n}\n\nexport class OperationError extends Error {\n constructor(error: string) {\n super(error)\n this.name = \"OperationError\"\n }\n}\n\nexport class OperationInaccessibleError extends Error {\n constructor() {\n super(\"ChainHead operation inaccessible\")\n this.name = \"OperationInaccessibleError\"\n }\n}\n","import { abortablePromiseFn, noop } from \"@/internal-utils\"\nimport {\n CommonOperationEventsRpc,\n OperationResponseRpc,\n} from \"./json-rpc-types\"\nimport {\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./errors\"\nimport { ClientInnerRequest } from \"./public-types\"\nimport { chainHead } from \"@/methods\"\n\nexport const createOperationPromise =\n <I extends { operationId: string; event: string }, O, A extends Array<any>>(\n operationName: string,\n factory: (\n ...args: A\n ) => [\n Array<any>,\n (e: I, res: (x: O) => void, rej: (e: Error) => void) => void,\n ],\n ) =>\n (\n request: ClientInnerRequest<\n OperationResponseRpc,\n I | CommonOperationEventsRpc\n >,\n ) =>\n abortablePromiseFn<O, A>((res, rej, ...args) => {\n let isRunning = true\n let cancel = () => {\n isRunning = false\n }\n\n const [requestArgs, logicCb] = factory(...args)\n request(operationName, requestArgs, {\n onSuccess: (response, followSubscription) => {\n if (response.result === \"limitReached\")\n return rej(new OperationLimitError())\n\n const { operationId } = response\n const stopOperation = () => {\n request(chainHead.stopOperation, [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n let done = noop\n const _res = (x: O) => {\n isRunning = false\n done()\n res(x)\n }\n const _rej = (x: Error) => {\n isRunning = false\n done()\n rej(x)\n }\n\n done = followSubscription(operationId, {\n next: (e) => {\n const _e = e as CommonOperationEventsRpc\n if (_e.event === \"operationError\")\n rej(new OperationError(_e.error))\n else if (_e.event === \"operationInaccessible\")\n rej(new OperationInaccessibleError())\n else logicCb(e as I, _res, _rej)\n },\n error: _rej,\n })\n\n cancel = () => {\n if (isRunning) {\n done()\n stopOperation()\n }\n }\n },\n onError: rej,\n })\n\n return () => {\n cancel()\n }\n })\n","import { chainHead } from \"@/methods\"\nimport type { OperationBodyDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createBodyFn = createOperationPromise(\n chainHead.body,\n (hash: string) => [\n [hash],\n (e: OperationBodyDoneRpc, res: (x: Array<string>) => void) => {\n res(e.value)\n },\n ],\n)\n","import { chainHead } from \"@/methods\"\nimport type { OperationCallDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createCallFn = createOperationPromise(\n chainHead.call,\n (hash: string, fnName: string, callParameters: string) => [\n [hash, fnName, callParameters],\n (e: OperationCallDoneRpc, res: (output: string) => void) => {\n res(e.output)\n },\n ],\n)\n","import { chainHead } from \"@/methods\"\nimport { ClientInnerRequest } from \"./public-types\"\n\nexport const createHeaderFn =\n (request: ClientInnerRequest<string, unknown>) => (hash: string) =>\n new Promise<string>((res, rej) => {\n request(chainHead.header, [hash], {\n onSuccess: res,\n onError: rej,\n })\n })\n","import { noop } from \"@polkadot-api/utils\"\nimport type { ClientInnerRequest, FollowResponse } from \"./public-types\"\nimport {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { chainHead } from \"@/methods\"\nimport {\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./errors\"\n\nexport const createStorageCb =\n (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n ): FollowResponse[\"storageSubscription\"] =>\n (hash, inputs, childTrie, onItems, onError, onDone, onDiscardedItems) => {\n if (inputs.length === 0) {\n onDone()\n return noop\n }\n\n let isRunning = true\n let cancel = () => {\n isRunning = false\n }\n\n request(chainHead.storage, [hash, inputs, childTrie], {\n onSuccess: (response, followSubscription) => {\n if (\n response.result === \"limitReached\" ||\n response.discardedItems === inputs.length\n )\n return onError(new OperationLimitError())\n\n const { operationId } = response\n const stopOperation = () => {\n request(chainHead.stopOperation, [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n const doneListening = followSubscription(response.operationId, {\n next: (event) => {\n switch (event.event) {\n case \"operationStorageItems\": {\n onItems(event.items)\n break\n }\n case \"operationStorageDone\": {\n _onDone()\n break\n }\n case \"operationError\": {\n _onError(new OperationError(event.error))\n break\n }\n case \"operationInaccessible\": {\n _onError(new OperationInaccessibleError())\n break\n }\n default:\n request(chainHead.continue, [event.operationId])\n }\n },\n error: onError,\n })\n\n cancel = () => {\n doneListening()\n request(chainHead.stopOperation, [response.operationId])\n }\n\n const _onError = (e: Error) => {\n cancel = noop\n doneListening()\n onError(e)\n }\n\n const _onDone = () => {\n cancel = noop\n doneListening()\n onDone()\n }\n\n onDiscardedItems(response.discardedItems)\n },\n onError,\n })\n\n return () => {\n cancel()\n }\n }\n","import { OperationLimitError } from \"./errors\"\nimport type {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { abortablePromiseFn } from \"@/internal-utils\"\nimport { createStorageCb } from \"./storage-subscription\"\nimport type { ClientInnerRequest, FollowResponse } from \"./public-types\"\n\nexport const createStorageFn = (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n): FollowResponse[\"storage\"] => {\n const cbStore = createStorageCb(request)\n return abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => {\n const isDescendants = type.startsWith(\"descendants\")\n let result: any = isDescendants ? [] : null\n\n const onItems: Parameters<typeof cbStore>[3] = isDescendants\n ? (items) => {\n result.push(items)\n }\n : (items) => {\n result = items[0]?.[type as \"value\"]\n }\n\n const cancel = cbStore(\n hash,\n [{ key, type }],\n childTrie ?? null,\n onItems,\n reject,\n () => {\n try {\n resolve(isDescendants ? result.flat() : result)\n } catch (e) {\n reject(e)\n }\n },\n (nDiscarded) => {\n if (nDiscarded > 0) {\n cancel()\n reject(new OperationLimitError())\n }\n },\n )\n return cancel\n })\n}\n","import { chainHead } from \"@/methods\"\nimport { ClientInnerRequest } from \"./public-types\"\n\nexport const createUnpinFn =\n (request: ClientInnerRequest<null, unknown>) => (hashes: string[]) =>\n hashes.length > 0\n ? new Promise<void>((res, rej) => {\n request(chainHead.unpin, [hashes], {\n onSuccess() {\n res()\n },\n onError: rej,\n })\n })\n : Promise.resolve()\n","export class DestroyedError extends Error {\n constructor() {\n super(\"Client destroyed\")\n this.name = \"DestroyedError\"\n }\n}\n","import type { ClientRequest, FollowSubscriptionCb } from \"@/client\"\nimport type {\n FollowEventWithRuntimeRpc,\n FollowEventWithoutRuntimeRpc,\n OperationEventsRpc,\n StopRpc,\n} from \"./json-rpc-types\"\nimport type {\n ChainHead,\n ClientInnerRequest,\n FollowEventWithoutRuntime,\n FollowEventWithRuntime,\n FollowResponse,\n} from \"./public-types\"\nimport {\n Subscriber,\n getSubscriptionsManager,\n noop,\n deferred,\n} from \"@/internal-utils\"\nimport { createBodyFn } from \"./body\"\nimport { createCallFn } from \"./call\"\nimport { createHeaderFn } from \"./header\"\nimport { createStorageFn } from \"./storage\"\nimport { createUnpinFn } from \"./unpin\"\nimport { DisjointError, StopError } from \"./errors\"\nimport { createStorageCb } from \"./storage-subscription\"\nimport { DestroyedError } from \"@/client/DestroyedError\"\nimport { chainHead } from \"@/methods\"\n\ntype FollowEventRpc =\n | FollowEventWithRuntimeRpc\n | FollowEventWithoutRuntimeRpc\n | OperationEventsRpc\n | StopRpc\n\nfunction isOperationEvent(event: FollowEventRpc): event is OperationEventsRpc {\n return (event as OperationEventsRpc).operationId !== undefined\n}\n\nexport function getChainHead(\n request: ClientRequest<string, FollowEventRpc>,\n): ChainHead {\n return (\n withRuntime: boolean,\n onFollowEvent:\n | ((event: FollowEventWithoutRuntime) => void)\n | ((event: FollowEventWithRuntime) => void),\n onFollowError: (e: Error) => void,\n ): FollowResponse => {\n const subscriptions = getSubscriptionsManager<OperationEventsRpc>()\n\n const ongoingRequests = new Set<() => void>()\n const deferredFollow = deferred<string | Error>()\n let followSubscription: Promise<string | Error> | string | null =\n deferredFollow.promise\n\n const onAllFollowEventsNext = (event: FollowEventRpc) => {\n if (isOperationEvent(event)) {\n if (!subscriptions.has(event.operationId))\n console.warn(\"Uknown operationId on\", event)\n\n return subscriptions.next(event.operationId, event)\n }\n\n if (event.event !== \"stop\") {\n if (event.event === \"initialized\") {\n return onFollowEvent({\n type: event.event,\n finalizedBlockHashes: event.finalizedBlockHashes,\n finalizedBlockRuntime: (event as any).finalizedBlockRuntime,\n })\n }\n\n const { event: type, ...rest } = event\n // This is kinda dangerous, but YOLO\n return onFollowEvent({ type, ...rest } as any)\n }\n\n onFollowError(new StopError())\n unfollow(false)\n }\n\n const onAllFollowEventsError = (error: Error) => {\n onFollowError(error)\n unfollow(!(error instanceof DestroyedError))\n }\n\n const onFollowRequestSuccess = (\n subscriptionId: string,\n follow: FollowSubscriptionCb<FollowEventRpc>,\n ) => {\n const done = follow(subscriptionId, {\n next: onAllFollowEventsNext,\n error: onAllFollowEventsError,\n })\n\n unfollow = (sendUnfollow = true) => {\n followSubscription = null\n unfollow = noop\n done()\n sendUnfollow && request(chainHead.unfollow, [subscriptionId])\n subscriptions.errorAll(new DisjointError())\n ongoingRequests.forEach((cb) => {\n cb()\n })\n ongoingRequests.clear()\n }\n\n followSubscription = subscriptionId\n deferredFollow.res(subscriptionId)\n }\n\n const onFollowRequestError = (e: Error) => {\n if (e instanceof DestroyedError) {\n unfollow(false)\n } else {\n onFollowError(e)\n }\n followSubscription = null\n deferredFollow.res(e)\n }\n\n let unfollow: (internal?: boolean) => void = request(\n chainHead.follow,\n [withRuntime],\n { onSuccess: onFollowRequestSuccess, onError: onFollowRequestError },\n )\n\n const fRequest: ClientInnerRequest<any, any> = (method, params, cb) => {\n const disjoint = () => {\n cb?.onError(new DisjointError())\n }\n\n if (followSubscription === null) {\n disjoint()\n return noop\n }\n\n const onSubscription = (subscription: string) => {\n if (!cb) return request(method, [subscription, ...params])\n\n ongoingRequests.add(disjoint)\n\n const onSubscribeOperation = (\n operationId: string,\n subscriber: Subscriber<any>,\n ) => {\n if (followSubscription === null) {\n subscriber.error(new DisjointError())\n return noop\n }\n\n subscriptions.subscribe(operationId, subscriber)\n\n return () => {\n subscriptions.unsubscribe(operationId)\n }\n }\n\n const cleanup = request(method, [subscription, ...params], {\n onSuccess: (response) => {\n ongoingRequests.delete(disjoint)\n cb.onSuccess(response, onSubscribeOperation)\n },\n onError: (e) => {\n ongoingRequests.delete(disjoint)\n cb.onError(e)\n },\n })\n\n return () => {\n ongoingRequests.delete(disjoint)\n cleanup()\n }\n }\n\n if (typeof followSubscription === \"string\")\n return onSubscription(followSubscription)\n\n let onCancel = noop\n followSubscription.then((x) => {\n if (x instanceof Error) return disjoint()\n if (followSubscription) onCancel = onSubscription(x)\n })\n\n return () => {\n onCancel()\n }\n }\n\n return {\n unfollow() {\n unfollow()\n followSubscription = null\n },\n body: createBodyFn(fRequest),\n call: createCallFn(fRequest),\n header: createHeaderFn(fRequest),\n storage: createStorageFn(fRequest),\n storageSubscription: createStorageCb(fRequest),\n unpin: createUnpinFn(fRequest),\n _request: fRequest,\n }\n }\n}\n","export interface IRpcError {\n code: number\n message: string\n data?: any\n}\n\nexport class RpcError extends Error implements IRpcError {\n code\n data\n constructor(e: IRpcError) {\n super(e.message)\n this.code = e.code\n this.data = e.data\n this.name = \"RpcError\"\n }\n}\n","import type {\n JsonRpcConnection,\n JsonRpcProvider,\n} from \"@polkadot-api/json-rpc-provider\"\nimport { UnsubscribeFn } from \"../common-types\"\nimport { RpcError, IRpcError } from \"./RpcError\"\nimport { getSubscriptionsManager, Subscriber } from \"@/internal-utils\"\nimport { DestroyedError } from \"./DestroyedError\"\n\nexport type FollowSubscriptionCb<T> = (\n subscriptionId: string,\n cb: Subscriber<T>,\n) => UnsubscribeFn\n\nexport type ClientRequestCb<T, TT> = {\n onSuccess: (result: T, followSubscription: FollowSubscriptionCb<TT>) => void\n onError: (e: Error) => void\n}\n\nexport type ClientRequest<T, TT> = (\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n) => UnsubscribeFn\n\nexport interface Client {\n disconnect: () => void\n request: ClientRequest<any, any>\n}\n\nlet nextClientId = 1\nexport const createClient = (gProvider: JsonRpcProvider): Client => {\n let clientId = nextClientId++\n const responses = new Map<string, ClientRequestCb<any, any>>()\n const subscriptions = getSubscriptionsManager()\n\n let connection: JsonRpcConnection | null = null\n\n const send = (\n id: string,\n method: string,\n params: Array<boolean | string | number | null>,\n ) => {\n connection!.send(\n JSON.stringify({\n jsonrpc: \"2.0\",\n id,\n method,\n params,\n }),\n )\n }\n\n function onMessage(message: string): void {\n try {\n let id: string,\n result,\n error: IRpcError | undefined,\n params: { subscription: any; result: any; error?: IRpcError },\n subscription: string\n\n const parsed = JSON.parse(message)\n ;({ id, result, error, params } = parsed)\n\n if (id) {\n const cb = responses.get(id)\n if (!cb) return\n\n responses.delete(id)\n\n return error\n ? cb.onError(new RpcError(error))\n : cb.onSuccess(result, (opaqueId, subscriber) => {\n const subscriptionId = opaqueId\n subscriptions.subscribe(subscriptionId, subscriber)\n return () => {\n subscriptions.unsubscribe(subscriptionId)\n }\n })\n }\n\n // at this point, it means that it should be a notification\n ;({ subscription, result, error } = params)\n if (!subscription || (!error && !Object.hasOwn(params, \"result\"))) throw 0\n\n const subscriptionId = subscription\n\n if (error) {\n subscriptions.error(subscriptionId, new RpcError(error!))\n } else {\n subscriptions.next(subscriptionId, result)\n }\n } catch (e) {\n console.warn(\"Error parsing incomming message: \" + message)\n console.error(e)\n }\n }\n connection = gProvider(onMessage)\n\n const disconnect = () => {\n connection?.disconnect()\n connection = null\n subscriptions.errorAll(new DestroyedError())\n responses.forEach((r) => r.onError(new DestroyedError()))\n responses.clear()\n }\n\n let nextId = 1\n const request = <T, TT>(\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n ): UnsubscribeFn => {\n if (!connection) throw new Error(\"Not connected\")\n const id = `${clientId}-${nextId++}`\n\n if (cb) responses.set(id, cb)\n send(id, method, params)\n\n return (): void => {\n responses.delete(id)\n }\n }\n\n return {\n request,\n disconnect,\n }\n}\n","import { ClientRequest } from \"./client\"\nimport { abortablePromiseFn } from \"./internal-utils\"\nimport { chainSpec } from \"./methods\"\n\nexport interface ChainSpecData {\n name: string\n genesisHash: string\n properties: any\n}\n\nexport const createGetChainSpec = (clientRequest: ClientRequest<any, any>) => {\n const request = abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => clientRequest(method, params, { onSuccess, onError }),\n )\n let cachedPromise: null | Promise<ChainSpecData> = null\n\n return async (): Promise<ChainSpecData> => {\n if (cachedPromise) return cachedPromise\n return (cachedPromise = Promise.all([\n request<string>(chainSpec.chainName, []),\n request<string>(chainSpec.genesisHash, []),\n request<any>(chainSpec.properties, []),\n ]).then(([name, genesisHash, properties]) => ({\n name,\n genesisHash,\n properties,\n })))\n }\n}\n","import type { JsonRpcProvider } from \"@polkadot-api/json-rpc-provider\"\nimport { getTransaction } from \"./transaction/transaction\"\nimport { getChainHead } from \"./chainhead\"\nimport { ClientRequestCb, createClient as createRawClient } from \"./client\"\nimport type { ChainHead } from \"./chainhead\"\nimport type { Transaction } from \"./transaction\"\nimport { UnsubscribeFn } from \"./common-types\"\nimport { abortablePromiseFn } from \"./internal-utils\"\nimport { ChainSpecData, createGetChainSpec } from \"./chainspec\"\n\nexport { AbortError } from \"@polkadot-api/utils\"\nexport type * from \"@polkadot-api/json-rpc-provider\"\n\nexport type * from \"./common-types\"\nexport type * from \"./client\"\nexport type * from \"./transaction\"\nexport type * from \"./chainhead\"\nexport type * from \"./chainspec\"\n\nexport { RpcError, DestroyedError } from \"./client\"\nexport {\n StopError,\n DisjointError,\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./chainhead\"\n\nexport interface SubstrateClient {\n chainHead: ChainHead\n transaction: Transaction\n destroy: UnsubscribeFn\n getChainSpecData: () => Promise<ChainSpecData>\n request: <T>(\n method: string,\n params: any[],\n abortSignal?: AbortSignal,\n ) => Promise<T>\n _request: <Reply, Notification>(\n method: string,\n params: any[],\n cb?: ClientRequestCb<Reply, Notification>,\n ) => UnsubscribeFn\n}\n\nconst clientCache = new Map<\n JsonRpcProvider,\n { client: SubstrateClient; refCount: number }\n>()\n\nexport const createClient = (provider: JsonRpcProvider): SubstrateClient => {\n const cached = clientCache.get(provider)\n if (cached) {\n cached.refCount++\n return cached.client\n }\n\n const { request, disconnect } = createRawClient(provider)\n const destroy = () => {\n const cached = clientCache.get(provider)\n if (!cached || cached.refCount <= 1) {\n clientCache.delete(provider)\n disconnect()\n } else {\n cached.refCount--\n }\n }\n const client: SubstrateClient = {\n chainHead: getChainHead(request),\n transaction: getTransaction(request),\n getChainSpecData: createGetChainSpec(request),\n destroy,\n request: abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => request(method, params, { onSuccess, onError }),\n ),\n _request: request,\n }\n clientCache.set(provider, { client, refCount: 1 })\n return client\n}\n"],"names":["noop","AbortError","fn","createClient","subscriptionId","createRawClient","cached"],"mappings":";;;;AAGa,MAAA,kBAAA,GACX,CACE,EAIF,KAAA,CAAA,GAAI,SACF,IAAI,OAAA,CAAQ,CAAC,GAAA,EAAK,GAAQ,KAAA;AACxB,EAAA,IAAI,MAAS,GAAAA,UAAA;AAEb,EAAM,MAAA,CAAC,UAAY,EAAA,WAAW,CAC5B,GAAA,IAAA,CAAK,KAAK,MAAS,GAAA,CAAC,CAAa,YAAA,WAAA,GAC5B,CAAC,IAAA,CAAK,MAAM,CAAG,EAAA,IAAA,CAAK,MAAS,GAAA,CAAC,CAAG,EAAA,IAAA,CAAK,IAAK,CAAA,MAAA,GAAS,CAAC,CAAC,CAItD,GAAA,CAAC,IAAI,CAAA;AAEZ,EAAA,MAAM,UAAU,MAAM;AACpB,IAAO,MAAA,EAAA;AACP,IAAI,GAAA,CAAA,IAAIC,kBAAY,CAAA;AAAA,GACtB;AAEA,EAAA,WAAA,EAAa,iBAAiB,OAAS,EAAA,OAAA,EAAS,EAAE,IAAA,EAAM,MAAM,CAAA;AAE9D,EAAA,MAA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E,MAAQ,EAAA,QAAA,EAAU,GAAG,CAAA;AACjD,EAAO,OAAA,MAAA;AACT;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/client/RpcError.ts","../src/internal-utils/abortablePromiseFn.ts","../src/internal-utils/deferred-promise.ts","../src/internal-utils/noop.ts","../src/internal-utils/subscriptions-manager.ts","../src/client/DestroyedError.ts","../src/client/createClient.ts","../src/chainhead/errors.ts","../src/methods.ts","../src/chainhead/operation-promise.ts","../src/chainhead/body.ts","../src/chainhead/call.ts","../src/chainhead/header.ts","../src/chainhead/storage-subscription.ts","../src/chainhead/storage.ts","../src/chainhead/unpin.ts","../src/chainhead/chainhead.ts","../src/archive/errors.ts","../src/archive/storage-subscription.ts","../src/archive/storage.ts","../src/archive/archive.ts","../src/transaction/transaction.ts","../src/chainspec.ts","../src/substrate-client.ts"],"sourcesContent":["export interface IRpcError {\n code: number\n message: string\n data?: any\n}\n\nexport class RpcError extends Error implements IRpcError {\n code\n data\n constructor(e: IRpcError) {\n super(e.message)\n this.code = e.code\n this.data = e.data\n this.name = \"RpcError\"\n }\n}\n","import { AbortError, noop } from \"@polkadot-api/utils\"\nimport { AbortablePromiseFn } from \"../common-types\"\n\nexport const abortablePromiseFn =\n <T, A extends Array<any>>(\n fn: (\n ...args: [...[res: (x: T) => void, rej: (e: any) => void], ...A]\n ) => () => void,\n ): AbortablePromiseFn<A, T> =>\n (...args): Promise<T> =>\n new Promise((res, rej) => {\n let cancel = noop\n\n const [actualArgs, abortSignal] =\n args[args.length - 1] instanceof AbortSignal\n ? ([args.slice(0, args.length - 1), args[args.length - 1]] as [\n A,\n AbortSignal,\n ])\n : ([args] as unknown as [A])\n\n const onAbort = () => {\n cancel()\n rej(new AbortError())\n }\n\n abortSignal?.addEventListener(\"abort\", onAbort, { once: true })\n\n const withCleanup =\n <T>(fn: (x: T) => void): ((x: T) => void) =>\n (x) => {\n cancel = noop\n abortSignal?.removeEventListener(\"abort\", onAbort)\n fn(x)\n }\n\n cancel = fn(...[withCleanup(res), withCleanup(rej), ...actualArgs])\n })\n","export interface DeferredPromise<T> {\n promise: Promise<T>\n res: (value: T) => void\n rej: (err: Error) => void\n}\n\nexport function deferred<T>(): DeferredPromise<T> {\n let res: (value: T) => void = () => {}\n let rej: (err: Error) => void = () => {}\n\n const promise = new Promise<T>((_res, _rej) => {\n res = _res\n rej = _rej\n })\n\n return { promise, res, rej }\n}\n","export const noop = (): void => {}\n","export interface Subscriber<T> {\n next: (data: T) => void\n error: (e: Error) => void\n}\n\nexport const getSubscriptionsManager = <T>() => {\n const subscriptions = new Map<string, Subscriber<T>>()\n\n return {\n has: subscriptions.has.bind(subscriptions),\n subscribe(id: string, subscriber: Subscriber<T>) {\n subscriptions.set(id, subscriber)\n },\n unsubscribe(id: string) {\n subscriptions.delete(id)\n },\n next(id: string, data: T) {\n subscriptions.get(id)?.next(data)\n },\n error(id: string, e: Error) {\n const subscriber = subscriptions.get(id)\n if (subscriber) {\n subscriptions.delete(id)\n subscriber.error(e)\n }\n },\n errorAll(e: Error) {\n const subscribers = [...subscriptions.values()]\n subscriptions.clear()\n subscribers.forEach((s) => {\n s.error(e)\n })\n },\n }\n}\n\nexport type SubscriptionManager<T> = ReturnType<\n typeof getSubscriptionsManager<T>\n>\n","export class DestroyedError extends Error {\n constructor() {\n super(\"Client destroyed\")\n this.name = \"DestroyedError\"\n }\n}\n","import type {\n JsonRpcConnection,\n JsonRpcProvider,\n} from \"@polkadot-api/json-rpc-provider\"\nimport { UnsubscribeFn } from \"../common-types\"\nimport { RpcError, IRpcError } from \"./RpcError\"\nimport { getSubscriptionsManager, Subscriber } from \"@/internal-utils\"\nimport { DestroyedError } from \"./DestroyedError\"\n\nexport type FollowSubscriptionCb<T> = (\n subscriptionId: string,\n cb: Subscriber<T>,\n) => UnsubscribeFn\n\nexport type ClientRequestCb<T, TT> = {\n onSuccess: (result: T, followSubscription: FollowSubscriptionCb<TT>) => void\n onError: (e: Error) => void\n}\n\nexport type ClientRequest<T, TT> = (\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n) => UnsubscribeFn\n\nexport interface Client {\n disconnect: () => void\n request: ClientRequest<any, any>\n}\n\nlet nextClientId = 1\nexport const createClient = (gProvider: JsonRpcProvider): Client => {\n let clientId = nextClientId++\n const responses = new Map<string, ClientRequestCb<any, any>>()\n const subscriptions = getSubscriptionsManager()\n\n let connection: JsonRpcConnection | null = null\n\n const send = (\n id: string,\n method: string,\n params: Array<boolean | string | number | null>,\n ) => {\n connection!.send(\n JSON.stringify({\n jsonrpc: \"2.0\",\n id,\n method,\n params,\n }),\n )\n }\n\n function onMessage(message: string): void {\n try {\n let id: string,\n result,\n error: IRpcError | undefined,\n params: { subscription: any; result: any; error?: IRpcError },\n subscription: string\n\n const parsed = JSON.parse(message)\n ;({ id, result, error, params } = parsed)\n\n if (id) {\n const cb = responses.get(id)\n if (!cb) return\n\n responses.delete(id)\n\n return error\n ? cb.onError(new RpcError(error))\n : cb.onSuccess(result, (opaqueId, subscriber) => {\n const subscriptionId = opaqueId\n subscriptions.subscribe(subscriptionId, subscriber)\n return () => {\n subscriptions.unsubscribe(subscriptionId)\n }\n })\n }\n\n // at this point, it means that it should be a notification\n ;({ subscription, result, error } = params)\n if (!subscription || (!error && !Object.hasOwn(params, \"result\"))) throw 0\n\n const subscriptionId = subscription\n\n if (error) {\n subscriptions.error(subscriptionId, new RpcError(error!))\n } else {\n subscriptions.next(subscriptionId, result)\n }\n } catch (e) {\n console.warn(\"Error parsing incomming message: \" + message)\n console.error(e)\n }\n }\n connection = gProvider(onMessage)\n\n const disconnect = () => {\n connection?.disconnect()\n connection = null\n subscriptions.errorAll(new DestroyedError())\n responses.forEach((r) => r.onError(new DestroyedError()))\n responses.clear()\n }\n\n let nextId = 1\n const request = <T, TT>(\n method: string,\n params: Array<any>,\n cb?: ClientRequestCb<T, TT>,\n ): UnsubscribeFn => {\n if (!connection) throw new Error(\"Not connected\")\n const id = `${clientId}-${nextId++}`\n\n if (cb) responses.set(id, cb)\n send(id, method, params)\n\n return (): void => {\n responses.delete(id)\n }\n }\n\n return {\n request,\n disconnect,\n }\n}\n","export class StopError extends Error {\n constructor() {\n super(\"ChainHead stopped\")\n this.name = \"StopError\"\n }\n}\n\nexport class DisjointError extends Error {\n constructor() {\n super(\"ChainHead disjointed\")\n this.name = \"DisjointError\"\n }\n}\n\nexport class OperationLimitError extends Error {\n constructor() {\n super(\"ChainHead operations limit reached\")\n this.name = \"OperationLimitError\"\n }\n}\n\nexport class OperationError extends Error {\n constructor(error: string) {\n super(error)\n this.name = \"OperationError\"\n }\n}\n\nexport class OperationInaccessibleError extends Error {\n constructor() {\n super(\"ChainHead operation inaccessible\")\n this.name = \"OperationInaccessibleError\"\n }\n}\n","const chainHead = {\n body: \"\",\n call: \"\",\n continue: \"\",\n follow: \"\",\n header: \"\",\n stopOperation: \"\",\n storage: \"\",\n unfollow: \"\",\n unpin: \"\",\n followEvent: \"\",\n}\n\nconst chainSpec = {\n chainName: \"\",\n genesisHash: \"\",\n properties: \"\",\n}\n\nconst transaction = {\n broadcast: \"\",\n stop: \"\",\n}\n\nObject.entries({ chainHead, chainSpec, transaction }).forEach(\n ([fnGroupName, methods]) => {\n Object.keys(methods).forEach((methodName) => {\n ;(methods as any)[methodName] = `${fnGroupName}_v1_${methodName}`\n })\n },\n)\n\nexport { chainHead, transaction, chainSpec }\n","import { abortablePromiseFn, noop } from \"@/internal-utils\"\nimport {\n CommonOperationEventsRpc,\n OperationResponseRpc,\n} from \"./json-rpc-types\"\nimport {\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./errors\"\nimport { ClientInnerRequest } from \"./public-types\"\nimport { chainHead } from \"@/methods\"\n\nexport const createOperationPromise =\n <I extends { operationId: string; event: string }, O, A extends Array<any>>(\n operationName: string,\n factory: (\n ...args: A\n ) => [\n Array<any>,\n (e: I, res: (x: O) => void, rej: (e: Error) => void) => void,\n ],\n ) =>\n (\n request: ClientInnerRequest<\n OperationResponseRpc,\n I | CommonOperationEventsRpc\n >,\n ) =>\n abortablePromiseFn<O, A>((res, rej, ...args) => {\n let isRunning = true\n let cancel = () => {\n isRunning = false\n }\n\n const [requestArgs, logicCb] = factory(...args)\n request(operationName, requestArgs, {\n onSuccess: (response, followSubscription) => {\n if (response.result === \"limitReached\")\n return rej(new OperationLimitError())\n\n const { operationId } = response\n const stopOperation = () => {\n request(chainHead.stopOperation, [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n let done = noop\n const _res = (x: O) => {\n isRunning = false\n done()\n res(x)\n }\n const _rej = (x: Error) => {\n isRunning = false\n done()\n rej(x)\n }\n\n done = followSubscription(operationId, {\n next: (e) => {\n const _e = e as CommonOperationEventsRpc\n if (_e.event === \"operationError\")\n rej(new OperationError(_e.error))\n else if (_e.event === \"operationInaccessible\")\n rej(new OperationInaccessibleError())\n else logicCb(e as I, _res, _rej)\n },\n error: _rej,\n })\n\n cancel = () => {\n if (isRunning) {\n done()\n stopOperation()\n }\n }\n },\n onError: rej,\n })\n\n return () => {\n cancel()\n }\n })\n","import { chainHead } from \"@/methods\"\nimport type { OperationBodyDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createBodyFn = createOperationPromise(\n chainHead.body,\n (hash: string) => [\n [hash],\n (e: OperationBodyDoneRpc, res: (x: Array<string>) => void) => {\n res(e.value)\n },\n ],\n)\n","import { chainHead } from \"@/methods\"\nimport type { OperationCallDoneRpc } from \"./json-rpc-types\"\nimport { createOperationPromise } from \"./operation-promise\"\n\nexport const createCallFn = createOperationPromise(\n chainHead.call,\n (hash: string, fnName: string, callParameters: string) => [\n [hash, fnName, callParameters],\n (e: OperationCallDoneRpc, res: (output: string) => void) => {\n res(e.output)\n },\n ],\n)\n","import { chainHead } from \"@/methods\"\nimport { ClientInnerRequest } from \"./public-types\"\n\nexport const createHeaderFn =\n (request: ClientInnerRequest<string, unknown>) => (hash: string) =>\n new Promise<string>((res, rej) => {\n request(chainHead.header, [hash], {\n onSuccess: res,\n onError: rej,\n })\n })\n","import { noop } from \"@polkadot-api/utils\"\nimport type { ClientInnerRequest, FollowResponse } from \"./public-types\"\nimport {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { chainHead } from \"@/methods\"\nimport {\n OperationError,\n OperationInaccessibleError,\n OperationLimitError,\n} from \"./errors\"\n\nexport const createStorageCb =\n (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n ): FollowResponse[\"storageSubscription\"] =>\n (hash, inputs, childTrie, onItems, onError, onDone, onDiscardedItems) => {\n if (inputs.length === 0) {\n onDone()\n return noop\n }\n\n let isRunning = true\n let cancel = () => {\n isRunning = false\n }\n\n request(chainHead.storage, [hash, inputs, childTrie], {\n onSuccess: (response, followSubscription) => {\n if (\n response.result === \"limitReached\" ||\n response.discardedItems === inputs.length\n )\n return onError(new OperationLimitError())\n\n const { operationId } = response\n const stopOperation = () => {\n request(chainHead.stopOperation, [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n const doneListening = followSubscription(response.operationId, {\n next: (event) => {\n switch (event.event) {\n case \"operationStorageItems\": {\n onItems(event.items)\n break\n }\n case \"operationStorageDone\": {\n _onDone()\n break\n }\n case \"operationError\": {\n _onError(new OperationError(event.error))\n break\n }\n case \"operationInaccessible\": {\n _onError(new OperationInaccessibleError())\n break\n }\n default:\n request(chainHead.continue, [event.operationId])\n }\n },\n error: onError,\n })\n\n cancel = () => {\n doneListening()\n request(chainHead.stopOperation, [response.operationId])\n }\n\n const _onError = (e: Error) => {\n cancel = noop\n doneListening()\n onError(e)\n }\n\n const _onDone = () => {\n cancel = noop\n doneListening()\n onDone()\n }\n\n onDiscardedItems(response.discardedItems)\n },\n onError,\n })\n\n return () => {\n cancel()\n }\n }\n","import { OperationLimitError } from \"./errors\"\nimport type {\n CommonOperationEventsRpc,\n LimitReachedRpc,\n OperationStorageDoneRpc,\n OperationStorageItemsRpc,\n OperationWaitingForContinueRpc,\n OperationStorageStartedRpc,\n} from \"./json-rpc-types\"\nimport { abortablePromiseFn } from \"@/internal-utils\"\nimport { createStorageCb } from \"./storage-subscription\"\nimport type { ClientInnerRequest, FollowResponse } from \"./public-types\"\n\nexport const createStorageFn = (\n request: ClientInnerRequest<\n OperationStorageStartedRpc | LimitReachedRpc,\n | CommonOperationEventsRpc\n | OperationStorageItemsRpc\n | OperationStorageDoneRpc\n | OperationWaitingForContinueRpc\n >,\n): FollowResponse[\"storage\"] => {\n const cbStore = createStorageCb(request)\n return abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => {\n const isDescendants = type.startsWith(\"descendants\")\n let result: any = isDescendants ? [] : null\n\n const onItems: Parameters<typeof cbStore>[3] = isDescendants\n ? (items) => {\n result.push(items)\n }\n : (items) => {\n result = items[0]?.[type as \"value\"]\n }\n\n const cancel = cbStore(\n hash,\n [{ key, type }],\n childTrie ?? null,\n onItems,\n reject,\n () => {\n try {\n resolve(isDescendants ? result.flat() : result)\n } catch (e) {\n reject(e)\n }\n },\n (nDiscarded) => {\n if (nDiscarded > 0) {\n cancel()\n reject(new OperationLimitError())\n }\n },\n )\n return cancel\n })\n}\n","import { chainHead } from \"@/methods\"\nimport { ClientInnerRequest } from \"./public-types\"\n\nexport const createUnpinFn =\n (request: ClientInnerRequest<null, unknown>) => (hashes: string[]) =>\n hashes.length > 0\n ? new Promise<void>((res, rej) => {\n request(chainHead.unpin, [hashes], {\n onSuccess() {\n res()\n },\n onError: rej,\n })\n })\n : Promise.resolve()\n","import type { ClientRequest, FollowSubscriptionCb } from \"@/client\"\nimport type {\n FollowEventWithRuntimeRpc,\n FollowEventWithoutRuntimeRpc,\n OperationEventsRpc,\n StopRpc,\n} from \"./json-rpc-types\"\nimport type {\n ChainHead,\n ClientInnerRequest,\n FollowEventWithoutRuntime,\n FollowEventWithRuntime,\n FollowResponse,\n} from \"./public-types\"\nimport {\n Subscriber,\n getSubscriptionsManager,\n noop,\n deferred,\n} from \"@/internal-utils\"\nimport { createBodyFn } from \"./body\"\nimport { createCallFn } from \"./call\"\nimport { createHeaderFn } from \"./header\"\nimport { createStorageFn } from \"./storage\"\nimport { createUnpinFn } from \"./unpin\"\nimport { DisjointError, StopError } from \"./errors\"\nimport { createStorageCb } from \"./storage-subscription\"\nimport { DestroyedError } from \"@/client/DestroyedError\"\nimport { chainHead } from \"@/methods\"\n\ntype FollowEventRpc =\n | FollowEventWithRuntimeRpc\n | FollowEventWithoutRuntimeRpc\n | OperationEventsRpc\n | StopRpc\n\nfunction isOperationEvent(event: FollowEventRpc): event is OperationEventsRpc {\n return (event as OperationEventsRpc).operationId !== undefined\n}\n\nexport function getChainHead(\n request: ClientRequest<string, FollowEventRpc>,\n): ChainHead {\n return (\n withRuntime: boolean,\n onFollowEvent:\n | ((event: FollowEventWithoutRuntime) => void)\n | ((event: FollowEventWithRuntime) => void),\n onFollowError: (e: Error) => void,\n ): FollowResponse => {\n const subscriptions = getSubscriptionsManager<OperationEventsRpc>()\n\n const ongoingRequests = new Set<() => void>()\n const deferredFollow = deferred<string | Error>()\n let followSubscription: Promise<string | Error> | string | null =\n deferredFollow.promise\n\n const onAllFollowEventsNext = (event: FollowEventRpc) => {\n if (isOperationEvent(event)) {\n if (!subscriptions.has(event.operationId))\n console.warn(\"Uknown operationId on\", event)\n\n return subscriptions.next(event.operationId, event)\n }\n\n if (event.event !== \"stop\") {\n if (event.event === \"initialized\") {\n return onFollowEvent({\n type: event.event,\n finalizedBlockHashes: event.finalizedBlockHashes,\n finalizedBlockRuntime: (event as any).finalizedBlockRuntime,\n })\n }\n\n const { event: type, ...rest } = event\n // This is kinda dangerous, but YOLO\n return onFollowEvent({ type, ...rest } as any)\n }\n\n onFollowError(new StopError())\n unfollow(false)\n }\n\n const onAllFollowEventsError = (error: Error) => {\n onFollowError(error)\n unfollow(!(error instanceof DestroyedError))\n }\n\n const onFollowRequestSuccess = (\n subscriptionId: string,\n follow: FollowSubscriptionCb<FollowEventRpc>,\n ) => {\n const done = follow(subscriptionId, {\n next: onAllFollowEventsNext,\n error: onAllFollowEventsError,\n })\n\n unfollow = (sendUnfollow = true) => {\n followSubscription = null\n unfollow = noop\n done()\n sendUnfollow && request(chainHead.unfollow, [subscriptionId])\n subscriptions.errorAll(new DisjointError())\n ongoingRequests.forEach((cb) => {\n cb()\n })\n ongoingRequests.clear()\n }\n\n followSubscription = subscriptionId\n deferredFollow.res(subscriptionId)\n }\n\n const onFollowRequestError = (e: Error) => {\n if (e instanceof DestroyedError) {\n unfollow(false)\n } else {\n onFollowError(e)\n }\n followSubscription = null\n deferredFollow.res(e)\n }\n\n let unfollow: (internal?: boolean) => void = request(\n chainHead.follow,\n [withRuntime],\n { onSuccess: onFollowRequestSuccess, onError: onFollowRequestError },\n )\n\n const fRequest: ClientInnerRequest<any, any> = (method, params, cb) => {\n const disjoint = () => {\n cb?.onError(new DisjointError())\n }\n\n if (followSubscription === null) {\n disjoint()\n return noop\n }\n\n const onSubscription = (subscription: string) => {\n if (!cb) return request(method, [subscription, ...params])\n\n ongoingRequests.add(disjoint)\n\n const onSubscribeOperation = (\n operationId: string,\n subscriber: Subscriber<any>,\n ) => {\n if (followSubscription === null) {\n subscriber.error(new DisjointError())\n return noop\n }\n\n subscriptions.subscribe(operationId, subscriber)\n\n return () => {\n subscriptions.unsubscribe(operationId)\n }\n }\n\n const cleanup = request(method, [subscription, ...params], {\n onSuccess: (response) => {\n ongoingRequests.delete(disjoint)\n cb.onSuccess(response, onSubscribeOperation)\n },\n onError: (e) => {\n ongoingRequests.delete(disjoint)\n cb.onError(e)\n },\n })\n\n return () => {\n ongoingRequests.delete(disjoint)\n cleanup()\n }\n }\n\n if (typeof followSubscription === \"string\")\n return onSubscription(followSubscription)\n\n let onCancel = noop\n followSubscription.then((x) => {\n if (x instanceof Error) return disjoint()\n if (followSubscription) onCancel = onSubscription(x)\n })\n\n return () => {\n onCancel()\n }\n }\n\n return {\n unfollow() {\n unfollow()\n followSubscription = null\n },\n body: createBodyFn(fRequest),\n call: createCallFn(fRequest),\n header: createHeaderFn(fRequest),\n storage: createStorageFn(fRequest),\n storageSubscription: createStorageCb(fRequest),\n unpin: createUnpinFn(fRequest),\n _request: fRequest,\n }\n }\n}\n","export class BlockHashNotFoundError extends Error {\n constructor(hash: string) {\n super(`Invalid BlockHash: ${hash}`)\n this.name = \"BlockHashNotFoundError\"\n }\n}\n\nexport class StorageError extends Error {\n constructor(message: string) {\n super(`Storage Error: ${message}`)\n this.name = \"StorageError\"\n }\n}\n\nexport class CallError extends Error {\n constructor(message: string) {\n super(`Call Error: ${message}`)\n this.name = \"CallError\"\n }\n}\n","import type { ClientRequest } from \"@/client\"\nimport { noop } from \"@polkadot-api/utils\"\nimport { Archive } from \"./public-types\"\nimport { StorageItemResponse } from \"@/chainhead\"\nimport { StorageError } from \"./errors\"\n\ntype StorageEvent = {\n event: \"storage\"\n} & StorageItemResponse\n\ntype StorageDone = {\n event: \"storageDone\"\n}\n\ntype StorageErrorEvent = {\n event: \"storageError\"\n error: string\n}\n\nexport const createStorageCb =\n (\n archiveRequest: ClientRequest<\n string,\n StorageEvent | StorageDone | StorageErrorEvent\n >,\n ): Archive[\"storageSubscription\"] =>\n (hash, inputs, childTrie, onItem, onError, onDone) => {\n if (inputs.length === 0) {\n onDone()\n return noop\n }\n\n let isRunning = true\n let cancel = () => {\n isRunning = false\n }\n\n archiveRequest(\"storage\", [hash, inputs, childTrie], {\n onSuccess: (operationId, followSubscription) => {\n const stopOperation = () => {\n archiveRequest(\"stopStorage\", [operationId])\n }\n\n if (!isRunning) return stopOperation()\n\n const doneListening = followSubscription(operationId, {\n next: (event) => {\n const { event: type } = event\n if (type === \"storage\") {\n const { event: _, ...item } = event\n onItem(item)\n } else if (type === \"storageDone\") _onDone()\n else _onError(new StorageError(event.error))\n },\n error: onError,\n })\n\n const tearDown = () => {\n cancel = noop\n doneListening()\n }\n\n cancel = () => {\n tearDown()\n stopOperation()\n }\n\n const _onError = (e: Error) => {\n tearDown()\n onError(e)\n }\n\n const _onDone = () => {\n tearDown()\n onDone()\n }\n },\n onError,\n })\n\n return () => {\n cancel()\n }\n }\n","import { abortablePromiseFn } from \"@/internal-utils\"\nimport type { Archive } from \"./public-types\"\n\nexport const createStorageFn = (\n cbStore: Archive[\"storageSubscription\"],\n): Archive[\"storage\"] =>\n abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => {\n const isDescendants = type.startsWith(\"descendants\")\n\n let result: any = isDescendants ? [] : null\n const onItem: Parameters<typeof cbStore>[3] = isDescendants\n ? result.push.bind(result)\n : ({ [type]: res }) => {\n result = res\n }\n\n return cbStore(\n hash,\n [{ key, type }],\n childTrie,\n onItem,\n (e) => {\n reject(e)\n result = null\n },\n () => {\n resolve(result)\n result = null\n },\n )\n })\n","import { abortablePromiseFn } from \"@/internal-utils\"\nimport { type ClientRequest } from \"../client\"\nimport { createStorageCb } from \"./storage-subscription\"\nimport { createStorageFn } from \"./storage\"\nimport { Archive } from \"./public-types\"\nimport { CallError, BlockHashNotFoundError } from \"./errors\"\n\nconst identity =\n <T>() =>\n (x: T): T =>\n x\n\nconst handleInvalidBlockHash =\n <T>() =>\n (result: T | null, hash: string): T => {\n if (result === null) throw new BlockHashNotFoundError(hash)\n return result\n }\n\nexport const getArchive = (request: ClientRequest<any, any>): Archive => {\n const archiveRequest: ClientRequest<any, any> = (method: string, ...rest) =>\n request(`archive_v1_${method}`, ...rest)\n\n const fnCreator =\n <A extends Array<any>>(method: string) =>\n <I, O>(mapper: (input: I, ...args: A) => O) =>\n abortablePromiseFn<O, A>((res, rej, ...args) =>\n archiveRequest(method, args, {\n onSuccess: (x: I) => {\n try {\n res(mapper(x, ...args))\n } catch (e) {\n rej(e)\n }\n },\n onError: rej,\n }),\n )\n\n const header = fnCreator<[hash: string]>(\"header\")(\n handleInvalidBlockHash<string>(),\n )\n\n const body = fnCreator<[hash: string]>(\"body\")(\n handleInvalidBlockHash<string[]>(),\n )\n\n const storageSubscription = createStorageCb(archiveRequest)\n const storage = createStorageFn(storageSubscription)\n\n const call = fnCreator<\n [hash: string, function: string, callParameters: string]\n >(\"call\")((\n x:\n | { success: true; value: string }\n | { success: false; error: string }\n | null,\n hash,\n ) => {\n if (!x) throw new BlockHashNotFoundError(hash)\n if (!x.success) throw new CallError(x.error)\n return x.value\n })\n\n const finalizedHeight = fnCreator<[]>(\"finalizedHeight\")(identity<number>())\n const hashByHeight =\n fnCreator<[height: number]>(\"hashByHeight\")(identity<string[]>())\n\n return {\n header,\n body,\n storageSubscription,\n storage,\n call,\n finalizedHeight,\n hashByHeight,\n }\n}\n","import { noop } from \"@/internal-utils\"\nimport { type ClientRequest } from \"../client\"\nimport { transaction } from \"@/methods\"\n\nexport const getTransaction =\n (request: ClientRequest<string, any>) =>\n (tx: string, error: (e: Error) => void) => {\n let cancel = request(transaction.broadcast, [tx], {\n onSuccess: (subscriptionId) => {\n cancel =\n subscriptionId === null\n ? noop\n : () => {\n request(transaction.stop, [subscriptionId])\n }\n\n if (subscriptionId === null) {\n error(new Error(\"Max # of broadcasted transactions has been reached\"))\n }\n },\n onError: error,\n })\n\n return () => {\n cancel()\n }\n }\n","import { ClientRequest } from \"./client\"\nimport { abortablePromiseFn } from \"./internal-utils\"\nimport { chainSpec } from \"./methods\"\n\nexport interface ChainSpecData {\n name: string\n genesisHash: string\n properties: any\n}\n\nexport const createGetChainSpec = (clientRequest: ClientRequest<any, any>) => {\n const request = abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => clientRequest(method, params, { onSuccess, onError }),\n )\n let cachedPromise: null | Promise<ChainSpecData> = null\n\n return async (): Promise<ChainSpecData> => {\n if (cachedPromise) return cachedPromise\n return (cachedPromise = Promise.all([\n request<string>(chainSpec.chainName, []),\n request<string>(chainSpec.genesisHash, []),\n request<any>(chainSpec.properties, []),\n ]).then(([name, genesisHash, properties]) => ({\n name,\n genesisHash,\n properties,\n })))\n }\n}\n","import type { JsonRpcProvider } from \"@polkadot-api/json-rpc-provider\"\nimport { getTransaction } from \"./transaction/transaction\"\nimport { getChainHead } from \"./chainhead\"\nimport { ClientRequestCb, createClient as createRawClient } from \"./client\"\nimport type { ChainHead } from \"./chainhead\"\nimport type { Transaction } from \"./transaction\"\nimport { UnsubscribeFn } from \"./common-types\"\nimport { abortablePromiseFn } from \"./internal-utils\"\nimport { ChainSpecData, createGetChainSpec } from \"./chainspec\"\nimport { Archive, getArchive } from \"./archive\"\n\nexport interface SubstrateClient {\n archive: Archive\n chainHead: ChainHead\n transaction: Transaction\n destroy: UnsubscribeFn\n getChainSpecData: () => Promise<ChainSpecData>\n request: <T>(\n method: string,\n params: any[],\n abortSignal?: AbortSignal,\n ) => Promise<T>\n _request: <Reply, Notification>(\n method: string,\n params: any[],\n cb?: ClientRequestCb<Reply, Notification>,\n ) => UnsubscribeFn\n}\n\nconst clientCache = new Map<\n JsonRpcProvider,\n { client: SubstrateClient; refCount: number }\n>()\n\nexport const createClient = (provider: JsonRpcProvider): SubstrateClient => {\n const cached = clientCache.get(provider)\n if (cached) {\n cached.refCount++\n return cached.client\n }\n\n const { request, disconnect } = createRawClient(provider)\n const destroy = () => {\n const cached = clientCache.get(provider)\n if (!cached || cached.refCount <= 1) {\n clientCache.delete(provider)\n disconnect()\n } else {\n cached.refCount--\n }\n }\n const client: SubstrateClient = {\n archive: getArchive(request),\n chainHead: getChainHead(request),\n transaction: getTransaction(request),\n getChainSpecData: createGetChainSpec(request),\n destroy,\n request: abortablePromiseFn(\n <T>(\n onSuccess: (value: T) => void,\n onError: (e: any) => void,\n method: string,\n params: any[],\n ) => request(method, params, { onSuccess, onError }),\n ),\n _request: request,\n }\n clientCache.set(provider, { client, refCount: 1 })\n return client\n}\n"],"names":["noop","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;AACA,EAAA,MAAM,MAA0B,GAAA;AAAA,IAC9B,OAAA,EAAS,WAAW,OAAO,CAAA;AAAA,IAC3B,SAAA,EAAW,aAAa,OAAO,CAAA;AAAA,IAC/B,WAAA,EAAa,eAAe,OAAO,CAAA;AAAA,IACnC,gBAAA,EAAkB,mBAAmB,OAAO,CAAA;AAAA,IAC5C,OAAA;AAAA,IACA,OAAS,EAAA,kBAAA;AAAA,MACP,CACE,SACA,EAAA,OAAA,EACA,MACA,EAAA,MAAA,KACG,OAAQ,CAAA,MAAA,EAAQ,MAAQ,EAAA,EAAE,SAAW,EAAA,OAAA,EAAS;AAAA,KACrD;AAAA,IACA,QAAU,EAAA;AAAA,GACZ;AACA,EAAA,WAAA,CAAY,IAAI,QAAU,EAAA,EAAE,MAAQ,EAAA,QAAA,EAAU,GAAG,CAAA;AACjD,EAAO,OAAA,MAAA;AACT;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polkadot-api/substrate-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"author": "Josep M Sobrepere (https://github.com/josepot)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"dist"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@polkadot-api/utils": "0.
|
|
38
|
+
"@polkadot-api/utils": "0.2.0",
|
|
39
39
|
"@polkadot-api/json-rpc-provider": "0.0.4"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|