@@ -16,7 +16,7 @@
Loading
16 16
    auto key = PrivateKey(Data(input.private_key().begin(), input.private_key().end()));
17 17
    auto pubkey = key.getPublicKey(TWPublicKeyTypeSECP256k1Extended);
18 18
    Address from_address(pubkey);
19 -
    Address to_address(input.to_address());
19 +
    Address to_address(input.to());
20 20
    Transaction transaction(
21 21
        /* to */ to_address,
22 22
        /* from */ from_address,
@@ -24,16 +24,17 @@
Loading
24 24
        /* value */ load(input.value()),
25 25
        /* gasLimit */ input.gas_limit(),
26 26
        /* gasFeeCap */ load(input.gas_fee_cap()),
27 -
        /* gasPremium */ load(input.gas_premium()));
27 +
        /* gasPremium */ load(input.gas_premium())
28 +
    );
28 29
29 30
    // Sign transaction.
30 31
    auto signature = sign(key, transaction);
31 -
    auto encoded = transaction.serialize(signature);
32 +
    const auto json = transaction.serialize(signature);
32 33
33 34
    // Return Protobuf output.
34 -
    Proto::SigningOutput protoOutput;
35 -
    protoOutput.set_encoded(encoded.data(), encoded.size());
36 -
    return protoOutput;
35 +
    Proto::SigningOutput output;
36 +
    output.set_json(json.data(), json.size());
37 +
    return output;
37 38
}
38 39
39 40
Data Signer::sign(const PrivateKey& privateKey, Transaction& transaction) noexcept {
@@ -47,5 +48,5 @@
Loading
47 48
    google::protobuf::util::JsonStringToMessage(json, &input);
48 49
    input.set_private_key(key.data(), key.size());
49 50
    auto output = Signer::sign(input);
50 -
    return hex(output.encoded());
51 +
    return output.json();
51 52
}

@@ -56,8 +56,8 @@
Loading
56 56
    // cid returns the raw Filecoin message CID (excluding the signature).
57 57
    Data cid() const;
58 58
59 -
    // serialize returns the CBOR encoding of the Filecoin SignedMessage.
60 -
    Data serialize(Data& signature) const;
59 +
    // serialize returns json ready for MpoolPush rpc
60 +
    std::string serialize(Data& signature) const;
61 61
};
62 62
63 63
} // namespace TW::Filecoin

@@ -5,7 +5,10 @@
Loading
5 5
// file LICENSE at the root of the source code distribution tree.
6 6
7 7
#include "Transaction.h"
8 +
#include <nlohmann/json.hpp>
9 +
#include "Base64.h"
8 10
11 +
using json = nlohmann::json;
9 12
using namespace TW;
10 13
using namespace TW::Filecoin;
11 14
@@ -57,13 +60,23 @@
Loading
57 60
    cid.insert(cid.end(), hash.begin(), hash.end());
58 61
    return cid;
59 62
}
60 -
61 -
Data Transaction::serialize(Data& signature) const {
62 -
    // Wrap signature in object.
63 -
    Data sigObject;
64 -
    TW::append(sigObject, 0x01); // Prepend IKTSecp256k1 type
65 -
    TW::append(sigObject, signature);
66 -
    // Create Filecoin SignedMessage
67 -
    auto signedMessage = Cbor::Encode::array({message(), Cbor::Encode::bytes(sigObject)});
68 -
    return signedMessage.encoded();
63 +
std::string Transaction::serialize(Data& signature) const {
64 +
    json tx = {
65 +
        {"Message", json{
66 +
                {"To", to.string()},
67 +
                {"From", from.string()},
68 +
                {"Nonce", nonce},
69 +
                {"Value", toString(value)},
70 +
                {"GasPremium", toString(gasPremium)},
71 +
                {"GasFeeCap", toString(gasFeeCap)},
72 +
                {"GasLimit", gasLimit},
73 +
            }
74 +
        },
75 +
        {"Signature", json{
76 +
                {"Type", 1},
77 +
                {"Data", Base64::encode(signature)},
78 +
            }
79 +
        },
80 +
    };
81 +
    return tx.dump();
69 82
}
Files Coverage
src 95.26%
walletconsole/lib 95.09%
Project Totals (430 files) 95.25%
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