shutdown: () => Promise<void>
-
const matchAwaitAcquire = (data: string) => {
-
const response = safeJSON.parse(data) as Ogmios['AwaitAcquireResponse']
-
if ((response.type as string) !== 'jsonwsp/fault' && response.methodname !== 'AwaitAcquire') {
-
const matchHasTx = (data: string) => {
-
const response = safeJSON.parse(data) as Ogmios['HasTxResponse']
-
if ((response.type as string) !== 'jsonwsp/fault' && response.methodname !== 'HasTx') {
-
const matchNextTx = (data: string) => {
-
const response = safeJSON.parse(data) as Ogmios['NextTxResponse']
-
if ((response.type as string) !== 'jsonwsp/fault' && response.methodname !== 'NextTx') {
-
const matchSizeAndCapacity = (data: string) => {
-
const response = safeJSON.parse(data) as Ogmios['SizeAndCapacityResponse']
-
if ((response.type as string) !== 'jsonwsp/fault' && response.methodname !== 'SizeAndCapacity') {
-
const matchReleaseMempool = (data: string) => {
-
const response = safeJSON.parse(data) as Ogmios['ReleaseMempoolResponse']
-
if ((response.type as string) !== 'jsonwsp/fault' && response.methodname !== 'ReleaseMempool') {
* Create a client for inspect the node’s local mempool.
): Promise<TxMonitorClient> => {
const { socket } = context
-
const awaitAcquireResponse = eventEmitterToGenerator(socket, 'message', matchAwaitAcquire)() as
-
AsyncGenerator<Ogmios['AwaitAcquireResponse']>
-
const hasTxResponse = eventEmitterToGenerator(socket, 'message', matchHasTx)() as
-
AsyncGenerator<Ogmios['HasTxResponse']>
-
const nextTxResponse = eventEmitterToGenerator(socket, 'message', matchNextTx)() as
-
AsyncGenerator<Ogmios['NextTxResponse']>
-
const sizeAndCapacityResponse = eventEmitterToGenerator(socket, 'message', matchSizeAndCapacity)() as
-
AsyncGenerator<Ogmios['SizeAndCapacityResponse']>
+
const matchAny = (data: string) => {
+
const json = safeJSON.parse(data)
+
const methods = ['AwaitAcquire', 'HasTx', 'NextTx', 'SizeAndCapacity', 'ReleaseMempool']
+
if (json.type !== 'jsonwsp/fault' && !methods.includes(json.methodname)) {
-
const releaseMempoolResponse = eventEmitterToGenerator(socket, 'message', matchReleaseMempool)() as
-
AsyncGenerator<Ogmios['ReleaseMempoolResponse']>
+
const response = eventEmitterToGenerator(socket, 'message', matchAny)() as
+
| Ogmios['AwaitAcquireResponse']
+
| Ogmios['HasTxResponse']
+
| Ogmios['NextTxResponse']
+
| Ogmios['SizeAndCapacityTxResponse']
+
| Ogmios['ReleaseMempoolTxResponse']
} as unknown as Ogmios['AwaitAcquire']))
-
return handleAwaitAcquireResponse((await awaitAcquireResponse.next()).value)
+
return handleAwaitAcquireResponse((await response.next()).value)
} as unknown as Ogmios['HasTx']))
-
return handleHasTxResponse((await hasTxResponse.next()).value)
+
return handleHasTxResponse((await response.next()).value)
nextTx: (args?: {fields?: "all"}) => {
} as unknown as Ogmios['NextTx']))
-
return handleNextTxResponse((await nextTxResponse.next()).value, args)
+
return handleNextTxResponse((await response.next()).value, args)
sizeAndCapacity: (args?: {}) => {
} as unknown as Ogmios['SizeAndCapacity']))
-
return handleSizeAndCapacityResponse((await sizeAndCapacityResponse.next()).value)
+
return handleSizeAndCapacityResponse((await response.next()).value)
release: (args?: {}) => {
} as unknown as Ogmios['ReleaseMempool']))
-
return handleReleaseResponse((await releaseMempoolResponse.next()).value)
+
return handleReleaseResponse((await response.next()).value)
shutdown: () => new Promise(resolve => {