trustwallet / wallet-core

@@ -34,8 +34,6 @@
Loading
34 34
    virtual void sign(TWCoinType coin, const Data& dataIn, Data& dataOut) const;
35 35
    virtual bool supportsJSONSigning() const { return true; }
36 36
    virtual std::string signJSON(TWCoinType coin, const std::string& json, const Data& key) const;
37 -
    virtual void encodeRawTx(TWCoinType coin, const Data& dataIn, Data& dataOut) const;
38 -
    virtual void decodeRawTx(TWCoinType coin, const Data& dataIn, Data& dataOut) const;
39 37
};
40 38
41 39
} // namespace TW::Ethereum

@@ -86,10 +86,6 @@
Loading
86 86
87 87
bool supportsJSONSigning(TWCoinType coinType);
88 88
89 -
void anyCoinEncode(TWCoinType coinType, const Data& dataIn, Data& dataOut);
90 -
91 -
void anyCoinDecode(TWCoinType coinType, const Data& dataIn, Data& dataOut);
92 -
93 89
void anyCoinPlan(TWCoinType coinType, const Data& dataIn, Data& dataOut);
94 90
95 91
// Return coins handled by the same dispatcher as the given coin (mostly for testing)

@@ -9,16 +9,12 @@
Loading
9 9
#include "../Data.h"
10 10
#include "../uint256.h"
11 11
#include "../BinaryCoding.h"
12 -
#include "../HexCoding.h"
13 12
14 -
#include <nlohmann/json.hpp>
15 13
#include <tuple>
16 14
17 15
using namespace TW;
18 16
using namespace TW::Ethereum;
19 17
20 -
using json = nlohmann::json;
21 -
22 18
Data RLP::encode(const uint256_t& value) noexcept {
23 19
    using boost::multiprecision::cpp_int;
24 20
@@ -141,26 +137,7 @@
Loading
141 137
    // clang-format on
142 138
}
143 139
144 -
Data RLP::decodeRawTransaction(const Data& data) {
145 -
    auto decoded = decode(data).decoded;
146 -
    if (decoded.size() < 9) {
147 -
        return {};
148 -
    }
149 -
    auto result = json {
150 -
        {"nonce", hexEncoded(decoded[0])},
151 -
        {"gasPrice", hexEncoded(decoded[1])},
152 -
        {"gas", hexEncoded(decoded[2])},
153 -
        {"to", hexEncoded(decoded[3])},
154 -
        {"value", hexEncoded(decoded[4])},
155 -
        {"input", hexEncoded(decoded[5])},
156 -
        {"v", hexEncoded(decoded[6])},
157 -
        {"r", hexEncoded(decoded[7])},
158 -
        {"s", hexEncoded(decoded[8])},
159 -
    }.dump();
160 -
    return Data(result.begin(), result.end());
161 -
}
162 -
163 -
static RLP::DecodedItem decodeList(const Data& input) {
140 +
RLP::DecodedItem RLP::decodeList(const Data& input) {
164 141
    RLP::DecodedItem item;
165 142
    auto remainder = input;
166 143
    while(true) {
@@ -175,7 +152,7 @@
Loading
175 152
    return item;
176 153
}
177 154
178 -
static uint64_t decodeLength(const Data& data) {
155 +
uint64_t RLP::decodeLength(const Data& data) {
179 156
    size_t index = 0;
180 157
    auto decodedLen = decodeVarInt(data, index);
181 158
    if (!std::get<0>(decodedLen)) {
@@ -237,7 +214,6 @@
Loading
237 214
        if (inputLen < listLen) {
238 215
            throw std::invalid_argument("Invalid rlp string length");
239 216
        }
240 -
        
241 217
        // empty list
242 218
        if (listLen == 0) {
243 219
            item.remainder = Data(input.begin() + 1, input.end());

@@ -232,18 +232,6 @@
Loading
232 232
    return dispatcher->supportsJSONSigning();
233 233
}
234 234
235 -
void TW::anyCoinEncode(TWCoinType coinType, const Data& dataIn, Data& dataOut) {
236 -
    auto dispatcher = coinDispatcher(coinType);
237 -
    assert(dispatcher != nullptr);
238 -
    dispatcher->encodeRawTx(coinType, dataIn, dataOut);
239 -
}
240 -
241 -
void TW::anyCoinDecode(TWCoinType coinType, const Data& dataIn, Data& dataOut) {
242 -
    auto dispatcher = coinDispatcher(coinType);
243 -
    assert(dispatcher != nullptr);
244 -
    dispatcher->decodeRawTx(coinType, dataIn, dataOut);
245 -
}
246 -
247 235
void TW::anyCoinPlan(TWCoinType coinType, const Data& dataIn, Data& dataOut) {
248 236
    auto dispatcher = coinDispatcher(coinType);
249 237
    assert(dispatcher != nullptr);

@@ -32,9 +32,6 @@
Loading
32 32
    virtual bool supportsJSONSigning() const { return false; }
33 33
    // It is optional, Signing JSON input with private key
34 34
    virtual std::string signJSON(TWCoinType coin, const std::string& json, const Data& key) const { return ""; }
35 -
    // Sign and encode broadcastable raw transaction
36 -
    virtual void encodeRawTx(TWCoinType coin, const Data& dataIn, Data& dataOut) const { return; }
37 -
    virtual void decodeRawTx(TWCoinType coin, const Data& dataIn, Data& dataOut) const { return; }
38 35
    // Planning, for UTXO chains, in preparation for signing
39 36
    // It is optional, only UTXO chains need it, default impl. leaves empty result.
40 37
    virtual void plan(TWCoinType coin, const Data& dataIn, Data& dataOut) const { return; }
@@ -51,14 +48,6 @@
Loading
51 48
    dataOut.insert(dataOut.end(), serializedOut.begin(), serializedOut.end());
52 49
}
53 50
54 -
template <typename Signer, typename Input>
55 -
void encodeTemplate(const Data& dataIn, Data& dataOut) {
56 -
    auto input = Input();
57 -
    input.ParseFromArray(dataIn.data(), (int)dataIn.size());
58 -
    auto encoded = Signer::sign(input).encoded();
59 -
    dataOut.insert(dataOut.end(), encoded.begin(), encoded.end());
60 -
}
61 -
62 51
// Note: use output parameter to avoid unneeded copies
63 52
template <typename Planner, typename Input>
64 53
void planTemplate(const Data& dataIn, Data& dataOut) {

@@ -27,20 +27,6 @@
Loading
27 27
    return TW::supportsJSONSigning(coin);
28 28
}
29 29
30 -
TWData* _Nonnull TWAnySignerEncode(TWData* _Nonnull data, enum TWCoinType coin) {
31 -
    const Data& dataIn = *(reinterpret_cast<const Data*>(data));
32 -
    Data dataOut;
33 -
    TW::anyCoinEncode(coin, dataIn, dataOut);
34 -
    return TWDataCreateWithBytes(dataOut.data(), dataOut.size());
35 -
}
36 -
37 -
TWData* _Nonnull TWAnySignerDecode(TWData* _Nonnull data, enum TWCoinType coin) {
38 -
    const Data& dataIn = *(reinterpret_cast<const Data*>(data));
39 -
    Data dataOut;
40 -
    TW::anyCoinDecode(coin, dataIn, dataOut);
41 -
    return TWDataCreateWithBytes(dataOut.data(), dataOut.size());
42 -
}
43 -
44 30
TWData* _Nonnull TWAnySignerPlan(TWData* _Nonnull data, enum TWCoinType coin) {
45 31
    const Data& dataIn = *(reinterpret_cast<const Data*>(data));
46 32
    Data dataOut;

@@ -8,7 +8,6 @@
Loading
8 8
9 9
#include "Address.h"
10 10
#include "Signer.h"
11 -
#include "RLP.h"
12 11
13 12
using namespace TW::Ethereum;
14 13
using namespace std;
@@ -33,16 +32,3 @@
Loading
33 32
string Entry::signJSON(TWCoinType coin, const std::string& json, const Data& key) const { 
34 33
    return Signer::signJSON(json, key);
35 34
}
36 -
37 -
void Entry::encodeRawTx(TWCoinType coin, const TW::Data& dataIn, TW::Data& dataOut) const {
38 -
    encodeTemplate<Signer, Proto::SigningInput>(dataIn, dataOut);
39 -
}
40 -
41 -
void Entry::decodeRawTx(TWCoinType coin, const TW::Data& dataIn, TW::Data& dataOut) const {
42 -
    try {
43 -
        auto data = RLP::decodeRawTransaction(dataIn);
44 -
        dataOut.insert(dataOut.end(), data.begin(), data.end());
45 -
    } catch(...) {
46 -
        return;
47 -
    }
48 -
}

@@ -100,9 +100,8 @@
Loading
100 100
        Data remainder;
101 101
    };
102 102
103 -
    /// Decodes raw transaction to json data
104 -
    static Data decodeRawTransaction(const Data& data);
105 -
103 +
    static DecodedItem decodeList(const Data& input);
104 +
    static uint64_t decodeLength(const Data& data);
106 105
    /// Decodes data, remainder from RLP encoded data
107 106
    static DecodedItem decode(const Data& data);
108 107
};
Files Coverage
src 95.40%
walletconsole/lib 94.71%
Project Totals (443 files) 95.38%
1
codecov:
2
  require_ci_to_pass: yes
3

4
coverage:
5
  precision: 2
6
  round: down
7
  range: "70...100"
8
  status:
9
    project:
10
      default:
11
        informational: true
12

13
parsers:
14
  gcov:
15
    branch_detection:
16
      conditional: yes
17
      loop: yes
18
      method: no
19
      macro: no
20

21
comment:
22
  layout: "reach,diff,flags,files,footer"
23
  behavior: default
24
  require_changes: no
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading