51 lines
921 B
Go
51 lines
921 B
Go
package btc
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
type BitcoinService struct {
|
|
host string
|
|
auth string
|
|
zmqAddress string
|
|
walletAddress string
|
|
testNet bool
|
|
}
|
|
|
|
func NewBitcoinService(host, auth, zmqAddress, walletAddress string) *BitcoinService {
|
|
bs := BitcoinService{
|
|
host: host,
|
|
auth: auth,
|
|
zmqAddress: zmqAddress,
|
|
walletAddress: walletAddress,
|
|
}
|
|
|
|
from, err := bs.getAddressGroupings(false)
|
|
if err != nil {
|
|
panic(fmt.Errorf("bs.getAddressGroupings %s", err))
|
|
}
|
|
|
|
found := false
|
|
for _, a := range from {
|
|
if a.address == bs.walletAddress {
|
|
found = true
|
|
}
|
|
}
|
|
if !found {
|
|
return nil
|
|
}
|
|
return &bs
|
|
}
|
|
|
|
func (bc *BitcoinService) WithTestnet() *BitcoinService {
|
|
bc.testNet = true
|
|
return bc
|
|
}
|
|
|
|
func (bc *BitcoinService) Explorer(tx string) string {
|
|
if bc.testNet {
|
|
return "https://testnet.bitcoinexplorer.org/tx/" + tx
|
|
}
|
|
return "https://btcscan.org/tx/" + tx
|
|
}
|