-
Notifications
You must be signed in to change notification settings - Fork 1
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 logging and tracing middleware and slight reorg #10
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
|
@@ -100,3 +100,4 @@ workflows: | |
only: | ||
- main | ||
- dev | ||
- logging-middleware |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package tracing | ||
|
||
import ( | ||
"context" | ||
"github.com/google/uuid" | ||
) | ||
|
||
type TraceContextKey string | ||
|
||
const TraceInfoKey = TraceContextKey("requestTracingInfo") | ||
const TraceIdKey = TraceContextKey("requestTraceId") | ||
|
||
type SpanDetail struct { | ||
Name string | ||
Duration int64 | ||
} | ||
|
||
type TracingInfo struct { | ||
SpanDetails []SpanDetail | ||
} | ||
|
||
func AttachTracingIntoContext(ctx context.Context) context.Context { | ||
// Attach traceId into context | ||
traceID := uuid.New().String() | ||
ctx = context.WithValue(ctx, TraceIdKey, traceID) | ||
|
||
// Start tracingInfo | ||
return context.WithValue(ctx, TraceInfoKey, &TracingInfo{}) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package handlers | ||
|
||
import ( | ||
"context" | ||
s "github.com/babylonchain/covenant-signer/signerapp" | ||
"net/http" | ||
) | ||
|
||
type Handler struct { | ||
s *s.SignerApp | ||
} | ||
|
||
type Result struct { | ||
Data interface{} | ||
Status int | ||
} | ||
|
||
type PublicResponse[T any] struct { | ||
Data T `json:"data"` | ||
} | ||
|
||
func NewResult[T any](data T) *Result { | ||
res := &PublicResponse[T]{Data: data} | ||
return &Result{Data: res, Status: http.StatusOK} | ||
} | ||
|
||
func NewHandler( | ||
_ context.Context, s *s.SignerApp, | ||
) (*Handler, error) { | ||
return &Handler{ | ||
s: s, | ||
}, 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,60 @@ | ||
package handlers | ||
|
||
import ( | ||
"encoding/hex" | ||
"encoding/json" | ||
"github.com/babylonchain/covenant-signer/signerservice/types" | ||
"github.com/babylonchain/covenant-signer/utils" | ||
"github.com/btcsuite/btcd/btcec/v2" | ||
"net/http" | ||
) | ||
|
||
func (h *Handler) SignUnbonding(request *http.Request) (*Result, *types.Error) { | ||
payload := &types.SignUnbondingTxRequest{} | ||
err := json.NewDecoder(request.Body).Decode(payload) | ||
if err != nil { | ||
return nil, types.NewErrorWithMsg(http.StatusBadRequest, types.BadRequest, "invalid request payload") | ||
} | ||
|
||
pkScript, err := hex.DecodeString(payload.StakingOutputPkScriptHex) | ||
|
||
if err != nil { | ||
return nil, types.NewErrorWithMsg(http.StatusBadRequest, types.BadRequest, "invalid staking output pk script") | ||
} | ||
|
||
covenantPublicKeyBytes, err := hex.DecodeString(payload.CovenantPublicKey) | ||
|
||
if err != nil { | ||
return nil, types.NewErrorWithMsg(http.StatusBadRequest, types.BadRequest, "invalid covenant public key") | ||
} | ||
|
||
covenantPublicKey, err := btcec.ParsePubKey(covenantPublicKeyBytes) | ||
|
||
if err != nil { | ||
return nil, types.NewErrorWithMsg(http.StatusBadRequest, types.BadRequest, "invalid covenant public key") | ||
} | ||
|
||
unbondingTx, _, err := utils.NewBTCTxFromHex(payload.UnbondingTxHex) | ||
|
||
if err != nil { | ||
return nil, types.NewErrorWithMsg(http.StatusBadRequest, types.BadRequest, "invalid unbonding transaction") | ||
} | ||
|
||
sig, err := h.s.SignUnbondingTransaction( | ||
request.Context(), | ||
pkScript, | ||
unbondingTx, | ||
covenantPublicKey, | ||
) | ||
|
||
if err != nil { | ||
// TODO Properly translate errors between layers | ||
return nil, types.NewErrorWithMsg(http.StatusInternalServerError, types.InternalServiceError, err.Error()) | ||
} | ||
|
||
resp := types.SignUnbondingTxResponse{ | ||
SignatureHex: hex.EncodeToString(sig.Serialize()), | ||
} | ||
|
||
return NewResult(resp), 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
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.
I find this change a bit controversial tbh. Mainly:
slog
). Imo it is better to minimze amount of dependendcies.Not a blocker for this pr as I understand this makes it consistent with staking api, but nevertheless we can re-think this at some point.
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.
Makes sense, created #12 to track it