Skip to content

Commit

Permalink
fix: BlockRejectReason serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
zone117x committed Oct 24, 2024
1 parent f6450da commit 30f5d66
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
6 changes: 3 additions & 3 deletions components/chainhook-sdk/src/indexer/stacks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,8 @@ pub fn standardize_stacks_stackerdb_chunks(
reason: block_rejection.reason,
reason_code: match block_rejection.reason_code {
RejectCode::ValidationFailed(validate_reject_code) => {
BlockRejectReasonCode::ValidationFailed(
match validate_reject_code {
BlockRejectReasonCode::ValidationFailed {
validation_failed: match validate_reject_code {
ValidateRejectCode::BadBlockHash => {
BlockValidationFailedCode::BadBlockHash
}
Expand All @@ -751,7 +751,7 @@ pub fn standardize_stacks_stackerdb_chunks(
BlockValidationFailedCode::NoSuchTenure
}
},
)
}
}
RejectCode::NoSortitionView => BlockRejectReasonCode::NoSortitionView,
RejectCode::ConnectivityIssues => {
Expand Down
5 changes: 4 additions & 1 deletion components/chainhook-types-rs/src/signers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub struct SignerMessageMetadata {
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum BlockValidationFailedCode {
BadBlockHash,
BadTransaction,
Expand All @@ -54,9 +55,11 @@ pub enum BlockValidationFailedCode {
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[serde(untagged)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum BlockRejectReasonCode {
ValidationFailed(BlockValidationFailedCode),
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
ValidationFailed { validation_failed: BlockValidationFailedCode },
ConnectivityIssues,
RejectedInPriorRound,
NoSortitionView,
Expand Down
12 changes: 11 additions & 1 deletion components/client/typescript/src/schemas/stacks/signers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,17 @@ export const StacksSignerMessageBlockResponseRejectedSchema = Type.Object({
data: Type.Object({
reason: Type.String(),
reason_code: Type.Union([
Type.Literal('VALIDATION_FAILED'),
Type.Object({
VALIDATION_FAILED: Type.Union([
Type.Literal('BAD_BLOCK_HASH'),
Type.Literal('BAD_TRANSACTION'),
Type.Literal('INVALID_BLOCK'),
Type.Literal('CHAINSTATE_ERROR'),
Type.Literal('UNKNOWN_PARENT'),
Type.Literal('NON_CANONICAL_TENURE'),
Type.Literal('NO_SUCH_TENURE'),
]),
}),
Type.Literal('CONNECTIVITY_ISSUES'),
Type.Literal('REJECTED_IN_PRIOR_ROUND'),
Type.Literal('NO_SORTITION_VIEW'),
Expand Down

0 comments on commit 30f5d66

Please sign in to comment.