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

Commit 74fcd02

Browse files
author
Remi Barjon
committed
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 74fcd02

9 files changed

+572
-723
lines changed

core/src/wallet/tezos/TezosLikeAccount.cpp

Lines changed: 7 additions & 8 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 178 additions & 241 deletions
Large diffs are not rendered by default.

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

Lines changed: 47 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -28,97 +28,77 @@
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>
34-
#include <wallet/tezos/explorers/api/TezosLikeTransactionsParser.h>
35-
#include <wallet/tezos/explorers/api/TezosLikeTransactionsBulkParser.h>
36-
#include <wallet/tezos/explorers/api/TezosLikeBlockParser.h>
37-
#include <api/TezosLikeNetworkParameters.hpp>
3835
#include <wallet/tezos/api_impl/TezosLikeTransactionApi.h>
3936

4037
namespace ledger {
4138
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> {
39+
40+
class ExternalTezosLikeBlockchainExplorer : public TezosLikeBlockchainExplorer
41+
{
5442
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);
43+
ExternalTezosLikeBlockchainExplorer(
44+
const std::shared_ptr<api::ExecutionContext> &context,
45+
const std::shared_ptr<HttpClient> &http,
46+
const api::TezosLikeNetworkParameters &parameters,
47+
const std::shared_ptr<ledger::core::api::DynamicObject> &configuration);
5948

6049
Future<std::shared_ptr<BigInt>>
61-
getBalance(const std::vector<TezosLikeKeychain::Address> &addresses) override;
50+
getBalance(const TezosLikeKeychain::Address &address) const override;
6251

6352
Future<std::shared_ptr<BigInt>>
64-
getFees() override;
53+
getFees() const override;
6554

6655
Future<std::shared_ptr<BigInt>>
67-
getGasPrice() override;
68-
69-
Future<String> pushLedgerApiTransaction(const std::vector<uint8_t> &transaction) override;
70-
71-
Future<void *> startSession() override;
56+
getGasPrice() const override;
7257

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;
58+
Future<String> pushLedgerApiTransaction(const std::vector<uint8_t> &transaction) override ;
7859

7960
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;
83-
84-
FuturePtr<Block> getCurrentBlock() const override;
85-
86-
FuturePtr<TezosLikeBlockchainExplorerTransaction>
87-
getTransactionByHash(const String &transactionHash) const override;
61+
getTransactions(const std::string& address,
62+
const Either<std::string, uint32_t>& token = {}) const override;
8863

89-
Future<int64_t> getTimestamp() const override;
90-
91-
std::shared_ptr<api::ExecutionContext> getExplorerContext() const override;
92-
93-
api::TezosLikeNetworkParameters getNetworkParameters() const override;
64+
FuturePtr<Block>
65+
getCurrentBlock() const override;
9466

9567
std::string getExplorerVersion() const override;
9668

9769
Future<std::shared_ptr<BigInt>>
98-
getEstimatedGasLimit(const std::string &address) override;
70+
getEstimatedGasLimit(const std::string &address) const override;
9971

10072
Future<std::shared_ptr<GasLimit>>
101-
getEstimatedGasLimit(const std::shared_ptr<TezosLikeTransactionApi> &transaction) override;
73+
getEstimatedGasLimit(const std::shared_ptr<TezosLikeTransactionApi> &tx) const override;
10274

10375
Future<std::shared_ptr<BigInt>>
104-
getStorage(const std::string &address) override;
76+
getStorage(const std::string &address) const override;
10577

106-
Future<std::shared_ptr<BigInt>> getCounter(const std::string &address) override;
78+
Future<std::vector<uint8_t>>
79+
forgeKTOperation(const std::shared_ptr<TezosLikeTransactionApi> &tx) const override;
10780

108-
Future<std::vector<uint8_t>> forgeKTOperation(const std::shared_ptr<TezosLikeTransactionApi> &tx) override;
81+
Future<std::string>
82+
getManagerKey(const std::string &address) const override;
10983

110-
Future<std::string> getManagerKey(const std::string &address) override;
84+
Future<bool>
85+
isAllocated(const std::string &address) const override;
11186

112-
Future<bool> isAllocated(const std::string &address) override;
87+
Future<std::string>
88+
getCurrentDelegate(const std::string &address) const override;
11389

114-
Future<std::string> getCurrentDelegate(const std::string &address) override;
90+
Future<std::shared_ptr<BigInt>>
91+
getCounter(const std::string &address) const override;
11592

116-
Future<bool> isFunded(const std::string &address) override;
93+
Future<bool>
94+
isFunded(const std::string &address) const override;
11795

118-
Future<std::shared_ptr<BigInt>>
119-
getTokenBalance(const std::string& accountAddress, const std::string& tokenAddress) const override;
96+
Future<bool>
97+
isDelegate(const std::string &address) const override;
12098

121-
Future<bool> isDelegate(const std::string &address) override;
99+
Future<std::shared_ptr<BigInt>>
100+
getTokenBalance(const std::string& accountAddress,
101+
const std::string& tokenAddress) const override;
122102

123103
private:
124104
/*
@@ -132,14 +112,16 @@ namespace ledger {
132112
Future<std::shared_ptr<BigInt>>
133113
getHelper(const std::string &url,
134114
const std::string &field,
135-
const std::unordered_map<std::string, std::string> &params = std::unordered_map<std::string, std::string>(),
115+
const std::unordered_map<std::string, std::string> &params = {},
136116
const std::string &fallbackValue = "",
137117
const std::string &forceUrl = "",
138-
bool isDecimal = false);
118+
bool isDecimal = false) const;
139119

140-
api::TezosLikeNetworkParameters _parameters;
141-
std::unordered_map<std::string, uint64_t> _sessions;
120+
private:
142121
std::string _bcd;
143122
};
144-
}
145-
}
123+
124+
} // namespace core
125+
} // namespace ledger
126+
127+
#endif //LEDGER_CORE_EXTERNALTEZOSLIKEBLOCKCHAINEXPLORER_H

0 commit comments

Comments
 (0)