Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.

Commit 0cacdf4

Browse files
Remi Barjonbarjonr
Remi Barjon
authored andcommitted
Remove AbstractBlockchainExplorer dependency from TezosLikeBlockchainExplorer
- Remove some unused code - Use single address instead of vector of addresses in explorer endpoints - Remove sessions mechanism from TezosLikeBlockchainExplorer
1 parent 67221f8 commit 0cacdf4

9 files changed

+526
-656
lines changed

core/src/wallet/tezos/TezosLikeAccount.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@ namespace ledger {
129129
if (transaction.type == api::TezosOperationTag::OPERATION_TAG_ORIGINATION && transaction.status == 1) {
130130
updateOriginatedAccounts(sql, operation);
131131
}
132-
out.push_back(operation);
132+
out.push_back(operation);
133133
result = static_cast<int>(transaction.type);
134134
}
135135

136136
if (_accountAddress == transaction.receiver) {
137137
operation.amount = transaction.value;
138138
operation.type = api::OperationType::RECEIVE;
139139
operation.refreshUid();
140-
out.push_back(operation);
140+
out.push_back(operation);
141141
result = static_cast<int>(transaction.type);
142142
}
143143
}
@@ -164,13 +164,13 @@ namespace ledger {
164164
auto originatedAccountUid = TezosLikeAccountDatabaseHelper::createOriginatedAccountUid(getAccountUid(), origAccount.address);
165165

166166
const auto found = std::find_if (
167-
_originatedAccounts.begin(),
168-
_originatedAccounts.end(),
169-
[&originatedAccountUid](const std::shared_ptr<api::TezosLikeOriginatedAccount>& element) {
167+
_originatedAccounts.begin(),
168+
_originatedAccounts.end(),
169+
[&originatedAccountUid](const std::shared_ptr<api::TezosLikeOriginatedAccount>& element) {
170170
return std::dynamic_pointer_cast<TezosLikeOriginatedAccount>(element)->getAccountUid() == originatedAccountUid;
171171
});
172172

173-
if (found == _originatedAccounts.end()) {
173+
if (found == _originatedAccounts.end()) {
174174
_originatedAccounts.emplace_back(
175175
std::make_shared<TezosLikeOriginatedAccount>(originatedAccountUid,
176176
origAccount.address,
@@ -205,10 +205,9 @@ namespace ledger {
205205
if (cachedBalance.hasValue()) {
206206
return FuturePtr<Amount>::successful(std::make_shared<Amount>(cachedBalance.getValue()));
207207
}
208-
std::vector<TezosLikeKeychain::Address> listAddresses{_keychain->getAddress()};
209208
auto currency = getWallet()->getCurrency();
210209
auto self = getSelf();
211-
return _explorer->getBalance(listAddresses).mapPtr<Amount>(getMainExecutionContext(), [self, currency](
210+
return _explorer->getBalance(_keychain->getAddress()).mapPtr<Amount>(getMainExecutionContext(), [self, currency](
212211
const std::shared_ptr<BigInt> &balance) -> std::shared_ptr<Amount> {
213212
Amount b(currency, 0, BigInt(balance->toString()));
214213
self->getWallet()->updateBalanceCache(self->getIndex(), b);

core/src/wallet/tezos/TezosLikeAccount2.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ namespace ledger {
215215
// Check if balance is sufficient
216216
auto currency = self->getWallet()->getCurrency();
217217
auto accountAddress = TezosLikeAddress::fromBase58(senderAddress, currency);
218-
return explorer->getBalance(std::vector<std::shared_ptr<TezosLikeAddress>>{accountAddress}).flatMapPtr<api::TezosLikeTransaction>(
218+
return explorer->getBalance(accountAddress).flatMapPtr<api::TezosLikeTransaction>(
219219
self->getMainExecutionContext(),
220220
[self, request, explorer, accountAddress, currency, senderAddress](const std::shared_ptr<BigInt> &balance) {
221221
// Check if all needed values are set

core/src/wallet/tezos/explorers/ExternalTezosLikeBlockchainExplorer.cpp

+187-231
Large diffs are not rendered by default.

core/src/wallet/tezos/explorers/ExternalTezosLikeBlockchainExplorer.h

+50-57
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
*
2929
*/
3030

31-
#pragma once
32-
#include <wallet/common/explorers/AbstractLedgerApiBlockchainExplorer.h>
31+
#ifndef LEDGER_CORE_EXTERNALTEZOSLIKEBLOCKCHAINEXPLORER_H
32+
#define LEDGER_CORE_EXTERNALTEZOSLIKEBLOCKCHAINEXPLORER_H
33+
3334
#include <wallet/tezos/explorers/TezosLikeBlockchainExplorer.h>
3435
#include <wallet/tezos/explorers/api/TezosLikeTransactionsParser.h>
3536
#include <wallet/tezos/explorers/api/TezosLikeTransactionsBulkParser.h>
@@ -39,86 +40,76 @@
3940

4041
namespace ledger {
4142
namespace core {
42-
using ExternalApiBlockchainExplorer = AbstractLedgerApiBlockchainExplorer<
43-
TezosLikeBlockchainExplorerTransaction,
44-
TezosLikeBlockchainExplorer::TransactionsBulk,
45-
TezosLikeTransactionsParser,
46-
TezosLikeTransactionsBulkParser,
47-
TezosLikeBlockParser,
48-
api::TezosLikeNetworkParameters>;
49-
50-
class ExternalTezosLikeBlockchainExplorer : public TezosLikeBlockchainExplorer,
51-
public ExternalApiBlockchainExplorer,
52-
public DedicatedContext,
53-
public std::enable_shared_from_this<ExternalTezosLikeBlockchainExplorer> {
43+
44+
class ExternalTezosLikeBlockchainExplorer : public TezosLikeBlockchainExplorer
45+
{
5446
public:
55-
ExternalTezosLikeBlockchainExplorer(const std::shared_ptr<api::ExecutionContext> &context,
56-
const std::shared_ptr<HttpClient> &http,
57-
const api::TezosLikeNetworkParameters &parameters,
58-
const std::shared_ptr<api::DynamicObject> &configuration);
47+
ExternalTezosLikeBlockchainExplorer(
48+
const std::shared_ptr<api::ExecutionContext> &context,
49+
const std::shared_ptr<HttpClient> &http,
50+
const api::TezosLikeNetworkParameters &parameters,
51+
const std::shared_ptr<ledger::core::api::DynamicObject> &configuration);
5952

6053
Future<std::shared_ptr<BigInt>>
61-
getBalance(const std::vector<TezosLikeKeychain::Address> &addresses) override;
54+
getBalance(const TezosLikeKeychain::Address &address) const override;
6255

6356
Future<std::shared_ptr<BigInt>>
64-
getFees() override;
57+
getFees() const override;
6558

6659
Future<std::shared_ptr<BigInt>>
67-
getGasPrice() override;
68-
69-
Future<String> pushLedgerApiTransaction(const std::vector<uint8_t> &transaction) override;
60+
getGasPrice() const override;
7061

71-
Future<void *> startSession() override;
62+
Future<String> pushLedgerApiTransaction(const std::vector<uint8_t> &transaction) override ;
7263

73-
Future<Unit> killSession(void *session) override;
74-
75-
Future<Bytes> getRawTransaction(const String &transactionHash) override;
76-
77-
Future<String> pushTransaction(const std::vector<uint8_t> &transaction) override;
64+
Future<String> pushTransaction(const std::vector<uint8_t>& transaction) override;
7865

7966
FuturePtr<TezosLikeBlockchainExplorer::TransactionsBulk>
80-
getTransactions(const std::vector<std::string> &addresses,
81-
Option<std::string> offset = Option<std::string>(),
82-
Option<void *> session = Option<void *>()) override;
67+
getTransactions(const std::string& address,
68+
const Either<std::string, uint32_t>& token = {}) const override;
8369

84-
FuturePtr<Block> getCurrentBlock() const override;
70+
FuturePtr<Block>
71+
getCurrentBlock() const override;
8572

86-
FuturePtr<TezosLikeBlockchainExplorerTransaction>
73+
FuturePtr<Transaction>
8774
getTransactionByHash(const String &transactionHash) const override;
8875

89-
Future<int64_t> getTimestamp() const override;
90-
91-
std::shared_ptr<api::ExecutionContext> getExplorerContext() const override;
92-
93-
api::TezosLikeNetworkParameters getNetworkParameters() const override;
94-
9576
std::string getExplorerVersion() const override;
9677

9778
Future<std::shared_ptr<BigInt>>
98-
getEstimatedGasLimit(const std::string &address) override;
79+
getEstimatedGasLimit(const std::string &address) const override;
9980

10081
Future<std::shared_ptr<GasLimit>>
101-
getEstimatedGasLimit(const std::shared_ptr<TezosLikeTransactionApi> &transaction) override;
82+
getEstimatedGasLimit(const std::shared_ptr<TezosLikeTransactionApi> &tx) const override;
10283

10384
Future<std::shared_ptr<BigInt>>
104-
getStorage(const std::string &address) override;
85+
getStorage(const std::string &address) const override;
10586

106-
Future<std::shared_ptr<BigInt>> getCounter(const std::string &address) override;
87+
Future<std::shared_ptr<BigInt>>
88+
getCounter(const std::string &address) const override;
10789

108-
Future<std::vector<uint8_t>> forgeKTOperation(const std::shared_ptr<TezosLikeTransactionApi> &tx) override;
90+
Future<std::vector<uint8_t>>
91+
forgeKTOperation(const std::shared_ptr<TezosLikeTransactionApi> &tx) const override;
10992

110-
Future<std::string> getManagerKey(const std::string &address) override;
93+
Future<std::string>
94+
getManagerKey(const std::string &address) const override;
11195

112-
Future<bool> isAllocated(const std::string &address) override;
96+
Future<bool>
97+
isAllocated(const std::string &address) const override;
11398

114-
Future<std::string> getCurrentDelegate(const std::string &address) override;
99+
Future<std::string>
100+
getCurrentDelegate(const std::string &address) const override;
115101

116-
Future<bool> isFunded(const std::string &address) override;
102+
/// Check that the account is funded.
103+
Future<bool>
104+
isFunded(const std::string &address) const override;
117105

106+
/// Get a token balance for an account
118107
Future<std::shared_ptr<BigInt>>
119-
getTokenBalance(const std::string& accountAddress, const std::string& tokenAddress) const override;
108+
getTokenBalance(const std::string& accountAddress,
109+
const std::string& tokenAddress) const override;
120110

121-
Future<bool> isDelegate(const std::string &address) override;
111+
Future<bool>
112+
isDelegate(const std::string &address) const override;
122113

123114
private:
124115
/*
@@ -132,14 +123,16 @@ namespace ledger {
132123
Future<std::shared_ptr<BigInt>>
133124
getHelper(const std::string &url,
134125
const std::string &field,
135-
const std::unordered_map<std::string, std::string> &params = std::unordered_map<std::string, std::string>(),
126+
const std::unordered_map<std::string, std::string> &params = {},
136127
const std::string &fallbackValue = "",
137128
const std::string &forceUrl = "",
138-
bool isDecimal = false);
129+
bool isDecimal = false) const;
139130

140-
api::TezosLikeNetworkParameters _parameters;
141-
std::unordered_map<std::string, uint64_t> _sessions;
131+
private:
142132
std::string _bcd;
143133
};
144-
}
145-
}
134+
135+
} // namespace core
136+
} // namespace ledger
137+
138+
#endif //LEDGER_CORE_EXTERNALTEZOSLIKEBLOCKCHAINEXPLORER_H

0 commit comments

Comments
 (0)