Skip to content

Commit ba5b2ff

Browse files
authored
Merge pull request #30 from spacesprotocol/json-format-cleanup
Update json format for bid psbt errors
2 parents 3107be9 + d373eea commit ba5b2ff

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

protocol/src/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,41 +117,47 @@ pub enum Covenant {
117117
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
118118
#[cfg_attr(
119119
feature = "serde",
120-
serde(rename_all = "snake_case", tag = "revoke_reason")
120+
serde(rename_all = "snake_case", tag = "reason")
121121
)]
122122
pub enum RevokeReason {
123-
BidPsbt(BidPsbtReason),
124123
/// Space was prematurely spent during the auctions phase
125124
PrematureClaim,
126125
/// Space output was spent either by spending it directly
127126
/// Space was transferred without following Input N => Output N+1 rule
128127
BadSpend,
129128
Expired,
129+
#[cfg_attr(feature = "serde", serde(untagged))]
130+
BidPsbt(BidPsbtReason)
130131
}
131132

132133
#[derive(Copy, Clone, PartialEq, Debug, Eq)]
133134
#[cfg_attr(
134135
feature = "serde",
135136
derive(Serialize, Deserialize),
136-
serde(rename_all = "snake_case")
137+
serde(rename_all = "snake_case", tag="reason")
137138
)]
138139
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
139140
pub enum RejectReason {
140141
AlreadyExists,
141-
BidPSBT(BidPsbtReason),
142+
#[cfg_attr(feature = "serde", serde(untagged))]
143+
BidPsbt(BidPsbtReason),
142144
}
143145

144146
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
145147
#[cfg_attr(
146148
feature = "serde",
147149
derive(Serialize, Deserialize),
148-
serde(rename_all = "snake_case", tag = "bid_psbt_reason")
150+
serde(tag = "reason")
149151
)]
150152
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
151153
pub enum BidPsbtReason {
154+
#[cfg_attr(feature = "serde", serde(rename = "bid_psbt_required"))]
152155
Required,
156+
#[cfg_attr(feature = "serde", serde(rename = "bid_psbt_low_bid_amount"))]
153157
LowBidAmount,
158+
#[cfg_attr(feature = "serde", serde(rename = "bid_psbt_bad_signature"))]
154159
BadSignature,
160+
#[cfg_attr(feature = "serde", serde(rename = "bid_psbt_output_spent"))]
155161
OutputSpent,
156162
}
157163

protocol/src/validate.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ pub struct RevokeParams {
8282
pub struct RejectParams {
8383
#[cfg_attr(feature = "bincode", bincode(with_serde))]
8484
pub name: SName,
85+
86+
#[cfg_attr(feature = "serde", serde(flatten))]
8587
pub reason: RejectReason,
8688
}
8789

@@ -338,7 +340,7 @@ impl Validator {
338340
None => {
339341
let reject = ScriptError::Reject(RejectParams {
340342
name,
341-
reason: RejectReason::BidPSBT(BidPsbtReason::Required),
343+
reason: RejectReason::BidPsbt(BidPsbtReason::Required),
342344
});
343345

344346
changeset.spends[spend_index].script_error = Some(reject);
@@ -350,7 +352,7 @@ impl Validator {
350352
if auctiond.output.is_none() {
351353
let reject = ScriptError::Reject(RejectParams {
352354
name,
353-
reason: RejectReason::BidPSBT(BidPsbtReason::OutputSpent),
355+
reason: RejectReason::BidPsbt(BidPsbtReason::OutputSpent),
354356
});
355357
changeset.spends[spend_index].script_error = Some(reject);
356358
return;
@@ -379,7 +381,7 @@ impl Validator {
379381
if !fullspaceout.verify_bid_sig() {
380382
let reject = ScriptError::Reject(RejectParams {
381383
name: fullspaceout.spaceout.space.unwrap().name,
382-
reason: RejectReason::BidPSBT(BidPsbtReason::BadSignature),
384+
reason: RejectReason::BidPsbt(BidPsbtReason::BadSignature),
383385
});
384386
changeset.spends[spend_index].script_error = Some(reject);
385387
return;

0 commit comments

Comments
 (0)