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

7
#pragma once
8

9
#include "../BinaryCoding.h"
10
#include "../Data.h"
11

12
#include <boost/any.hpp>
13

14
#include <array>
15
#include <stdexcept>
16
#include <string>
17
#include <vector>
18

19
namespace TW::Ontology {
20

21 1
class ParamsBuilder {
22

23
  private:
24
    std::vector<uint8_t> bytes;
25

26
  public:
27
    static const size_t MAX_PK_SIZE = 16;
28

29 1
    std::vector<uint8_t> getBytes() { return bytes; }
30

31
    void cleanUp() { bytes.clear(); }
32

33
    static Data fromSigs(const std::vector<Data>& sigs);
34

35
    static Data fromPubkey(const Data& publicKey);
36

37
    static Data fromMultiPubkey(uint8_t m, const std::vector<Data>& pubKeys);
38

39
    static void buildNeoVmParam(ParamsBuilder& builder, const boost::any& param);
40

41
    static void buildNeoVmParam(ParamsBuilder& builder, const std::string& param);
42

43
    static void buildNeoVmParam(ParamsBuilder& builder, const std::array<uint8_t, 20>& param);
44

45
    static void buildNeoVmParam(ParamsBuilder& builder, const std::vector<uint8_t>& param);
46

47
    void pushVar(const std::vector<uint8_t>& data);
48

49
    void pushVar(std::size_t value);
50

51
    void push(const std::string& data);
52

53
    void push(const std::array<uint8_t, 20>& data);
54

55
    void push(const std::vector<uint8_t>& data);
56

57
    void push(uint64_t num, uint8_t len);
58

59
    void push(uint64_t num);
60

61
    void push(uint8_t num);
62

63
    void pushBack(uint8_t data);
64

65
    void pushBack(uint32_t data);
66

67
    void pushBack(uint64_t data);
68

69
    void pushBack(const std::string& data);
70

71
    void pushBack(const std::array<uint8_t, 20>& data);
72

73
    template <typename T>
74 1
    void pushBack(const std::vector<T>& data) {
75 1
        bytes.insert(bytes.end(), data.begin(), data.end());
76
    }
77

78
    static std::vector<uint8_t> buildNativeInvokeCode(const std::vector<uint8_t>& contractAddress,
79
                                                      uint8_t version, const std::string& method,
80
                                                      const boost::any& params);
81
};
82

83
} // namespace TW::Ontology

Read our documentation on viewing source code .

Loading