forked from NebulousLabs/Sia
/
explorer.go
93 lines (80 loc) · 2.55 KB
/
explorer.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
package modules
import (
"github.com/NebulousLabs/Sia/types"
)
const (
ExplorerDir = "explorer"
)
// Used for the BlockInfo call
type (
ExplorerBlockData struct {
ID types.BlockID // The id hash of the block
Timestamp types.Timestamp // The timestamp on the block
Target types.Target // The target the block was mined for
Size uint64 // The size in bytes of the marshalled block
}
ExplorerStatus struct {
Height types.BlockHeight
Block types.Block
Target types.Target
MatureTime types.Timestamp
TotalCurrency types.Currency
ActiveContractCount uint64
ActiveContractCosts types.Currency
ActiveContractSize types.Currency
TotalContractCount uint64
TotalContractCosts types.Currency
TotalContractSize types.Currency
}
// The following are used when returning information about a
// hash (using the GetHashInfo function)
//
// The responseType field is used to differentiate the structs
// blindly, and must be set
BlockResponse struct {
Block types.Block
Height types.BlockHeight
ResponseType string
}
// Wrapper for a transaction, with a little extra info
TransactionResponse struct {
Tx types.Transaction
ParentID types.BlockID
TxNum int
ResponseType string
}
// Wrapper for fcInfo struct, defined in database.go
FcResponse struct {
Contract types.TransactionID
Revisions []types.TransactionID
Proof types.TransactionID
ResponseType string
}
// Wrapper for the address type response
AddrResponse struct {
Txns []types.TransactionID
ResponseType string
}
OutputResponse struct {
OutputTx types.TransactionID
InputTx types.TransactionID
ResponseType string
}
// The BlockExplorer interface provides access to the block explorer
Explorer interface {
// Returns a slice of data points about blocks. Called
// primarly by the blockdata api call
BlockInfo(types.BlockHeight, types.BlockHeight) ([]ExplorerBlockData, error)
// Function to return status of a bunch of static variables,
// in the form of an ExplorerStatus struct
ExplorerStatus() ExplorerStatus
// Function to safely shut down the block explorer. Closes the database
Close() error
// Returns information pertaining to a given hash. The
// type of the returned value depends on what the hash
// was, so an interface is returned instead (i.e. an
// address will return a list of transactions while a
// block ID will return a block
GetHashInfo([]byte) (interface{}, error)
}
)