-
Notifications
You must be signed in to change notification settings - Fork 11
/
Ledger.hpp
41 lines (28 loc) · 1.45 KB
/
Ledger.hpp
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
#include "ImpliedTransaction.hpp"
#include <map>
#pragma once
//
// Simplified ledger that adds valid transactions to UTXO set; transactions are looked up based on public key
// of the owner. A 2:2 multisig UTXO is looked up with an aggregate public key
//
namespace lot49
{
class Ledger {
public:
typedef std::map< std::vector<uint8_t>, ImpliedTransaction > TransactionMap;
static Ledger sInstance;
void Issue(const bls::PublicKey& inOwner, const uint16_t inAmount, const uint16_t inCount);
bool Add(const std::vector<ImpliedTransaction>& inTransactions);
bool Unspent(const std::vector<uint8_t>& inTransactionHash) const;
private:
static const std::vector<ImpliedTransaction> Sort(const std::vector<ImpliedTransaction>& inTransactions);
// find input transaction for
bool FindInputTransaction(const ImpliedTransaction& inTransaction, const TransactionMap& inProposedUTXOs, ImpliedTransaction& outInput);
// true if value from input earmarked for output is sufficient to fund output
bool ValidTransfer(const ImpliedTransaction& inInput, const ImpliedTransaction& inOutput) const;
TransactionMap::const_iterator Find(const std::vector<uint8_t>& inTransactionHash) const;
TransactionMap::const_iterator Find(const bls::PublicKey& inOwner, const uint16_t inAmount) const;
// map from transaction hash of an unspent transaction output to the transaction itself
TransactionMap mUTXOs;
};
}; // namespace lot49