Comparing version 2.0.18 to 2.0.19
@@ -69,3 +69,4 @@ "use strict"; | ||
connections: new Map(), | ||
addChainResults: [], | ||
addChainIdAllocations: [], | ||
addChainResults: new Map(), | ||
onExecutorShutdownOrWasmPanic: () => { }, | ||
@@ -89,6 +90,10 @@ chains: new Map(), | ||
state.connections.clear(); | ||
for (const addChainResult of state.addChainResults) { | ||
for (const addChainResult of state.addChainIdAllocations) { | ||
addChainResult({ success: false, error: "Smoldot has crashed" }); | ||
} | ||
state.addChainResults = []; | ||
state.addChainIdAllocations = []; | ||
state.addChainResults.forEach((addChainResult) => { | ||
addChainResult({ success: false, error: "Smoldot has crashed" }); | ||
}); | ||
state.addChainResults.clear(); | ||
for (const chain of Array.from(state.chains.values())) { | ||
@@ -116,4 +121,10 @@ for (const callback of chain.jsonRpcResponsesPromises) { | ||
} | ||
case "add-chain-id-allocated": { | ||
const callback = state.addChainIdAllocations.shift(); | ||
state.addChainResults.set(event.chainId, callback); | ||
break; | ||
} | ||
case "add-chain-result": { | ||
(state.addChainResults.shift())(event); | ||
(state.addChainResults.get(event.chainId))(event); | ||
state.addChainResults.delete(event.chainId); | ||
break; | ||
@@ -296,3 +307,3 @@ } | ||
throw new public_types_js_1.AddChainError("`databaseContent` is not a string"); | ||
const promise = new Promise((resolve) => state.addChainResults.push(resolve)); | ||
const promise = new Promise((resolve) => state.addChainIdAllocations.push(resolve)); | ||
state.instance.instance.addChain(options.chainSpec, options.databaseContent || "", potentialRelayChainsIds, !!options.disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions); | ||
@@ -378,6 +389,10 @@ const outcome = yield promise; | ||
state.connections.clear(); | ||
for (const addChainResult of state.addChainResults) { | ||
for (const addChainResult of state.addChainIdAllocations) { | ||
addChainResult({ success: false, error: "Client.terminate() has been called" }); | ||
} | ||
state.addChainResults = []; | ||
state.addChainIdAllocations = []; | ||
state.addChainResults.forEach((addChainResult) => { | ||
addChainResult({ success: false, error: "Client.terminate() has been called" }); | ||
}); | ||
state.addChainResults.clear(); | ||
for (const chain of Array.from(state.chains.values())) { | ||
@@ -384,0 +399,0 @@ for (const callback of chain.jsonRpcResponsesPromises) { |
@@ -33,7 +33,11 @@ /** | ||
export type Event = { | ||
ty: "add-chain-id-allocated"; | ||
chainId: number; | ||
} | { | ||
ty: "add-chain-result"; | ||
chainId: number; | ||
success: true; | ||
chainId: number; | ||
} | { | ||
ty: "add-chain-result"; | ||
chainId: number; | ||
success: false; | ||
@@ -96,2 +100,11 @@ error: string; | ||
peekJsonRpcResponse: (chainId: number) => string | null; | ||
/** | ||
* Later generates a `add-chain-id-allocated` event. | ||
* If this function is called multiple times, the `add-chain-id-allocated` events are generated | ||
* in the same order as the function calls. | ||
* | ||
* Then, later and asynchronously, a `add-chain-result` event is generated in order to | ||
* indicate whether the initialization was actually successful. If `success` is `false`, then | ||
* the `chainId` becomes unallocated. | ||
*/ | ||
addChain: (chainSpec: string, databaseContent: string, potentialRelayChains: number[], disableJsonRpc: boolean, jsonRpcMaxPendingRequests: number, jsonRpcMaxSubscriptions: number) => void; | ||
@@ -98,0 +111,0 @@ removeChain: (chainId: number) => void; |
@@ -62,2 +62,15 @@ "use strict"; | ||
}, | ||
chain_initialized: (chainId, errorMsgPtr, errorMsgLen) => { | ||
const instance = state.instance; | ||
const mem = new Uint8Array(instance.exports.memory.buffer); | ||
errorMsgPtr >>>= 0; | ||
errorMsgLen >>>= 0; | ||
if (errorMsgPtr === 0) { | ||
eventCallback({ ty: "add-chain-result", chainId, success: true }); | ||
} | ||
else { | ||
const errorMsg = buffer.utf8BytesToString(mem, errorMsgPtr, errorMsgLen); | ||
eventCallback({ ty: "add-chain-result", chainId, success: false, error: errorMsg }); | ||
} | ||
}, | ||
random_get: (ptr, len) => { | ||
@@ -372,3 +385,4 @@ const instance = state.instance; | ||
if (!state.instance) { | ||
eventCallback({ ty: "add-chain-result", success: false, error: "Smoldot has crashed" }); | ||
eventCallback({ ty: "add-chain-id-allocated", chainId: 0 }); | ||
eventCallback({ ty: "add-chain-result", chainId: 0, success: false, error: "Smoldot has crashed" }); | ||
return; | ||
@@ -392,12 +406,3 @@ } | ||
delete state.bufferIndices[2]; | ||
if (state.instance.exports.chain_is_ok(chainId) != 0) { | ||
eventCallback({ ty: "add-chain-result", success: true, chainId }); | ||
} | ||
else { | ||
const errorMsgLen = state.instance.exports.chain_error_len(chainId) >>> 0; | ||
const errorMsgPtr = state.instance.exports.chain_error_ptr(chainId) >>> 0; | ||
const errorMsg = buffer.utf8BytesToString(new Uint8Array(state.instance.exports.memory.buffer), errorMsgPtr, errorMsgLen); | ||
state.instance.exports.remove_chain(chainId); | ||
eventCallback({ ty: "add-chain-result", success: false, error: errorMsg }); | ||
} | ||
eventCallback({ ty: "add-chain-id-allocated", chainId }); | ||
}, | ||
@@ -404,0 +409,0 @@ removeChain: (chainId) => { |
@@ -66,3 +66,4 @@ // Smoldot | ||
connections: new Map(), | ||
addChainResults: [], | ||
addChainIdAllocations: [], | ||
addChainResults: new Map(), | ||
onExecutorShutdownOrWasmPanic: () => { }, | ||
@@ -86,6 +87,10 @@ chains: new Map(), | ||
state.connections.clear(); | ||
for (const addChainResult of state.addChainResults) { | ||
for (const addChainResult of state.addChainIdAllocations) { | ||
addChainResult({ success: false, error: "Smoldot has crashed" }); | ||
} | ||
state.addChainResults = []; | ||
state.addChainIdAllocations = []; | ||
state.addChainResults.forEach((addChainResult) => { | ||
addChainResult({ success: false, error: "Smoldot has crashed" }); | ||
}); | ||
state.addChainResults.clear(); | ||
for (const chain of Array.from(state.chains.values())) { | ||
@@ -113,4 +118,10 @@ for (const callback of chain.jsonRpcResponsesPromises) { | ||
} | ||
case "add-chain-id-allocated": { | ||
const callback = state.addChainIdAllocations.shift(); | ||
state.addChainResults.set(event.chainId, callback); | ||
break; | ||
} | ||
case "add-chain-result": { | ||
(state.addChainResults.shift())(event); | ||
(state.addChainResults.get(event.chainId))(event); | ||
state.addChainResults.delete(event.chainId); | ||
break; | ||
@@ -293,3 +304,3 @@ } | ||
throw new AddChainError("`databaseContent` is not a string"); | ||
const promise = new Promise((resolve) => state.addChainResults.push(resolve)); | ||
const promise = new Promise((resolve) => state.addChainIdAllocations.push(resolve)); | ||
state.instance.instance.addChain(options.chainSpec, options.databaseContent || "", potentialRelayChainsIds, !!options.disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions); | ||
@@ -375,6 +386,10 @@ const outcome = yield promise; | ||
state.connections.clear(); | ||
for (const addChainResult of state.addChainResults) { | ||
for (const addChainResult of state.addChainIdAllocations) { | ||
addChainResult({ success: false, error: "Client.terminate() has been called" }); | ||
} | ||
state.addChainResults = []; | ||
state.addChainIdAllocations = []; | ||
state.addChainResults.forEach((addChainResult) => { | ||
addChainResult({ success: false, error: "Client.terminate() has been called" }); | ||
}); | ||
state.addChainResults.clear(); | ||
for (const chain of Array.from(state.chains.values())) { | ||
@@ -381,0 +396,0 @@ for (const callback of chain.jsonRpcResponsesPromises) { |
@@ -33,7 +33,11 @@ /** | ||
export type Event = { | ||
ty: "add-chain-id-allocated"; | ||
chainId: number; | ||
} | { | ||
ty: "add-chain-result"; | ||
chainId: number; | ||
success: true; | ||
chainId: number; | ||
} | { | ||
ty: "add-chain-result"; | ||
chainId: number; | ||
success: false; | ||
@@ -96,2 +100,11 @@ error: string; | ||
peekJsonRpcResponse: (chainId: number) => string | null; | ||
/** | ||
* Later generates a `add-chain-id-allocated` event. | ||
* If this function is called multiple times, the `add-chain-id-allocated` events are generated | ||
* in the same order as the function calls. | ||
* | ||
* Then, later and asynchronously, a `add-chain-result` event is generated in order to | ||
* indicate whether the initialization was actually successful. If `success` is `false`, then | ||
* the `chainId` becomes unallocated. | ||
*/ | ||
addChain: (chainSpec: string, databaseContent: string, potentialRelayChains: number[], disableJsonRpc: boolean, jsonRpcMaxPendingRequests: number, jsonRpcMaxSubscriptions: number) => void; | ||
@@ -98,0 +111,0 @@ removeChain: (chainId: number) => void; |
@@ -59,2 +59,15 @@ // Smoldot | ||
}, | ||
chain_initialized: (chainId, errorMsgPtr, errorMsgLen) => { | ||
const instance = state.instance; | ||
const mem = new Uint8Array(instance.exports.memory.buffer); | ||
errorMsgPtr >>>= 0; | ||
errorMsgLen >>>= 0; | ||
if (errorMsgPtr === 0) { | ||
eventCallback({ ty: "add-chain-result", chainId, success: true }); | ||
} | ||
else { | ||
const errorMsg = buffer.utf8BytesToString(mem, errorMsgPtr, errorMsgLen); | ||
eventCallback({ ty: "add-chain-result", chainId, success: false, error: errorMsg }); | ||
} | ||
}, | ||
random_get: (ptr, len) => { | ||
@@ -369,3 +382,4 @@ const instance = state.instance; | ||
if (!state.instance) { | ||
eventCallback({ ty: "add-chain-result", success: false, error: "Smoldot has crashed" }); | ||
eventCallback({ ty: "add-chain-id-allocated", chainId: 0 }); | ||
eventCallback({ ty: "add-chain-result", chainId: 0, success: false, error: "Smoldot has crashed" }); | ||
return; | ||
@@ -389,12 +403,3 @@ } | ||
delete state.bufferIndices[2]; | ||
if (state.instance.exports.chain_is_ok(chainId) != 0) { | ||
eventCallback({ ty: "add-chain-result", success: true, chainId }); | ||
} | ||
else { | ||
const errorMsgLen = state.instance.exports.chain_error_len(chainId) >>> 0; | ||
const errorMsgPtr = state.instance.exports.chain_error_ptr(chainId) >>> 0; | ||
const errorMsg = buffer.utf8BytesToString(new Uint8Array(state.instance.exports.memory.buffer), errorMsgPtr, errorMsgLen); | ||
state.instance.exports.remove_chain(chainId); | ||
eventCallback({ ty: "add-chain-result", success: false, error: errorMsg }); | ||
} | ||
eventCallback({ ty: "add-chain-id-allocated", chainId }); | ||
}, | ||
@@ -401,0 +406,0 @@ removeChain: (chainId) => { |
{ | ||
"name": "smoldot", | ||
"version": "2.0.18", | ||
"version": "2.0.19", | ||
"description": "Light client that connects to Polkadot and Substrate-based blockchains", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30024
6231147