Adds `issued_assets` fields on `ChainInner` and `ContextuallyValidatedBlock`
This commit is contained in:
parent
c7116f33b1
commit
bb62c67ba0
|
@ -103,8 +103,12 @@ impl ContextuallyVerifiedBlock {
|
||||||
.map(|outpoint| (outpoint, zero_utxo.clone()))
|
.map(|outpoint| (outpoint, zero_utxo.clone()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
ContextuallyVerifiedBlock::with_block_and_spent_utxos(block, zero_spent_utxos)
|
ContextuallyVerifiedBlock::with_block_and_spent_utxos(
|
||||||
.expect("all UTXOs are provided with zero values")
|
block,
|
||||||
|
zero_spent_utxos,
|
||||||
|
Default::default(),
|
||||||
|
)
|
||||||
|
.expect("all UTXOs are provided with zero values")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a [`ContextuallyVerifiedBlock`] from a [`Block`] or [`SemanticallyVerifiedBlock`],
|
/// Create a [`ContextuallyVerifiedBlock`] from a [`Block`] or [`SemanticallyVerifiedBlock`],
|
||||||
|
@ -133,6 +137,7 @@ impl ContextuallyVerifiedBlock {
|
||||||
spent_outputs: new_outputs,
|
spent_outputs: new_outputs,
|
||||||
transaction_hashes,
|
transaction_hashes,
|
||||||
chain_value_pool_change: ValueBalance::zero(),
|
chain_value_pool_change: ValueBalance::zero(),
|
||||||
|
issued_assets: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -227,6 +227,10 @@ pub struct ContextuallyVerifiedBlock {
|
||||||
|
|
||||||
/// The sum of the chain value pool changes of all transactions in this block.
|
/// The sum of the chain value pool changes of all transactions in this block.
|
||||||
pub(crate) chain_value_pool_change: ValueBalance<NegativeAllowed>,
|
pub(crate) chain_value_pool_change: ValueBalance<NegativeAllowed>,
|
||||||
|
|
||||||
|
/// A partial map of `issued_assets` with entries for asset states that were updated in
|
||||||
|
/// this block.
|
||||||
|
pub(crate) issued_assets: IssuedAssets,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wraps note commitment trees and the history tree together.
|
/// Wraps note commitment trees and the history tree together.
|
||||||
|
@ -431,6 +435,7 @@ impl ContextuallyVerifiedBlock {
|
||||||
pub fn with_block_and_spent_utxos(
|
pub fn with_block_and_spent_utxos(
|
||||||
semantically_verified: SemanticallyVerifiedBlock,
|
semantically_verified: SemanticallyVerifiedBlock,
|
||||||
mut spent_outputs: HashMap<transparent::OutPoint, transparent::OrderedUtxo>,
|
mut spent_outputs: HashMap<transparent::OutPoint, transparent::OrderedUtxo>,
|
||||||
|
issued_assets: IssuedAssets,
|
||||||
) -> Result<Self, ValueBalanceError> {
|
) -> Result<Self, ValueBalanceError> {
|
||||||
let SemanticallyVerifiedBlock {
|
let SemanticallyVerifiedBlock {
|
||||||
block,
|
block,
|
||||||
|
@ -459,6 +464,7 @@ impl ContextuallyVerifiedBlock {
|
||||||
&utxos_from_ordered_utxos(spent_outputs),
|
&utxos_from_ordered_utxos(spent_outputs),
|
||||||
deferred_balance,
|
deferred_balance,
|
||||||
)?,
|
)?,
|
||||||
|
issued_assets,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -325,7 +325,7 @@ impl NonFinalizedState {
|
||||||
finalized_state,
|
finalized_state,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let _issued_assets =
|
let issued_assets =
|
||||||
check::issuance::valid_burns_and_issuance(finalized_state, &new_chain, &prepared)?;
|
check::issuance::valid_burns_and_issuance(finalized_state, &new_chain, &prepared)?;
|
||||||
|
|
||||||
// Reads from disk
|
// Reads from disk
|
||||||
|
@ -346,6 +346,8 @@ impl NonFinalizedState {
|
||||||
let contextual = ContextuallyVerifiedBlock::with_block_and_spent_utxos(
|
let contextual = ContextuallyVerifiedBlock::with_block_and_spent_utxos(
|
||||||
prepared.clone(),
|
prepared.clone(),
|
||||||
spent_utxos.clone(),
|
spent_utxos.clone(),
|
||||||
|
// TODO: Refactor this into repeated `With::with()` calls, see http_request_compatibility module.
|
||||||
|
issued_assets,
|
||||||
)
|
)
|
||||||
.map_err(|value_balance_error| {
|
.map_err(|value_balance_error| {
|
||||||
ValidateContextError::CalculateBlockChainValueChange {
|
ValidateContextError::CalculateBlockChainValueChange {
|
||||||
|
|
|
@ -177,6 +177,11 @@ pub struct ChainInner {
|
||||||
pub(crate) orchard_subtrees:
|
pub(crate) orchard_subtrees:
|
||||||
BTreeMap<NoteCommitmentSubtreeIndex, NoteCommitmentSubtreeData<orchard::tree::Node>>,
|
BTreeMap<NoteCommitmentSubtreeIndex, NoteCommitmentSubtreeData<orchard::tree::Node>>,
|
||||||
|
|
||||||
|
/// A partial map of `issued_assets` with entries for asset states that were updated in
|
||||||
|
/// this chain.
|
||||||
|
// TODO: Add reference to ZIP
|
||||||
|
pub(crate) issued_assets: HashMap<AssetBase, AssetState>,
|
||||||
|
|
||||||
// Nullifiers
|
// Nullifiers
|
||||||
//
|
//
|
||||||
/// The Sprout nullifiers revealed by `blocks`.
|
/// The Sprout nullifiers revealed by `blocks`.
|
||||||
|
@ -240,6 +245,7 @@ impl Chain {
|
||||||
orchard_anchors_by_height: Default::default(),
|
orchard_anchors_by_height: Default::default(),
|
||||||
orchard_trees_by_height: Default::default(),
|
orchard_trees_by_height: Default::default(),
|
||||||
orchard_subtrees: Default::default(),
|
orchard_subtrees: Default::default(),
|
||||||
|
issued_assets: Default::default(),
|
||||||
sprout_nullifiers: Default::default(),
|
sprout_nullifiers: Default::default(),
|
||||||
sapling_nullifiers: Default::default(),
|
sapling_nullifiers: Default::default(),
|
||||||
orchard_nullifiers: Default::default(),
|
orchard_nullifiers: Default::default(),
|
||||||
|
@ -942,9 +948,8 @@ impl Chain {
|
||||||
|
|
||||||
/// Returns the Orchard issued asset state if one is present in
|
/// Returns the Orchard issued asset state if one is present in
|
||||||
/// the chain for the provided asset base.
|
/// the chain for the provided asset base.
|
||||||
pub fn issued_asset(&self, _asset_base: &AssetBase) -> Option<AssetState> {
|
pub fn issued_asset(&self, asset_base: &AssetBase) -> Option<AssetState> {
|
||||||
// self.orchard_issued_assets.get(asset_base).cloned()
|
self.issued_assets.get(asset_base).cloned()
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds the Orchard `tree` to the tree and anchor indexes at `height`.
|
/// Adds the Orchard `tree` to the tree and anchor indexes at `height`.
|
||||||
|
|
|
@ -52,6 +52,7 @@ fn push_genesis_chain() -> Result<()> {
|
||||||
ContextuallyVerifiedBlock::with_block_and_spent_utxos(
|
ContextuallyVerifiedBlock::with_block_and_spent_utxos(
|
||||||
block,
|
block,
|
||||||
only_chain.unspent_utxos(),
|
only_chain.unspent_utxos(),
|
||||||
|
Default::default(),
|
||||||
)
|
)
|
||||||
.map_err(|e| (e, chain_values.clone()))
|
.map_err(|e| (e, chain_values.clone()))
|
||||||
.expect("invalid block value pool change");
|
.expect("invalid block value pool change");
|
||||||
|
@ -148,6 +149,7 @@ fn forked_equals_pushed_genesis() -> Result<()> {
|
||||||
let block = ContextuallyVerifiedBlock::with_block_and_spent_utxos(
|
let block = ContextuallyVerifiedBlock::with_block_and_spent_utxos(
|
||||||
block,
|
block,
|
||||||
partial_chain.unspent_utxos(),
|
partial_chain.unspent_utxos(),
|
||||||
|
Default::default()
|
||||||
)?;
|
)?;
|
||||||
partial_chain = partial_chain
|
partial_chain = partial_chain
|
||||||
.push(block)
|
.push(block)
|
||||||
|
@ -167,7 +169,7 @@ fn forked_equals_pushed_genesis() -> Result<()> {
|
||||||
|
|
||||||
for block in chain.iter().cloned() {
|
for block in chain.iter().cloned() {
|
||||||
let block =
|
let block =
|
||||||
ContextuallyVerifiedBlock::with_block_and_spent_utxos(block, full_chain.unspent_utxos())?;
|
ContextuallyVerifiedBlock::with_block_and_spent_utxos(block, full_chain.unspent_utxos(), Default::default())?;
|
||||||
|
|
||||||
// Check some properties of the genesis block and don't push it to the chain.
|
// Check some properties of the genesis block and don't push it to the chain.
|
||||||
if block.height == block::Height(0) {
|
if block.height == block::Height(0) {
|
||||||
|
@ -210,7 +212,7 @@ fn forked_equals_pushed_genesis() -> Result<()> {
|
||||||
// same original full chain.
|
// same original full chain.
|
||||||
for block in chain.iter().skip(fork_at_count).cloned() {
|
for block in chain.iter().skip(fork_at_count).cloned() {
|
||||||
let block =
|
let block =
|
||||||
ContextuallyVerifiedBlock::with_block_and_spent_utxos(block, forked.unspent_utxos())?;
|
ContextuallyVerifiedBlock::with_block_and_spent_utxos(block, forked.unspent_utxos(), Default::default())?;
|
||||||
forked = forked.push(block).expect("forked chain push is valid");
|
forked = forked.push(block).expect("forked chain push is valid");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue