Skip to content

Commit 648e22e

Browse files
committed
Allow inserting inputs/outputs at specified positions
While the positions of inputs and outputs don't usually matter, they do matter in covenant constructions. This allows easier construction rather than creating a new vec or swapping things around
1 parent 7bc95f4 commit 648e22e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/pset/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ impl PartiallySignedTransaction {
100100
self.inputs.push(inp);
101101
}
102102

103+
/// Add an input to pset at position i. This also updates the
104+
/// pset global input count
105+
/// Panics if index is more than length.
106+
pub fn insert_input(&mut self, inp: Input, pos: usize) {
107+
self.global.tx_data.input_count += 1;
108+
self.inputs.insert(pos, inp);
109+
}
110+
103111
/// Read accessor to inputs
104112
pub fn inputs(&self) -> &[Input] {
105113
&self.inputs
@@ -127,6 +135,14 @@ impl PartiallySignedTransaction {
127135
self.outputs.push(out);
128136
}
129137

138+
/// Add an output to pset at position i. This also updates the
139+
/// pset global output count
140+
/// Panics if index is more than length.
141+
pub fn insert_output(&mut self, out: Output, pos: usize) {
142+
self.global.tx_data.output_count += 1;
143+
self.outputs.insert(pos, out);
144+
}
145+
130146
/// read accessor to outputs
131147
pub fn outputs(&self) -> &[Output] {
132148
&self.outputs

0 commit comments

Comments
 (0)