-
Notifications
You must be signed in to change notification settings - Fork 0
/
transactions.go
55 lines (50 loc) · 1.35 KB
/
transactions.go
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
package btcapi
import (
"encoding/json"
"fmt"
)
const TxRoute string = "/tx/"
type TXSummary struct {
TXID string `json:"txid"`
Hash string `json:"hash"`
Version int `json:"version"`
Size int `json:"size"`
VSize int `json:"vsize"`
Weight int `json:"Weight"`
Locktime int `json:"locktime"`
VIn []struct {
TXID string `json:"txid"`
VOut int `json:"vout"`
ScriptSig struct {
ASM string `json:"asm"`
Hex string `json:"hex"`
Sequence int `json:"sequence"`
} `json:"scriptSig"`
} `json:"vin"`
VOut []struct {
Value int `json:"value"`
N int `json:"n"`
ScriptSig struct {
ASM string `json:"asm"`
Hex string `json:"hex"`
Type string `json:"type"`
} `json:"scriptSig"`
} `json:"vout"`
Hex string `json:"hex"`
BlockHash string `json:"blockhash"`
Confirmations int `json:"confirmations"`
BlockTime int `json:"blocktime"`
}
// TXSummary takes a Bitcoin transaction ID and returns an TXSummary object.
func (c Config) Tx(tx string) (TXSummary, error) {
var TXSummary TXSummary
body, err := getAPI(c.ExplorerURL + api + TxRoute + tx)
if err != nil {
return TXSummary, err
}
err = json.Unmarshal(body, &TXSummary)
if err != nil {
return TXSummary, fmt.Errorf("unable to parse returned body: %w", err)
}
return TXSummary, nil
}