Skip to content

Commit

Permalink
Use enums for status field (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomendezroyo authored May 16, 2024
1 parent 0ca3428 commit aa0185e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
11 changes: 10 additions & 1 deletion listener/internal/api/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@ type SignatureRequestDecoded struct {
SignatureRequest
}

type Status string

// create enum with status
const (
Unknown Status = "unknown"
Active Status = "active"
Inactive Status = "inactive"
)

type SignatureRequestDecodedWithActive struct {
SignatureRequestDecoded
Status string `json:"status"` // "unknown" | "active" | "inactive"
Status Status `json:"status"` // "unknown" | "active" | "inactive"
}

type DecodedPayload struct {
Expand Down
4 changes: 2 additions & 2 deletions listener/internal/api/validation/GetActiveValidators.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func GetActiveValidators(requestsDecoded []types.SignatureRequestDecoded, beacon
if _, isActive := activeValidatorMap[req.Pubkey]; isActive {
activeValidators = append(activeValidators, types.SignatureRequestDecodedWithActive{
SignatureRequestDecoded: req,
Status: "active",
Status: types.Active,
})
} else {
// do not append inactive validators
Expand All @@ -127,7 +127,7 @@ func GetSignatureRequestsDecodedWithUnknown(requests []types.SignatureRequestDec
for _, req := range requests {
signatureRequestsDecodedWithActive = append(signatureRequestsDecodedWithActive, types.SignatureRequestDecodedWithActive{
SignatureRequestDecoded: req,
Status: "unknown",
Status: types.Unknown,
})
}
return signatureRequestsDecodedWithActive
Expand Down
4 changes: 2 additions & 2 deletions listener/internal/api/validation/VerifySignature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestVerifySignature(t *testing.T) {
Network: "mainnet",
Tag: "solo"},
},
Status: "active",
Status: types.Active,
}

// Validate the signature
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestVerifySignatureError(t *testing.T) {
Tag: "solo",
},
},
Status: "active",
Status: types.Active,
}

// Validate the signature
Expand Down

0 comments on commit aa0185e

Please sign in to comment.