1
// Copyright © 2017-2020 Trust Wallet.
2
//
3
// This file is part of Trust. The full Trust copyright notice, including
4
// terms governing use, modification, and redistribution, is contained in the
5
// file LICENSE at the root of the source code distribution tree.
6
#pragma once
7
#include "../proto/NULS.pb.h"
8

9
#include <stdint.h>
10
#include <algorithm>
11
#include "Data.h"
12
#include "../uint256.h"
13

14
namespace TW::NULS {
15

16
/// Helper class that performs NULS transaction signing.
17 1
class Signer {
18
  public:
19
    /// Signs a Proto::SigningInput transaction
20
    static Proto::SigningOutput sign(const Proto::SigningInput& input) noexcept;
21
  public:
22
    static const uint16_t TRANSACTION_FIX_SIZE = 11; //type size 2, time size 4, txData size 1, hash size 4
23
    static const uint16_t TRANSACTION_SIG_MAX_SIZE = 110;
24
    static const uint16_t TRANSACTION_INPUT_SIZE = 70;
25
    static const uint16_t TRANSACTION_OUTPUT_SIZE = 70;
26
    /// Transaction size must less that 300KB
27
    static const uint64_t MAX_TRANSACTION_SIZE = 300 * 1024;
28
    /// 0.001 NULS per KB
29
    static const uint64_t MIN_PRICE_PRE_1024_BYTES = 100000;
30

31
    static const uint16_t TX_TYPE = 2;
32

33
    Proto::Transaction tx;
34

35
    Proto::SigningInput input;
36

37
    /// Initializes a transaction signer.
38
    Signer(const Proto::SigningInput& input);
39

40
    /// Signs the transaction.
41
    ///
42
    /// \returns the transaction signature or an empty vector if there is an error.
43
    Data sign() const;
44
  private:
45
    uint64_t CalculatorTransactionFee(uint64_t size) const;
46
    int32_t CalculatorMaxInput(uint32_t remarkSize) const;
47
    uint32_t CalculatorTransactionSize(uint32_t inputCount, uint32_t outputCount, uint32_t remarkSize) const;
48
};
49

50
} // namespace TW::NULS

Read our documentation on viewing source code .

Loading