Skip to content

Commit

Permalink
Merge pull request #81 from RGB-WG/fix/80
Browse files Browse the repository at this point in the history
Add blank state transitions to state
  • Loading branch information
dr-orlovsky authored Jul 8, 2023
2 parents 79eb02c + 3e9166f commit ed81f8a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ wasm-bindgen-test = "0.3"
features = [ "all" ]

[patch.crates-io]
rgb-core = { git = "https://github.com/RGB-WG/rgb-core" }
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "preserve-historic-state" }
24 changes: 21 additions & 3 deletions std/src/interface/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,13 @@ impl<Seal: ExposedSeal> OperationBuilder<Seal> {
let serialized = value.to_strict_serialized::<{ u16::MAX as usize }>()?;

// Check value matches type requirements
let Some(type_id) = self.iimpl.global_state.iter().find(|t| t.name == name).map(|t| t.id) else {
let Some(type_id) = self
.iimpl
.global_state
.iter()
.find(|t| t.name == name)
.map(|t| t.id)
else {
return Err(BuilderError::GlobalNotFound(name));
};
let sem_id = self
Expand All @@ -383,7 +389,13 @@ impl<Seal: ExposedSeal> OperationBuilder<Seal> {
) -> Result<Self, BuilderError> {
let name = name.into();

let Some(type_id) = self.iimpl.assignments.iter().find(|t| t.name == name).map(|t| t.id) else {
let Some(type_id) = self
.iimpl
.assignments
.iter()
.find(|t| t.name == name)
.map(|t| t.id)
else {
return Err(BuilderError::AssignmentNotFound(name));
};

Expand Down Expand Up @@ -418,7 +430,13 @@ impl<Seal: ExposedSeal> OperationBuilder<Seal> {
let name = name.into();
let serialized = value.to_strict_serialized::<U16>()?;

let Some(type_id) = self.iimpl.assignments.iter().find(|t| t.name == name).map(|t| t.id) else {
let Some(type_id) = self
.iimpl
.assignments
.iter()
.find(|t| t.name == name)
.map(|t| t.id)
else {
return Err(BuilderError::AssignmentNotFound(name));
};

Expand Down
13 changes: 12 additions & 1 deletion std/src/persistence/stock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ use rgb::validation::{Status, Validity, Warning};
use rgb::{
validation, AnchorId, AnchoredBundle, Assign, AssignmentType, BundleId, ContractHistory,
ContractId, ContractState, ExposedState, Extension, Genesis, GenesisSeal, GraphSeal, OpId,
Operation, Opout, SecretSeal, SubSchema, Transition, TransitionBundle, TxoSeal, TypedAssigns,
Operation, Opout, OrderedTxid, SecretSeal, SubSchema, Transition, TransitionBundle, TxoSeal,
TypedAssigns,
};
use strict_encoding::{StrictDeserialize, StrictSerialize};

Expand Down Expand Up @@ -511,6 +512,16 @@ impl Inventory for Stock {
witness_txid: Txid,
) -> Result<(), InventoryError<<Self as Inventory>::Error>> {
self.index_bundle(contract_id, &bundle, witness_txid)?;
let history = self
.history
.get_mut(&contract_id)
.ok_or(InventoryInconsistency::StateAbsent(contract_id))?;
for item in bundle.values() {
if let Some(transition) = &item.transition {
let ord_txid = OrderedTxid::new(0, witness_txid);
history.add_transition(transition, ord_txid);
}
}
self.hoard.consume_bundle(bundle)?;
Ok(())
}
Expand Down

0 comments on commit ed81f8a

Please sign in to comment.