Repository navigation
Expand file tree
/
Copy pathTransaction.cpp
More file actions
47 lines (41 loc) · 1.47 KB
/
Copy pathTransaction.cpp
File metadata and controls
47 lines (41 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright © 2017-2020 Trust Wallet.
//
// This file is part of Trust. The full Trust copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.
#include "Transaction.h"
#include "../Ethereum/RLP.h"
using namespace TW;
using namespace TW::VeChain;
using RLP = Ethereum::RLP;
Data encode(const Clause& clause) noexcept {
auto encoded = Data();
append(encoded, RLP::encode(clause.to.bytes));
append(encoded, RLP::encode(clause.value));
append(encoded, RLP::encode(clause.data));
return RLP::encodeList(encoded);
}
Data encodeClauses(std::vector<Clause> clauses) noexcept {
auto encoded = Data();
for (const auto& clause : clauses) {
auto encodedClause = encode(clause);
append(encoded, encodedClause);
}
return RLP::encodeList(encoded);
}
Data Transaction::encode() const noexcept {
auto encoded = Data();
append(encoded, RLP::encode(chainTag));
append(encoded, RLP::encode(blockRef));
append(encoded, RLP::encode(expiration));
append(encoded, encodeClauses(clauses));
append(encoded, RLP::encode(gasPriceCoef));
append(encoded, RLP::encode(gas));
append(encoded, RLP::encode(dependsOn));
append(encoded, RLP::encode(nonce));
append(encoded, RLP::encodeList(reserved));
if (!signature.empty()) {
append(encoded, RLP::encode(signature));
}
return RLP::encodeList(encoded);
}