Skip to content

Commit

Permalink
feat: BRC20 ingored vindicated inscription.
Browse files Browse the repository at this point in the history
  • Loading branch information
wanyvic authored and yann-sjtu committed Jan 5, 2024
1 parent 40d14f8 commit 7c442a4
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index/updater/inscription_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,6 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
.or_default()
.push(InscriptionOp {
txid: flotsam.txid,
// TODO by yxq
sequence_number,
inscription_number: self
.sequence_number_to_entry
Expand All @@ -661,10 +660,11 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
reinscription: _,
unbound,
inscription,
..
vindicated,
} => Action::New {
cursed,
unbound,
vindicated,
inscription,
},
},
Expand Down
103 changes: 103 additions & 0 deletions src/okx/datastore/ord/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,109 @@ pub enum Action {
cursed: bool,
unbound: bool,
inscription: Inscription,
#[serde(default)]
vindicated: bool,
},
Transfer,
}

#[cfg(test)]
mod tests {

use super::*;
use crate::test::inscription;
use bitcoin::OutPoint;
use std::str::FromStr;

#[test]
fn test_inscription_op_deserialize_with_default_vindicated() {
let txid =
Txid::from_str("b61b0172d95e266c18aea0c624db987e971a5d6d4ebc2aaed85da4642d635735").unwrap();

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
struct OldInscriptionOp {
pub txid: Txid,
pub action: OldAction,
pub sequence_number: u32,
pub inscription_number: Option<i32>,
pub inscription_id: InscriptionId,
pub old_satpoint: SatPoint,
pub new_satpoint: Option<SatPoint>,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
enum OldAction {
New {
cursed: bool,
unbound: bool,
inscription: Inscription,
},
Transfer,
}

let old_action = OldAction::New {
cursed: true,
unbound: true,
inscription: inscription("text/plain;charset=utf-8", "foobar"),
};
let bytes = rmp_serde::to_vec(&old_action).unwrap();
let new_action: Action = rmp_serde::from_slice(&bytes).unwrap();
assert_eq!(
new_action,
Action::New {
cursed: true,
unbound: true,
vindicated: false,
inscription: inscription("text/plain;charset=utf-8", "foobar"),
}
);

let old_operation = OldInscriptionOp {
txid,
action: OldAction::New {
cursed: true,
unbound: true,
inscription: inscription("text/plain;charset=utf-8", "foobar"),
},
sequence_number: 100,
inscription_number: Some(100),
inscription_id: InscriptionId { txid, index: 0 },
old_satpoint: SatPoint::from_str(
"1111111111111111111111111111111111111111111111111111111111111111:1:1",
)
.unwrap(),
new_satpoint: Some(SatPoint {
outpoint: OutPoint { txid, vout: 0 },
offset: 1,
}),
};

let bytes = rmp_serde::to_vec(&old_operation).unwrap();

let new_operation: InscriptionOp = rmp_serde::from_slice(&bytes).unwrap();

assert_eq!(
new_operation,
InscriptionOp {
txid,
action: Action::New {
cursed: true,
unbound: true,
vindicated: false,
inscription: inscription("text/plain;charset=utf-8", "foobar"),
},
sequence_number: 100,
inscription_number: Some(100),
inscription_id: InscriptionId { txid, index: 0 },
old_satpoint: SatPoint::from_str(
"1111111111111111111111111111111111111111111111111111111111111111:1:1",
)
.unwrap(),
new_satpoint: Some(SatPoint {
outpoint: OutPoint { txid, vout: 0 },
offset: 1,
}),
}
);
}
}
1 change: 1 addition & 0 deletions src/okx/datastore/ord/redb/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ mod tests {
action: Action::New {
cursed: false,
unbound: false,
vindicated: false,
inscription: inscription("text/plain;charset=utf-8", "foobar"),
},
sequence_number: 100,
Expand Down
1 change: 1 addition & 0 deletions src/okx/protocol/brc20/msg_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl Message {
Action::New {
cursed: false,
unbound: false,
vindicated: false,
inscription: _,
} if sat_in_outputs => {
match deserialize_brc20_operation(
Expand Down
3 changes: 3 additions & 0 deletions src/okx/protocol/brc20/operation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ mod tests {
&Action::New {
cursed: false,
unbound: false,
vindicated: false,
inscription: inscription.clone()
},
)
Expand All @@ -233,6 +234,7 @@ mod tests {
&Action::New {
cursed: false,
unbound: false,
vindicated: false,
inscription: inscription.clone()
},
)
Expand All @@ -253,6 +255,7 @@ mod tests {
&Action::New {
cursed: false,
unbound: false,
vindicated: false,
inscription: inscription.clone()
},
)
Expand Down
1 change: 1 addition & 0 deletions src/okx/protocol/ord/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub fn index_bitmap(
Action::New {
cursed: _,
unbound: _,
vindicated: _,
inscription,
} => {
if let Some((inscription_id, district)) =
Expand Down

0 comments on commit 7c442a4

Please sign in to comment.