This repository has been archived by the owner on Oct 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(BUX-120): initializes repository with architecure (#1)
* feat: initializes repository with architecure * Update .gitignore Co-authored-by: Damian Orzepowski <damian.orzepowski@softwarelab.com.pl> * fix: removes composite broadcaster wrapper for a single client --------- Co-authored-by: Damian Orzepowski <damian.orzepowski@softwarelab.com.pl>
- Loading branch information
1 parent
85ee7a3
commit 8f2ad7b
Showing
9 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# If you prefer the allow list template instead of the deny list, see community template: | ||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
# | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# Go workspace file | ||
go.work | ||
|
||
## Jetbrains | ||
.idea/ | ||
*.iml | ||
|
||
#asdf | ||
.tool-versions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package arc | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/bitcoin-sv/go-broadcast-client/broadcast" | ||
"github.com/bitcoin-sv/go-broadcast-client/config" | ||
) | ||
|
||
type ArcClient struct { | ||
apiURL string | ||
token string | ||
} | ||
|
||
func NewArcClient(config config.ArcClientConfig) broadcast.Broadcaster { | ||
return &ArcClient{apiURL: config.APIUrl, token: config.Token} | ||
} | ||
|
||
func (a *ArcClient) BestQuote(ctx context.Context, feeCategory, feeType string) error { | ||
// implementacja | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package broadcast | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type BroadcastFactory func() Broadcaster | ||
|
||
type Broadcaster interface { | ||
BestQuoter | ||
// FastestQuoter | ||
// FeeQuoter | ||
// PolicyQuoter | ||
// TransactionQuerier | ||
// TransactionSubmitter | ||
// TransactionsSubmitter | ||
} | ||
|
||
type compositeBroadcaster struct { | ||
broadcasters []Broadcaster | ||
strategy Strategy | ||
} | ||
|
||
func NewCompositeBroadcaster(strategy Strategy, factories ...BroadcastFactory) Broadcaster { | ||
var broadcasters []Broadcaster | ||
for _, factory := range factories { | ||
broadcasters = append(broadcasters, factory()) | ||
} | ||
return &compositeBroadcaster{ | ||
broadcasters: broadcasters, | ||
strategy: strategy, | ||
} | ||
} | ||
|
||
func (c *compositeBroadcaster) BestQuote(ctx context.Context, feeCategory, feeType string) error { | ||
executionFuncs := make([]func(context.Context) error, len(c.broadcasters)) | ||
for i, broadcaster := range c.broadcasters { | ||
executionFuncs[i] = func(ctx context.Context) error { | ||
return broadcaster.BestQuote(ctx, feeCategory, feeType) | ||
} | ||
} | ||
return c.strategy.Execute(ctx, executionFuncs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package broadcast | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type BestQuoter interface { | ||
// BestQuote(ctx context.Context, feeCategory, feeType string) (*FeeQuoteResponse, error) | ||
BestQuote(ctx context.Context, feeCategory, feeType string) error | ||
} | ||
|
||
// type FastestQuoter interface { | ||
// // FastestQuote(ctx context.Context, timeout time.Duration) (*FeeQuoteResponse, error) | ||
// FastestQuote(ctx context.Context, timeout time.Duration) error | ||
// } | ||
|
||
// type FeeQuoter interface { | ||
// // FeeQuote(ctx context.Context, miner *Miner) (*FeeQuoteResponse, error) | ||
// FeeQuote(ctx context.Context) error | ||
// } | ||
|
||
// type PolicyQuoter interface { | ||
// // PolicyQuote(ctx context.Context, miner *Miner) (*PolicyQuoteResponse, error) | ||
// PolicyQuote(ctx context.Context) error | ||
// } | ||
|
||
// type TransactionQuerier interface { | ||
// // // QueryTransaction(ctx context.Context, miner *Miner, txID string, opts ...QueryTransactionOptFunc) (*QueryTransactionResponse, error) | ||
// QueryTransaction(ctx context.Context, txID string) error | ||
// } | ||
|
||
// type TransactionSubmitter interface { | ||
// // SubmitTransaction(ctx context.Context, miner *Miner, tx *Transaction) (*SubmitTransactionResponse, error) | ||
// SubmitTransaction(ctx context.Context) error | ||
// } | ||
|
||
// type TransactionsSubmitter interface { | ||
// // SubmitTransactions(ctx context.Context, miner *Miner, txs []Transaction) (*SubmitTransactionsResponse, error) | ||
// SubmitTransactions(ctx context.Context) error | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package broadcast | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
type StrategyName string | ||
|
||
const ( | ||
OneByOneStrategy StrategyName = "OneByOneStrategy" | ||
) | ||
|
||
type ExecutionFunc func(context.Context, []func(context.Context) error) error | ||
|
||
type Strategy struct { | ||
name StrategyName | ||
executionFunc ExecutionFunc | ||
} | ||
|
||
func New(name StrategyName, executionFunc ExecutionFunc) *Strategy { | ||
return &Strategy{name: name, executionFunc: executionFunc} | ||
} | ||
|
||
func (s *Strategy) Execute(ctx context.Context, executionFuncs []func(context.Context) error) error { | ||
return s.executionFunc(ctx, executionFuncs) | ||
} | ||
|
||
var ( | ||
OneByOne = New(OneByOneStrategy, func(ctx context.Context, executionFuncs []func(context.Context) error) error { | ||
for _, executionFunc := range executionFuncs { | ||
err := executionFunc(ctx) | ||
if err != nil { | ||
continue | ||
} | ||
return nil | ||
} | ||
// return factory.ErrAllBroadcastersFailed | ||
return fmt.Errorf("all broadcasters failed") | ||
}) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package config | ||
|
||
type ArcClientConfig struct { | ||
APIUrl string | ||
Token string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package config | ||
|
||
import "github.com/bitcoin-sv/go-broadcast-client/broadcast" | ||
|
||
type Config interface{} | ||
|
||
var DefaultStrategy broadcast.Strategy = *broadcast.OneByOne |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package factory | ||
|
||
import ( | ||
"github.com/bitcoin-sv/go-broadcast-client/broadcast" | ||
"github.com/bitcoin-sv/go-broadcast-client/broadcast/arc" | ||
"github.com/bitcoin-sv/go-broadcast-client/config" | ||
) | ||
|
||
func NewBroadcastClient(factories ...broadcast.BroadcastFactory) broadcast.Broadcaster { | ||
if len(factories) == 1 { | ||
return factories[0]() | ||
} | ||
|
||
return broadcast.NewCompositeBroadcaster(config.DefaultStrategy, factories...) | ||
} | ||
|
||
func WithArc(config config.ArcClientConfig) broadcast.BroadcastFactory { | ||
return func() broadcast.Broadcaster { | ||
return arc.NewArcClient(config) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/bitcoin-sv/go-broadcast-client | ||
|
||
go 1.20 |