mirror of
https://github.com/mimblewimble/grin-wallet.git
synced 2025-01-20 19:11:09 +03:00
rework kernel features support to handle fee and lock_height on features variants
This commit is contained in:
parent
a58cae651e
commit
6c322acaf8
4 changed files with 41 additions and 34 deletions
|
@ -119,13 +119,9 @@ fn basic_transaction_api(test_dir: &'static str) -> Result<(), libwallet::Error>
|
|||
|
||||
// Check we have a single kernel and that it is a Plain kernel (no lock_height).
|
||||
assert_eq!(slate.tx.kernels().len(), 1);
|
||||
assert_eq!(
|
||||
slate.tx.kernels().first().map(|k| k.lock_height).unwrap(),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
slate.tx.kernels().first().map(|k| k.features).unwrap(),
|
||||
transaction::KernelFeatures::Plain
|
||||
transaction::KernelFeatures::Plain { fee: 0 }
|
||||
);
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -20,8 +20,7 @@ use crate::error::{Error, ErrorKind};
|
|||
use crate::grin_core::core::amount_to_hr_string;
|
||||
use crate::grin_core::core::committed::Committed;
|
||||
use crate::grin_core::core::transaction::{
|
||||
kernel_features, kernel_sig_msg, Input, Output, Transaction, TransactionBody, TxKernel,
|
||||
Weighting,
|
||||
Input, KernelFeatures, Output, Transaction, TransactionBody, TxKernel, Weighting,
|
||||
};
|
||||
use crate::grin_core::core::verifier_cache::LruVerifierCache;
|
||||
use crate::grin_core::libtx::{aggsig, build, proof::ProofBuild, secp_ser, tx_fee};
|
||||
|
@ -290,11 +289,16 @@ impl Slate {
|
|||
}
|
||||
|
||||
// This is the msg that we will sign as part of the tx kernel.
|
||||
// Currently includes the fee and the lock_height.
|
||||
// If lock_height is 0 then build a plain kernel, otherwise build a height locked kernel.
|
||||
fn msg_to_sign(&self) -> Result<secp::Message, Error> {
|
||||
// Currently we only support interactively creating a tx with a "default" kernel.
|
||||
let features = kernel_features(self.lock_height);
|
||||
let msg = kernel_sig_msg(self.fee, self.lock_height, features)?;
|
||||
let features = match self.lock_height {
|
||||
0 => KernelFeatures::Plain { fee: self.fee },
|
||||
_ => KernelFeatures::HeightLocked {
|
||||
fee: self.fee,
|
||||
lock_height: self.lock_height,
|
||||
},
|
||||
};
|
||||
let msg = features.kernel_sig_msg()?;
|
||||
Ok(msg)
|
||||
}
|
||||
|
||||
|
@ -881,19 +885,19 @@ impl From<&Output> for OutputV2 {
|
|||
|
||||
impl From<&TxKernel> for TxKernelV2 {
|
||||
fn from(kernel: &TxKernel) -> TxKernelV2 {
|
||||
let TxKernel {
|
||||
features,
|
||||
fee,
|
||||
lock_height,
|
||||
excess,
|
||||
excess_sig,
|
||||
} = *kernel;
|
||||
let (features, fee, lock_height) = match kernel.features {
|
||||
KernelFeatures::Plain { fee } => (CompatKernelFeatures::Plain, fee, 0),
|
||||
KernelFeatures::Coinbase => (CompatKernelFeatures::Coinbase, 0, 0),
|
||||
KernelFeatures::HeightLocked { fee, lock_height } => {
|
||||
(CompatKernelFeatures::HeightLocked, fee, lock_height)
|
||||
}
|
||||
};
|
||||
TxKernelV2 {
|
||||
features,
|
||||
fee,
|
||||
lock_height,
|
||||
excess,
|
||||
excess_sig,
|
||||
excess: kernel.excess,
|
||||
excess_sig: kernel.excess_sig,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1025,19 +1029,23 @@ impl From<&OutputV2> for Output {
|
|||
|
||||
impl From<&TxKernelV2> for TxKernel {
|
||||
fn from(kernel: &TxKernelV2) -> TxKernel {
|
||||
let TxKernelV2 {
|
||||
features,
|
||||
fee,
|
||||
lock_height,
|
||||
excess,
|
||||
excess_sig,
|
||||
} = *kernel;
|
||||
let (fee, lock_height) = (kernel.fee, kernel.lock_height);
|
||||
let features = match kernel.features {
|
||||
CompatKernelFeatures::Plain => KernelFeatures::Plain { fee },
|
||||
CompatKernelFeatures::Coinbase => KernelFeatures::Coinbase,
|
||||
CompatKernelFeatures::HeightLocked => KernelFeatures::HeightLocked { fee, lock_height },
|
||||
};
|
||||
TxKernel {
|
||||
features,
|
||||
fee,
|
||||
lock_height,
|
||||
excess,
|
||||
excess_sig,
|
||||
excess: kernel.excess,
|
||||
excess_sig: kernel.excess_sig,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||
pub enum CompatKernelFeatures {
|
||||
Plain,
|
||||
Coinbase,
|
||||
HeightLocked,
|
||||
}
|
||||
|
|
|
@ -35,13 +35,14 @@
|
|||
//! orig_version: u16,
|
||||
//! block_header_version: u16,
|
||||
|
||||
use crate::grin_core::core::transaction::{KernelFeatures, OutputFeatures};
|
||||
use crate::grin_core::core::transaction::OutputFeatures;
|
||||
use crate::grin_core::libtx::secp_ser;
|
||||
use crate::grin_keychain::BlindingFactor;
|
||||
use crate::grin_util::secp;
|
||||
use crate::grin_util::secp::key::PublicKey;
|
||||
use crate::grin_util::secp::pedersen::{Commitment, RangeProof};
|
||||
use crate::grin_util::secp::Signature;
|
||||
use crate::slate::CompatKernelFeatures;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
|
@ -162,7 +163,7 @@ pub struct OutputV2 {
|
|||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct TxKernelV2 {
|
||||
/// Options for a kernel's structure or use
|
||||
pub features: KernelFeatures,
|
||||
pub features: CompatKernelFeatures,
|
||||
/// Fee originally included in the transaction this proof is for.
|
||||
#[serde(with = "secp_ser::string_or_u64")]
|
||||
pub fee: u64,
|
||||
|
|
|
@ -23,7 +23,9 @@ use grin_wallet_util::grin_util::secp::key::{PublicKey, SecretKey};
|
|||
use rand::thread_rng;
|
||||
|
||||
fn kernel_sig_msg() -> secp::Message {
|
||||
transaction::kernel_sig_msg(0, 0, transaction::KernelFeatures::Plain).unwrap()
|
||||
transaction::KernelFeatures::Plain { fee: 0 }
|
||||
.kernel_sig_msg()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue