2020-07-22 19:44:06 -07:00
|
|
|
use zcash_primitives::{
|
|
|
|
block::BlockHash,
|
2020-08-04 19:49:41 -07:00
|
|
|
consensus::{self, BlockHeight},
|
2020-08-06 17:13:24 -07:00
|
|
|
merkle_tree::CommitmentTree,
|
2020-08-05 16:01:22 -07:00
|
|
|
primitives::PaymentAddress,
|
2020-08-06 17:13:24 -07:00
|
|
|
sapling::Node,
|
2020-08-06 09:23:15 -07:00
|
|
|
transaction::components::Amount,
|
2020-08-04 19:49:41 -07:00
|
|
|
zip32::ExtendedFullViewingKey,
|
2020-07-22 19:44:06 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
use crate::proto::compact_formats::CompactBlock;
|
|
|
|
|
|
|
|
pub mod chain;
|
|
|
|
pub mod error;
|
|
|
|
|
|
|
|
pub trait DBOps {
|
|
|
|
type Error;
|
2020-08-06 13:11:25 -07:00
|
|
|
type AccountId;
|
|
|
|
type NoteId;
|
2020-07-22 19:44:06 -07:00
|
|
|
// type TxRef; // Backend-specific transaction handle
|
|
|
|
// type NoteRef; // Backend-specific note identifier`
|
|
|
|
|
2020-08-04 15:34:09 -07:00
|
|
|
fn init_db(&self) -> Result<(), Self::Error>;
|
2020-08-04 19:49:41 -07:00
|
|
|
|
2020-08-05 16:01:22 -07:00
|
|
|
fn init_account_storage<P: consensus::Parameters>(
|
2020-08-04 19:49:41 -07:00
|
|
|
&self,
|
|
|
|
params: &P,
|
|
|
|
extfvks: &[ExtendedFullViewingKey],
|
|
|
|
) -> Result<(), Self::Error>;
|
|
|
|
|
2020-08-05 16:01:22 -07:00
|
|
|
fn init_block_storage(
|
|
|
|
&self,
|
|
|
|
height: BlockHeight,
|
|
|
|
hash: BlockHash,
|
|
|
|
time: u32, //TODO: Newtype!
|
|
|
|
sapling_tree: &[u8], //TODO: Newtype!
|
|
|
|
) -> Result<(), Self::Error>;
|
2020-08-04 19:49:41 -07:00
|
|
|
|
2020-07-22 19:44:06 -07:00
|
|
|
fn block_height_extrema(&self) -> Result<Option<(BlockHeight, BlockHeight)>, Self::Error>;
|
|
|
|
|
|
|
|
fn get_block_hash(&self, block_height: BlockHeight) -> Result<Option<BlockHash>, Self::Error>;
|
|
|
|
|
|
|
|
fn rewind_to_height<P: consensus::Parameters>(
|
|
|
|
&self,
|
|
|
|
parameters: &P,
|
|
|
|
block_height: BlockHeight,
|
|
|
|
) -> Result<(), Self::Error>;
|
2020-08-04 19:49:41 -07:00
|
|
|
|
2020-08-05 16:01:22 -07:00
|
|
|
fn get_address<P: consensus::Parameters>(
|
|
|
|
&self,
|
|
|
|
params: &P,
|
2020-08-06 13:11:25 -07:00
|
|
|
account: Self::AccountId,
|
2020-08-05 16:01:22 -07:00
|
|
|
) -> Result<Option<PaymentAddress>, Self::Error>;
|
|
|
|
|
2020-08-06 13:11:25 -07:00
|
|
|
fn get_balance(&self, account: Self::AccountId) -> Result<Amount, Self::Error>;
|
2020-08-06 09:23:15 -07:00
|
|
|
|
2020-08-06 13:11:25 -07:00
|
|
|
fn get_verified_balance(&self, account: Self::AccountId) -> Result<Amount, Self::Error>;
|
|
|
|
|
|
|
|
fn get_received_memo_as_utf8(
|
|
|
|
&self,
|
|
|
|
id_note: Self::NoteId,
|
|
|
|
) -> Result<Option<String>, Self::Error>;
|
|
|
|
|
|
|
|
fn get_extended_full_viewing_keys<P: consensus::Parameters>(
|
|
|
|
&self,
|
|
|
|
params: &P,
|
|
|
|
) -> Result<Vec<ExtendedFullViewingKey>, Self::Error>;
|
2020-08-06 09:23:15 -07:00
|
|
|
|
2020-08-06 17:13:24 -07:00
|
|
|
fn get_commitment_tree(
|
|
|
|
&self,
|
|
|
|
block_height: BlockHeight,
|
|
|
|
) -> Result<Option<CommitmentTree<Node>>, Self::Error>;
|
|
|
|
|
2020-07-22 19:44:06 -07:00
|
|
|
// fn get_witnesses(block_height: BlockHeight) -> Result<Box<dyn Iterator<Item = IncrementalWitness<Node>>>, Self::Error>;
|
|
|
|
//
|
|
|
|
// fn get_nullifiers() -> Result<(Vec<u8>, Account), Self::Error>;
|
|
|
|
//
|
|
|
|
// fn create_block(block_height: BlockHeight, hash: BlockHash, time: u32, sapling_tree: CommitmentTree<Node>) -> Result<(), Self::Error>;
|
|
|
|
//
|
|
|
|
// fn put_transaction(transaction: Transaction, block_height: BlockHeight) -> Result<Self::TxRef, Self::Error>;
|
|
|
|
//
|
|
|
|
// fn get_txref(txid: TxId) -> Result<Option<Self::TxRef>, Self::Error>;
|
|
|
|
//
|
|
|
|
// fn mark_spent(tx_ref: Self::TxRef, nullifier: Vec<u8>) -> Result<(), Self::Error>;
|
|
|
|
//
|
|
|
|
// fn put_note(output: WalletShieldedOutput, tx_ref: Self::TxRef, nullifier: Vec<u8>) -> Result<(), Self::Error>;
|
|
|
|
//
|
|
|
|
// fn get_note(tx_ref: Self::TxRef, output_index: i64) -> Result<Self::NoteRef, Self::Error>;
|
|
|
|
//
|
|
|
|
// fn prune_witnesses(to_height: BlockHeight) -> Result<(), Self::Error>;
|
|
|
|
//
|
|
|
|
// fn mark_expired_unspent(to_height: BlockHeight) -> Result<(), Self::Error>;
|
|
|
|
//
|
|
|
|
// fn put_sent_note(tx_ref: Self::TxRef, output: DecryptedOutput) -> Result<(), Self::Error>;
|
|
|
|
//
|
|
|
|
// fn put_received_note(tx_ref: Self::TxRef, output: DecryptedOutput) -> Result<(), Self::Error>;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait CacheOps {
|
|
|
|
type Error;
|
|
|
|
|
2020-08-04 15:34:09 -07:00
|
|
|
fn init_cache(&self) -> Result<(), Self::Error>;
|
|
|
|
|
2020-07-22 19:44:06 -07:00
|
|
|
// Validate the cached chain by applying a function that checks pairwise constraints
|
|
|
|
// (top_block :: &CompactBlock, next_block :: &CompactBlock) -> Result<(), Self::Error)
|
|
|
|
// beginning with the current maximum height walking backward through the chain, terminating
|
|
|
|
// with the block at `from_height`. Returns the hash of the block at height `from_height`
|
|
|
|
fn validate_chain<F>(
|
|
|
|
&self,
|
|
|
|
from_height: BlockHeight,
|
|
|
|
validate: F,
|
|
|
|
) -> Result<Option<BlockHash>, Self::Error>
|
|
|
|
where
|
|
|
|
F: Fn(&CompactBlock, &CompactBlock) -> Result<(), Self::Error>;
|
|
|
|
}
|