<commit_before>package nodetxlog

import (
	"encoding/json"
	"time"

	"golang.org/x/net/context"

	"chain/api/appdb"
	chainjson "chain/encoding/json"
	"chain/errors"
	"chain/fedchain/bc"
)

type nodeTx struct {
	ID       bc.Hash            `json:"id"`
	Time     time.Time          `json:"transaction_time"`
	Inputs   []nodeTxInput      `json:"inputs"`
	Outputs  []nodeTxOutput     `json:"outputs"`
	Metadata chainjson.HexBytes `json:"metadata"`
}

type nodeTxInput struct {
	Type         string             `json:"type"`
	TxID         *bc.Hash           `json:"transaction_id,omitempty"`
	TxOut        *uint32            `json:"transaction_output,omitempty"`
	AssetID      bc.AssetID         `json:"asset_id"`
	AssetLabel   string             `json:"asset_label,omitempty"`
	Amount       uint64             `json:"amount"`
	Address      chainjson.HexBytes `json:"address,omitempty"`
	Script       chainjson.HexBytes `json:"address,omitempty"`
	AccountID    string             `json:"account_id,omitempty"`
	AccountLabel string             `json:"account_label,omitempty"`
	Metadata     chainjson.HexBytes `json:"metadata"`

	mNodeID string
}

type nodeTxOutput struct {
	AssetID      bc.AssetID         `json:"asset_id"`
	AssetLabel   string             `json:"asset_label,omitempty"`
	Amount       uint64             `json:"amount"`
	Address      chainjson.HexBytes `json:"address,omitempty"`
	Script       chainjson.HexBytes `json:"address,omitempty"`
	AccountID    string             `json:"account_id,omitempty"`
	AccountLabel string             `json:"account_label,omitempty"`
	Metadata     chainjson.HexBytes `json:"metadata"`

	mNodeID string
}

// Write persists a transaction along with its metadata
// for every node (issuer, manager) associated with the transaction.
func Write(ctx context.Context, tx *bc.Tx, ts time.Time) error {
	ins, outs, err := appdb.GetActUTXOs(ctx, tx)
	if err != nil {
		return errors.Wrap(err, "fetching utxo account data")
	}

	assetMap := make(map[string]*appdb.ActAsset)
	var assetIDs []string
	for _, out := range tx.Outputs {
		assetIDs = append(assetIDs, out.AssetID.String())
	}
	assets, err := appdb.GetActAssets(ctx, assetIDs)
	if err != nil {
		return errors.Wrap(err, "getting assets")
	}
	for _, asset := range assets {<commit_msg>api/asset/nodetxlog: fix script serialization<commit_after>package nodetxlog

import (
	"encoding/json"
	"time"

	"golang.org/x/net/context"

	"chain/api/appdb"
	chainjson "chain/encoding/json"
	"chain/errors"
	"chain/fedchain/bc"
)

type nodeTx struct {
	ID       bc.Hash            `json:"id"`
	Time     time.Time          `json:"transaction_time"`
	Inputs   []nodeTxInput      `json:"inputs"`
	Outputs  []nodeTxOutput     `json:"outputs"`
	Metadata chainjson.HexBytes `json:"metadata"`
}

type nodeTxInput struct {
	Type         string             `json:"type"`
	TxID         *bc.Hash           `json:"transaction_id,omitempty"`
	TxOut        *uint32            `json:"transaction_output,omitempty"`
	AssetID      bc.AssetID         `json:"asset_id"`
	AssetLabel   string             `json:"asset_label,omitempty"`
	Amount       uint64             `json:"amount"`
	Address      chainjson.HexBytes `json:"address,omitempty"`
	Script       chainjson.HexBytes `json:"script,omitempty"`
	AccountID    string             `json:"account_id,omitempty"`
	AccountLabel string             `json:"account_label,omitempty"`
	Metadata     chainjson.HexBytes `json:"metadata"`

	mNodeID string
}

type nodeTxOutput struct {
	AssetID      bc.AssetID         `json:"asset_id"`
	AssetLabel   string             `json:"asset_label,omitempty"`
	Amount       uint64             `json:"amount"`
	Address      chainjson.HexBytes `json:"address,omitempty"`
	Script       chainjson.HexBytes `json:"script,omitempty"`
	AccountID    string             `json:"account_id,omitempty"`
	AccountLabel string             `json:"account_label,omitempty"`
	Metadata     chainjson.HexBytes `json:"metadata"`

	mNodeID string
}

// Write persists a transaction along with its metadata
// for every node (issuer, manager) associated with the transaction.
func Write(ctx context.Context, tx *bc.Tx, ts time.Time) error {
	ins, outs, err := appdb.GetActUTXOs(ctx, tx)
	if err != nil {
		return errors.Wrap(err, "fetching utxo account data")
	}

	assetMap := make(map[string]*appdb.ActAsset)
	var assetIDs []string
	for _, out := range tx.Outputs {
		assetIDs = append(assetIDs, out.AssetID.String())
	}
	assets, err := appdb.GetActAssets(ctx, assetIDs)
	if err != nil {
		return errors.Wrap(err, "getting assets")
	}
	for _, asset := range assets {
{'fraction_non_alphanumeric': 0.11689159773617762, 'fraction_numerical': 0.00261210274270788, 'mean_word_length': 3.073581560283688, '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': '645948', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1394, 'n_words': 327}