forked from jprjr/turtlecoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ITransfersSynchronizer.h
94 lines (70 loc) · 2.9 KB
/
ITransfersSynchronizer.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
// Copyright (c) 2012-2017, The CryptoNote developers, The Bytecoin developers
// Copyright (c) 2018-2019, The TurtleCoin Developers
//
// Please see the included LICENSE file for more information.
#pragma once
#include "IStreamSerializable.h"
#include "ITransaction.h"
#include "ITransfersContainer.h"
#include <cstdint>
#include <system_error>
namespace CryptoNote
{
struct SynchronizationStart
{
uint64_t timestamp;
uint64_t height;
};
struct AccountSubscription
{
AccountKeys keys;
SynchronizationStart syncStart;
size_t transactionSpendableAge;
};
class ITransfersSubscription;
class ITransfersObserver
{
public:
virtual void onError(ITransfersSubscription *object, uint32_t height, std::error_code ec) {}
virtual void onTransactionUpdated(ITransfersSubscription *object, const Crypto::Hash &transactionHash) {}
/**
* \note The sender must guarantee that onTransactionDeleted() is called only after onTransactionUpdated() is
* called for the same \a transactionHash.
*/
virtual void onTransactionDeleted(ITransfersSubscription *object, const Crypto::Hash &transactionHash) {}
};
class ITransfersSubscription : public IObservable<ITransfersObserver>
{
public:
virtual ~ITransfersSubscription() {}
virtual AccountPublicAddress getAddress() = 0;
virtual ITransfersContainer &getContainer() = 0;
};
class ITransfersSynchronizerObserver
{
public:
virtual void onBlocksAdded(const Crypto::PublicKey &viewPublicKey, const std::vector<Crypto::Hash> &blockHashes)
{
}
virtual void onBlockchainDetach(const Crypto::PublicKey &viewPublicKey, uint32_t blockIndex) {}
virtual void onTransactionDeleteBegin(const Crypto::PublicKey &viewPublicKey, Crypto::Hash transactionHash) {}
virtual void onTransactionDeleteEnd(const Crypto::PublicKey &viewPublicKey, Crypto::Hash transactionHash) {}
virtual void onTransactionUpdated(
const Crypto::PublicKey &viewPublicKey,
const Crypto::Hash &transactionHash,
const std::vector<ITransfersContainer *> &containers)
{
}
};
class ITransfersSynchronizer : public IStreamSerializable
{
public:
virtual ~ITransfersSynchronizer() {}
virtual ITransfersSubscription &addSubscription(const AccountSubscription &acc) = 0;
virtual bool removeSubscription(const AccountPublicAddress &acc) = 0;
virtual void getSubscriptions(std::vector<AccountPublicAddress> &subscriptions) = 0;
// returns nullptr if address is not found
virtual ITransfersSubscription *getSubscription(const AccountPublicAddress &acc) = 0;
virtual std::vector<Crypto::Hash> getViewKeyKnownBlocks(const Crypto::PublicKey &publicViewKey) = 0;
};
} // namespace CryptoNote