-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce code duplication to reveal masp nullifiers
- Loading branch information
Showing
5 changed files
with
37 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//! MASP utilities | ||
use masp_primitives::transaction::Transaction; | ||
|
||
use super::storage_api::StorageWrite; | ||
use crate::ledger::storage_api::Result; | ||
use crate::types::address::MASP; | ||
use crate::types::hash::Hash; | ||
use crate::types::storage::{Key, KeySeg}; | ||
use crate::types::token::MASP_NULLIFIERS_KEY_PREFIX; | ||
|
||
/// Writes the nullifiers of the provided masp transaction to storage | ||
pub fn reveal_nullifiers( | ||
ctx: &mut impl StorageWrite, | ||
transaction: &Transaction, | ||
) -> Result<()> { | ||
for description in transaction | ||
.sapling_bundle() | ||
.map_or(&vec![], |description| &description.shielded_spends) | ||
{ | ||
let nullifier_key = Key::from(MASP.to_db_key()) | ||
.push(&MASP_NULLIFIERS_KEY_PREFIX.to_owned()) | ||
.expect("Cannot obtain a storage key") | ||
.push(&Hash(description.nullifier.0)) | ||
.expect("Cannot obtain a storage key"); | ||
ctx.write(&nullifier_key, ())?; | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters