forked from OdyseeTeam/chainquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.go
121 lines (96 loc) · 3.63 KB
/
request.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package lbrycrd
import (
"time"
"github.com/lbryio/chainquery/util"
"github.com/lbryio/lbry.go/extras/errors"
)
//GetBlock performs a jsonrpc that returns the structured data as a GetBlockResponse.
//If LBRYcrd contains this block it will be returned.
func GetBlock(blockHash string) (*GetBlockResponse, error) {
defer util.TimeTrack(time.Now(), "getblock", "lbrycrdprofile")
response := new(GetBlockResponse)
return response, call(&response, "getblock", blockHash)
}
//GetBlockHash performs a jsonrpc that returns the hash of the block as a string.
func GetBlockHash(i uint64) (*string, error) {
defer util.TimeTrack(time.Now(), "getblockhash", "lbrycrdprofile")
rawresponse, err := callNoDecode("getblockhash", i)
if err != nil {
return nil, err
}
value := rawresponse.(string)
return &value, nil
}
// GetBlockCount returns the highest block LBRYcrd is aware of.
func GetBlockCount() (*uint64, error) {
defer util.TimeTrack(time.Now(), "getblockcount", "lbrycrdprofile")
rawresponse, err := callNoDecode("getblockcount")
if err != nil {
return nil, err
}
value, err := decodeNumber(rawresponse)
if err != nil {
return nil, err
}
intValue := uint64(value.IntPart())
return &intValue, nil
}
// GetRawTransactionResponse returns the raw transactions structured data. This will not always work. LBRYcrd must have
//-txindex turned on otherwise only transactions in the memory pool can be returned.
func GetRawTransactionResponse(hash string) (*TxRawResult, error) {
defer util.TimeTrack(time.Now(), "getrawtransaction", "lbrycrdprofile")
response := new(TxRawResult)
return response, call(&response, "getrawtransaction", hash, 1)
}
// GetBalance returns the balance of a wallet address.
func GetBalance() (*float64, error) {
defer util.TimeTrack(time.Now(), "getbalance", "lbrycrdprofile")
rawresponse, err := callNoDecode("getbalance")
if err != nil {
return nil, err
}
value, err := decodeNumber(rawresponse)
if err != nil {
return nil, err
}
floatValue, _ := value.Float64()
return &floatValue, nil
}
// GetClaimsInTrie gets all the claims current active in the claim trie
func GetClaimsInTrie() ([]ClaimNameResult, error) {
defer util.TimeTrack(time.Now(), "getclaimsintrie", "lbrycrdprofile")
response := new([]ClaimNameResult)
return *response, call(&response, "getclaimsintrie")
}
// GetClaimsForName gets all the claims for a name in the claimtrie.
func GetClaimsForName(name string) (ClaimsForNameResult, error) {
response := new(ClaimsForNameResult)
return *response, call(&response, "getclaimsforname", name)
}
// RawMempoolVerboseResponse models the object of mempool results
type RawMempoolVerboseResponse map[string]GetRawMempoolVerboseResult
// GetRawMempool gets all the transactions in the mempool
func GetRawMempool() (RawMempoolVerboseResponse, error) {
defer util.TimeTrack(time.Now(), "getrawmempool", "lbrycrdprofile")
response := new(RawMempoolVerboseResponse)
return *response, call(&response, "getrawmempool", true)
}
// ClaimName creates a claim transaction for lbrycrd.
func ClaimName(name string, hexValue string, amount float64) (string, error) {
defer util.TimeTrack(time.Now(), "claimname", "lbrycrdprofile")
rawresponse, err := callNoDecode("claimname", name, hexValue, amount)
if err != nil {
return "", err
}
value, ok := rawresponse.(string)
if !ok {
return "", errors.Err("response is not a string")
}
return value, nil
}
//GenerateBlocks generates n blocks in regtest. Will error in mainnet or testnet.
func GenerateBlocks(count int64) ([]string, error) {
defer util.TimeTrack(time.Now(), "generate", "lbrycrdprofile")
var response []string
return response, call(&response, "generate", count)
}