refactor(db!: store the one-off transaction signature by component

This commit is contained in:
CleverWild
2026-08-27 12:46:40 +02:00
parent 15b826310b
commit 8421a09d9f
6 changed files with 65 additions and 29 deletions

View File

@@ -661,7 +661,6 @@ impl ProposalManager {
tx: one_off_transaction::Settings,
) -> Result<(), Error> {
use crate::actors::evm::ClientSignTransaction;
use crate::db::models::NewProposalResult;
use alloy::{
consensus::TxEip1559,
eips::eip2930::AccessList,
@@ -691,12 +690,7 @@ impl ProposalManager {
.map_err(|e| Error::ExecutionFailed(format!("sign one-off tx: {e}")))?;
let mut conn = self.db.get().await.map_err(Error::DatabaseConnection)?;
diesel::insert_into(schema::proposal_result::table)
.values(NewProposalResult {
proposal_id,
data: sig.as_bytes().to_vec(),
})
.execute(&mut conn)
one_off_transaction::store_signature(proposal_id, &sig, &mut conn)
.await
.map_err(|e| Error::ExecutionFailed(format!("store proposal result: {e}")))?;

View File

@@ -515,13 +515,6 @@ pub struct NewProposalVote {
pub signature: Vec<u8>,
}
#[derive(Debug, Insertable)]
#[diesel(table_name = schema::proposal_result, check_for_backend(Sqlite))]
pub struct NewProposalResult {
pub proposal_id: i32,
pub data: Vec<u8>,
}
#[derive(Debug, Insertable)]
#[diesel(table_name = schema::recovery_proposal_vote, check_for_backend(Sqlite))]
pub struct NewRecoveryProposalVote {

View File

@@ -1,7 +1,10 @@
//! Signing a single EIP-1559 transaction.
use super::{Proposal, ProposalKindTag, as_i64, as_u64, fixed};
use crate::db::{DatabaseConnection, schema::proposal_one_off_transaction};
use crate::db::{
DatabaseConnection,
schema::{proposal_one_off_transaction, proposal_one_off_transaction_result},
};
use diesel::{
Insertable, QueryDsl as _, QueryResult, Queryable, Selectable, SelectableHelper as _,
sqlite::Sqlite,
@@ -100,3 +103,32 @@ impl Proposal for OneOffTransaction {
row.into_settings()
}
}
/// The signature the vault produced for an approved transaction.
#[derive(Debug, Insertable)]
#[diesel(table_name = proposal_one_off_transaction_result, check_for_backend(Sqlite))]
struct SignatureRow {
proposal_id: i32,
r: Vec<u8>,
s: Vec<u8>,
y_parity: i32,
}
/// Records the signature produced for an approved transaction, by component, so what
/// came back is as readable as what was signed.
pub async fn store_signature(
proposal_id: i32,
signature: &alloy::signers::Signature,
conn: &mut DatabaseConnection,
) -> QueryResult<()> {
diesel::insert_into(proposal_one_off_transaction_result::table)
.values(&SignatureRow {
proposal_id,
r: signature.r().to_be_bytes::<32>().to_vec(),
s: signature.s().to_be_bytes::<32>().to_vec(),
y_parity: i32::from(signature.v()),
})
.execute(conn)
.await
.map(drop)
}

View File

@@ -270,9 +270,11 @@ diesel::table! {
}
diesel::table! {
proposal_result (proposal_id) {
proposal_one_off_transaction_result (proposal_id) {
proposal_id -> Integer,
data -> Binary,
r -> Binary,
s -> Binary,
y_parity -> Integer,
created_at -> Integer,
}
}
@@ -383,7 +385,7 @@ diesel::joinable!(evm_wallet_access -> program_client (client_id));
diesel::joinable!(operator -> operator_identity (id));
diesel::joinable!(program_client -> client_metadata (metadata_id));
diesel::joinable!(proposal -> operator_identity (initiator_id));
diesel::joinable!(proposal_result -> proposal (proposal_id));
diesel::joinable!(proposal_one_off_transaction_result -> proposal_one_off_transaction (proposal_id));
diesel::joinable!(proposal_approve_sdk_client -> proposal (proposal_id));
diesel::joinable!(proposal_grant_wallet_access -> proposal (proposal_id));
diesel::joinable!(proposal_replace_operator -> proposal (proposal_id));
@@ -400,7 +402,7 @@ diesel::joinable!(recovery_wakeup_request -> operator_identity (requested_by));
diesel::allow_tables_to_appear_in_same_query!(
aead_encrypted,
proposal_result,
proposal_one_off_transaction_result,
proposal_approve_sdk_client,
proposal_grant_wallet_access,
proposal_replace_operator,