Skip to content

Commit 484afab

Browse files
committed
stockpile: forward implementation
1 parent d37dff0 commit 484afab

File tree

5 files changed

+27
-30
lines changed

5 files changed

+27
-30
lines changed

Cargo.lock

+5-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ wasm-bindgen-test = "0.3"
108108
features = ["all"]
109109

110110
[patch.crates-io]
111+
aora = { git = "https://github.com/rust-amplify/aora", branch = "master" }
111112
aluvm = { git = "https://github.com/AluVM/aluvm", branch = "master" }
112113
zk-aluvm = { git = "https://github.com/AluVM/zk-aluvm", branch = "master" }
113114
ultrasonic = { git = "https://github.com/AluVM/ultrasonic", branch = "master" }
114-
sonic-api = { git = "https://github.com/AluVM/sonic", branch = "master" }
115-
sonic-callreq = { git = "https://github.com/AluVM/sonic", branch = "master" }
116-
hypersonic = { git = "https://github.com/AluVM/sonic", branch = "master" }
115+
sonic-api = { git = "https://github.com/AluVM/sonic", branch = "rollback" }
116+
sonic-callreq = { git = "https://github.com/AluVM/sonic", branch = "rollback" }
117+
hypersonic = { git = "https://github.com/AluVM/sonic", branch = "rollback" }
117118
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "v0.12" }

src/pile.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,14 @@ pub struct WitnessStatus {
6767
pub mining_id: Bytes32,
6868
}
6969

70-
pub trait Pile {
70+
pub trait Pile
71+
where <Self::Seal as RgbSeal>::WitnessId: From<[u8; 32]> + Into<[u8; 32]>
72+
{
7173
type Seal: RgbSeal;
7274

73-
type Hoard: Aora<
74-
Id = <Self::Seal as RgbSeal>::WitnessId,
75-
Item = <Self::Seal as RgbSeal>::Client,
76-
>;
77-
type Cache: Aora<
78-
Id = <Self::Seal as RgbSeal>::WitnessId,
79-
Item = <Self::Seal as RgbSeal>::Published,
80-
>;
81-
type Keep: Aora<Id = Opid, Item = SmallOrdMap<u16, <Self::Seal as RgbSeal>::Definiton>>;
75+
type Hoard: Aora<<Self::Seal as RgbSeal>::WitnessId, <Self::Seal as RgbSeal>::Client>;
76+
type Cache: Aora<<Self::Seal as RgbSeal>::WitnessId, <Self::Seal as RgbSeal>::Published>;
77+
type Keep: Aora<Opid, SmallOrdMap<u16, <Self::Seal as RgbSeal>::Definiton>>;
8278
type Index: Index<Opid, <Self::Seal as RgbSeal>::WitnessId>;
8379
type Stand: Index<<Self::Seal as RgbSeal>::WitnessId, Opid>;
8480
type Mine: Cru<<Self::Seal as RgbSeal>::WitnessId, Option<WitnessStatus>>;
@@ -109,7 +105,7 @@ pub trait Pile {
109105
self.index_mut().add(opid, pubid);
110106
self.stand_mut().add(pubid, opid);
111107
if self.hoard_mut().has(&pubid) {
112-
let mut prev_anchor = self.hoard_mut().read(pubid);
108+
let mut prev_anchor = self.hoard_mut().read(&pubid);
113109
if prev_anchor != anchor {
114110
prev_anchor.merge(anchor).expect(
115111
"existing anchor is not compatible with new one; this indicates either bug in \
@@ -384,8 +380,8 @@ pub mod fs {
384380

385381
fn retrieve(&mut self, opid: Opid) -> impl ExactSizeIterator<Item = SealWitness<Seal>> {
386382
self.index.get(opid).map(|pubid| {
387-
let client = self.hoard.read(pubid);
388-
let published = self.cache.read(pubid);
383+
let client = self.hoard.read(&pubid);
384+
let published = self.cache.read(&pubid);
389385
SealWitness::new(published, client)
390386
})
391387
}

src/popls/bp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ impl<W: WalletProvider, S: Supply, P: Pile<Seal = TxoSeal>, X: Excavate<S, P>> B
662662
.iter()
663663
.flat_map(|(name, map)| map.iter().map(move |(addr, val)| (name, *addr, val)))
664664
.filter_map(|(name, addr, val)| {
665-
let seals = stockpile.pile_mut().keep_mut().read(addr.opid);
665+
let seals = stockpile.pile_mut().keep_mut().read(&addr.opid);
666666
let seal = seals.get(&addr.pos)?;
667667
let outpoint = if let WOutpoint::Extern(outpoint) = seal.primary {
668668
if !outpoints.contains(&outpoint) {

src/stockpile.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ use chrono::{DateTime, Utc};
3535
use commit_verify::ReservedBytes;
3636
use hypersonic::sigs::ContentSigs;
3737
use hypersonic::{
38-
Articles, AuthToken, CellAddr, Codex, CodexId, Consensus, Contract, ContractId, CoreParams,
39-
DataCell, IssueParams, LibRepo, Memory, MergeError, MethodName, NamedState, Operation, Opid,
40-
Schema, StateAtom, StateName, Stock, Supply,
38+
AcceptError, Articles, AuthToken, CellAddr, Codex, CodexId, Consensus, Contract, ContractId,
39+
CoreParams, DataCell, IssueParams, LibRepo, Memory, MergeError, MethodName, NamedState,
40+
Operation, Opid, Schema, StateAtom, StateName, Stock, Supply,
4141
};
4242
use rgb::{
4343
ContractApi, ContractVerify, OperationSeals, ReadOperation, ReadWitness, RgbSeal, RgbSealDef,
@@ -290,7 +290,7 @@ impl<S: Supply, P: Pile> Stockpile<S, P> {
290290
let since = *cache
291291
.entry(addr.opid)
292292
.or_insert_with(|| self.pile().since(addr.opid));
293-
let seals = self.pile_mut().keep_mut().read(addr.opid);
293+
let seals = self.pile_mut().keep_mut().read(&addr.opid);
294294
let Some(seal) = seals.get(&addr.pos) else {
295295
continue;
296296
};
@@ -344,7 +344,7 @@ impl<S: Supply, P: Pile> Stockpile<S, P> {
344344
self.stock
345345
.export_aux(terminals, writer, |opid, mut writer| {
346346
// Write seal definitions
347-
let seals = self.pile.keep_mut().read(opid);
347+
let seals = self.pile.keep_mut().read(&opid);
348348
writer = seals.strict_encode(writer)?;
349349

350350
// Write witnesses
@@ -438,14 +438,15 @@ impl<S: Supply, P: Pile> Stockpile<S, P> {
438438
&mut self,
439439
pubid: <P::Seal as RgbSeal>::WitnessId,
440440
status: Option<WitnessStatus>,
441-
) {
441+
) -> Result<(), AcceptError> {
442442
let opids = self.pile.stand().get(pubid);
443443
if status.is_none() {
444444
self.stock.rollback(opids);
445445
} else {
446-
self.stock.forward(opids);
446+
self.stock.forward(opids)?;
447447
}
448448
self.pile_mut().mine_mut().update(pubid, status);
449+
Ok(())
449450
}
450451
}
451452

0 commit comments

Comments
 (0)