Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tezos synchronizer #742

Open
wants to merge 5 commits into
base: nrt_tezos
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ auto TezosLikeAccountSynchronizer::performSynchronization() const -> Future<Resu
return async::sequence(getContext(), futures)
.map<Result>(
getContext(),
[this](const auto& tuple) {
[this, state](const auto& tuple) {
const auto duration = std::chrono::duration_cast<
std::chrono::milliseconds>(DateUtils::now() - _start);
_logger->info(
Expand All @@ -134,17 +134,18 @@ auto TezosLikeAccountSynchronizer::performSynchronization() const -> Future<Resu
const auto block = std::get<0>(tuple);
const auto syncs = std::get<1>(tuple);

const auto newOperations = std::accumulate(
std::begin(syncs), std::end(syncs), 0);

if (block.height > 0) {
auto state = SavedState(block.height, block.hash);
auto newState = SavedState(
block.height, block.hash, state.offset + newOperations);
_account->getInternalPreferences()
->editor()
->putObject<SavedState>("state", state)
->putObject<SavedState>("state", newState)
->commit();
}

const auto newOperations = std::accumulate(
std::begin(syncs), std::end(syncs), 0);

return Result(block.height, newOperations);
})
.recoverWith(
Expand Down Expand Up @@ -179,7 +180,7 @@ auto TezosLikeAccountSynchronizer::synchronizeTransactions(
}
return std::string("");
}();
return _explorer->getTransactions({address}, Option<std::string>(state.blockHash))
return _explorer->getTransactions({address}, std::to_string(state.offset))
.flatMap<uint32_t>(
_account->getContext(),
[this, address, state, uid, nbTxns](
Expand All @@ -192,12 +193,6 @@ auto TezosLikeAccountSynchronizer::synchronizeTransactions(
newState.blockHeight = tx.block->height;
newState.blockHash = tx.block->hash;
}
/*
if (tx.block.hasValue()) {
newState.blockHeight = tx.block->height;
newState.blockHash = tx.block->hash;
}
*/

if (orig) {
tx.originatedAccountUid = uid;
Expand All @@ -219,6 +214,8 @@ auto TezosLikeAccountSynchronizer::synchronizeTransactions(
}

const auto count = tryPutTx.getValue();
newState.offset += count;

_logger->info(
"Successfully inserted {} transactions for account {}.",
count, _account->getAccountUid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,23 @@ class TezosLikeAccountSynchronizer : public DedicatedContext
{
uint64_t blockHeight{0};
std::string blockHash{""};

SavedState(uint64_t blockHeight, std::string blockHash)
: blockHeight(blockHeight), blockHash(blockHash)
uint64_t offset{0};

SavedState(
uint64_t blockHeight,
std::string blockHash,
uint64_t offset)
: blockHeight(blockHeight)
, blockHash(blockHash)
, offset(offset)
{}

SavedState() = default;

template<typename Archive>
void serialize(Archive& archive)
{
archive(blockHeight, blockHash);
archive(blockHeight, blockHash, offset);
barjonr marked this conversation as resolved.
Show resolved Hide resolved
}
};

Expand Down