danicoin/tests/CoreTests/TransactionBuilder.h

67 lines
2.3 KiB
C
Raw Normal View History

// Copyright (c) 2011-2016 The Cryptonote developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
2014-08-13 10:51:37 +00:00
#pragma once
2015-07-30 15:22:07 +00:00
#include "CryptoNoteCore/Account.h"
#include "CryptoNoteCore/CryptoNoteFormatUtils.h"
#include "CryptoNoteCore/Currency.h"
2014-08-13 10:51:37 +00:00
class TransactionBuilder {
public:
2015-07-30 15:22:07 +00:00
typedef std::vector<CryptoNote::AccountKeys> KeysVector;
typedef std::vector<Crypto::Signature> SignatureVector;
2014-08-13 10:51:37 +00:00
typedef std::vector<SignatureVector> SignatureMultivector;
struct MultisignatureSource {
2015-07-30 15:22:07 +00:00
CryptoNote::MultisignatureInput input;
KeysVector keys;
2015-07-30 15:22:07 +00:00
Crypto::PublicKey srcTxPubKey;
size_t srcOutputIndex;
};
2015-05-27 12:08:46 +00:00
TransactionBuilder(const CryptoNote::Currency& currency, uint64_t unlockTime = 0);
2014-08-13 10:51:37 +00:00
// regenerate transaction keys
TransactionBuilder& newTxKeys();
2015-05-27 12:08:46 +00:00
TransactionBuilder& setTxKeys(const CryptoNote::KeyPair& txKeys);
2014-08-13 10:51:37 +00:00
// inputs
2015-07-30 15:22:07 +00:00
TransactionBuilder& setInput(const std::vector<CryptoNote::TransactionSourceEntry>& sources, const CryptoNote::AccountKeys& senderKeys);
TransactionBuilder& addMultisignatureInput(const MultisignatureSource& source);
2014-08-13 10:51:37 +00:00
// outputs
2015-07-30 15:22:07 +00:00
TransactionBuilder& setOutput(const std::vector<CryptoNote::TransactionDestinationEntry>& destinations);
TransactionBuilder& addOutput(const CryptoNote::TransactionDestinationEntry& dest);
2014-08-13 10:51:37 +00:00
TransactionBuilder& addMultisignatureOut(uint64_t amount, const KeysVector& keys, uint32_t required);
2015-05-27 12:08:46 +00:00
CryptoNote::Transaction build() const;
2014-08-13 10:51:37 +00:00
2015-07-30 15:22:07 +00:00
std::vector<CryptoNote::TransactionSourceEntry> m_sources;
std::vector<CryptoNote::TransactionDestinationEntry> m_destinations;
2014-08-13 10:51:37 +00:00
private:
2015-05-27 12:08:46 +00:00
void fillInputs(CryptoNote::Transaction& tx, std::vector<CryptoNote::KeyPair>& contexts) const;
void fillOutputs(CryptoNote::Transaction& tx) const;
2015-07-30 15:22:07 +00:00
void signSources(const Crypto::Hash& prefixHash, const std::vector<CryptoNote::KeyPair>& contexts, CryptoNote::Transaction& tx) const;
2014-08-13 10:51:37 +00:00
struct MultisignatureDestination {
uint64_t amount;
uint32_t requiredSignatures;
KeysVector keys;
2014-08-13 10:51:37 +00:00
};
2015-07-30 15:22:07 +00:00
CryptoNote::AccountKeys m_senderKeys;
2014-08-13 10:51:37 +00:00
std::vector<MultisignatureSource> m_msigSources;
std::vector<MultisignatureDestination> m_msigDestinations;
size_t m_version;
uint64_t m_unlockTime;
2015-05-27 12:08:46 +00:00
CryptoNote::KeyPair m_txKey;
const CryptoNote::Currency& m_currency;
2014-08-13 10:51:37 +00:00
};