cleanup inputs_mut, outputs_mut, kernels_mut fns (#3405)

This commit is contained in:
Antioch Peverell 2020-07-27 11:54:43 +01:00 committed by GitHub
parent 80841f16d2
commit b43666af80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 35 deletions

View file

@ -467,7 +467,7 @@ pub struct Block {
/// The header with metadata and commitments to the rest of the data /// The header with metadata and commitments to the rest of the data
pub header: BlockHeader, pub header: BlockHeader,
/// The body - inputs/outputs/kernels /// The body - inputs/outputs/kernels
body: TransactionBody, pub body: TransactionBody,
} }
impl Hashed for Block { impl Hashed for Block {
@ -666,31 +666,16 @@ impl Block {
&self.body.inputs &self.body.inputs
} }
/// Get inputs mutable
pub fn inputs_mut(&mut self) -> &mut [Input] {
&mut self.body.inputs
}
/// Get outputs /// Get outputs
pub fn outputs(&self) -> &[Output] { pub fn outputs(&self) -> &[Output] {
&self.body.outputs &self.body.outputs
} }
/// Get outputs mutable
pub fn outputs_mut(&mut self) -> &mut [Output] {
&mut self.body.outputs
}
/// Get kernels /// Get kernels
pub fn kernels(&self) -> &[TxKernel] { pub fn kernels(&self) -> &[TxKernel] {
&self.body.kernels &self.body.kernels
} }
/// Get kernels mut
pub fn kernels_mut(&mut self) -> &mut [TxKernel] {
&mut self.body.kernels
}
/// Sum of all fees (inputs less outputs) in the block /// Sum of all fees (inputs less outputs) in the block
pub fn total_fees(&self) -> u64 { pub fn total_fees(&self) -> u64 {
self.body.fee() self.body.fee()

View file

@ -1199,31 +1199,16 @@ impl Transaction {
&self.body.inputs &self.body.inputs
} }
/// Get inputs mutable
pub fn inputs_mut(&mut self) -> &mut [Input] {
&mut self.body.inputs
}
/// Get outputs /// Get outputs
pub fn outputs(&self) -> &[Output] { pub fn outputs(&self) -> &[Output] {
&self.body.outputs &self.body.outputs
} }
/// Get outputs mutable
pub fn outputs_mut(&mut self) -> &mut [Output] {
&mut self.body.outputs
}
/// Get kernels /// Get kernels
pub fn kernels(&self) -> &[TxKernel] { pub fn kernels(&self) -> &[TxKernel] {
&self.body.kernels &self.body.kernels
} }
/// Get kernels mut
pub fn kernels_mut(&mut self) -> &mut [TxKernel] {
&mut self.body.kernels
}
/// Total fee for a transaction is the sum of fees of all kernels. /// Total fee for a transaction is the sum of fees of all kernels.
pub fn fee(&self) -> u64 { pub fn fee(&self) -> u64 {
self.body.fee() self.body.fee()

View file

@ -345,8 +345,9 @@ fn remove_coinbase_output_flag() {
let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0);
let mut b = new_block(&[], &keychain, &builder, &prev, &key_id); let mut b = new_block(&[], &keychain, &builder, &prev, &key_id);
assert!(b.outputs()[0].is_coinbase()); let mut output = b.outputs()[0].clone();
b.outputs_mut()[0].features = OutputFeatures::Plain; output.features = OutputFeatures::Plain;
b.body.outputs = vec![output];
assert_eq!(b.verify_coinbase(), Err(Error::CoinbaseSumMismatch)); assert_eq!(b.verify_coinbase(), Err(Error::CoinbaseSumMismatch));
assert!(b assert!(b
@ -369,8 +370,9 @@ fn remove_coinbase_kernel_flag() {
let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0); let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0);
let mut b = new_block(&[], &keychain, &builder, &prev, &key_id); let mut b = new_block(&[], &keychain, &builder, &prev, &key_id);
assert!(b.kernels()[0].is_coinbase()); let mut kernel = b.kernels()[0].clone();
b.kernels_mut()[0].features = KernelFeatures::Plain { fee: 0 }; kernel.features = KernelFeatures::Plain { fee: 0 };
b.body = b.body.replace_kernel(kernel);
// Flipping the coinbase flag results in kernels not summing correctly. // Flipping the coinbase flag results in kernels not summing correctly.
assert_eq!( assert_eq!(