forked from trustwallet/wallet-core
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTransaction.h
More file actions
74 lines (54 loc) · 2.34 KB
/
Copy pathTransaction.h
File metadata and controls
74 lines (54 loc) · 2.34 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
68
69
70
71
72
73
74
// 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.
#pragma once
#include "TransactionInput.h"
#include "TransactionOutput.h"
#include "../Bitcoin/Script.h"
#include "../Data.h"
#include "../proto/Decred.pb.h"
#include <TrustWalletCore/TWBitcoin.h>
#include <vector>
namespace TW::Decred {
enum class SerializeType : uint16_t { full, noWitness, onlyWitness };
struct Transaction {
/// Serialization format
SerializeType serializeType = SerializeType::full;
/// Transaction data format version
uint16_t version = 1;
/// A list of 1 or more transaction inputs or sources for coins
std::vector<TransactionInput> inputs;
/// A list of 1 or more transaction outputs or destinations for coins
std::vector<TransactionOutput> outputs;
/// The time when a transaction can be spent (usually zero, in which case it
/// has no effect).
uint32_t lockTime = 0;
/// The block height at which the transaction expires and is no longer
/// valid.
uint32_t expiry = 0;
Transaction()
: inputs()
, outputs() {}
/// Whether the transaction is empty.
bool empty() const { return inputs.empty() && outputs.empty(); }
/// Generates the signature pre-image.
Data computeSignatureHash(const Bitcoin::Script& scriptCode, size_t index,
enum TWBitcoinSigHashType hashType) const;
/// Generates the transaction hash.
Data hash() const;
/// Encodes the transaction into the provided buffer.
void encode(Data& data) const;
/// Converts to Protobuf model
Proto::Transaction proto() const;
private:
Data computePrefixHash(const std::vector<TransactionInput>& inputsToSign,
const std::vector<TransactionOutput>& outputsToSign,
std::size_t signIndex, std::size_t index, enum TWBitcoinSigHashType hashType) const;
Data computeWitnessHash(const std::vector<TransactionInput>& inputsToSign,
const Bitcoin::Script& signScript, std::size_t signIndex) const;
void encodePrefix(Data& data) const;
void encodeWitness(Data& data) const;
};
} // namespace TW::Decred