NAME
Bitcoin::Crypto::Transaction::Input - Bitcoin transaction input instance
SYNOPSIS
use Bitcoin::Crypto qw(btc_transaction);
my $tx = btc_transaction->new;
$tx->add_input(
utxo => [$txid, $output_index],
);
print $tx->inputs->[0]->dump;
DESCRIPTION
This is an input instance implementation used in transactions. It is rarely interacted with directly.
INTERFACE
Attributes
utxo
An instance of Bitcoin::Crypto::Transaction::UTXO. Required.
Can also be passed an array reference of two parameters, which will be fed to "get" in Bitcoin::Crypto::Transaction::UTXO to fetch the UTXO instance. It will be done lazily, so that you can freely deserialize transactions without the need to set up their UTXOs.
Available in the constructor.
utxo_location
An array reference with the same data as passed to "get" in Bitcoin::Crypto::Transaction::UTXO. Will be pulled out of whatever was passed to "utxo".
signature_script
The script used to unlock the coins from the UTXO.
By default, it is an empty script.
Available in the constructor.
writer: set_signature_script
sequence_no
Also known as nSequence
in Bitcoin Core. The sequence number used in various applications. Non-negative integer.
By default, it is set to 0xffffffff
(max_sequence_no
in Bitcoin::Crypto::Constants
).
Available in the constructor.
writer: set_sequence_no
witness
SegWit data for this input. It is an array reference of bytestrings. Note that each element in the witness must be a separate element in this array (concatenating the witness into one bytestring will not work as intended).
Empty by default.
Available in the constructor.
writer: set_witness
predicate: has_witness
Methods
new
$block = $class->new(%args)
This is a standard Moo constructor, which can be used to create the object. It takes arguments specified in "Attributes".
Returns class instance.
utxo_registered
$boolean = $object->utxo_registered()
Returns boolean value indicating whether UTXO for this input is reachable. If it isn't, getting "utxo" will throw an exception.
Creating transactions without registered UTXOs will work in very basic cases but can raise Bitcoin::Crypto::Exception::UTXO
exception if a function cannot be finished without a full UTXO data. It is mainly useful for getting data encoded in a serialized transaction.
to_serialized
$bytestring = $object->to_serialized()
Returns the serialized input data to be included into a serialized transaction.
NOTE: serialized input does not include witness data, which is a part of this class.
from_serialized
$object = $class->from_serialized($bytestring, %params)
Creates an object instance from serialized data.
%params
can be any of:
pos
Position for partial string decoding. Optional. If passed, must be a scalar reference to an integer value.
This integer will mark the starting position of
$bytestring
from which to start decoding. It will be set to the next byte after end of input stream.
is_segwit
$boolean = $object->is_segwit()
Returns true if this input represents a segwit output.
For scripts which have signature_script
filled out, this method is able to detect both native and compatibility segwit outputs (unlike "is_native_segwit" in Bitcoin::Crypto::Script).
prevout
$bytestring = $object->prevout()
Returns a bytestring with prevout data ready to be encoded in places like digest preimages. Mostly used internally.
script_base
$script = $object->script_base()
Returns a base script for the digest. Mostly used internally.
dump
$text = $object->dump()
Returns a readable description of the input.
EXCEPTIONS
This module throws an instance of Bitcoin::Crypto::Exception if it encounters an error. It can produce the following error types from the Bitcoin::Crypto::Exception namespace:
Transaction - general error with transaction