Repository navigation
Expand file tree
/
Copy pathMempoolSpace.fs
More file actions
65 lines (54 loc) · 1.95 KB
/
Copy pathMempoolSpace.fs
File metadata and controls
65 lines (54 loc) · 1.95 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module Explora.MempoolSpace
open Fable.Core
open Thoth.Fetch
open Thoth.Json
type SpentUnconfirmed = {
txid: string
vin: int
}
type SpentConfirmed = {
txid: string
vin: int
blockHeight: int
blockHash: string
blockTime: int
}
type SpendingStatus =
| SpentUnconfirmed of SpentUnconfirmed
| SpentConfirmed of SpentConfirmed
| Unspent
let SpentUnconfirmedDecoder : Decoder<SpentUnconfirmed> =
Decode.object(fun get -> {
txid = get.Required.Field "txid" Decode.string
vin = get.Required.Field "vin" Decode.int})
let SpentConfirmedDecoder : Decoder<SpentConfirmed> =
Decode.object(fun get -> {
txid = get.Required.Field "txid" Decode.string
vin = get.Required.Field "vin" Decode.int
blockHeight = get.Required.At ["status"; "block_height"] Decode.int
blockHash = get.Required.At ["status"; "block_hash"] Decode.string
blockTime = get.Required.At ["status"; "block_time"] Decode.int})
let SpendingDecoder : Decoder<SpendingStatus> =
Decode.at ["status"; "confirmed"] Decode.bool
|> Decode.andThen( function
| true -> SpentConfirmedDecoder |> Decode.map SpentConfirmed
| false -> SpentUnconfirmedDecoder |> Decode.map SpentUnconfirmed
)
let SpendingStatusDecoder =
Decode.field "spent" Decode.bool
|> Decode.andThen (function
| true -> SpendingDecoder
| false -> Decode.succeed Unspent)
let getSpenderTransaction (txId: string) (index: int) =
promise {
let endpoints =
[|
//"https://mempool.cakewallet.com"
//"https://mempool.lyberry.com"
"https://mempool.space"
|]
let rnd = JS.Math.floor(JS.Math.random() * 100.0)
let endpoint = endpoints[int rnd % endpoints.Length]
let! result = Fetch.get($"{endpoint}/api/tx/{txId}/outspend/{index}", decoder = SpendingStatusDecoder)
return result
}