Merge branch 'autoshielding-poc-write-orig' into autoshielding-poc
This commit is contained in:
commit
0a1ed9b8ac
|
@ -207,6 +207,7 @@ pub struct PrunedBlock<'a> {
|
|||
/// The purpose of this struct is to permit atomic updates of the
|
||||
/// wallet database when transactions are successfully decrypted.
|
||||
pub struct DecryptedTransaction<'a> {
|
||||
pub tx_bytes: &'a[u8],
|
||||
pub tx: &'a Transaction,
|
||||
pub sapling_outputs: &'a Vec<DecryptedOutput>,
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ pub const ANCHOR_OFFSET: u32 = 10;
|
|||
pub fn decrypt_and_store_transaction<N, E, P, D>(
|
||||
params: &P,
|
||||
data: &mut D,
|
||||
tx_bytes: &[u8],
|
||||
tx: &Transaction,
|
||||
) -> Result<(), E>
|
||||
where
|
||||
|
@ -62,6 +63,7 @@ where
|
|||
let nullifiers = data.get_all_nullifiers()?;
|
||||
data.store_decrypted_tx(
|
||||
&DecryptedTransaction {
|
||||
tx_bytes,
|
||||
tx,
|
||||
sapling_outputs: &sapling_outputs,
|
||||
},
|
||||
|
|
|
@ -530,7 +530,7 @@ impl<'a, P: consensus::Parameters> WalletWrite for DataConnStmtCache<'a, P> {
|
|||
nullifiers: &[(AccountId, Nullifier)],
|
||||
) -> Result<Self::TxRef, Self::Error> {
|
||||
self.transactionally(|up| {
|
||||
let tx_ref = wallet::put_tx_data(up, d_tx.tx, None)?;
|
||||
let tx_ref = wallet::put_tx_data(up, d_tx.tx_bytes, d_tx.tx, None)?;
|
||||
|
||||
let mut spending_account_id: Option<AccountId> = None;
|
||||
for output in d_tx.sapling_outputs {
|
||||
|
@ -591,7 +591,10 @@ impl<'a, P: consensus::Parameters> WalletWrite for DataConnStmtCache<'a, P> {
|
|||
fn store_sent_tx(&mut self, sent_tx: &SentTransaction) -> Result<Self::TxRef, Self::Error> {
|
||||
// Update the database atomically, to ensure the result is internally consistent.
|
||||
self.transactionally(|up| {
|
||||
let tx_ref = wallet::put_tx_data(up, &sent_tx.tx, Some(sent_tx.created))?;
|
||||
let mut tx_bytes = vec![];
|
||||
sent_tx.tx.write(&mut tx_bytes)?;
|
||||
|
||||
let tx_ref = wallet::put_tx_data(up, &tx_bytes, &sent_tx.tx, Some(sent_tx.created))?;
|
||||
|
||||
// Mark notes as spent.
|
||||
//
|
||||
|
|
|
@ -796,17 +796,15 @@ pub fn put_tx_meta<'a, P, N>(
|
|||
/// Inserts full transaction data into the database.
|
||||
pub fn put_tx_data<'a, P>(
|
||||
stmts: &mut DataConnStmtCache<'a, P>,
|
||||
tx_bytes: &[u8],
|
||||
tx: &Transaction,
|
||||
created_at: Option<time::OffsetDateTime>,
|
||||
) -> Result<i64, SqliteClientError> {
|
||||
let txid = tx.txid().0.to_vec();
|
||||
|
||||
let mut raw_tx = vec![];
|
||||
tx.write(&mut raw_tx)?;
|
||||
|
||||
if stmts
|
||||
.stmt_update_tx_data
|
||||
.execute(params![u32::from(tx.expiry_height), raw_tx, txid,])?
|
||||
.execute(params![u32::from(tx.expiry_height), tx_bytes, txid,])?
|
||||
== 0
|
||||
{
|
||||
// It isn't there, so insert our transaction into the database.
|
||||
|
@ -814,7 +812,7 @@ pub fn put_tx_data<'a, P>(
|
|||
txid,
|
||||
created_at,
|
||||
u32::from(tx.expiry_height),
|
||||
raw_tx
|
||||
tx_bytes
|
||||
])?;
|
||||
|
||||
Ok(stmts.wallet_db.conn.last_insert_rowid())
|
||||
|
|
Loading…
Reference in New Issue