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
#include "Transaction.h"
8
#include "Address.h"
9
#include "ParamsBuilder.h"
10

11
#include "../Hash.h"
12
#include "../HexCoding.h"
13

14
#include <string>
15

16
using namespace TW;
17
using namespace TW::Ontology;
18

19 1
const std::string Transaction::ZERO_PAYER = "AFmseVrdL9f9oyCzZefL9tG6UbvhPbdYzM";
20

21 1
std::vector<uint8_t> Transaction::serializeUnsigned() {
22 1
    ParamsBuilder builder;
23 1
    builder.pushBack(version);
24 1
    builder.pushBack(txType);
25 1
    builder.pushBack(nonce);
26 1
    builder.pushBack(gasPrice);
27 1
    builder.pushBack(gasLimit);
28 1
    builder.pushBack(Address(payer).data);
29 1
    if (!payload.empty()) {
30 1
        builder.pushVar(payload);
31
    }
32 1
    builder.pushBack((uint8_t)0x00);
33 1
    return builder.getBytes();
34
}
35

36 1
std::vector<uint8_t> Transaction::serialize() {
37 1
    std::vector<uint8_t> txData;
38 1
    auto unsignedData = serializeUnsigned();
39 1
    txData.insert(txData.end(), unsignedData.begin(), unsignedData.end());
40 1
    ParamsBuilder builder;
41 1
    builder.pushVar(sigVec.size());
42 1
    for (auto sig : sigVec) {
43 1
        builder.pushBack(sig.serialize());
44
    }
45 1
    auto sigData = builder.getBytes();
46 1
    txData.insert(txData.end(), sigData.begin(), sigData.end());
47 1
    return txData;
48
}
49

50 1
std::vector<uint8_t> Transaction::txHash() {
51 1
    auto txSerialized = Transaction::serializeUnsigned();
52 1
    return Hash::sha256(Hash::sha256(txSerialized));
53
}
54

55 0
std::vector<uint8_t> Transaction::serialize(const PublicKey& pk) {
56 0
    ParamsBuilder builder;
57 0
    builder.push(pk.bytes);
58 0
    builder.pushBack((uint8_t)0xAC);
59 0
    return builder.getBytes();
60
}

Read our documentation on viewing source code .

Loading