-
Notifications
You must be signed in to change notification settings - Fork 32
/
chain.go
47 lines (36 loc) · 1.1 KB
/
chain.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
package bus
import (
"github.com/ledgerhq/satstack/types"
"github.com/ledgerhq/satstack/utils"
"github.com/btcsuite/btcd/btcjson"
"github.com/btcsuite/btcd/chaincfg/chainhash"
)
func (b *Bus) GetBestBlockHash() (*chainhash.Hash, error) {
return b.mainClient.GetBestBlockHash()
}
func (b *Bus) GetBlockCount() (int64, error) {
return b.mainClient.GetBlockCount()
}
func (b *Bus) GetBlockHash(height int64) (*chainhash.Hash, error) {
return b.mainClient.GetBlockHash(height)
}
func (b *Bus) GetBlock(hash *chainhash.Hash) (*types.Block, error) {
nativeBlock, err := b.mainClient.GetBlockVerbose(hash)
if err != nil {
return nil, err
}
transactions := make([]string, len(nativeBlock.Tx))
for idx, transaction := range nativeBlock.Tx {
transactions[idx] = transaction
}
block := types.Block{
Hash: nativeBlock.Hash,
Height: nativeBlock.Height,
Time: utils.ParseUnixTimestamp(nativeBlock.Time),
Transactions: &transactions,
}
return &block, nil
}
func (b *Bus) GetBlockChainInfo() (*btcjson.GetBlockChainInfoResult, error) {
return b.mainClient.GetBlockChainInfo()
}