-
Notifications
You must be signed in to change notification settings - Fork 452
Restructure electrum/esplora sync logic #461
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3f5cb69
Invert dependencies in electrum sync
LLFourn 732166f
Fix feerate calculation for esplora
LLFourn 808d7d8
Update changelog
LLFourn e7c1357
Don't request conftime during tx request
LLFourn aaad560
Always get up to chunk_size heights to request headers for
LLFourn 5eadf5c
Add some logging to script_sync
LLFourn 188d9a4
Make variable names consistent
LLFourn dfb63d3
s/observed_txs/finished_txs/g
LLFourn d394011
Less intermediary data states in sync
LLFourn d3779fa
Fix comments
LLFourn 1a64fd9
Delete src/blockchain/utils.rs
LLFourn 0f0a01a
s/vin/vout/
LLFourn 9c57708
Make stop_gap a parameter to EsploraBlockchainConfig::new
LLFourn a630685
Merge branch 'master' into sync_pipeline
LLFourn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| //! structs from the esplora API | ||
| //! | ||
| //! see: <https://github.com/Blockstream/esplora/blob/master/API.md> | ||
| use crate::BlockTime; | ||
| use bitcoin::{OutPoint, Script, Transaction, TxIn, TxOut, Txid}; | ||
|
|
||
| #[derive(serde::Deserialize, Clone, Debug)] | ||
| pub struct PrevOut { | ||
| pub value: u64, | ||
| pub scriptpubkey: Script, | ||
| } | ||
|
|
||
| #[derive(serde::Deserialize, Clone, Debug)] | ||
| pub struct Vin { | ||
| pub txid: Txid, | ||
| pub vout: u32, | ||
| // None if coinbase | ||
| pub prevout: Option<PrevOut>, | ||
| pub scriptsig: Script, | ||
| #[serde(deserialize_with = "deserialize_witness")] | ||
| pub witness: Vec<Vec<u8>>, | ||
| pub sequence: u32, | ||
| pub is_coinbase: bool, | ||
| } | ||
|
|
||
| #[derive(serde::Deserialize, Clone, Debug)] | ||
| pub struct Vout { | ||
| pub value: u64, | ||
| pub scriptpubkey: Script, | ||
| } | ||
|
|
||
| #[derive(serde::Deserialize, Clone, Debug)] | ||
| pub struct TxStatus { | ||
| pub confirmed: bool, | ||
| pub block_height: Option<u32>, | ||
| pub block_time: Option<u64>, | ||
| } | ||
|
|
||
| #[derive(serde::Deserialize, Clone, Debug)] | ||
| pub struct Tx { | ||
| pub txid: Txid, | ||
| pub version: i32, | ||
| pub locktime: u32, | ||
| pub vin: Vec<Vin>, | ||
| pub vout: Vec<Vout>, | ||
| pub status: TxStatus, | ||
| pub fee: u64, | ||
| } | ||
|
|
||
| impl Tx { | ||
| pub fn to_tx(&self) -> Transaction { | ||
| Transaction { | ||
| version: self.version, | ||
| lock_time: self.locktime, | ||
| input: self | ||
| .vin | ||
| .iter() | ||
| .cloned() | ||
| .map(|vin| TxIn { | ||
| previous_output: OutPoint { | ||
| txid: vin.txid, | ||
| vout: vin.vout, | ||
| }, | ||
| script_sig: vin.scriptsig, | ||
| sequence: vin.sequence, | ||
| witness: vin.witness, | ||
| }) | ||
| .collect(), | ||
| output: self | ||
| .vout | ||
| .iter() | ||
| .cloned() | ||
| .map(|vout| TxOut { | ||
| value: vout.value, | ||
| script_pubkey: vout.scriptpubkey, | ||
| }) | ||
| .collect(), | ||
| } | ||
| } | ||
|
|
||
| pub fn confirmation_time(&self) -> Option<BlockTime> { | ||
| match self.status { | ||
| TxStatus { | ||
| confirmed: true, | ||
| block_height: Some(height), | ||
| block_time: Some(timestamp), | ||
| } => Some(BlockTime { timestamp, height }), | ||
| _ => None, | ||
| } | ||
| } | ||
|
|
||
| pub fn previous_outputs(&self) -> Vec<Option<TxOut>> { | ||
| self.vin | ||
| .iter() | ||
| .cloned() | ||
| .map(|vin| { | ||
| vin.prevout.map(|po| TxOut { | ||
| script_pubkey: po.scriptpubkey, | ||
| value: po.value, | ||
| }) | ||
| }) | ||
| .collect() | ||
| } | ||
| } | ||
|
|
||
| fn deserialize_witness<'de, D>(d: D) -> Result<Vec<Vec<u8>>, D::Error> | ||
| where | ||
| D: serde::de::Deserializer<'de>, | ||
| { | ||
| use crate::serde::Deserialize; | ||
| use bitcoin::hashes::hex::FromHex; | ||
| let list = Vec::<String>::deserialize(d)?; | ||
| list.into_iter() | ||
| .map(|hex_str| Vec::<u8>::from_hex(&hex_str)) | ||
| .collect::<Result<Vec<Vec<u8>>, _>>() | ||
| .map_err(serde::de::Error::custom) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.