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
feat(BUX-120, BUX-148, BUX-150): broadcast, query subtasks #2
Merged
Merged
Changes from 7 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7c3af4e
feat: prepares query tx with unit tests
wregulski a967652
feat: arc query tx - fixes unit tests
wregulski 37bff94
feat: initializes SubmitTransaction in broadcaster and arc client
wregulski 6b9c9ac
feat: creates a paylaod wrapper for httpclient
wregulski 1dc6a59
feat: finishes submit-tx func
wregulski 398f67d
feat: adds acceptance test for query_tx
wregulski 74de824
fix: change to correct models
wregulski 0870d72
feat: refactors broadcast package
wregulski bd93c41
feat: finishes query tx tests
wregulski cc16c26
fix: adds given/when/then and proper names
wregulski 51b3bec
fix: modifies packages inside files to expose correct methods
wregulski 0a09a9c
refactor(BUX-120): move components across packages to cut circular de…
dorzepowski 217cc14
feat: working examples
wregulski 5ae1d1c
feat: finishes acceptance_test
wregulski b14a341
fix: cr requests
wregulski 2b13a68
fix: adds WithHttpClient option to builder instead of passing it as p…
wregulski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
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 |
---|---|---|
|
@@ -2,7 +2,8 @@ package broadcast | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/bitcoin-sv/go-broadcast-client/shared" | ||
) | ||
|
||
type StrategyName string | ||
|
@@ -11,31 +12,33 @@ const ( | |
OneByOneStrategy StrategyName = "OneByOneStrategy" | ||
) | ||
|
||
type ExecutionFunc func(context.Context, []func(context.Context) error) error | ||
type Result interface{} | ||
|
||
type ExecutionFunc func(context.Context) (Result, error) | ||
type StrategyExecutionFunc func(context.Context, []ExecutionFunc) (Result, error) | ||
|
||
type Strategy struct { | ||
name StrategyName | ||
executionFunc ExecutionFunc | ||
executionFunc StrategyExecutionFunc | ||
} | ||
|
||
func New(name StrategyName, executionFunc ExecutionFunc) *Strategy { | ||
func New(name StrategyName, executionFunc StrategyExecutionFunc) *Strategy { | ||
return &Strategy{name: name, executionFunc: executionFunc} | ||
} | ||
|
||
func (s *Strategy) Execute(ctx context.Context, executionFuncs []func(context.Context) error) error { | ||
func (s *Strategy) Execute(ctx context.Context, executionFuncs []ExecutionFunc) (Result, error) { | ||
return s.executionFunc(ctx, executionFuncs) | ||
} | ||
|
||
var ( | ||
OneByOne = New(OneByOneStrategy, func(ctx context.Context, executionFuncs []func(context.Context) error) error { | ||
OneByOne = New(OneByOneStrategy, func(ctx context.Context, executionFuncs []ExecutionFunc) (Result, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now, I'm not sure if this is best approach to create this strategy here.
dorzepowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for _, executionFunc := range executionFuncs { | ||
err := executionFunc(ctx) | ||
result, err := executionFunc(ctx) | ||
if err != nil { | ||
continue | ||
} | ||
return nil | ||
return result, nil | ||
} | ||
// return factory.ErrAllBroadcastersFailed | ||
return fmt.Errorf("all broadcasters failed") | ||
return nil, shared.ErrAllBroadcastersFailed | ||
}) | ||
) |
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,13 @@ | ||
package common | ||
wregulski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Transaction is the body contents in the "submit transaction" request | ||
type Transaction struct { | ||
CallBackEncryption string `json:"callBackEncryption,omitempty"` | ||
CallBackToken string `json:"callBackToken,omitempty"` | ||
CallBackURL string `json:"callBackUrl,omitempty"` | ||
DsCheck bool `json:"dsCheck,omitempty"` | ||
MerkleFormat string `json:"merkleFormat,omitempty"` | ||
MerkleProof bool `json:"merkleProof,omitempty"` | ||
RawTx string `json:"rawtx"` | ||
WaitForStatus TxStatus `json:"waitForStatus,omitempty"` | ||
} |
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,77 @@ | ||
package common | ||
|
||
// TxStatus is the status of the transaction | ||
type TxStatus string | ||
|
||
// List of statuses available here: https://github.com/bitcoin-sv/arc | ||
const ( | ||
// Unknown contains value for unknown status | ||
dorzepowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Unknown TxStatus = "UNKNOWN" // 0 | ||
// Queued contains value for queued status | ||
Queued TxStatus = "QUEUED" // 1 | ||
// Received contains value for received status | ||
Received TxStatus = "RECEIVED" // 2 | ||
// Stored contains value for stored status | ||
Stored TxStatus = "STORED" // 3 | ||
// AnnouncedToNetwork contains value for announced to network status | ||
AnnouncedToNetwork TxStatus = "ANNOUNCED_TO_NETWORK" // 4 | ||
// RequestedByNetwork contains value for requested by network status | ||
RequestedByNetwork TxStatus = "REQUESTED_BY_NETWORK" // 5 | ||
// SentToNetwork contains value for sent to network status | ||
SentToNetwork TxStatus = "SENT_TO_NETWORK" // 6 | ||
// AcceptedByNetwork contains value for accepted by network status | ||
AcceptedByNetwork TxStatus = "ACCEPTED_BY_NETWORK" // 7 | ||
// SeenOnNetwork contains value for seen on network status | ||
SeenOnNetwork TxStatus = "SEEN_ON_NETWORK" // 8 | ||
// Mined contains value for mined status | ||
Mined TxStatus = "MINED" // 9 | ||
// Confirmed contains value for confirmed status | ||
Confirmed TxStatus = "CONFIRMED" // 108 | ||
// Rejected contains value for rejected status | ||
Rejected TxStatus = "REJECTED" // 109 | ||
) | ||
|
||
// String returns the string representation of the TxStatus | ||
func (s TxStatus) String() string { | ||
statuses := map[TxStatus]string{ | ||
Unknown: "UNKNOWN", | ||
Queued: "QUEUED", | ||
Received: "RECEIVED", | ||
Stored: "STORED", | ||
AnnouncedToNetwork: "ANNOUNCED_TO_NETWORK", | ||
RequestedByNetwork: "REQUESTED_BY_NETWORK", | ||
SentToNetwork: "SENT_TO_NETWORK", | ||
AcceptedByNetwork: "ACCEPTED_BY_NETWORK", | ||
SeenOnNetwork: "SEEN_ON_NETWORK", | ||
Mined: "MINED", | ||
Confirmed: "CONFIRMED", | ||
Rejected: "REJECTED", | ||
} | ||
|
||
if status, ok := statuses[s]; ok { | ||
return status | ||
} | ||
|
||
return "Can't parse status" | ||
} | ||
wregulski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// MapTxStatusToInt maps the TxStatus to an int value | ||
func MapTxStatusToInt(status TxStatus) (int, bool) { | ||
waitForStatusMap := map[TxStatus]int{ | ||
Unknown: 0, | ||
Queued: 1, | ||
Received: 2, | ||
Stored: 3, | ||
AnnouncedToNetwork: 4, | ||
RequestedByNetwork: 5, | ||
SentToNetwork: 6, | ||
AcceptedByNetwork: 7, | ||
SeenOnNetwork: 8, | ||
Mined: 9, | ||
Confirmed: 108, | ||
Rejected: 109, | ||
} | ||
|
||
value, ok := waitForStatusMap[status] | ||
return value, ok | ||
wregulski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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
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
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 |
---|---|---|
@@ -1,3 +1,11 @@ | ||
module github.com/bitcoin-sv/go-broadcast-client | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/stretchr/objx v0.5.0 // indirect | ||
github.com/stretchr/testify v1.8.4 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
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,17 @@ | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= | ||
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= | ||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= | ||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= | ||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= | ||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this is here and not in
internal
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why it shouldn't be here