-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathPayment.h
127 lines (96 loc) · 3.85 KB
/
Payment.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
/*
This file is part of the Zero Reserve Plugin for Retroshare.
Zero Reserve is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zero Reserve is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Zero Reserve. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PAYMENT_H
#define PAYMENT_H
#include "zrtypes.h"
#include "Credit.h"
#include "Currency.h"
#include <string>
#include <map>
class QListWidget;
/**
* Take care of the actual payment on behalf of the @TransactionManager
*/
class Payment
{
Payment();
public:
enum Category {
PAYMENT, // generic payment where the other leg of the deal is outside the system
DEBT_CANCEL, // triangle payments with the aim to cancel out debt
BITCOIN_CONTRACT // Bitcoin deal governed by a series of contracts
};
class Request {
public:
Request() : m_Amount(0), m_Currency( Currency::INVALID ){}
Request( const ZR::ZR_Number & amount, const Currency::CurrencySymbols & currency) :
m_Amount( amount ), m_Currency( currency ){}
bool isValid(){ return (m_Currency != Currency::INVALID ); }
ZR::ZR_Number m_Amount;
Currency::CurrencySymbols m_Currency;
};
typedef std::map< ZR::VirtualAddress, Request > Requests;
Payment(const std::string & counterparty, const ZR::ZR_Number &amount, const std::string & currency, Category category);
virtual ~Payment(){}
virtual ZR::ZR_Number newBalance() const = 0;
virtual int init() = 0;
virtual int commit() = 0;
const std::string & getCounterparty(){ return m_credit.m_id; }
void setCounterparty( const std::string & counterparty );
const std::string & getCurrency(){ return m_credit.m_currency; }
ZR::ZR_Number getAmount(){ return m_amount; }
Category getCategory(){ return m_category; }
void referrerId( const std::string & referrer ){ m_referrer = referrer; }
const ZR::VirtualAddress & referrerId(){ return m_referrer; }
void setAmount( const ZR::ZR_Number & amount ){ m_amount = amount; }
static void addRequest( const ZR::VirtualAddress & addr, const Request & req )
{
requestList.insert( std::pair< ZR::VirtualAddress, Request >( addr, req ) );
}
static void addMyRequest( const ZR::VirtualAddress & addr, const Request & req )
{
myRequests.insert( std::pair< ZR::VirtualAddress, Request >( addr, req ) );
}
static const Request getRequest( const ZR::VirtualAddress & addr );
static const Request getMyRequest( const ZR::VirtualAddress & addr );
protected:
Credit m_credit;
ZR::ZR_Number m_amount;
Category m_category;
ZR::VirtualAddress m_referrer;
public:
static QListWidget * txLogView;
private:
static Requests requestList;
static Requests myRequests;
};
class PaymentReceiver : public Payment
{
public:
PaymentReceiver(const std::string & counterparty, const ZR::ZR_Number &amount, const std::string & currency, Category category);
virtual ~PaymentReceiver(){}
virtual ZR::ZR_Number newBalance() const;
virtual int init();
virtual int commit();
};
class PaymentSpender : public Payment
{
public:
PaymentSpender(const std::string & counterparty, ZR::ZR_Number amount, const std::string & currency, Category category);
virtual ~PaymentSpender(){}
virtual ZR::ZR_Number newBalance() const;
virtual int init();
virtual int commit();
};
#endif // PAYMENT_H