-
Notifications
You must be signed in to change notification settings - Fork 0
/
callapi.go
147 lines (127 loc) · 3.92 KB
/
callapi.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package colx
import (
"fmt"
"math/big"
"github.com/weijun-sh/gethscan-server/tokens/btc/electrs"
)
// GetLatestBlockNumberOf impl
func (b *Bridge) GetLatestBlockNumberOf(apiAddress string) (uint64, error) {
num, err := electrs.GetLatestBlockNumberOf(apiAddress)
return num, err
}
// GetLatestBlockNumber impl
func (b *Bridge) GetLatestBlockNumber() (uint64, error) {
num, err := electrs.GetLatestBlockNumber(b)
return num, err
}
// GetTransactionByHash impl
func (b *Bridge) GetTransactionByHash(txHash string) (*electrs.ElectTx, error) {
result, err := electrs.GetTransactionByHash(b, txHash)
if err == nil {
*result = *b.ToCOLXTx(result)
}
return result, err
}
// GetElectTransactionStatus impl
func (b *Bridge) GetElectTransactionStatus(txHash string) (*electrs.ElectTxStatus, error) {
result, err := electrs.GetElectTransactionStatus(b, txHash)
if err != nil {
return nil, err
}
return result, err
}
// FindUtxos impl
func (b *Bridge) FindUtxos(addr string) ([]*electrs.ElectUtxo, error) {
btcaddr, cvterr := b.ConvertCOLXAddress(addr, "")
if cvterr == nil {
addr = btcaddr.String()
}
return electrs.FindUtxos(b, addr)
}
// GetPoolTxidList impl
func (b *Bridge) GetPoolTxidList() ([]string, error) {
return electrs.GetPoolTxidList(b)
}
// GetPoolTransactions impl
func (b *Bridge) GetPoolTransactions(addr string) ([]*electrs.ElectTx, error) {
btcaddr, cvterr := b.ConvertCOLXAddress(addr, "")
if cvterr == nil {
addr = btcaddr.String()
}
results, err := electrs.GetPoolTransactions(b, addr)
if err == nil {
for _, result := range results {
*result = *b.ToCOLXTx(result)
}
}
return results, err
}
// GetTransactionHistory impl
func (b *Bridge) GetTransactionHistory(addr, lastSeenTxid string) ([]*electrs.ElectTx, error) {
btcaddr, cvterr := b.ConvertCOLXAddress(addr, "")
if cvterr == nil {
addr = btcaddr.String()
}
results, err := electrs.GetTransactionHistory(b, addr, lastSeenTxid)
if err == nil {
for _, result := range results {
*result = *b.ToCOLXTx(result)
}
}
return results, err
}
// GetOutspend impl
func (b *Bridge) GetOutspend(txHash string, vout uint32) (*electrs.ElectOutspend, error) {
return electrs.GetOutspend(b, txHash, vout)
}
// PostTransaction impl
func (b *Bridge) PostTransaction(txHex string) (txHash string, err error) {
return electrs.PostTransaction(b, txHex)
}
// GetBlockHash impl
func (b *Bridge) GetBlockHash(height uint64) (string, error) {
return electrs.GetBlockHash(b, height)
}
// GetBlockTxids impl
func (b *Bridge) GetBlockTxids(blockHash string) ([]string, error) {
return electrs.GetBlockTxids(b, blockHash)
}
// GetBlock impl
func (b *Bridge) GetBlock(blockHash string) (*electrs.ElectBlock, error) {
return electrs.GetBlock(b, blockHash)
}
// GetBlockTransactions impl
func (b *Bridge) GetBlockTransactions(blockHash string, startIndex uint32) ([]*electrs.ElectTx, error) {
results, err := electrs.GetBlockTransactions(b, blockHash, startIndex)
if err == nil {
for _, result := range results {
*result = *b.ToCOLXTx(result)
}
}
return results, err
}
// EstimateFeePerKb impl
func (b *Bridge) EstimateFeePerKb(blocks int) (int64, error) {
//#return electrs.EstimateFeePerKb(b, blocks)
return int64(100100000), nil
}
// GetBalance impl
func (b *Bridge) GetBalance(account string) (*big.Int, error) {
utxos, err := b.FindUtxos(account)
if err != nil {
return nil, err
}
var balance uint64
for _, utxo := range utxos {
balance += *utxo.Value
}
return new(big.Int).SetUint64(balance), nil
}
// GetTokenBalance impl
func (b *Bridge) GetTokenBalance(tokenType, tokenAddress, accountAddress string) (*big.Int, error) {
return nil, fmt.Errorf("[%v] can not get token balance of token with type '%v'", b.ChainConfig.BlockChain, tokenType)
}
// GetTokenSupply impl
func (b *Bridge) GetTokenSupply(tokenType, tokenAddress string) (*big.Int, error) {
return nil, fmt.Errorf("[%v] can not get token supply of token with type '%v'", b.ChainConfig.BlockChain, tokenType)
}