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
67 lines (56 loc) · 2.38 KB
/
Copy pathTransaction.cpp
File metadata and controls
67 lines (56 loc) · 2.38 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// 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 "Hash.h"
#include "Signer.h"
#include "../BinaryCoding.h"
#include "../PublicKey.h"
using namespace TW;
using namespace TW::Solana;
Data Transaction::serialize() const {
Data buffer;
append(buffer, shortVecLength<Signature>(this->signatures));
for (auto signature : this->signatures) {
Data signature_vec(signature.bytes.begin(), signature.bytes.end());
append(buffer, signature_vec);
}
append(buffer, this->messageData());
return buffer;
}
Data Transaction::messageData() const {
Data buffer;
buffer.push_back(this->message.header.numRequiredSignatures);
buffer.push_back(this->message.header.numCreditOnlySignedAccounts);
buffer.push_back(this->message.header.numCreditOnlyUnsignedAccounts);
append(buffer, shortVecLength<Address>(this->message.accountKeys));
for (auto account_key : this->message.accountKeys) {
Data account_key_vec(account_key.bytes.begin(), account_key.bytes.end());
append(buffer, account_key_vec);
}
Data recentBlockhash(this->message.recentBlockhash.bytes.begin(),
this->message.recentBlockhash.bytes.end());
append(buffer, recentBlockhash);
append(buffer, shortVecLength<CompiledInstruction>(this->message.instructions));
for (auto instruction : this->message.instructions) {
buffer.push_back(instruction.programIdIndex);
append(buffer, shortVecLength<uint8_t>(instruction.accounts));
append(buffer, instruction.accounts);
append(buffer, shortVecLength<uint8_t>(instruction.data));
append(buffer, instruction.data);
}
return buffer;
}
uint8_t Transaction::getAccountIndex(Address publicKey) {
std::vector<Address>::iterator item =
std::find(this->message.accountKeys.begin(), this->message.accountKeys.end(), publicKey);
if (item == this->message.accountKeys.end()) {
throw std::invalid_argument("publicKey not found in message.accountKeys");
}
return (uint8_t)std::distance(this->message.accountKeys.begin(), item);
}
bool Signature::operator==(const Signature& v) const {
return bytes == v.bytes;
}