-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module structure inside state key file
- Loading branch information
Showing
5 changed files
with
67 additions
and
34 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
1 change: 1 addition & 0 deletions
1
crates/core/component/funding/src/component/liquidity_tournament/mod.rs
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 @@ | ||
pub mod nullifier; |
49 changes: 49 additions & 0 deletions
49
crates/core/component/funding/src/component/liquidity_tournament/nullifier/mod.rs
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,49 @@ | ||
use async_trait::async_trait; | ||
use penumbra_sdk_txhash::TransactionId; | ||
|
||
use crate::component::state_key; | ||
use cnidarium::{StateRead, StateWrite}; | ||
use penumbra_sdk_proto::{StateReadProto, StateWriteProto}; | ||
use penumbra_sdk_sct::{component::clock::EpochRead, Nullifier}; | ||
|
||
#[async_trait] | ||
pub trait NullifierRead: StateRead { | ||
/// Gets the transaction id associated with the given nullifier from the JMT. | ||
async fn get_txid_from_nullifier(&self, nullifier: Nullifier) -> Option<TransactionId> { | ||
// Grab the ambient epoch index. | ||
let epoch_index = self | ||
.get_current_epoch() | ||
.await | ||
.expect("epoch is always set") | ||
.index; | ||
|
||
let nullifier_key = &state_key::lqt::v1::nf::by_epoch::lqt_nullifier_lookup_for_txid( | ||
epoch_index, | ||
&nullifier, | ||
); | ||
|
||
let tx_id: Option<TransactionId> = self | ||
.nonverifiable_get(&nullifier_key.as_bytes()) | ||
.await | ||
.expect("infallible"); | ||
|
||
tx_id | ||
} | ||
} | ||
|
||
impl<T: StateRead + ?Sized> NullifierRead for T {} | ||
|
||
#[async_trait] | ||
pub trait NullifierWrite: StateWrite { | ||
/// Sets the LQT nullifier in the JMT. | ||
fn put_lqt_nullifier(&mut self, epoch_index: u64, nullifier: Nullifier, tx_id: TransactionId) { | ||
let nullifier_key = state_key::lqt::v1::nf::by_epoch::lqt_nullifier_lookup_for_txid( | ||
epoch_index, | ||
&nullifier, | ||
); | ||
|
||
self.put(nullifier_key, tx_id); | ||
} | ||
} | ||
|
||
impl<T: StateWrite + ?Sized> NullifierWrite for T {} |
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 |
---|---|---|
@@ -1,9 +1,20 @@ | ||
use penumbra_sdk_sct::Nullifier; | ||
|
||
pub fn staking_funding_parameters() -> &'static str { | ||
"funding/parameters" | ||
} | ||
|
||
pub fn lqt_nullifier_lookup_for_txid(epoch_index: u64, nullifier: &Nullifier) -> String { | ||
format!("funding/lqt/v1/nf/by_epoch/{epoch_index:020}/lookup/{nullifier}") | ||
pub mod lqt { | ||
pub mod v1 { | ||
pub mod nf { | ||
pub mod by_epoch { | ||
use penumbra_sdk_sct::Nullifier; | ||
|
||
pub(crate) fn lqt_nullifier_lookup_for_txid( | ||
epoch_index: u64, | ||
nullifier: &Nullifier, | ||
) -> String { | ||
format!("funding/lqt/v1/nf/by_epoch/{epoch_index:020}/lookup/{nullifier}") | ||
} | ||
} | ||
} | ||
} | ||
} |
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