forked from stellar/stellar-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrustLineWrapper.h
160 lines (108 loc) · 4.49 KB
/
TrustLineWrapper.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#pragma once
// Copyright 2018 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
#include "ledger/LedgerTxnEntry.h"
#include "xdr/Stellar-ledger-entries.h"
#include <memory>
namespace stellar
{
class LedgerTxn;
class LedgerTxnHeader;
class TrustLineWrapper
{
class AbstractImpl;
class IssuerImpl;
class NonIssuerImpl;
std::unique_ptr<AbstractImpl> mImpl;
std::unique_ptr<AbstractImpl> const& getImpl() const;
public:
TrustLineWrapper();
TrustLineWrapper(AbstractLedgerTxn& ltx, AccountID const& accountID,
Asset const& asset);
explicit TrustLineWrapper(LedgerTxnEntry&& entry);
TrustLineWrapper(TrustLineWrapper const&) = delete;
TrustLineWrapper& operator=(TrustLineWrapper const&) = delete;
TrustLineWrapper(TrustLineWrapper&&) = default;
TrustLineWrapper& operator=(TrustLineWrapper&&) = default;
explicit operator bool() const;
AccountID const& getAccountID() const;
Asset const& getAsset() const;
int64_t getBalance() const;
bool addBalance(LedgerTxnHeader const& header, int64_t delta);
int64_t getBuyingLiabilities(LedgerTxnHeader const& header);
int64_t getSellingLiabilities(LedgerTxnHeader const& header);
int64_t addBuyingLiabilities(LedgerTxnHeader const& header, int64_t delta);
int64_t addSellingLiabilities(LedgerTxnHeader const& header, int64_t delta);
bool isAuthorized() const;
int64_t getAvailableBalance(LedgerTxnHeader const& header) const;
int64_t getMaxAmountReceive(LedgerTxnHeader const& header) const;
void deactivate();
};
class TrustLineWrapper::AbstractImpl
{
public:
AbstractImpl() = default;
AbstractImpl(AbstractImpl const&) = delete;
AbstractImpl& operator=(AbstractImpl const&) = delete;
AbstractImpl(AbstractImpl&&) = delete;
AbstractImpl& operator=(AbstractImpl&&) = delete;
virtual ~AbstractImpl(){};
virtual operator bool() const = 0;
virtual AccountID const& getAccountID() const = 0;
virtual Asset const& getAsset() const = 0;
virtual int64_t getBalance() const = 0;
virtual bool addBalance(LedgerTxnHeader const& header, int64_t delta) = 0;
virtual int64_t getBuyingLiabilities(LedgerTxnHeader const& header) = 0;
virtual int64_t getSellingLiabilities(LedgerTxnHeader const& header) = 0;
virtual int64_t addBuyingLiabilities(LedgerTxnHeader const& header,
int64_t delta) = 0;
virtual int64_t addSellingLiabilities(LedgerTxnHeader const& header,
int64_t delta) = 0;
virtual bool isAuthorized() const = 0;
virtual int64_t
getAvailableBalance(LedgerTxnHeader const& header) const = 0;
virtual int64_t
getMaxAmountReceive(LedgerTxnHeader const& header) const = 0;
};
class ConstTrustLineWrapper
{
class AbstractImpl;
class IssuerImpl;
class NonIssuerImpl;
std::unique_ptr<AbstractImpl> mImpl;
std::unique_ptr<AbstractImpl> const& getImpl() const;
public:
ConstTrustLineWrapper();
ConstTrustLineWrapper(AbstractLedgerTxn& ltx, AccountID const& accountID,
Asset const& asset);
explicit ConstTrustLineWrapper(ConstLedgerTxnEntry&& entry);
ConstTrustLineWrapper(ConstTrustLineWrapper const&) = delete;
ConstTrustLineWrapper& operator=(ConstTrustLineWrapper const&) = delete;
ConstTrustLineWrapper(ConstTrustLineWrapper&&) = default;
ConstTrustLineWrapper& operator=(ConstTrustLineWrapper&&) = default;
explicit operator bool() const;
int64_t getBalance() const;
bool isAuthorized() const;
int64_t getAvailableBalance(LedgerTxnHeader const& header) const;
int64_t getMaxAmountReceive(LedgerTxnHeader const& header) const;
void deactivate();
};
class ConstTrustLineWrapper::AbstractImpl
{
public:
AbstractImpl() = default;
AbstractImpl(AbstractImpl const&) = delete;
AbstractImpl& operator=(AbstractImpl const&) = delete;
AbstractImpl(AbstractImpl&&) = delete;
AbstractImpl& operator=(AbstractImpl&&) = delete;
virtual ~AbstractImpl(){};
virtual operator bool() const = 0;
virtual int64_t getBalance() const = 0;
virtual bool isAuthorized() const = 0;
virtual int64_t
getAvailableBalance(LedgerTxnHeader const& header) const = 0;
virtual int64_t
getMaxAmountReceive(LedgerTxnHeader const& header) const = 0;
};
}