<commit_before><?php

namespace BitWasp\Bitcoin\Transaction;

use BitWasp\Bitcoin\Bitcoin;
use BitWasp\Bitcoin\Collection\Transaction\TransactionInputCollection;
use BitWasp\Bitcoin\Collection\Transaction\TransactionOutputCollection;
use BitWasp\Bitcoin\Crypto\Hash;
use BitWasp\Bitcoin\Serializable;
use BitWasp\Bitcoin\Serializer\Transaction\TransactionSerializer;
use BitWasp\Bitcoin\Transaction\SignatureHash\Hasher;
use BitWasp\Buffertools\Buffer;
use BitWasp\CommonTrait\FunctionAliasArrayAccess;

class Transaction extends Serializable implements TransactionInterface
{
    use FunctionAliasArrayAccess;

    /**
     * @var int|string
     */
    private $version;

    /**
     * @var TransactionInputCollection
     */
    private $inputs;

    /**
     * @var TransactionOutputCollection
     */
    private $outputs;

    /**
     * @var int|string
     */
    private $lockTime;

    /**
     * @param int|string $nVersion
     * @param TransactionInputCollection $inputs
     * @param TransactionOutputCollection $outputs
     * @param int|string $nLockTime
     * @throws \Exception
     */
    public function __construct(
        $nVersion = TransactionInterface::DEFAULT_VERSION,
        TransactionInputCollection $inputs = null,
        TransactionOutputCollection $outputs = null,
        $nLockTime = '0'
    ) {

        if (!is_numeric($nVersion)) {
            throw new \InvalidArgumentException('Transaction version must be numeric');
        }

        if (!is_numeric($nLockTime)) {
            throw new \InvalidArgumentException('Transaction locktime must be numeric');
        }

        $math = Bitcoin::getMath();
        if ($math->cmp($nVersion, TransactionInterface::MAX_VERSION) > 0) {
            throw new \InvalidArgumentException('Version must be less than ' . TransactionInterface::MAX_VERSION);
        }

        if ($math->cmp($nLockTime, TransactionInterface::MAX_LOCKTIME) > 0) {
            throw new \InvalidArgumentException('Locktime must be less than ' . TransactionInterface::MAX_LOCKTIME);
        }

        $this->version = $nVersion;
        $this->inputs = $inputs ?: new TransactionInputCollection();
        $this->outputs = $outputs ?: new TransactionOutputCollection();
        $this->lockTime = $nLockTime;

        $this
            ->initFunctionAlias('version', 'getVersion')
            ->initFunctionAlias('inputs', 'getInputs')
            ->initFunctionAlias('outputs', 'getOutputs')
            ->initFunctionAlias('locktime', 'getLockTime');
    }

    /**
     * @return Transaction
     */
    public function __clone()
    {
        $this->inputs = clone $this->inputs;
        $this->outputs = clone $this->outputs;<commit_msg>Transaction: check locktime is positive<commit_after><?php

namespace BitWasp\Bitcoin\Transaction;

use BitWasp\Bitcoin\Bitcoin;
use BitWasp\Bitcoin\Collection\Transaction\TransactionInputCollection;
use BitWasp\Bitcoin\Collection\Transaction\TransactionOutputCollection;
use BitWasp\Bitcoin\Crypto\Hash;
use BitWasp\Bitcoin\Serializable;
use BitWasp\Bitcoin\Serializer\Transaction\TransactionSerializer;
use BitWasp\Bitcoin\Transaction\SignatureHash\Hasher;
use BitWasp\Buffertools\Buffer;
use BitWasp\CommonTrait\FunctionAliasArrayAccess;

class Transaction extends Serializable implements TransactionInterface
{
    use FunctionAliasArrayAccess;

    /**
     * @var int|string
     */
    private $version;

    /**
     * @var TransactionInputCollection
     */
    private $inputs;

    /**
     * @var TransactionOutputCollection
     */
    private $outputs;

    /**
     * @var int|string
     */
    private $lockTime;

    /**
     * @param int|string $nVersion
     * @param TransactionInputCollection $inputs
     * @param TransactionOutputCollection $outputs
     * @param int|string $nLockTime
     * @throws \Exception
     */
    public function __construct(
        $nVersion = TransactionInterface::DEFAULT_VERSION,
        TransactionInputCollection $inputs = null,
        TransactionOutputCollection $outputs = null,
        $nLockTime = '0'
    ) {

        if (!is_numeric($nVersion)) {
            throw new \InvalidArgumentException('Transaction version must be numeric');
        }

        if (!is_numeric($nLockTime)) {
            throw new \InvalidArgumentException('Transaction locktime must be numeric');
        }

        $math = Bitcoin::getMath();
        if ($math->cmp($nVersion, TransactionInterface::MAX_VERSION) > 0) {
            throw new \InvalidArgumentException('Version must be less than ' . TransactionInterface::MAX_VERSION);
        }

        if ($math->cmp($nLockTime, 0) < 0 || $math->cmp($nLockTime, TransactionInterface::MAX_LOCKTIME) > 0) {
            throw new \InvalidArgumentException('Locktime must be positive and less than ' . TransactionInterface::MAX_LOCKTIME);
        }

        $this->version = $nVersion;
        $this->inputs = $inputs ?: new TransactionInputCollection();
        $this->outputs = $outputs ?: new TransactionOutputCollection();
        $this->lockTime = $nLockTime;

        $this
            ->initFunctionAlias('version', 'getVersion')
            ->initFunctionAlias('inputs', 'getInputs')
            ->initFunctionAlias('outputs', 'getOutputs')
            ->initFunctionAlias('locktime', 'getLockTime');
    }

    /**
     * @return Transaction
     */
    public function __clone()
    {
        $this->inputs = clone $this->inputs;
        $this->outputs = clone $this->outputs;
{'fraction_non_alphanumeric': 0.11222627737226278, 'fraction_numerical': 0.00145985401459854, 'mean_word_length': 3.0036523009495983, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1662720', 'n_tokens_mistral': 1461, 'n_tokens_neox': 1423, 'n_words': 304}