Monero
Loading...
Searching...
No Matches
rpc_payment.h
Go to the documentation of this file.
1// Copyright (c) 2018-2022, The Monero Project
2//
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without modification, are
6// permitted provided that the following conditions are met:
7//
8// 1. Redistributions of source code must retain the above copyright notice, this list of
9// conditions and the following disclaimer.
10//
11// 2. Redistributions in binary form must reproduce the above copyright notice, this list
12// of conditions and the following disclaimer in the documentation and/or other
13// materials provided with the distribution.
14//
15// 3. Neither the name of the copyright holder nor the names of its contributors may be
16// used to endorse or promote products derived from this software without specific
17// prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29#pragma once
30
31#include <string>
32#include <unordered_set>
33#include <unordered_map>
34#include <map>
35#include <boost/thread/mutex.hpp>
36#include <boost/serialization/version.hpp>
39#include <boost/serialization/list.hpp>
40#include <boost/serialization/vector.hpp>
43#include "serialization/pair.h"
45
46namespace cryptonote
47{
49 {
50 public:
52 {
65 std::unordered_set<uint64_t> payments;
66 std::unordered_set<uint64_t> previous_payments;
76
78
79 template <class t_archive>
80 inline void serialize(t_archive &a, const unsigned int ver)
81 {
82 a & block;
86 a & seed_height;
88 a & seed_hash;
90 a & cookie;
91 a & top;
93 a & credits;
94 a & payments;
96 a & update_time;
100 a & credits_used;
101 a & nonces_good;
102 a & nonces_stale;
103 a & nonces_bad;
104 a & nonces_dupe;
105 }
106
109 FIELD(block)
118 FIELD(top)
133 };
134
135 public:
137 uint64_t balance(const crypto::public_key &client, int64_t delta = 0);
138 bool pay(const crypto::public_key &client, uint64_t ts, uint64_t payment, const std::string &rpc, bool same_ts, uint64_t &credits);
139 bool get_info(const crypto::public_key &client, const std::function<bool(const cryptonote::blobdata&, cryptonote::block&, uint64_t &seed_height, crypto::hash &seed_hash)> &get_block_template, cryptonote::blobdata &hashing_blob, uint64_t &seed_height, crypto::hash &seed_hash, const crypto::hash &top, uint64_t &diff, uint64_t &credits_per_hash_found, uint64_t &credits, uint32_t &cookie);
140 bool submit_nonce(const crypto::public_key &client, uint32_t nonce, const crypto::hash &top, int64_t &error_code, std::string &error_message, uint64_t &credits, crypto::hash &hash, cryptonote::block &block, uint32_t cookie, bool &stale);
142 bool foreach(const std::function<bool(const crypto::public_key &client, const client_info &info)> &f) const;
143 unsigned int flush_by_age(time_t seconds = 0);
144 uint64_t get_hashes(unsigned int seconds) const;
145 void prune_hashrate(unsigned int seconds);
146 bool on_idle();
147
148 template <class t_archive>
149 inline void serialize(t_archive &a, const unsigned int ver)
150 {
151 a & m_client_info.parent();
152 a & m_hashrate.parent();
157 a & m_nonces_bad;
159 }
160
172
173 bool load(std::string directory);
174 bool store(const std::string &directory = std::string()) const;
175
176 private:
189 mutable boost::mutex mutex;
190 };
191}
uint64_t m_credits_per_hash_found
Definition rpc_payment.h:179
uint64_t m_nonces_bad
Definition rpc_payment.h:187
uint64_t m_diff
Definition rpc_payment.h:178
bool on_idle()
Definition rpc_payment.cpp:423
void serialize(t_archive &a, const unsigned int ver)
Definition rpc_payment.h:149
const cryptonote::account_public_address & get_payment_address() const
Definition rpc_payment.h:141
bool pay(const crypto::public_key &client, uint64_t ts, uint64_t payment, const std::string &rpc, bool same_ts, uint64_t &credits)
Definition rpc_payment.cpp:108
uint64_t m_nonces_stale
Definition rpc_payment.h:186
uint64_t get_hashes(unsigned int seconds) const
Definition rpc_payment.cpp:396
uint64_t m_nonces_good
Definition rpc_payment.h:185
uint64_t balance(const crypto::public_key &client, int64_t delta=0)
Definition rpc_payment.cpp:92
uint64_t m_nonces_dupe
Definition rpc_payment.h:188
serializable_unordered_map< crypto::public_key, client_info > m_client_info
Definition rpc_payment.h:180
uint64_t m_credits_used
Definition rpc_payment.h:184
serializable_map< uint64_t, uint64_t > m_hashrate
Definition rpc_payment.h:182
boost::mutex mutex
Definition rpc_payment.h:189
bool submit_nonce(const crypto::public_key &client, uint32_t nonce, const crypto::hash &top, int64_t &error_code, std::string &error_message, uint64_t &credits, crypto::hash &hash, cryptonote::block &block, uint32_t cookie, bool &stale)
Definition rpc_payment.cpp:183
unsigned int flush_by_age(time_t seconds=0)
Definition rpc_payment.cpp:368
cryptonote::account_public_address m_address
Definition rpc_payment.h:177
bool store(const std::string &directory=std::string()) const
Definition rpc_payment.cpp:333
std::string m_directory
Definition rpc_payment.h:181
bool get_info(const crypto::public_key &client, const std::function< bool(const cryptonote::blobdata &, cryptonote::block &, uint64_t &seed_height, crypto::hash &seed_hash)> &get_block_template, cryptonote::blobdata &hashing_blob, uint64_t &seed_height, crypto::hash &seed_hash, const crypto::hash &top, uint64_t &diff, uint64_t &credits_per_hash_found, uint64_t &credits, uint32_t &cookie)
Definition rpc_payment.cpp:132
uint64_t m_credits_total
Definition rpc_payment.h:183
void prune_hashrate(unsigned int seconds)
Definition rpc_payment.cpp:410
bool load(std::string directory)
Definition rpc_payment.cpp:285
Definition containers.h:60
Definition containers.h:49
#define BEGIN_SERIALIZE_OBJECT()
#define FIELD(f)
#define VERSION_FIELD(v)
#define END_SERIALIZE()
#define VARINT_FIELD(f)
static epee::net_utils::http::http_simple_client_template< dummy_client > client
Definition http-client.cpp:62
#define const
Definition ipfrdr.c:80
static MDB_envinfo info
Definition mdb_load.c:37
uint32_t address
Definition getifaddr.c:269
Definition portable_binary_archive.hpp:29
crypto namespace.
Definition crypto.cpp:60
POD_CLASS public_key
Definition crypto.h:64
POD_CLASS hash
Definition hash.h:49
Definition daemon_handler.cpp:49
Holds cryptonote related classes and helpers.
Definition blockchain_db.cpp:45
std::string blobdata
Definition blobdatatype.h:39
Definition rpc_payment.py:1
Definition enums.h:68
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1124
#define ts
Definition skein.c:522
signed __int64 int64_t
Definition stdint.h:135
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136
Definition cryptonote_basic.h:512
Definition cryptonote_basic.h:475
Definition rpc_payment.h:52
uint64_t update_time
Definition rpc_payment.h:67
std::unordered_set< uint64_t > previous_payments
Definition rpc_payment.h:66
crypto::hash previous_top
Definition rpc_payment.h:63
cryptonote::blobdata previous_hashing_blob
Definition rpc_payment.h:56
crypto::hash top
Definition rpc_payment.h:62
uint64_t last_request_timestamp
Definition rpc_payment.h:68
uint64_t seed_height
Definition rpc_payment.h:58
crypto::hash previous_seed_hash
Definition rpc_payment.h:59
uint64_t nonces_bad
Definition rpc_payment.h:74
uint64_t block_template_update_time
Definition rpc_payment.h:69
uint64_t nonces_dupe
Definition rpc_payment.h:75
uint64_t nonces_stale
Definition rpc_payment.h:73
uint64_t credits_total
Definition rpc_payment.h:70
uint64_t nonces_good
Definition rpc_payment.h:72
client_info()
Definition rpc_payment.cpp:58
uint64_t credits
Definition rpc_payment.h:64
uint64_t previous_seed_height
Definition rpc_payment.h:57
crypto::hash seed_hash
Definition rpc_payment.h:60
cryptonote::block block
Definition rpc_payment.h:53
uint32_t cookie
Definition rpc_payment.h:61
uint64_t credits_used
Definition rpc_payment.h:71
cryptonote::blobdata hashing_blob
Definition rpc_payment.h:55
std::unordered_set< uint64_t > payments
Definition rpc_payment.h:65
void serialize(t_archive &a, const unsigned int ver)
Definition rpc_payment.h:80
cryptonote::block previous_block
Definition rpc_payment.h:54