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
#pragma once
8

9
#include "../Bitcoin/Script.h"
10
#include "../Bitcoin/Transaction.h"
11
#include "../Bitcoin/TransactionInput.h"
12
#include "../Bitcoin/TransactionOutput.h"
13
#include "../proto/Bitcoin.pb.h"
14

15
#include <array>
16
#include <vector>
17

18
namespace TW::Zcash {
19

20
extern const std::array<byte, 4> SaplingBranchID;
21
extern const std::array<byte, 4> BlossomBranchID;
22

23
/// Only supports transparent transaction right now
24
/// See also https://github.com/zcash/zips/blob/master/zip-0243.rst
25 1
struct Transaction {
26 1
    uint32_t version = 0x80000004;
27 1
    uint32_t versionGroupId = 0x892F2085;
28 1
    uint32_t lockTime = 0;
29 1
    uint32_t expiryHeight = 0;
30 1
    uint64_t valueBalance = 0;
31

32
    std::vector<Bitcoin::TransactionInput> inputs;
33
    std::vector<Bitcoin::TransactionOutput> outputs;
34
    std::array<byte, 4> branchId;
35

36
    /// Used for diagnostics; store previously estimated virtual size (if any; size in bytes)
37 1
    int previousEstimatedVirtualSize = 0;
38

39 1
    Transaction() = default;
40

41
    Transaction(uint32_t version, uint32_t versionGroupId, uint32_t lockTime, uint32_t expiryHeight,
42
                uint64_t valueBalance, std::array<byte, 4> branchId)
43
        : version(version)
44
        , versionGroupId(versionGroupId)
45
        , lockTime(lockTime)
46
        , expiryHeight(expiryHeight)
47
        , valueBalance(valueBalance)
48
        , branchId(branchId) {}
49

50
    /// Whether the transaction is empty.
51
    bool empty() const { return inputs.empty() && outputs.empty(); }
52

53
    /// Generates the signature pre-image.
54
    Data getPreImage(const Bitcoin::Script& scriptCode, size_t index,
55
                     enum TWBitcoinSigHashType hashType, uint64_t amount) const;
56
    Data getPrevoutHash() const;
57
    Data getSequenceHash() const;
58
    Data getOutputsHash() const;
59

60
    Data getJoinSplitsHash() const;
61
    Data getShieldedSpendsHash() const;
62
    Data getShieldedOutputsHash() const;
63

64
    /// Encodes the rawtx into the provided buffer.
65
    void encode(Data& data) const;
66

67
    Data getSignatureHash(const Bitcoin::Script& scriptCode, size_t index,
68
                          enum TWBitcoinSigHashType hashType, uint64_t amount,
69
                          enum Bitcoin::SignatureVersion version) const;
70

71
    /// Converts to Protobuf model
72
    Bitcoin::Proto::Transaction proto() const;
73
};
74

75
} // namespace TW::Zcash

Read our documentation on viewing source code .

Loading