Bitcoin::Crypto::Segwit - Segregated Witness version definitions
use Bitcoin::Crypto::Segwit qw(validate_program); my $program_version = validate_program($segwit_program);
This module provides tools required to define and use a Segregated Witness version validator.
$segwit_version = validate_program($program)
Performs a segwit program validation on $program, which is expected to be a byte string in which the first byte is a segwit version. Based on this version a validator is invoked, present in %Bitcoin::Crypto::Segwit::validators module hash. If the validator is not defined for a segwit version being validated, a warning is issued.
The function returns the detected segwit program version. Please note that it does not perform any more checks than ensuring the byte string is in correct format.
The current implementation defines a validator for segwit version 0. In the future (when another segwit program version is defined) it might be neccessary to define another one in the program until it's added to the library. This can be done like so:
use Bitcoin::Crypto::Segwit; use Bitcoin::Crypto::Exception; $Bitcoin::Crypto::Segwit::validators{1} = sub { my ($data) = @_; # perform validation Bitcoin::Crypto::Exception::SegwitProgram->raise( "validation of program version 1 failed" ) if ...; # if validation is successful just do nothing return; };
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:
SegwitProgram - a validation of a segwit program has failed
To install Bitcoin::Crypto, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Bitcoin::Crypto
CPAN shell
perl -MCPAN -e shell install Bitcoin::Crypto
For more information on module installation, please visit the detailed CPAN module installation guide.