-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(ingress-egress-tracker): remove unnecessary fields #4425
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use crate::{Storable, Store}; | ||
use bitcoin::{Amount, BlockHash, Network, ScriptBuf, Transaction, Txid}; | ||
use bitcoin::{BlockHash, Network, ScriptBuf, Transaction, Txid}; | ||
use cf_chains::btc::BitcoinNetwork; | ||
use cf_primitives::ForeignChain; | ||
use chainflip_engine::{ | ||
|
@@ -15,19 +15,30 @@ use std::{ | |
use tracing::{error, info}; | ||
use utilities::task_scope; | ||
|
||
#[derive(Clone, Serialize)] | ||
#[derive(Clone)] | ||
pub struct QueryResult { | ||
confirmations: u32, | ||
#[serde(skip_serializing)] | ||
destination: String, | ||
value: f64, | ||
value: u64, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed this to return sats because that's our practice across the board |
||
tx_hash: Txid, | ||
} | ||
|
||
impl Serialize for QueryResult { | ||
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { | ||
use serde::ser::SerializeMap; | ||
|
||
let mut map = serializer.serialize_map(Some(3))?; | ||
map.serialize_entry("confirmations", &self.confirmations)?; | ||
map.serialize_entry("tx_hash", &self.tx_hash)?; | ||
map.serialize_entry("value", &format!("0x{:x}", self.value))?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hex encode the u64 |
||
map.end() | ||
} | ||
} | ||
|
||
impl Storable for QueryResult { | ||
fn get_key(&self) -> String { | ||
let chain = ForeignChain::Bitcoin.to_string(); | ||
format!("confirmations:{chain}:{}", self.destination) | ||
format!("mempool:{chain}:{}", self.destination) | ||
} | ||
|
||
fn get_expiry_duration(&self) -> Duration { | ||
|
@@ -122,7 +133,7 @@ async fn update_cache<T: BtcRpcApi>( | |
QueryResult { | ||
destination: addr, | ||
confirmations: 0, | ||
value: Amount::from_sat(txout.value).to_btc(), | ||
value: txout.value, | ||
tx_hash: txid, | ||
}, | ||
); | ||
|
@@ -151,7 +162,7 @@ async fn update_cache<T: BtcRpcApi>( | |
QueryResult { | ||
destination: addr, | ||
confirmations, | ||
value: txout.value.to_btc(), | ||
value: txout.value.to_sat(), | ||
tx_hash, | ||
}, | ||
); | ||
|
@@ -207,23 +218,21 @@ pub fn start<S: Store>( | |
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use anyhow::anyhow; | ||
use std::collections::BTreeMap; | ||
|
||
use bitcoin::{ | ||
absolute::{Height, LockTime}, | ||
address::{self}, | ||
block::Version, | ||
hash_types::TxMerkleNode, | ||
hashes::Hash, | ||
secp256k1::rand::{self, Rng}, | ||
TxOut, | ||
Amount, TxOut, | ||
}; | ||
use chainflip_engine::btc::rpc::{ | ||
BlockHeader, Difficulty, VerboseBlock, VerboseTransaction, VerboseTxOut, | ||
}; | ||
|
||
use super::*; | ||
use std::collections::BTreeMap; | ||
|
||
#[derive(Clone)] | ||
struct MockBtcRpc { | ||
|
@@ -514,6 +523,6 @@ mod tests { | |
let cache: Cache = Default::default(); | ||
let cache = update_cache(&btc, cache.clone(), Network::Bitcoin).await.unwrap(); | ||
assert_eq!(cache.transactions.get(&address1).unwrap().confirmations, 3); | ||
assert_eq!(cache.transactions.get(&address1).unwrap().value, tx_value.to_btc()); | ||
assert_eq!(cache.transactions.get(&address1).unwrap().value, tx_value.to_sat()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,46 +15,22 @@ use serde::Serialize; | |
use utilities::rpc::NumberOrHex; | ||
|
||
#[derive(Serialize)] | ||
pub struct WitnessAsset { | ||
pub chain: ForeignChain, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the chain is part of the key in redis so it doesn't need to be serialized |
||
pub asset: Asset, | ||
} | ||
|
||
impl From<cf_chains::assets::eth::Asset> for WitnessAsset { | ||
fn from(asset: cf_chains::assets::eth::Asset) -> Self { | ||
Self { chain: ForeignChain::Ethereum, asset: asset.into() } | ||
} | ||
} | ||
|
||
impl From<cf_chains::assets::dot::Asset> for WitnessAsset { | ||
fn from(asset: cf_chains::assets::dot::Asset) -> Self { | ||
Self { chain: ForeignChain::Polkadot, asset: asset.into() } | ||
} | ||
} | ||
|
||
impl From<cf_chains::assets::btc::Asset> for WitnessAsset { | ||
fn from(asset: cf_chains::assets::btc::Asset) -> Self { | ||
Self { chain: ForeignChain::Bitcoin, asset: asset.into() } | ||
} | ||
} | ||
|
||
#[derive(Serialize)] | ||
#[serde(tag = "deposit_chain")] | ||
#[serde(untagged)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this tag is part of the key in redis so it doesn't need to be serialized |
||
enum TransactionId { | ||
Bitcoin { hash: String }, | ||
Ethereum { signature: SchnorrVerificationComponents }, | ||
Polkadot { signature: String }, | ||
} | ||
|
||
#[derive(Serialize)] | ||
#[serde(tag = "type", rename_all = "snake_case")] | ||
#[serde(untagged)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this tag is part of the key in redis so it doesn't need to be serialized |
||
enum WitnessInformation { | ||
Deposit { | ||
deposit_chain_block_height: <AnyChain as Chain>::ChainBlockNumber, | ||
#[serde(skip_serializing)] | ||
deposit_address: String, | ||
amount: NumberOrHex, | ||
asset: WitnessAsset, | ||
asset: Asset, | ||
}, | ||
Broadcast { | ||
#[serde(skip_serializing)] | ||
|
@@ -66,7 +42,7 @@ enum WitnessInformation { | |
impl WitnessInformation { | ||
fn to_foreign_chain(&self) -> ForeignChain { | ||
match self { | ||
Self::Deposit { asset, .. } => asset.chain, | ||
Self::Deposit { asset, .. } => (*asset).into(), | ||
Self::Broadcast { tx_out_id, .. } => match tx_out_id { | ||
TransactionId::Bitcoin { .. } => ForeignChain::Bitcoin, | ||
TransactionId::Ethereum { .. } => ForeignChain::Ethereum, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no longer need to multicast the witnessing calls to different websockets so i removed the channel logic