forked from VluCash/vlucash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathITransaction.h
132 lines (103 loc) · 4.36 KB
/
ITransaction.h
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright (c) 2011-2017 The Cryptonote developers
// Copyright (c) 2014-2017 XDN developers
// Copyright (c) 2016-2017 BXC developers
// Copyright (c) 2017 Royalties developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#pragma once
#include <array>
#include <cstdint>
#include <string>
#include <vector>
#include "CryptoNote.h"
namespace CryptoNote {
namespace TransactionTypes {
enum class InputType : uint8_t { Invalid, Key, Multisignature, Generating };
enum class OutputType : uint8_t { Invalid, Key, Multisignature };
struct GlobalOutput {
Crypto::PublicKey targetKey;
uint32_t outputIndex;
};
typedef std::vector<GlobalOutput> GlobalOutputsContainer;
struct OutputKeyInfo {
Crypto::PublicKey transactionPublicKey;
size_t transactionIndex;
size_t outputInTransaction;
};
struct InputKeyInfo {
uint64_t amount;
GlobalOutputsContainer outputs;
OutputKeyInfo realOutput;
};
}
//
// ITransactionReader
//
class ITransactionReader {
public:
virtual ~ITransactionReader() { }
virtual Crypto::Hash getTransactionHash() const = 0;
virtual Crypto::Hash getTransactionPrefixHash() const = 0;
virtual Crypto::PublicKey getTransactionPublicKey() const = 0;
virtual bool getTransactionSecretKey(Crypto::SecretKey& key) const = 0;
virtual uint64_t getUnlockTime() const = 0;
// extra
virtual bool getPaymentId(Crypto::Hash& paymentId) const = 0;
virtual bool getExtraNonce(BinaryArray& nonce) const = 0;
virtual BinaryArray getExtra() const = 0;
// inputs
virtual size_t getInputCount() const = 0;
virtual uint64_t getInputTotalAmount() const = 0;
virtual TransactionTypes::InputType getInputType(size_t index) const = 0;
virtual void getInput(size_t index, KeyInput& input) const = 0;
virtual void getInput(size_t index, MultisignatureInput& input) const = 0;
// outputs
virtual size_t getOutputCount() const = 0;
virtual uint64_t getOutputTotalAmount() const = 0;
virtual TransactionTypes::OutputType getOutputType(size_t index) const = 0;
virtual void getOutput(size_t index, KeyOutput& output, uint64_t& amount) const = 0;
virtual void getOutput(size_t index, MultisignatureOutput& output, uint64_t& amount) const = 0;
// signatures
virtual size_t getRequiredSignaturesCount(size_t inputIndex) const = 0;
virtual bool findOutputsToAccount(const AccountPublicAddress& addr, const Crypto::SecretKey& viewSecretKey, std::vector<uint32_t>& outs, uint64_t& outputAmount) const = 0;
// various checks
virtual bool validateInputs() const = 0;
virtual bool validateOutputs() const = 0;
virtual bool validateSignatures() const = 0;
// serialized transaction
virtual BinaryArray getTransactionData() const = 0;
};
//
// ITransactionWriter
//
class ITransactionWriter {
public:
virtual ~ITransactionWriter() { }
// transaction parameters
virtual void setUnlockTime(uint64_t unlockTime) = 0;
// extra
virtual void setPaymentId(const Crypto::Hash& paymentId) = 0;
virtual void setExtraNonce(const BinaryArray& nonce) = 0;
virtual void appendExtra(const BinaryArray& extraData) = 0;
// Inputs/Outputs
virtual size_t addInput(const KeyInput& input) = 0;
virtual size_t addInput(const MultisignatureInput& input) = 0;
virtual size_t addInput(const AccountKeys& senderKeys, const TransactionTypes::InputKeyInfo& info, KeyPair& ephKeys) = 0;
virtual size_t addOutput(uint64_t amount, const AccountPublicAddress& to) = 0;
virtual size_t addOutput(uint64_t amount, const std::vector<AccountPublicAddress>& to, uint32_t requiredSignatures, uint32_t term = 0) = 0;
virtual size_t addOutput(uint64_t amount, const KeyOutput& out) = 0;
virtual size_t addOutput(uint64_t amount, const MultisignatureOutput& out) = 0;
// transaction info
virtual void setTransactionSecretKey(const Crypto::SecretKey& key) = 0;
// signing
virtual void signInputKey(size_t input, const TransactionTypes::InputKeyInfo& info, const KeyPair& ephKeys) = 0;
virtual void signInputMultisignature(size_t input, const Crypto::PublicKey& sourceTransactionKey, size_t outputIndex, const AccountKeys& accountKeys) = 0;
virtual void signInputMultisignature(size_t input, const KeyPair& ephemeralKeys) = 0;
};
class ITransaction :
public ITransactionReader,
public ITransactionWriter {
public:
virtual ~ITransaction() { }
};
}