-
Notifications
You must be signed in to change notification settings - Fork 452
rpc: manually add the immature utxos to the db #687
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
Closed
danielabrozzoni
wants to merge
1
commit into
bitcoindevkit:master
from
danielabrozzoni:20220728_rpc_coinbases
Closed
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,8 +39,9 @@ use crate::database::{BatchDatabase, DatabaseUtils}; | |
| use crate::descriptor::get_checksum; | ||
| use crate::{BlockTime, Error, FeeRate, KeychainKind, LocalUtxo, TransactionDetails}; | ||
| use bitcoincore_rpc::json::{ | ||
| GetAddressInfoResultLabel, ImportMultiOptions, ImportMultiRequest, | ||
| ImportMultiRequestScriptPubkey, ImportMultiRescanSince, | ||
| GetAddressInfoResultLabel, GetTransactionResultDetailCategory, ImportMultiOptions, | ||
| ImportMultiRequest, ImportMultiRequestScriptPubkey, ImportMultiRescanSince, | ||
| ListUnspentResultEntry, | ||
| }; | ||
| use bitcoincore_rpc::jsonrpc::serde_json::{json, Value}; | ||
| use bitcoincore_rpc::Auth as RpcAuth; | ||
|
|
@@ -276,7 +277,7 @@ impl WalletSync for RpcBlockchain { | |
| let known_utxos: HashSet<_> = db.iter_utxos()?.into_iter().collect(); | ||
|
|
||
| //TODO list_since_blocks would be more efficient | ||
| let current_utxo = self | ||
| let mut current_utxo = self | ||
| .client | ||
| .list_unspent(Some(0), None, None, Some(true), None)?; | ||
| debug!("current_utxo len {}", current_utxo.len()); | ||
|
|
@@ -294,6 +295,38 @@ impl WalletSync for RpcBlockchain { | |
| }) { | ||
| let txid = tx_result.info.txid; | ||
| list_txs_ids.insert(txid); | ||
| if tx_result.detail.category == GetTransactionResultDetailCategory::Immature { | ||
| // Immature UTXOs don't appear in rpc's listunspent, so we | ||
| // have to manually add them to the current_utxos list | ||
| // FIXME: This will produce a wrong result if the immature utxo is spent, | ||
| // which *should* be impossible. | ||
| let utxo = ListUnspentResultEntry { | ||
| txid: tx_result.info.txid, | ||
| vout: tx_result.detail.vout, | ||
| amount: tx_result | ||
| .detail | ||
| .amount | ||
| .to_unsigned() | ||
| .expect("immature txs amount can't be negative"), | ||
| script_pub_key: tx_result | ||
| .detail | ||
| .address | ||
| .as_ref() | ||
| .expect("Should always be here") | ||
|
Member
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. Some descriptors are encoded as scripts that don't have an address form, so I don't think it's safe to expect here |
||
| .script_pubkey(), | ||
| // We don't care about those other fields, we set them to their default | ||
| address: None, | ||
| confirmations: 0, | ||
| descriptor: None, | ||
| label: None, | ||
| redeem_script: None, | ||
| witness_script: None, | ||
| safe: true, | ||
| solvable: true, | ||
| spendable: true, | ||
| }; | ||
| current_utxo.push(utxo); | ||
| } | ||
| if let Some(mut known_tx) = known_txs.get_mut(&txid) { | ||
| let confirmation_time = | ||
| BlockTime::new(tx_result.info.blockheight, tx_result.info.blocktime); | ||
|
|
||
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
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.
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.
I don't think this warning is necessary, it's impossible to spend immature stuff