<commit_before>%%%-------------------------------------------------------------------
%%% @copyright (C) 2017, <NAME>
%%%-------------------------------------------------------------------

-module(aec_spend_tx).

%% API
-export([new/1,
         type/0,
         fee/1,
         nonce/1,
         origin/1,
         recipient/1,
         check/5,
         process/5,
         accounts/1,
         signers/1,
         serialization_template/1,
         serialize/1,
         deserialize/2,
         for_client/1
        ]).

-export([payload/1]).

-behavior(aetx).

-include("common.hrl").
-include("blocks.hrl").

-define(SPEND_TX_VSN, 2).
-define(SPEND_TX_TYPE, spend_tx).

-record(spend_tx, {
          sender    = <<>>          :: pubkey(),
          recipient = <<>>          :: pubkey(),
          amount    = 0             :: non_neg_integer(),
          fee       = 0             :: non_neg_integer(),
          nonce     = 0             :: non_neg_integer(),
          payload   = <<>>          :: binary()}).

-opaque tx() :: #spend_tx{}.

-export_type([tx/0]).

-spec new(map()) -> {ok, aetx:tx()}.
new(#{sender := SenderPubkey,
      recipient := RecipientPubkey,
      amount := Amount,
      fee := Fee,
      nonce := Nonce,
      payload := Payload}=M) when is_integer(Amount), Amount >= 0,
                                  is_integer(Nonce), Nonce >= 0,
                                  is_integer(Fee), Fee >= 0,
                                  is_binary(SenderPubkey),
                                  is_binary(RecipientPubkey),
                                  is_binary(Payload)
                                  ->
    Tx = #spend_tx{sender = SenderPubkey,
                   recipient = RecipientPubkey,
                   amount = Amount,
                   fee = Fee,
                   nonce = Nonce,
                   payload = Payload},
    {ok, aetx:new(?MODULE, Tx)}.

-spec type() -> atom().
type() ->
    ?SPEND_TX_TYPE.

-spec fee(tx()) -> integer().
fee(#spend_tx{fee = F}) ->
    F.

-spec nonce(tx()) -> non_neg_integer().
nonce(#spend_tx{nonce = Nonce}) ->
    Nonce.

-spec origin(tx()) -> pubkey().
origin(#spend_tx{sender = Sender}) ->
    Sender.

-spec recipient(tx()) -> pubkey().<commit_msg>Remove warning re unused variable<commit_after>%%%-------------------------------------------------------------------
%%% @copyright (C) 2017, Aeternity Anstalt
%%%-------------------------------------------------------------------

-module(aec_spend_tx).

%% API
-export([new/1,
         type/0,
         fee/1,
         nonce/1,
         origin/1,
         recipient/1,
         check/5,
         process/5,
         accounts/1,
         signers/1,
         serialization_template/1,
         serialize/1,
         deserialize/2,
         for_client/1
        ]).

-export([payload/1]).

-behavior(aetx).

-include("common.hrl").
-include("blocks.hrl").

-define(SPEND_TX_VSN, 2).
-define(SPEND_TX_TYPE, spend_tx).

-record(spend_tx, {
          sender    = <<>>          :: pubkey(),
          recipient = <<>>          :: pubkey(),
          amount    = 0             :: non_neg_integer(),
          fee       = 0             :: non_neg_integer(),
          nonce     = 0             :: non_neg_integer(),
          payload   = <<>>          :: binary()}).

-opaque tx() :: #spend_tx{}.

-export_type([tx/0]).

-spec new(map()) -> {ok, aetx:tx()}.
new(#{sender := SenderPubkey,
      recipient := RecipientPubkey,
      amount := Amount,
      fee := Fee,
      nonce := Nonce,
      payload := Payload}) when is_integer(Amount), Amount >= 0,
                                is_integer(Nonce), Nonce >= 0,
                                is_integer(Fee), Fee >= 0,
                                is_binary(SenderPubkey),
                                is_binary(RecipientPubkey),
                                is_binary(Payload)
                                ->
    Tx = #spend_tx{sender = SenderPubkey,
                   recipient = RecipientPubkey,
                   amount = Amount,
                   fee = Fee,
                   nonce = Nonce,
                   payload = Payload},
    {ok, aetx:new(?MODULE, Tx)}.

-spec type() -> atom().
type() ->
    ?SPEND_TX_TYPE.

-spec fee(tx()) -> integer().
fee(#spend_tx{fee = F}) ->
    F.

-spec nonce(tx()) -> non_neg_integer().
nonce(#spend_tx{nonce = Nonce}) ->
    Nonce.

-spec origin(tx()) -> pubkey().
origin(#spend_tx{sender = Sender}) ->
    Sender.

-spec recipient(tx()) -> pubkey().
{'fraction_non_alphanumeric': 0.20684292379471228, 'fraction_numerical': 0.011997333925794268, 'mean_word_length': 1.2442671984047857, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7297816', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1362, 'n_words': 244}