-
-
Notifications
You must be signed in to change notification settings - Fork 86
/
hasTx.ts
44 lines (41 loc) · 1.07 KB
/
hasTx.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { Ogmios, TxId } from "@cardano-ogmios/schema"
import { UnknownResultError } from "../errors";
import { InteractionContext } from '../Connection'
import { Query } from '../StateQuery'
/**
* Ask whether a given transaction is present in the acquired mempool snapshot.
*
* @category TxMonitor
*/
export const hasTx = (context: InteractionContext, id: TxId) =>
Query<
Ogmios['HasTx'],
Ogmios['HasTxResponse'],
boolean
>({
methodName: 'HasTx',
args: { id }
}, {
handler: (response, resolve, reject) => {
try {
resolve(handleHasTxResponse(response))
} catch (e) {
reject(e)
}
}
}, context)
/**
* @internal
*/
export const isHasTxResult = (result: any): result is boolean =>
(typeof result === 'boolean')
/**
* @internal
*/
export const handleHasTxResponse = (response: Ogmios['HasTxResponse']): boolean => {
const { result } = response
if (isHasTxResult(result)) {
return result
}
throw new UnknownResultError(response)
}