mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-17 07:11:36 +02:00
share proof kernel lookup
This commit is contained in:
@@ -19,7 +19,7 @@ use strum::IntoEnumIterator;
|
|||||||
use super::owner::tx_lock_outputs;
|
use super::owner::tx_lock_outputs;
|
||||||
use crate::api_impl::owner::contract_new as owner_contract_new;
|
use crate::api_impl::owner::contract_new as owner_contract_new;
|
||||||
use crate::api_impl::owner::contract_sign as owner_contract_sign;
|
use crate::api_impl::owner::contract_sign as owner_contract_sign;
|
||||||
use crate::api_impl::owner::{check_ttl, post_tx};
|
use crate::api_impl::owner::{check_ttl, payment_proof_kernel, post_tx};
|
||||||
use crate::api_impl::types::update_tx_slate_state;
|
use crate::api_impl::types::update_tx_slate_state;
|
||||||
use crate::backend::WalletBackend;
|
use crate::backend::WalletBackend;
|
||||||
use crate::contract::types::{ContractNewArgsAPI, ContractSetupArgsAPI};
|
use crate::contract::types::{ContractNewArgsAPI, ContractSetupArgsAPI};
|
||||||
@@ -307,21 +307,7 @@ where
|
|||||||
Error::PaymentProof("Cannot verify early payment proof with no witness data".to_string())
|
Error::PaymentProof("Cannot verify early payment proof with no witness data".to_string())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let (retrieved_kernel, _) = match client.get_kernel(&wd.kernel_commitment, None, None) {
|
let (retrieved_kernel, _) = payment_proof_kernel(&mut client, &wd.kernel_commitment)?;
|
||||||
Err(e) => {
|
|
||||||
return Err(Error::PaymentProof(format!(
|
|
||||||
"Error retrieving kernel from chain: {}",
|
|
||||||
e
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
Ok(None) => {
|
|
||||||
return Err(Error::PaymentProof(format!(
|
|
||||||
"Transaction kernel with excess {:?} not found on chain",
|
|
||||||
wd.kernel_commitment
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
Ok(Some((k, _, index))) => (k, index),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Now verify with retrieved data
|
// Now verify with retrieved data
|
||||||
proof.verify_witness(
|
proof.verify_witness(
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ use uuid::Uuid;
|
|||||||
use crate::api_impl::foreign::finalize_tx as foreign_finalize;
|
use crate::api_impl::foreign::finalize_tx as foreign_finalize;
|
||||||
use crate::grin_core::core::amount_to_hr_string;
|
use crate::grin_core::core::amount_to_hr_string;
|
||||||
use crate::grin_core::core::hash::Hashed;
|
use crate::grin_core::core::hash::Hashed;
|
||||||
use crate::grin_core::core::{FeeFields, Output, OutputFeatures, Transaction};
|
use crate::grin_core::core::{FeeFields, Output, OutputFeatures, Transaction, TxKernel};
|
||||||
use crate::grin_core::libtx::proof;
|
use crate::grin_core::libtx::proof;
|
||||||
use crate::grin_keychain::ViewKey;
|
use crate::grin_keychain::ViewKey;
|
||||||
use crate::grin_util::secp::key::SecretKey;
|
use crate::grin_util::secp::key::SecretKey;
|
||||||
@@ -542,6 +542,24 @@ where
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Look up the kernel used by a payment proof
|
||||||
|
pub(super) fn payment_proof_kernel<C: NodeClient>(
|
||||||
|
client: &mut C,
|
||||||
|
excess: &Commitment,
|
||||||
|
) -> Result<(TxKernel, u64), Error> {
|
||||||
|
match client.get_kernel(excess, None, None) {
|
||||||
|
Err(e) => Err(Error::PaymentProof(format!(
|
||||||
|
"Error retrieving kernel from chain: {}",
|
||||||
|
e
|
||||||
|
))),
|
||||||
|
Ok(None) => Err(Error::PaymentProof(format!(
|
||||||
|
"Transaction kernel with excess {:?} not found on chain",
|
||||||
|
excess
|
||||||
|
))),
|
||||||
|
Ok(Some((kernel, _, index))) => Ok((kernel, index)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Retrieve an early payment proof
|
/// Retrieve an early payment proof
|
||||||
pub fn retrieve_payment_proof_early<'a, L, C, K>(
|
pub fn retrieve_payment_proof_early<'a, L, C, K>(
|
||||||
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
|
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
|
||||||
@@ -613,30 +631,11 @@ where
|
|||||||
w.w2n_client().clone()
|
w.w2n_client().clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
let kernel_excess = match tx.kernel_excess {
|
let kernel_excess = tx.kernel_excess.ok_or_else(|| {
|
||||||
Some(k) => k,
|
Error::PaymentProofRetrieval("Early payment proof transaction kernel excess missing".into())
|
||||||
None => {
|
})?;
|
||||||
return Err(Error::PaymentProofRetrieval(format!(
|
|
||||||
"Early payment proof transaction kernel excess missing",
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let (retrieved_kernel, index) = match client.get_kernel(&kernel_excess, None, None) {
|
let (retrieved_kernel, index) = payment_proof_kernel(&mut client, &kernel_excess)?;
|
||||||
Err(e) => {
|
|
||||||
return Err(Error::PaymentProof(format!(
|
|
||||||
"Error retrieving kernel from chain: {}",
|
|
||||||
e
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
Ok(None) => {
|
|
||||||
return Err(Error::PaymentProof(format!(
|
|
||||||
"Transaction kernel with excess {:?} not found on chain",
|
|
||||||
kernel_excess
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
Ok(Some((k, _, index))) => (k, index),
|
|
||||||
};
|
|
||||||
|
|
||||||
proof.witness_data = Some(ProofWitness {
|
proof.witness_data = Some(ProofWitness {
|
||||||
kernel_index: index,
|
kernel_index: index,
|
||||||
@@ -1415,21 +1414,7 @@ where
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Check kernel exists
|
// Check kernel exists
|
||||||
match client.get_kernel(&proof.excess, None, None) {
|
payment_proof_kernel(&mut client, &proof.excess)?;
|
||||||
Err(e) => {
|
|
||||||
return Err(Error::PaymentProof(format!(
|
|
||||||
"Error retrieving kernel from chain: {}",
|
|
||||||
e
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
Ok(None) => {
|
|
||||||
return Err(Error::PaymentProof(format!(
|
|
||||||
"Transaction kernel with excess {:?} not found on chain",
|
|
||||||
proof.excess
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
Ok(Some(_)) => {}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Check Sigs
|
// Check Sigs
|
||||||
let recipient_pubkey = proof.recipient_address.pub_key;
|
let recipient_pubkey = proof.recipient_address.pub_key;
|
||||||
|
|||||||
Reference in New Issue
Block a user