feat: set up project
This commit is contained in:
53
internal/services/btc/btc.go
Normal file
53
internal/services/btc/btc.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package btc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type BitcoinService struct {
|
||||
host string
|
||||
auth string
|
||||
zmqAddress string
|
||||
walletAddress string
|
||||
client *http.Client
|
||||
testNet bool
|
||||
}
|
||||
|
||||
func NewBitcoinService(host, auth, zmqAddress, walletAddress string) *BitcoinService {
|
||||
bs := BitcoinService{
|
||||
host: host,
|
||||
auth: auth,
|
||||
zmqAddress: zmqAddress,
|
||||
walletAddress: walletAddress,
|
||||
client: &http.Client{},
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user