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-162): moves headers opts out of tx struct #14
Merged
Conversation
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
wregulski
requested review from
dorzepowski,
kuba-4chain and
arkadiuszos4chain
August 15, 2023 19:21
dorzepowski
reviewed
Aug 16, 2023
Comment on lines
157
to
177
func WithCallback(callbackURL string, callbackToken ...string) broadcast.TransactionOptFunc { | ||
return func(o *broadcast.TransactionOpts) { | ||
o.CallbackToken = callbackURL | ||
if len(callbackToken) > 0 { | ||
o.CallbackToken = callbackToken[0] | ||
} | ||
} | ||
} | ||
|
||
func WithMerkleProof() broadcast.TransactionOptFunc { | ||
return func(o *broadcast.TransactionOpts) { | ||
o.MerkleProof = true | ||
} | ||
} | ||
|
||
func WithWaitForStatus(status broadcast.TxStatus) broadcast.TransactionOptFunc { | ||
return func(o *broadcast.TransactionOpts) { | ||
o.WaitForStatus = status | ||
} | ||
} | ||
|
||
func appendSubmitTxHeaders(pld *httpclient.HTTPRequest, opts *broadcast.TransactionOpts) { | ||
if opts == nil { | ||
return | ||
} | ||
|
||
if opts.MerkleProof { | ||
pld.AddHeader("X-MerkleProof", "true") | ||
} | ||
|
||
if tx.CallBackURL != "" { | ||
pld.AddHeader("X-CallbackUrl", tx.CallBackURL) | ||
if opts.CallbackURL != "" { | ||
pld.AddHeader("X-CallbackUrl", opts.CallbackURL) | ||
} | ||
|
||
if tx.CallBackToken != "" { | ||
pld.AddHeader("X-CallbackToken", tx.CallBackToken) | ||
if opts.CallbackToken != "" { | ||
pld.AddHeader("X-CallbackToken", opts.CallbackToken) | ||
} | ||
|
||
if statusCode, ok := broadcast.MapTxStatusToInt(tx.WaitForStatus); ok { | ||
if statusCode, ok := broadcast.MapTxStatusToInt(opts.WaitForStatus); ok { | ||
pld.AddHeader("X-WaitForStatus", strconv.Itoa(statusCode)) | ||
} | ||
} |
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.
minor
I would rather want to see it as those With***
will append headers by themselves.
I will try to present that in the following pseudo code:
func submitTransaction(ctx context.Context, arc *ArcClient, tx *broadcast.Transaction, opts ...broadcast.TransactionOptFunc) (*broadcast.SubmitTxResponse, error) {
// (...)
// instead of this => appendSubmitTxHeaders(&pld, opts), there will be following:
for _, opt := range opts {
opt(&pld)
}
//(...)
}
func WithCallback(callbackURL string, callbackToken ...string) broadcast.TransactionOptFunc {
return func(o *broadcast.TransactionOpts) {
pld.AddHeader("X-CallbackUrl", callbackURL)
if len(callbackToken) > 0 {
pld.AddHeader("X-CallbackToken", callbackToken[])
}
}
}
// ... rest of With methods
dorzepowski
previously approved these changes
Aug 16, 2023
wregulski
force-pushed
the
feat-bux-162
branch
from
August 16, 2023 11:52
80a24d0
to
fbb0cd6
Compare
kuba-4chain
approved these changes
Aug 16, 2023
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 not just
func (a *ArcClient) SubmitTransaction(ctx context.Context, tx *broadcast.Transaction, options *TransactionOpts)
I don't understand why we need "functional" aproach here.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
No description provided.