Skip to content

Commit b43666a

Browse files
authored
cleanup inputs_mut, outputs_mut, kernels_mut fns (#3405)
1 parent 80841f1 commit b43666a

File tree

3 files changed

+7
-35
lines changed

3 files changed

+7
-35
lines changed

core/src/core/block.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ pub struct Block {
467467
/// The header with metadata and commitments to the rest of the data
468468
pub header: BlockHeader,
469469
/// The body - inputs/outputs/kernels
470-
body: TransactionBody,
470+
pub body: TransactionBody,
471471
}
472472

473473
impl Hashed for Block {
@@ -666,31 +666,16 @@ impl Block {
666666
&self.body.inputs
667667
}
668668

669-
/// Get inputs mutable
670-
pub fn inputs_mut(&mut self) -> &mut [Input] {
671-
&mut self.body.inputs
672-
}
673-
674669
/// Get outputs
675670
pub fn outputs(&self) -> &[Output] {
676671
&self.body.outputs
677672
}
678673

679-
/// Get outputs mutable
680-
pub fn outputs_mut(&mut self) -> &mut [Output] {
681-
&mut self.body.outputs
682-
}
683-
684674
/// Get kernels
685675
pub fn kernels(&self) -> &[TxKernel] {
686676
&self.body.kernels
687677
}
688678

689-
/// Get kernels mut
690-
pub fn kernels_mut(&mut self) -> &mut [TxKernel] {
691-
&mut self.body.kernels
692-
}
693-
694679
/// Sum of all fees (inputs less outputs) in the block
695680
pub fn total_fees(&self) -> u64 {
696681
self.body.fee()

core/src/core/transaction.rs

-15
Original file line numberDiff line numberDiff line change
@@ -1199,31 +1199,16 @@ impl Transaction {
11991199
&self.body.inputs
12001200
}
12011201

1202-
/// Get inputs mutable
1203-
pub fn inputs_mut(&mut self) -> &mut [Input] {
1204-
&mut self.body.inputs
1205-
}
1206-
12071202
/// Get outputs
12081203
pub fn outputs(&self) -> &[Output] {
12091204
&self.body.outputs
12101205
}
12111206

1212-
/// Get outputs mutable
1213-
pub fn outputs_mut(&mut self) -> &mut [Output] {
1214-
&mut self.body.outputs
1215-
}
1216-
12171207
/// Get kernels
12181208
pub fn kernels(&self) -> &[TxKernel] {
12191209
&self.body.kernels
12201210
}
12211211

1222-
/// Get kernels mut
1223-
pub fn kernels_mut(&mut self) -> &mut [TxKernel] {
1224-
&mut self.body.kernels
1225-
}
1226-
12271212
/// Total fee for a transaction is the sum of fees of all kernels.
12281213
pub fn fee(&self) -> u64 {
12291214
self.body.fee()

core/tests/block.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,9 @@ fn remove_coinbase_output_flag() {
345345
let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0);
346346
let mut b = new_block(&[], &keychain, &builder, &prev, &key_id);
347347

348-
assert!(b.outputs()[0].is_coinbase());
349-
b.outputs_mut()[0].features = OutputFeatures::Plain;
348+
let mut output = b.outputs()[0].clone();
349+
output.features = OutputFeatures::Plain;
350+
b.body.outputs = vec![output];
350351

351352
assert_eq!(b.verify_coinbase(), Err(Error::CoinbaseSumMismatch));
352353
assert!(b
@@ -369,8 +370,9 @@ fn remove_coinbase_kernel_flag() {
369370
let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0);
370371
let mut b = new_block(&[], &keychain, &builder, &prev, &key_id);
371372

372-
assert!(b.kernels()[0].is_coinbase());
373-
b.kernels_mut()[0].features = KernelFeatures::Plain { fee: 0 };
373+
let mut kernel = b.kernels()[0].clone();
374+
kernel.features = KernelFeatures::Plain { fee: 0 };
375+
b.body = b.body.replace_kernel(kernel);
374376

375377
// Flipping the coinbase flag results in kernels not summing correctly.
376378
assert_eq!(

0 commit comments

Comments
 (0)