Skip to main content

hypercall_db/traits/
nonces.rs

1//! RSM signer nonce persistence traits (async).
2//!
3//! Used by the transaction submitter to manage on-chain nonces.
4
5use anyhow::Result;
6use async_trait::async_trait;
7use hypercall_types::WalletAddress;
8
9use crate::{RsmSignerNonceRecord, RsmSignerRequestClaim, RsmSignerRequestRecord};
10
11/// Read-only nonce queries.
12#[async_trait]
13pub trait NonceReader: Send + Sync {
14    /// Load the current nonce state for a signer address.
15    async fn get_rsm_signer_nonce(
16        &self,
17        signer: &WalletAddress,
18    ) -> Result<Option<RsmSignerNonceRecord>>;
19}
20
21/// Nonce mutations for transaction sequencing.
22#[async_trait]
23pub trait NonceWriter: NonceReader {
24    /// Save or update a signer nonce record.
25    async fn save_rsm_signer_nonce(&self, record: &RsmSignerNonceRecord) -> Result<()>;
26
27    #[cfg(any(test, feature = "test-utils"))]
28    async fn reserve_next_rsm_signer_nonce(
29        &self,
30        signer: &WalletAddress,
31        initial_nonce: u64,
32    ) -> Result<u64>;
33
34    /// Claim a signer request slot, returning a nonce for signing.
35    ///
36    /// Uses advisory locks and transactional nonce reservation to ensure
37    /// exactly-once semantics per request_id.
38    async fn claim_rsm_signer_request(
39        &self,
40        request_id: &str,
41        signer: &WalletAddress,
42        account: &WalletAddress,
43        action: &[u8],
44        initial_nonce: u64,
45    ) -> Result<RsmSignerRequestClaim>;
46
47    /// Mark a pending request as completed with the signed directive.
48    async fn complete_rsm_signer_request(
49        &self,
50        request_id: &str,
51        directive: &[u8],
52        signature: &str,
53    ) -> Result<RsmSignerRequestRecord>;
54}