Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add telementry package #9

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
274 changes: 0 additions & 274 deletions devbox.lock

This file was deleted.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/joho/godotenv v1.5.1
github.com/onsi/ginkgo/v2 v2.21.0
github.com/onsi/gomega v1.35.1
github.com/robfig/cron/v3 v3.0.1
github.com/stretchr/testify v1.9.0
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
Expand Down
48 changes: 47 additions & 1 deletion internal/btcrpc/blockstream/blockstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ func (c *blockstream) GetUTXOs(address string) ([]UTXO, error) {
return utxos, nil
}

func (c *blockstream) GetBTCBalance(url string) (*model.Web3BigInt, error) {
func (c *blockstream) GetBTCBalance(address string) (*model.Web3BigInt, error) {
url := fmt.Sprintf("%s/address/%s", c.baseURL, address)
var lastErr error
maxRetries := 3

Expand Down Expand Up @@ -151,3 +152,48 @@ func (c *blockstream) GetBTCBalance(url string) (*model.Web3BigInt, error) {

return nil, lastErr
}

func (c *blockstream) GetTransactionsByAddress(address string, fromTxID string) ([]Transaction, error) {
var url string
if fromTxID == "" {
url = fmt.Sprintf("%s/address/%s/txs", c.baseURL, address)
} else {
url = fmt.Sprintf("%s/address/%s/txs/chain/%s", c.baseURL, address, fromTxID)
}

var lastErr error
maxRetries := 3

for attempt := 1; attempt <= maxRetries; attempt++ {
resp, err := c.client.Get(url)
if err != nil {
lastErr = err
c.logger.Error("[GetTransactionsByAddress][client.Get]", map[string]string{
"error": err.Error(),
"attempt": strconv.Itoa(attempt),
})
continue
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
lastErr = fmt.Errorf("unexpected status code: %d", resp.StatusCode)
c.logger.Error("[GetTransactionsByAddress][client.Get]", map[string]string{
"error": "unexpected status code",
"attempt": strconv.Itoa(attempt),
})
continue
}

var txs []Transaction
if err := json.NewDecoder(resp.Body).Decode(&txs); err != nil {
lastErr = err
c.logger.Error("[GetTransactionsByAddress][json.NewDecoder.Decode]", map[string]string{
"error": err.Error(),
})
continue
}
return txs, nil
}
return nil, lastErr
}
1 change: 1 addition & 0 deletions internal/btcrpc/blockstream/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ type IBlockStream interface {
EstimateFees() (fees map[string]float64, err error)
GetUTXOs(address string) ([]UTXO, error)
GetBTCBalance(address string) (balance *model.Web3BigInt, err error)
GetTransactionsByAddress(address string, fromTxID string) ([]Transaction, error)
}
Loading