Skip to content

Commit cedfc5f

Browse files
committed
module structure inside state key file
1 parent 4679c39 commit cedfc5f

File tree

5 files changed

+67
-34
lines changed

5 files changed

+67
-34
lines changed

crates/core/component/funding/src/component.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use penumbra_sdk_asset::{Value, STAKING_TOKEN_ASSET_ID};
99
use penumbra_sdk_proto::{DomainType, StateWriteProto};
1010
use penumbra_sdk_stake::component::validator_handler::ValidatorDataRead;
1111
pub use view::{StateReadExt, StateWriteExt};
12+
pub(crate) mod liquidity_tournament;
1213

1314
use std::sync::Arc;
1415

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod nullifier;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use async_trait::async_trait;
2+
use penumbra_sdk_txhash::TransactionId;
3+
4+
use crate::component::state_key;
5+
use cnidarium::{StateRead, StateWrite};
6+
use penumbra_sdk_proto::{StateReadProto, StateWriteProto};
7+
use penumbra_sdk_sct::{component::clock::EpochRead, Nullifier};
8+
9+
#[async_trait]
10+
pub trait NullifierRead: StateRead {
11+
/// Gets the transaction id associated with the given nullifier from the JMT.
12+
async fn get_txid_from_nullifier(&self, nullifier: Nullifier) -> Option<TransactionId> {
13+
// Grab the ambient epoch index.
14+
let epoch_index = self
15+
.get_current_epoch()
16+
.await
17+
.expect("epoch is always set")
18+
.index;
19+
20+
let nullifier_key = &state_key::lqt::v1::nf::by_epoch::lqt_nullifier_lookup_for_txid(
21+
epoch_index,
22+
&nullifier,
23+
);
24+
25+
let tx_id: Option<TransactionId> = self
26+
.nonverifiable_get(&nullifier_key.as_bytes())
27+
.await
28+
.expect("infallible");
29+
30+
tx_id
31+
}
32+
}
33+
34+
impl<T: StateRead + ?Sized> NullifierRead for T {}
35+
36+
#[async_trait]
37+
pub trait NullifierWrite: StateWrite {
38+
/// Sets the LQT nullifier in the JMT.
39+
fn put_lqt_nullifier(&mut self, epoch_index: u64, nullifier: Nullifier, tx_id: TransactionId) {
40+
let nullifier_key = state_key::lqt::v1::nf::by_epoch::lqt_nullifier_lookup_for_txid(
41+
epoch_index,
42+
&nullifier,
43+
);
44+
45+
self.put(nullifier_key, tx_id);
46+
}
47+
}
48+
49+
impl<T: StateWrite + ?Sized> NullifierWrite for T {}
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
use penumbra_sdk_sct::Nullifier;
2-
31
pub fn staking_funding_parameters() -> &'static str {
42
"funding/parameters"
53
}
64

7-
pub fn lqt_nullifier_lookup_for_txid(epoch_index: u64, nullifier: &Nullifier) -> String {
8-
format!("funding/lqt/v1/nf/by_epoch/{epoch_index:020}/lookup/{nullifier}")
5+
pub mod lqt {
6+
pub mod v1 {
7+
pub mod nf {
8+
pub mod by_epoch {
9+
use penumbra_sdk_sct::Nullifier;
10+
11+
pub(crate) fn lqt_nullifier_lookup_for_txid(
12+
epoch_index: u64,
13+
nullifier: &Nullifier,
14+
) -> String {
15+
format!("funding/lqt/v1/nf/by_epoch/{epoch_index:020}/lookup/{nullifier}")
16+
}
17+
}
18+
}
19+
}
920
}
Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
use async_trait::async_trait;
2-
use penumbra_sdk_txhash::TransactionId;
3-
41
use crate::{component::state_key, params::FundingParameters};
52
use anyhow::Result;
3+
use async_trait::async_trait;
64
use cnidarium::{StateRead, StateWrite};
75
use penumbra_sdk_proto::{StateReadProto, StateWriteProto};
8-
use penumbra_sdk_sct::{component::clock::EpochRead, Nullifier};
96

107
#[async_trait]
118
pub trait StateReadExt: StateRead {
@@ -15,25 +12,6 @@ pub trait StateReadExt: StateRead {
1512
.await?
1613
.ok_or_else(|| anyhow::anyhow!("Missing FundingParameters"))
1714
}
18-
19-
/// Gets the transaction id associated with the given nullifier from the JMT.
20-
async fn get_txid_from_nullifier(&self, nullifier: Nullifier) -> Option<TransactionId> {
21-
// Grab the ambient epoch index.
22-
let epoch_index = self
23-
.get_current_epoch()
24-
.await
25-
.expect("epoch is always set")
26-
.index;
27-
28-
let nullifier_key = &state_key::lqt_nullifier_lookup_for_txid(epoch_index, &nullifier);
29-
30-
let tx_id: Option<TransactionId> = self
31-
.nonverifiable_get(&nullifier_key.as_bytes())
32-
.await
33-
.expect("infallible");
34-
35-
tx_id
36-
}
3715
}
3816

3917
impl<T: StateRead + ?Sized> StateReadExt for T {}
@@ -44,12 +22,5 @@ pub trait StateWriteExt: StateWrite + StateReadExt {
4422
fn put_staking_funding_params(&mut self, params: FundingParameters) {
4523
self.put(state_key::staking_funding_parameters().into(), params)
4624
}
47-
48-
// Sets the LQT nullifier in the JMT.
49-
fn put_lqt_nullifier(&mut self, epoch_index: u64, nullifier: Nullifier, tx_id: TransactionId) {
50-
let nullifier_key = state_key::lqt_nullifier_lookup_for_txid(epoch_index, &nullifier);
51-
52-
self.put(nullifier_key, tx_id);
53-
}
5425
}
5526
impl<T: StateWrite + ?Sized> StateWriteExt for T {}

0 commit comments

Comments
 (0)