mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 11:31:08 +03:00
Remove reserved output on wallet receive failure
This commit is contained in:
parent
33c8e73403
commit
7e86e76787
1 changed files with 17 additions and 6 deletions
|
@ -54,15 +54,25 @@ pub fn receive_json_tx(
|
||||||
keychain: &Keychain,
|
keychain: &Keychain,
|
||||||
partial_tx: &PartialTx,
|
partial_tx: &PartialTx,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
|
||||||
|
// reading the partial transaction and finalizing it, adding our output
|
||||||
let (amount, blinding, tx) = read_partial_tx(keychain, partial_tx)?;
|
let (amount, blinding, tx) = read_partial_tx(keychain, partial_tx)?;
|
||||||
let final_tx = receive_transaction(config, keychain, amount, blinding, tx)?;
|
let (final_tx, key_id) = receive_transaction(config, keychain, amount, blinding, tx)?;
|
||||||
let tx_hex = util::to_hex(ser::ser_vec(&final_tx).unwrap());
|
let tx_hex = util::to_hex(ser::ser_vec(&final_tx).unwrap());
|
||||||
|
|
||||||
|
// pushing to the transaction pool, in case of error the output that was
|
||||||
|
// reserved needs to be removed
|
||||||
let url = format!("{}/v1/pool/push", config.check_node_api_http_addr.as_str());
|
let url = format!("{}/v1/pool/push", config.check_node_api_http_addr.as_str());
|
||||||
api::client::post(url.as_str(), &TxWrapper { tx_hex: tx_hex })
|
let res = api::client::post(url.as_str(), &TxWrapper { tx_hex: tx_hex });
|
||||||
.map_err(|e| Error::Node(e))?;
|
if let Err(e) = res {
|
||||||
|
WalletData::with_wallet(&config.data_file_dir, |wallet_data| {
|
||||||
|
wallet_data.delete_output(&key_id);
|
||||||
|
})?;
|
||||||
|
Err(Error::Node(e))
|
||||||
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Component used to receive coins, implements all the receiving end of the
|
/// Component used to receive coins, implements all the receiving end of the
|
||||||
/// wallet REST API as well as some of the command-line operations.
|
/// wallet REST API as well as some of the command-line operations.
|
||||||
|
@ -171,7 +181,8 @@ fn receive_transaction(
|
||||||
amount: u64,
|
amount: u64,
|
||||||
blinding: BlindingFactor,
|
blinding: BlindingFactor,
|
||||||
partial: Transaction,
|
partial: Transaction,
|
||||||
) -> Result<Transaction, Error> {
|
) -> Result<(Transaction, Identifier), Error> {
|
||||||
|
|
||||||
let root_key_id = keychain.root_key_id();
|
let root_key_id = keychain.root_key_id();
|
||||||
|
|
||||||
// double check the fee amount included in the partial tx
|
// double check the fee amount included in the partial tx
|
||||||
|
@ -227,5 +238,5 @@ fn receive_transaction(
|
||||||
derivation,
|
derivation,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(tx_final)
|
Ok((tx_final, key_id))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue