<commit_before>#include <erl_nif.h>
#include <iostream>
#include <sstream>
#include <bitcoin/bitcoin.hpp>
#include <bitcoin/bitcoin/chain/transaction.hpp>
#include <bitcoin/bitcoin/config/btc256.hpp>
#include <bitcoin/bitcoin/formats/base16.hpp>

#include <assert.h>
#include "erl_nif.h"
#include "nifpp.h"

#ifdef ERL_NIF_DIRTY_JOB_CPU_BOUND
#define LIBBITCOIN_NIF_FLAGS ERL_NIF_DIRTY_JOB_CPU_BOUND
#else
#define LIBBITCOIN_NIF_FLAGS 0
#endif

using namespace bc;
using namespace bc::chain;
using namespace bc::config;
using namespace bc::wallet;

nifpp::TERM make_binary(ErlNifEnv* env, std::string str)
{
    nifpp::binary newbin(str.length());
    std::memcpy(newbin.data, str.c_str(), str.length());
    return nifpp::make(env, newbin);
}

data_chunk make_data_chunk(ErlNifEnv* env, ErlNifBinary *bin)
{
    std::vector<char> data(bin->data, bin->data + bin->size);
    return to_chunk(data);
}

std::string make_string(ErlNifEnv* env, ErlNifBinary *bin)
{
    std::string data(bin->data, bin->data + bin->size);
    return data;
}

ERL_NIF_TERM
erlang_libbitcoin_tx_decode(ErlNifEnv* env, int, const ERL_NIF_TERM argv[])
{
    ErlNifBinary bin;
    if (!enif_inspect_binary(env, argv[0], &bin)) {
        return enif_make_badarg(env);
    }

    uint32_t flags = 0x00;
    chain::transaction tx;
    tx.from_data(make_data_chunk(env, &bin));
    std::map<nifpp::str_atom, nifpp::TERM> map_tx;
    long serialized_size = tx.serialized_size();
    ErlNifUInt64 total_output_value = tx.total_output_value();
    map_tx["version"] = nifpp::make(env, tx.version);
    map_tx["locktime"] = nifpp::make(env, tx.locktime);
    map_tx["hash"] = make_binary(env, btc256(tx.hash()).to_string());
    map_tx["coinbase"] = nifpp::make(env, tx.is_coinbase());
    map_tx["size"] = nifpp::make(env, serialized_size);
    map_tx["value"] = nifpp::make(env, total_output_value);
    std::list<nifpp::TERM> inputs;
    for (const auto input: tx.inputs) {
        std::map<nifpp::str_atom, nifpp::TERM> input_map;
        std::map<nifpp::str_atom, nifpp::TERM> prev_input_map;
        prev_input_map["hash"] = make_binary(env, btc256(input.previous_output.hash).to_string());
        prev_input_map["index"] = nifpp::make(env, input.previous_output.index);
        input_map["previous_output"] = nifpp::make(env, prev_input_map);<commit_msg>update to latest libbitcoin master naming chages. closes #1<commit_after>#include <erl_nif.h>
#include <iostream>
#include <sstream>
#include <bitcoin/bitcoin.hpp>
#include <bitcoin/bitcoin/chain/transaction.hpp>
#include <bitcoin/bitcoin/config/hash256.hpp>
#include <bitcoin/bitcoin/formats/base_16.hpp>

#include <assert.h>
#include "erl_nif.h"
#include "nifpp.h"

#ifdef ERL_NIF_DIRTY_JOB_CPU_BOUND
#define LIBBITCOIN_NIF_FLAGS ERL_NIF_DIRTY_JOB_CPU_BOUND
#else
#define LIBBITCOIN_NIF_FLAGS 0
#endif

using namespace bc;
using namespace bc::chain;
using namespace bc::config;
using namespace bc::wallet;

nifpp::TERM make_binary(ErlNifEnv* env, std::string str)
{
    nifpp::binary newbin(str.length());
    std::memcpy(newbin.data, str.c_str(), str.length());
    return nifpp::make(env, newbin);
}

data_chunk make_data_chunk(ErlNifEnv* env, ErlNifBinary *bin)
{
    std::vector<char> data(bin->data, bin->data + bin->size);
    return to_chunk(data);
}

std::string make_string(ErlNifEnv* env, ErlNifBinary *bin)
{
    std::string data(bin->data, bin->data + bin->size);
    return data;
}

ERL_NIF_TERM
erlang_libbitcoin_tx_decode(ErlNifEnv* env, int, const ERL_NIF_TERM argv[])
{
    ErlNifBinary bin;
    if (!enif_inspect_binary(env, argv[0], &bin)) {
        return enif_make_badarg(env);
    }

    uint32_t flags = 0x00;
    chain::transaction tx;
    tx.from_data(make_data_chunk(env, &bin));
    std::map<nifpp::str_atom, nifpp::TERM> map_tx;
    long serialized_size = tx.serialized_size();
    ErlNifUInt64 total_output_value = tx.total_output_value();
    map_tx["version"] = nifpp::make(env, tx.version);
    map_tx["locktime"] = nifpp::make(env, tx.locktime);
    map_tx["hash"] = make_binary(env, hash256(tx.hash()).to_string());
    map_tx["coinbase"] = nifpp::make(env, tx.is_coinbase());
    map_tx["size"] = nifpp::make(env, serialized_size);
    map_tx["value"] = nifpp::make(env, total_output_value);
    std::list<nifpp::TERM> inputs;
    for (const auto input: tx.inputs) {
        std::map<nifpp::str_atom, nifpp::TERM> input_map;
        std::map<nifpp::str_atom, nifpp::TERM> prev_input_map;
        prev_input_map["hash"] = make_binary(env, hash256(input.previous_output.hash).to_string());
        prev_input_map["index"] = nifpp::make(env, input.previous_output.index);
        input_map["previous_output"] = nifpp::make(env, prev_input_map);
{'fraction_non_alphanumeric': 0.152571185720357, 'fraction_numerical': 0.008712282192945177, 'mean_word_length': 5.360810810810811, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 41, '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': '339354', 'n_tokens_mistral': 1866, 'n_tokens_neox': 1831, 'n_words': 303}