Skip to content

Commit da1f370

Browse files
committed
add all addresses route
1 parent 3ee67d7 commit da1f370

File tree

9 files changed

+143
-85
lines changed

9 files changed

+143
-85
lines changed

crates/mockcore/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl Handle {
213213
.unwrap()
214214
}
215215

216-
pub fn state(&self) -> MutexGuard<State> {
216+
pub fn state<'a>(&'a self) -> MutexGuard<'a, State> {
217217
self.state.lock().unwrap()
218218
}
219219

crates/mockcore/src/server.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use {
22
super::*,
33
base64::Engine,
44
bellscoin::{consensus::Decodable, psbt::Psbt, Witness},
5+
bellscoincore_rpc::json::StringOrStringArray,
56
std::io::Cursor,
67
};
78

@@ -16,7 +17,7 @@ impl Server {
1617
Self { network, state }
1718
}
1819

19-
fn state(&self) -> MutexGuard<State> {
20+
fn state<'a>(&'a self) -> MutexGuard<'a, State> {
2021
self.state.lock().unwrap()
2122
}
2223

@@ -71,7 +72,7 @@ impl Api for Server {
7172
automatic_pruning: None,
7273
prune_target_size: None,
7374
softforks: HashMap::new(),
74-
warnings: String::new(),
75+
warnings: StringOrStringArray::String(String::new()),
7576
})
7677
}
7778

@@ -91,7 +92,7 @@ impl Api for Server {
9192
relay_fee: Amount::from_sat(0),
9293
incremental_fee: Amount::from_sat(0),
9394
local_addresses: Vec::new(),
94-
warnings: String::new(),
95+
warnings: StringOrStringArray::String(String::new()),
9596
})
9697
}
9798

crates/ordinals/src/subsidy.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ pub fn get_block_subsidy(n_height: u32, network: Network) -> u64 {
107107
return n_subsidy; // First 100 blocks have minimal rewards.
108108
}
109109

110-
if network == Network::Bellscoin {
111-
if n_height >= AUXPOW_START_HEIGHT && n_height < AUXPOW_START_HEIGHT + AUXPOW_THRESHOLD {
112-
return n_subsidy;
113-
}
110+
if network == Network::Bellscoin
111+
&& (AUXPOW_START_HEIGHT..AUXPOW_START_HEIGHT + AUXPOW_THRESHOLD).contains(&n_height)
112+
{
113+
return n_subsidy;
114114
}
115115

116116
let rand = generate_mt_random(n_height, 1000);

src/api.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,7 @@ pub struct AddressInfo {
226226
pub sat_balance: u64,
227227
pub runes_balances: Vec<(SpacedRune, Decimal, Option<char>)>,
228228
}
229+
230+
#[derive(Debug, PartialEq, Serialize, Deserialize)]
231+
#[repr(transparent)]
232+
pub struct AddressRunes(pub Vec<(SpacedRune, Decimal, Option<char>)>);

src/index.rs

Lines changed: 65 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,8 @@ impl Index {
385385
etching,
386386
terms: Some(Terms {
387387
amount: Some(100),
388-
cap: Some(1_000_000_000 as u128),
389-
height: (Some(350_000), Some(Epoch(5).starting_height().0 as u64)),
388+
cap: Some(1_000_000_000),
389+
height: (Some(350_000), Some(u64::from(Epoch(5).starting_height().0))),
390390
offset: (None, None),
391391
}),
392392
mints: 0,
@@ -1491,7 +1491,7 @@ impl Index {
14911491
.open_table(INSCRIPTION_ID_TO_OUTPOINTS)?
14921492
.get(&inscription_id.store())?
14931493
.map(|x| x.value())
1494-
.map(|x| Vec::<OutPoint>::load(x))
1494+
.map(Vec::<OutPoint>::load)
14951495
else {
14961496
return Ok(None);
14971497
};
@@ -1500,8 +1500,7 @@ impl Index {
15001500
.get_transactions(partial_txs.iter().map(|x| x.txid))?
15011501
.into_iter()
15021502
.zip(partial_txs.iter().map(|x| x.txid))
1503-
.map(|(tx, txid)| tx.map(|tx| (txid, tx)))
1504-
.flatten()
1503+
.filter_map(|(tx, txid)| tx.map(|tx| (txid, tx)))
15051504
.collect::<HashMap<_, _>>();
15061505

15071506
let scripts = partial_txs
@@ -2340,6 +2339,55 @@ impl Index {
23402339
.collect()
23412340
}
23422341

2342+
pub fn get_address_runes(
2343+
&self,
2344+
address: &Address,
2345+
) -> Result<Vec<(SpacedRune, Decimal, Option<char>)>> {
2346+
let v = self
2347+
.database
2348+
.begin_read()?
2349+
.open_multimap_table(SCRIPT_PUBKEY_TO_OUTPOINT)?
2350+
.get(address.script_pubkey().as_bytes())?
2351+
.map(|result| {
2352+
result
2353+
.map_err(|err| anyhow!(err))
2354+
.map(|value| OutPoint::load(value.value()))
2355+
.and_then(|outpoint| {
2356+
self
2357+
.get_rune_balances_for_output(outpoint)
2358+
.map_err(|err| anyhow!(err))
2359+
})
2360+
})
2361+
.collect::<Result<Vec<BTreeMap<SpacedRune, Pile>>>>()?;
2362+
2363+
let mut runes = BTreeMap::new();
2364+
2365+
for rune_balances in v {
2366+
for (spaced_rune, pile) in rune_balances {
2367+
runes
2368+
.entry(spaced_rune)
2369+
.and_modify(|(decimal, _symbol): &mut (Decimal, Option<char>)| {
2370+
assert_eq!(decimal.scale, pile.divisibility);
2371+
decimal.value += pile.amount;
2372+
})
2373+
.or_insert((
2374+
Decimal {
2375+
value: pile.amount,
2376+
scale: pile.divisibility,
2377+
},
2378+
pile.symbol,
2379+
));
2380+
}
2381+
}
2382+
2383+
Ok(
2384+
runes
2385+
.into_iter()
2386+
.map(|(spaced_rune, (decimal, symbol))| (spaced_rune, decimal, symbol))
2387+
.collect(),
2388+
)
2389+
}
2390+
23432391
pub(crate) fn get_aggregated_rune_balances_for_outputs(
23442392
&self,
23452393
outputs: &Vec<OutPoint>,
@@ -6053,13 +6101,9 @@ mod tests {
60536101
.unwrap()
60546102
.unwrap();
60556103

6056-
assert!(Charm::charms(entry.charms)
6057-
.iter()
6058-
.any(|charm| *charm == Charm::Cursed));
6104+
assert!(Charm::charms(entry.charms).contains(&Charm::Cursed));
60596105

6060-
assert!(!Charm::charms(entry.charms)
6061-
.iter()
6062-
.any(|charm| *charm == Charm::Vindicated));
6106+
assert!(!Charm::charms(entry.charms).contains(&Charm::Vindicated));
60636107

60646108
let sat = entry.sat;
60656109

@@ -6087,13 +6131,9 @@ mod tests {
60876131

60886132
assert_eq!(entry.inscription_number, 0);
60896133

6090-
assert!(!Charm::charms(entry.charms)
6091-
.iter()
6092-
.any(|charm| *charm == Charm::Cursed));
6134+
assert!(!Charm::charms(entry.charms).contains(&Charm::Cursed));
60936135

6094-
assert!(!Charm::charms(entry.charms)
6095-
.iter()
6096-
.any(|charm| *charm == Charm::Vindicated));
6136+
assert!(!Charm::charms(entry.charms).contains(&Charm::Vindicated));
60976137

60986138
assert_eq!(sat, entry.sat);
60996139

@@ -6117,13 +6157,9 @@ mod tests {
61176157
.unwrap()
61186158
.unwrap();
61196159

6120-
assert!(Charm::charms(entry.charms)
6121-
.iter()
6122-
.any(|charm| *charm == Charm::Cursed));
6160+
assert!(Charm::charms(entry.charms).contains(&Charm::Cursed));
61236161

6124-
assert!(!Charm::charms(entry.charms)
6125-
.iter()
6126-
.any(|charm| *charm == Charm::Vindicated));
6162+
assert!(!Charm::charms(entry.charms).contains(&Charm::Vindicated));
61276163

61286164
assert_eq!(entry.inscription_number, -2);
61296165

@@ -6164,13 +6200,9 @@ mod tests {
61646200
.unwrap()
61656201
.unwrap();
61666202

6167-
assert!(!Charm::charms(entry.charms)
6168-
.iter()
6169-
.any(|charm| *charm == Charm::Cursed));
6203+
assert!(!Charm::charms(entry.charms).contains(&Charm::Cursed));
61706204

6171-
assert!(Charm::charms(entry.charms)
6172-
.iter()
6173-
.any(|charm| *charm == Charm::Vindicated));
6205+
assert!(Charm::charms(entry.charms).contains(&Charm::Vindicated));
61746206

61756207
let sat = entry.sat;
61766208

@@ -6196,13 +6228,9 @@ mod tests {
61966228
.unwrap()
61976229
.unwrap();
61986230

6199-
assert!(!Charm::charms(entry.charms)
6200-
.iter()
6201-
.any(|charm| *charm == Charm::Cursed));
6231+
assert!(!Charm::charms(entry.charms).contains(&Charm::Cursed));
62026232

6203-
assert!(!Charm::charms(entry.charms)
6204-
.iter()
6205-
.any(|charm| *charm == Charm::Vindicated));
6233+
assert!(!Charm::charms(entry.charms).contains(&Charm::Vindicated));
62066234

62076235
assert_eq!(entry.inscription_number, 1);
62086236

@@ -6228,13 +6256,9 @@ mod tests {
62286256
.unwrap()
62296257
.unwrap();
62306258

6231-
assert!(!Charm::charms(entry.charms)
6232-
.iter()
6233-
.any(|charm| *charm == Charm::Cursed));
6259+
assert!(!Charm::charms(entry.charms).contains(&Charm::Cursed));
62346260

6235-
assert!(Charm::charms(entry.charms)
6236-
.iter()
6237-
.any(|charm| *charm == Charm::Vindicated));
6261+
assert!(Charm::charms(entry.charms).contains(&Charm::Vindicated));
62386262

62396263
assert_eq!(entry.inscription_number, 2);
62406264

src/index/updater/inscription_updater.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<'a, 'tx> InscriptionUpdater<'a, 'tx> {
139139
.unwrap_or(Partial {
140140
outpoints: vec![],
141141
inscription_idx: id_counter,
142-
vout: input_index as u32,
142+
vout: input_index.try_into().unwrap(),
143143
});
144144

145145
let mut txs = HashMap::<Txid, Transaction>::from_iter([(txid, tx.clone())]);
@@ -156,7 +156,7 @@ impl<'a, 'tx> InscriptionUpdater<'a, 'tx> {
156156

157157
partials.outpoints.push(OutPoint {
158158
txid,
159-
vout: input_index as u32,
159+
vout: input_index.try_into().unwrap(),
160160
});
161161

162162
let scripts = partials
@@ -249,7 +249,7 @@ impl<'a, 'tx> InscriptionUpdater<'a, 'tx> {
249249
self.partials.insert(
250250
&OutPoint {
251251
txid,
252-
vout: input_index as u32,
252+
vout: input_index.try_into().unwrap(),
253253
}
254254
.store(),
255255
partials.store(),

src/index/utxo_entry.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub struct UtxoEntry {
4141
}
4242

4343
impl UtxoEntry {
44-
pub fn parse(&self, index: &Index) -> ParsedUtxoEntry {
44+
pub fn parse<'a>(&'a self, index: &Index) -> ParsedUtxoEntry<'a> {
4545
let sats;
4646
let mut script_pubkey = None;
4747
let mut inscriptions = None;
@@ -91,8 +91,14 @@ impl UtxoEntry {
9191
}
9292

9393
impl redb::Value for &UtxoEntry {
94-
type SelfType<'a> = &'a UtxoEntry where Self: 'a;
95-
type AsBytes<'a> = &'a [u8] where Self: 'a;
94+
type SelfType<'a>
95+
= &'a UtxoEntry
96+
where
97+
Self: 'a;
98+
type AsBytes<'a>
99+
= &'a [u8]
100+
where
101+
Self: 'a;
96102

97103
fn fixed_width() -> Option<usize> {
98104
None

src/partials.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl InscriptionParser {
112112

113113
sig_scripts = &sig_scripts[1..];
114114

115-
push_datas_vec = match Self::decode_push_datas(&sig_scripts[0]) {
115+
push_datas_vec = match Self::decode_push_datas(sig_scripts[0]) {
116116
Some(push_datas) => push_datas,
117117
None => return ParsedInscription::None,
118118
};
@@ -228,7 +228,7 @@ impl InscriptionParser {
228228
let mut m: u64 = 0;
229229

230230
for i in data {
231-
n += (*i as u64) << m;
231+
n += u64::from(*i) << m;
232232
m += 8;
233233
}
234234

0 commit comments

Comments
 (0)