@@ -213,6 +213,43 @@ sub serialized_witness
213213 ;
214214}
215215
216+ signature_for set_serialized_witness => (
217+ method => !!1,
218+ head => [ByteStr],
219+ named => [
220+ pos => Maybe [ScalarRef [PositiveOrZeroInt]],
221+ {default => undef },
222+ ],
223+ bless => !!0,
224+ );
225+
226+ sub set_serialized_witness
227+ {
228+ my ($self , $serialized , $args ) = @_ ;
229+ my $partial = !!$args -> {pos };
230+ my $pos = $partial ? ${$args -> {pos }} : 0;
231+
232+ my $input_witness = unpack_compactsize $serialized , \$pos ;
233+ my @witness ;
234+ for (1 .. $input_witness ) {
235+ my $witness_count = unpack_compactsize $serialized , \$pos ;
236+
237+ push @witness , substr $serialized , $pos , $witness_count ;
238+ $pos += $witness_count ;
239+ }
240+
241+ $self -> set_witness(\@witness );
242+
243+ Bitcoin::Crypto::Exception::Transaction-> raise(
244+ ' serialized witness data is corrupted'
245+ ) if !$partial && $pos != length $serialized ;
246+
247+ ${$args -> {pos }} = $pos
248+ if $partial ;
249+
250+ return ;
251+ }
252+
216253sub script_base
217254{
218255 my ($self ) = @_ ;
@@ -431,6 +468,33 @@ start decoding. It will be set to the next byte after end of input stream.
431468
432469=back
433470
471+ =head3 serialized_witness
472+
473+ $bytestring = $object->serialized_witness()
474+
475+ Serializes witness data of the input as it would appear in the serialized
476+ transaction, and returns it as a bytestring.
477+
478+ =head3 set_serialized_witness
479+
480+ $object->set_serialized_witness($bytestring, %params)
481+
482+ Sets L</witness> to data obtained by deserializing C<$bytestring > .
483+
484+ C<%params > can be any of:
485+
486+ =over
487+
488+ =item * C<pos >
489+
490+ Position for partial string decoding. Optional. If passed, must be a scalar
491+ reference to an integer value.
492+
493+ This integer will mark the starting position of C<$bytestring > from which to
494+ start decoding. It will be set to the next byte after end of input stream.
495+
496+ =back
497+
434498=head3 is_segwit
435499
436500 $boolean = $object->is_segwit()
0 commit comments