Commit e2cca9b8 authored by Roman Zeyde's avatar Roman Zeyde
Browse files

Use explicit 'dyn' for trait objects

parent 05b653f7
......@@ -31,7 +31,7 @@ impl App {
&self.store
}
// TODO: use index for queries.
pub fn read_store(&self) -> &store::ReadStore {
pub fn read_store(&self) -> &dyn store::ReadStore {
&self.store
}
pub fn index(&self) -> &index::Index {
......
......@@ -241,7 +241,7 @@ impl Config {
config
}
pub fn cookie_getter(&self) -> Arc<CookieGetter> {
pub fn cookie_getter(&self) -> Arc<dyn CookieGetter> {
if let Some(ref value) = self.cookie {
Arc::new(StaticCookie {
value: value.as_bytes().to_vec(),
......
......@@ -150,7 +150,7 @@ pub trait CookieGetter: Send + Sync {
struct Connection {
tx: TcpStream,
rx: Lines<BufReader<TcpStream>>,
cookie_getter: Arc<CookieGetter>,
cookie_getter: Arc<dyn CookieGetter>,
addr: SocketAddr,
signal: Waiter,
}
......@@ -171,7 +171,7 @@ fn tcp_connect(addr: SocketAddr, signal: &Waiter) -> Result<TcpStream> {
impl Connection {
fn new(
addr: SocketAddr,
cookie_getter: Arc<CookieGetter>,
cookie_getter: Arc<dyn CookieGetter>,
signal: Waiter,
) -> Result<Connection> {
let conn = tcp_connect(addr, &signal)?;
......@@ -300,7 +300,7 @@ impl Daemon {
pub fn new(
daemon_dir: &PathBuf,
daemon_rpc_addr: SocketAddr,
cookie_getter: Arc<CookieGetter>,
cookie_getter: Arc<dyn CookieGetter>,
network: Network,
signal: Waiter,
blocktxids_cache: Arc<BlockTxIDsCache>,
......
......@@ -221,7 +221,7 @@ pub fn last_indexed_block(blockhash: &Sha256dHash) -> Row {
}
}
pub fn read_indexed_blockhashes(store: &ReadStore) -> HashSet<Sha256dHash> {
pub fn read_indexed_blockhashes(store: &dyn ReadStore) -> HashSet<Sha256dHash> {
let mut result = HashSet::new();
for row in store.scan(b"B") {
let key: BlockKey = bincode::deserialize(&row.key).unwrap();
......@@ -230,7 +230,7 @@ pub fn read_indexed_blockhashes(store: &ReadStore) -> HashSet<Sha256dHash> {
result
}
fn read_indexed_headers(store: &ReadStore) -> HeaderList {
fn read_indexed_headers(store: &dyn ReadStore) -> HeaderList {
let latest_blockhash: Sha256dHash = match store.get(b"L") {
// latest blockheader persisted in the DB.
Some(row) => deserialize(&row).unwrap(),
......@@ -336,7 +336,7 @@ pub struct Index {
impl Index {
pub fn load(
store: &ReadStore,
store: &dyn ReadStore,
daemon: &Daemon,
metrics: &Metrics,
batch_size: usize,
......@@ -352,7 +352,7 @@ impl Index {
})
}
pub fn reload(&self, store: &ReadStore) {
pub fn reload(&self, store: &dyn ReadStore) {
let mut headers = self.headers.write().unwrap();
*headers = read_indexed_headers(store);
}
......
......@@ -186,7 +186,7 @@ impl Tracker {
&self.histogram
}
pub fn index(&self) -> &ReadStore {
pub fn index(&self) -> &dyn ReadStore {
&self.index
}
......
......@@ -143,13 +143,13 @@ fn create_merkle_branch_and_root(
}
// TODO: the functions below can be part of ReadStore.
fn txrow_by_txid(store: &ReadStore, txid: &Sha256dHash) -> Option<TxRow> {
fn txrow_by_txid(store: &dyn ReadStore, txid: &Sha256dHash) -> Option<TxRow> {
let key = TxRow::filter_full(&txid);
let value = store.get(&key)?;
Some(TxRow::from_row(&Row { key, value }))
}
fn txrows_by_prefix(store: &ReadStore, txid_prefix: HashPrefix) -> Vec<TxRow> {
fn txrows_by_prefix(store: &dyn ReadStore, txid_prefix: HashPrefix) -> Vec<TxRow> {
store
.scan(&TxRow::filter_prefix(txid_prefix))
.iter()
......@@ -157,7 +157,7 @@ fn txrows_by_prefix(store: &ReadStore, txid_prefix: HashPrefix) -> Vec<TxRow> {
.collect()
}
fn txids_by_script_hash(store: &ReadStore, script_hash: &[u8]) -> Vec<HashPrefix> {
fn txids_by_script_hash(store: &dyn ReadStore, script_hash: &[u8]) -> Vec<HashPrefix> {
store
.scan(&TxOutRow::filter(script_hash))
.iter()
......@@ -166,7 +166,7 @@ fn txids_by_script_hash(store: &ReadStore, script_hash: &[u8]) -> Vec<HashPrefix
}
fn txids_by_funding_output(
store: &ReadStore,
store: &dyn ReadStore,
txn_id: &Sha256dHash,
output_index: usize,
) -> Vec<HashPrefix> {
......@@ -225,7 +225,7 @@ impl Query {
fn load_txns_by_prefix(
&self,
store: &ReadStore,
store: &dyn ReadStore,
prefixes: Vec<HashPrefix>,
) -> Result<Vec<TxnHeight>> {
let mut txns = vec![];
......@@ -244,7 +244,7 @@ impl Query {
fn find_spending_input(
&self,
store: &ReadStore,
store: &dyn ReadStore,
funding: &FundingOutput,
) -> Result<Option<SpendingInput>> {
let spending_txns: Vec<TxnHeight> = self.load_txns_by_prefix(
......
......@@ -188,7 +188,7 @@ pub fn full_compaction(store: DBStore) -> DBStore {
store
}
pub fn is_fully_compacted(store: &ReadStore) -> bool {
pub fn is_fully_compacted(store: &dyn ReadStore) -> bool {
let marker = store.get(&full_compaction_marker().key);
marker.is_some()
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment