@@ -8,9 +8,10 @@
Loading
8 8
#include "Address.h"
9 9
#include "Protobuf/ZilliqaMessage.pb.h"
10 10
11 -
#include "../Hash.h"
12 -
#include "../HexCoding.h"
13 -
#include "../uint256.h"
11 +
#include "Data.h"
12 +
#include "Hash.h"
13 +
#include "HexCoding.h"
14 +
#include "uint256.h"
14 15
15 16
#include <cassert>
16 17
@@ -18,6 +19,7 @@
Loading
18 19
19 20
using namespace TW;
20 21
using namespace TW::Zilliqa;
22 +
using ByteArray = ZilliqaMessage::ByteArray;
21 23
22 24
static inline Data prependZero(Data& data) {
23 25
    if (data.size() < 16) {
@@ -28,37 +30,58 @@
Loading
28 30
    return Data(data);
29 31
}
30 32
33 +
static inline ByteArray* byteArray(Data& amount) {
34 +
    auto array = new ByteArray();
35 +
    amount = prependZero(amount);
36 +
    array->set_data(amount.data(), amount.size());
37 +
    return array;
38 +
}
39 +
40 +
static inline ByteArray* byteArray(const void* data, size_t size) {
41 +
    auto array = new ByteArray();
42 +
    array->set_data(data, size);
43 +
    return array;
44 +
}
31 45
32 46
Data Signer::getPreImage(const Proto::SigningInput& input, Address& address) noexcept {
33 47
    auto internal = ZilliqaMessage::ProtoTransactionCoreInfo();
34 48
    const auto key = PrivateKey(Data(input.private_key().begin(), input.private_key().end()));
35 -
    if (!Address::decode(input.to_address(), address)) {
49 +
    if (!Address::decode(input.to(), address)) {
36 50
        // invalid input address
37 51
        return Data(0);
38 52
    }
39 53
    const auto pubKey = key.getPublicKey(TWPublicKeyTypeSECP256k1);
54 +
    auto gasPrice = Data(input.gas_price().begin(), input.gas_price().end());
40 55
41 56
    internal.set_version(input.version());
42 57
    internal.set_nonce(input.nonce());
43 58
    internal.set_toaddr(address.getKeyHash().data(), address.getKeyHash().size());
44 -
45 -
    auto sender = new ZilliqaMessage::ByteArray();
46 -
    sender->set_data(pubKey.bytes.data(), pubKey.bytes.size());
47 -
    internal.set_allocated_senderpubkey(sender);
48 -
49 -
    auto amountArray = new ZilliqaMessage::ByteArray();
50 -
    auto amount = Data(input.amount().begin(), input.amount().end());
51 -
    amount = prependZero(amount);
52 -
    amountArray->set_data(amount.data(), amount.size());
53 -
    internal.set_allocated_amount(amountArray);
54 -
55 -
    auto gasPriceArray = new ZilliqaMessage::ByteArray();
56 -
    auto gasPrice = Data(input.gas_price().begin(), input.gas_price().end());
57 -
    gasPrice = prependZero(gasPrice);
58 -
    gasPriceArray->set_data(gasPrice.data(), gasPrice.size());
59 -
    internal.set_allocated_gasprice(gasPriceArray);
60 -
61 59
    internal.set_gaslimit(input.gas_limit());
60 +
    internal.set_allocated_senderpubkey(byteArray(pubKey.bytes.data(), pubKey.bytes.size()));
61 +
    internal.set_allocated_gasprice(byteArray(gasPrice));
62 +
63 +
    Data amount;
64 +
    switch (input.transaction().message_oneof_case()) {
65 +
    case Proto::Transaction::kTransfer: {
66 +
        const auto transfer = input.transaction().transfer();
67 +
        amount = Data(transfer.amount().begin(), transfer.amount().end());
68 +
        break;
69 +
    }
70 +
    case Proto::Transaction::kRawTransaction: {
71 +
        const auto raw = input.transaction().raw_transaction();
72 +
        amount = Data(raw.amount().begin(), raw.amount().end());
73 +
        if (!raw.code().empty()) {
74 +
            internal.set_code(raw.code());
75 +
        }
76 +
        if (!raw.data().empty()) {
77 +
            internal.set_data(raw.data());
78 +
        }
79 +
        break;
80 +
    }
81 +
    default: break;
82 +
    }
83 +
84 +
    internal.set_allocated_amount(byteArray(amount));
62 85
63 86
    const auto serialized = internal.SerializeAsString();
64 87
    return Data(serialized.begin(), serialized.end());
@@ -71,20 +94,35 @@
Loading
71 94
    const auto key = PrivateKey(Data(input.private_key().begin(), input.private_key().end()));
72 95
    const auto pubKey = key.getPublicKey(TWPublicKeyTypeSECP256k1);
73 96
    const auto signature = key.signSchnorr(preImage, TWCurveSECP256k1);
97 +
    const auto transaction = input.transaction();
74 98
75 99
    // build json
76 100
    nlohmann::json json = {
77 101
        {"version", input.version()},
78 102
        {"toAddr", address.checksumed()},
79 -
        {"amount", toString(load(input.amount()))},
80 103
        {"nonce", input.nonce()},
81 104
        {"gasPrice", toString(load(input.gas_price()))},
82 105
        {"gasLimit", toString(input.gas_limit())},
83 -
        {"code", input.code()},
84 -
        {"data", input.data()},
106 +
        {"code", ""},
107 +
        {"data", ""},
85 108
        {"pubKey", hex(pubKey.bytes)},
86 109
        {"signature", hex(signature)},
87 110
    };
111 +
112 +
    if (transaction.has_transfer()) {
113 +
        const auto transfer = transaction.transfer();
114 +
        json["amount"] = toString(load(transfer.amount()));
115 +
    } else if (transaction.has_raw_transaction()) {
116 +
        const auto raw = transaction.raw_transaction();
117 +
        json["amount"] = toString(load(raw.amount()));
118 +
        if (!raw.code().empty()) {
119 +
            json["code"] = hex(Data(raw.code().begin(), raw.code().end()));
120 +
        }
121 +
        if (!raw.data().empty()) {
122 +
            json["data"] = std::string(raw.data().begin(), raw.data().end());
123 +
        }
124 +
    }
125 +
88 126
    output.set_json(json.dump());
89 127
    output.set_signature(signature.data(), signature.size());
90 128
Files Coverage
src 95.22%
walletconsole/lib 95.09%
Project Totals (430 files) 95.21%

No yaml found.

Create your codecov.yml to customize your Codecov experience

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