<commit_before>package recorder

import (
	"bytes"
	"encoding/binary"
	"strconv"

	"github.com/btcsuite/btcd/chaincfg"
	"github.com/btcsuite/btcd/txscript"
	"github.com/btcsuite/btcd/wire"
	"github.com/btcsuite/btcutil"
)

type OutputRecord struct {
	value   int64
	address btcutil.Address
}

func NewOutputRecord(txout *wire.TxOut) *OutputRecord {
	_, addrs, _, err := txscript.ExtractPkScriptAddrs(txout.PkScript,
		&chaincfg.MainNetParams)
	if err != nil {
		return &OutputRecord{value: 0}
	}
	if len(addrs) != 1 {
		return &OutputRecord{value: -1}
	}

	or := &OutputRecord{
		value:   txout.Value,
		address: addrs[0],
	}

	return or
}

func (or *OutputRecord) String() string {
	buf := new(bytes.Buffer)
	buf.WriteString(or.address.EncodeAddress())
	buf.WriteString(" ")
	buf.WriteString(strconv.FormatInt(or.value, 10))

	return buf.String()
}

func (or *OutputRecord) Bytes() []byte {
	buf := new(bytes.Buffer)
	binary.Write(buf, binary.LittleEndian, or.value)
	binary.Write(buf, binary.LittleEndian,
		[]byte(or.address.EncodeAddress()))

	return buf.Bytes()
}<commit_msg>Fixed complex output crash (multisig, advanced scripts, ...)<commit_after>package recorder

import (
	"bytes"
	"encoding/binary"
	"strconv"

	"github.com/btcsuite/btcd/chaincfg"
	"github.com/btcsuite/btcd/txscript"
	"github.com/btcsuite/btcd/wire"
	"github.com/btcsuite/btcutil"
)

type OutputRecord struct {
	value   int64
	address btcutil.Address
	code    uint32
}

func NewOutputRecord(txout *wire.TxOut) *OutputRecord {
	or := &OutputRecord{
		value: txout.Value,
	}

	_, addrs, _, err := txscript.ExtractPkScriptAddrs(txout.PkScript,
		&chaincfg.MainNetParams)
	if err != nil {
		or.code = 1
	}
	if len(addrs) != 1 {
		or.code = 2
	}

	if or.code == 0 {
		or.address = addrs[0]
	}

	return or
}

func (or *OutputRecord) String() string {
	buf := new(bytes.Buffer)

	switch or.code {
	case 0:
		buf.WriteString(or.address.EncodeAddress())

	case 1:
		buf.WriteString("complexescript....................")

	case 2:
		buf.WriteString("multisig..........................")

	default:
		buf.WriteString("extractfailure....................")
	}

	buf.WriteString(" ")
	buf.WriteString(strconv.FormatInt(or.value, 10))

	return buf.String()
}

func (or *OutputRecord) Bytes() []byte {
	buf := new(bytes.Buffer)

	binary.Write(buf, binary.LittleEndian, or.code)

	if or.code == 0 {
		binary.Write(buf, binary.LittleEndian, or.address.ScriptAddress())
	}

	binary.Write(buf, binary.LittleEndian, or.value)

	return buf.Bytes()
}
{'fraction_non_alphanumeric': 0.16966067864271456, 'fraction_numerical': 0.009181636726546906, 'mean_word_length': 3.76425855513308, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4791423', 'n_tokens_mistral': 991, 'n_tokens_neox': 931, 'n_words': 174}