Skip to content
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

VINDICATION #2950

Merged
merged 10 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ pub enum List {
#[derive(Copy, Clone)]
pub(crate) enum Statistic {
Schema = 0,
BlessedInscriptions,
Commits,
CursedInscriptions,
IndexRunes,
IndexSats,
LostSats,
OutputsTraversed,
ReservedRunes,
Runes,
SatRanges,
UnboundInscriptions,
IndexTransactions,
BlessedInscriptions = 1,
Commits = 2,
CursedInscriptions = 3,
IndexRunes = 4,
IndexSats = 5,
LostSats = 6,
OutputsTraversed = 7,
ReservedRunes = 8,
Runes = 9,
SatRanges = 10,
UnboundInscriptions = 11,
IndexTransactions = 12,
}

impl Statistic {
Expand Down
18 changes: 13 additions & 5 deletions src/index/updater/inscription_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum Origin {
pointer: Option<u64>,
reinscription: bool,
unbound: bool,
vindicated: bool,
},
Old {
old_satpoint: SatPoint,
Expand Down Expand Up @@ -76,6 +77,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
let mut floating_inscriptions = Vec::new();
let mut id_counter = 0;
let mut inscribed_offsets = BTreeMap::new();
let jubilant = self.height >= self.chain.jubilee_height();
let mut total_input_value = 0;
let total_output_value = tx.output.iter().map(|txout| txout.value).sum::<u64>();

Expand Down Expand Up @@ -142,9 +144,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
index: id_counter,
};

let curse = if self.height >= self.chain.jubilee_height() {
None
} else if inscription.payload.unrecognized_even_field {
let curse = if inscription.payload.unrecognized_even_field {
Some(Curse::UnrecognizedEvenField)
} else if inscription.payload.duplicate_field {
Some(Curse::DuplicateField)
Expand Down Expand Up @@ -187,6 +187,8 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
None
};

let vindicated = jubilant && curse.is_some();

let unbound = current_input_value == 0
|| curse == Some(Curse::UnrecognizedEvenField)
|| inscription.payload.unrecognized_even_field;
Expand All @@ -201,13 +203,14 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
inscription_id,
offset,
origin: Origin::New {
reinscription: inscribed_offsets.get(&offset).is_some(),
cursed: curse.is_some(),
cursed: curse.is_some() && !jubilant,
fee: 0,
casey marked this conversation as resolved.
Show resolved Hide resolved
hidden: inscription.payload.hidden(),
parent: inscription.payload.parent(),
pointer: inscription.payload.pointer(),
reinscription: inscribed_offsets.get(&offset).is_some(),
unbound,
vindicated,
},
});

Expand Down Expand Up @@ -404,6 +407,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
pointer: _,
reinscription,
unbound,
vindicated,
} => {
let inscription_number = if cursed {
let number: i32 = self.cursed_inscription_count.try_into().unwrap();
Expand Down Expand Up @@ -467,6 +471,10 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
Charm::Unbound.set(&mut charms);
}

if vindicated {
Charm::Vindicated.set(&mut charms);
}

if let Some(Sat(n)) = sat {
self.sat_to_sequence_number.insert(&n, &sequence_number)?;
}
Expand Down
26 changes: 15 additions & 11 deletions src/inscriptions/charm.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#[derive(Copy, Clone)]
pub(crate) enum Charm {
Coin,
Cursed,
Epic,
Legendary,
Lost,
Nineball,
Rare,
Reinscription,
Unbound,
Uncommon,
Coin = 0,
Cursed = 1,
Epic = 2,
Legendary = 3,
Lost = 4,
Nineball = 5,
Rare = 6,
Reinscription = 7,
Unbound = 8,
Uncommon = 9,
Vindicated = 10,
}

impl Charm {
pub(crate) const ALL: [Charm; 10] = [
pub(crate) const ALL: [Charm; 11] = [
Self::Coin,
Self::Uncommon,
Self::Rare,
Expand All @@ -24,6 +25,7 @@ impl Charm {
Self::Cursed,
Self::Unbound,
Self::Lost,
Self::Vindicated,
];

fn flag(self) -> u16 {
Expand All @@ -50,6 +52,7 @@ impl Charm {
Self::Reinscription => "♻️",
Self::Unbound => "🔓",
Self::Uncommon => "🌱",
Self::Vindicated => "❤️‍🔥",
}
}

Expand All @@ -65,6 +68,7 @@ impl Charm {
Self::Reinscription => "reinscription",
Self::Unbound => "unbound",
Self::Uncommon => "uncommon",
Self::Vindicated => "vindicated",
}
}
}
5 changes: 5 additions & 0 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,11 @@ impl Server {
Ok(if accept_json {
Json(InscriptionJson {
inscription_id: info.entry.id,
charms: Charm::ALL
.iter()
.filter(|charm| charm.is_set(info.charms))
.map(|charm| charm.title().into())
.collect(),
children: info.children,
inscription_number: info.entry.inscription_number,
genesis_height: info.entry.height,
Expand Down
1 change: 1 addition & 0 deletions src/templates/inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub(crate) struct InscriptionHtml {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct InscriptionJson {
pub address: Option<String>,
pub charms: Vec<String>,
pub children: Vec<InscriptionId>,
pub content_length: Option<usize>,
pub content_type: Option<String>,
Expand Down
19 changes: 10 additions & 9 deletions tests/json_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,23 @@ fn get_inscription() {
pretty_assert_eq!(
inscription_json,
InscriptionJson {
parent: None,
address: None,
charms: vec!["coin".into(), "uncommon".into()],
children: Vec::new(),
content_length: Some(3),
content_type: Some("text/plain;charset=utf-8".to_string()),
genesis_fee: 138,
genesis_height: 2,
inscription_id,
inscription_number: 0,
genesis_height: 2,
genesis_fee: 138,
next: None,
output_value: Some(10000),
address: None,
parent: None,
previous: None,
rune: None,
sat: Some(ord::Sat(50 * COIN_VALUE)),
satpoint: SatPoint::from_str(&format!("{}:{}:{}", reveal, 0, 0)).unwrap(),
content_type: Some("text/plain;charset=utf-8".to_string()),
content_length: Some(3),
timestamp: 2,
previous: None,
next: None,
rune: None,
}
)
}
Expand Down
Loading