forked from trustwallet/wallet-core
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTransaction.cpp
More file actions
52 lines (42 loc) · 1.62 KB
/
Copy pathTransaction.cpp
File metadata and controls
52 lines (42 loc) · 1.62 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
48
49
50
51
52
// 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 "Signer.h"
#include "../BinaryCoding.h"
#include "../HexCoding.h"
#include "../PublicKey.h"
using namespace TW;
using namespace TW::Nimiq;
const uint8_t NETWORK_ID = 42;
const uint8_t EMPTY_FLAGS = 0;
std::vector<uint8_t> Transaction::serialize() const {
std::vector<uint8_t> data;
data.push_back(0x00); // Basic TX type
data.insert(data.end(), sender_pub_key.begin(), sender_pub_key.end());
data.insert(data.end(), destination.bytes.begin(), destination.bytes.end());
encode64BE(amount, data);
encode64BE(fee, data);
encode32BE(vsh, data);
data.push_back(NETWORK_ID);
data.insert(data.end(), signature.begin(), signature.end());
return data;
}
std::vector<uint8_t> Transaction::getPreImage() const {
std::vector<uint8_t> data;
// Build pre-image
Address sender(Signer::publicKeyFromBytes(sender_pub_key));
encode16BE(0x00, data); // Data size (+ 0 bytes of data)
data.insert(data.end(), sender.bytes.begin(), sender.bytes.end());
data.push_back(0); // Sender is basic account type
data.insert(data.end(), destination.bytes.begin(), destination.bytes.end());
data.push_back(0); // Recipient is basic account type
encode64BE(amount, data);
encode64BE(fee, data);
encode32BE(vsh, data);
data.push_back(NETWORK_ID);
data.push_back(EMPTY_FLAGS);
return data;
}