Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 0 additions & 29 deletions core/src/wallet/bitcoin/BitcoinLikeAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,16 @@ namespace ledger {
void BitcoinLikeAccount::interpretTransaction(const BitcoinLikeBlockchainExplorerTransaction& transaction,
std::vector<Operation>& out, bool needExtendKeychain) {
auto nodeIndex = std::const_pointer_cast<const BitcoinLikeKeychain>(_keychain)->getFullDerivationScheme().getPositionForLevel(DerivationSchemeLevel::NODE);
std::cout << "2" << std::endl;
std::list<std::pair<BitcoinLikeBlockchainExplorerInput *, DerivationPath>> accountInputs;
std::list<std::pair<BitcoinLikeBlockchainExplorerOutput *, DerivationPath>> accountOutputs;
std::cout << "3" << std::endl;
uint64_t fees = 0L;
std::cout << "4" << std::endl;
uint64_t sentAmount = 0L;
uint64_t receivedAmount = 0L;
std::vector<std::string> senders;
senders.reserve(transaction.inputs.size());
std::cout << "5" << std::endl;
std::vector<std::string> recipients;
recipients.reserve(transaction.outputs.size());
std::cout << "6 " << std::endl;
int result = FLAG_TRANSACTION_IGNORED;
std::cout << "Find inputs" << std::endl;
// Find inputs
for (auto& input : transaction.inputs) {

Expand All @@ -156,7 +150,6 @@ namespace ledger {
fees += input.value.getValue().toUint64();
}
}
std::cout << "Find outputs" << std::endl;
// Find outputs
auto hasSpentNothing = sentAmount == 0L;
auto outputCount = transaction.outputs.size();
Expand Down Expand Up @@ -191,15 +184,13 @@ namespace ledger {
}
std::stringstream snds;
strings::join(senders, snds, ",");
std::cout << "inflateOperation" << std::endl;
Operation operation;
inflateOperation(operation, transaction);
operation.senders = std::move(senders);
operation.recipients = std::move(recipients);
operation.fees = std::move(BigInt().assignI64(fees));
operation.trust = std::make_shared<TrustIndicator>();
operation.date = transaction.receivedAt;
std::cout << "compute trust" << std::endl;
// Compute trust
computeOperationTrust(operation, transaction);

Expand All @@ -218,7 +209,6 @@ namespace ledger {
operation.refreshUid();
out.push_back(operation);
}
std::cout << "accountOutputs" << std::endl;
if (accountOutputs.size() > 0) {
// Receive
BigInt amount;
Expand Down Expand Up @@ -247,20 +237,13 @@ namespace ledger {
}

Try<int> BitcoinLikeAccount::bulkInsert(const std::vector<Operation> &ops) {
std::cout << "bulk insert method" << std::endl;
return Try<int>::from([&] () {
std::cout << "sql session" << std::endl;
soci::session sql(getWallet()->getDatabase()->getPool());
std::cout << "sql transaction" << std::endl;
soci::transaction tr(sql);
std::cout << "BitcoinLikeOperationDatabaseHelper::bulkInsert" << std::endl;
BitcoinLikeOperationDatabaseHelper::bulkInsert(sql, ops);
std::cout << "tr.commit" << std::endl;
tr.commit();
std::cout << "emitNewOperationsEvent" << std::endl;
// Emit
emitNewOperationsEvent(ops);
std::cout << "emitNewOperationsEvent finish" << std::endl;
return ops.size();
});
}
Expand Down Expand Up @@ -615,12 +598,10 @@ namespace ledger {
const std::shared_ptr<api::StringCallback> &callback) {
auto self = getSelf();
_explorer->pushTransaction(transaction).map<std::string>(getContext(), [self, transaction] (const String& seq) -> std::string {
std::cout<<"transaction send request finish"<<std::endl;
self->logger()->warn("transaction send request finish");
//Store newly broadcasted tx in db
//First parse it
auto txHash = seq.str();
std::cout << "got tx hash" << std::endl;
self->logger()->warn("got tx hash");
auto optimisticUpdate = Try<Unit>::from([&] () -> Unit {
//Get last block from DB or cache
Expand All @@ -632,7 +613,6 @@ namespace ledger {
} else {
lastBlockHeight = getLastBlockFromDB(sql, self->getWallet()->getCurrency().name);
}
std::cout << "parseRawSignedTransaction" << std::endl;
self->logger()->warn(" parseRawSignedTransaction");
auto tx = BitcoinLikeTransactionApi::parseRawSignedTransaction(self->getWallet()->getCurrency(), transaction, lastBlockHeight);

Expand All @@ -643,7 +623,6 @@ namespace ledger {
txExplorer.receivedAt = std::chrono::system_clock::now();
txExplorer.version = tx->getVersion();
txExplorer.confirmations = 0;
std::cout << "input" << std::endl;
self->logger()->warn(" input");
//Inputs
auto inputCount = tx->getInputs().size();
Expand All @@ -665,7 +644,6 @@ namespace ledger {
in.address = prevTx.outputs[prevTxOutputIndex].address.getValueOr("");
txExplorer.inputs.push_back(in);
}
std::cout << "output" << std::endl;
self->logger()->warn(" output");
//Outputs
auto keychain = self->getKeychain();
Expand All @@ -681,18 +659,13 @@ namespace ledger {
out.address = output->getAddress().value_or("");
txExplorer.outputs.push_back(out);
}
std::cout << "save db" << std::endl;
self->logger()->warn(" save db");
//Store in DB

std::vector<Operation> operations;
std::cout << "operations" << std::endl;
self->interpretTransaction(txExplorer, operations);
std::cout << "interpretTransaction finish" << std::endl;
self->bulkInsert(operations);
std::cout << "bulkInsert finish" << std::endl;
self->emitEventsNow();
std::cout << "saved db" << std::endl;
self->logger()->warn(" saved db");

return unit;
Expand All @@ -702,12 +675,10 @@ namespace ledger {
// because the tx was successfully broadcasted to the network,
// and the update will occur at next synchro ...
// But still let's log that !
std::cout << "optimisticUpdate" << std::endl;
self->logger()->warn(" optimisticUpdate");
if (optimisticUpdate.isFailure()) {
self->logger()->warn(" Optimistic update failed for broadcasted transaction : {}", txHash);
}
std::cout << "optimisticUpdate finish" << std::endl;
self->logger()->warn(" optimisticUpdate finish");
return txHash;
}).callback(getMainExecutionContext(), callback);
Expand Down
5 changes: 0 additions & 5 deletions core/src/wallet/common/AbstractAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,23 +231,18 @@ namespace ledger {

void AbstractAccount::emitEventsNow() {
auto self = shared_from_this();
std::cout << "emitEventsNow method" << std::endl;
run([self] () {
std::cout << "run" << std::endl;
std::list<std::shared_ptr<api::Event>> events;
std::shared_ptr<api::Event> batchedOperationsEvent;
std::shared_ptr<api::Event> batchedBlocksEvent;
{
std::cout << "batchedOperationsEvent" << std::endl;
std::lock_guard<std::mutex> lock(self->_eventsLock);
std::swap(events, self->_events);
batchedOperationsEvent = self->_batchedOperationsEvent;
self->_batchedOperationsEvent = nullptr;
}
std::cout << "publisher post" << std::endl;
if (batchedOperationsEvent)
self->_publisher->post(batchedOperationsEvent);
std::cout << "post event" << std::endl;
for (auto& event : events) {
self->_publisher->post(event);
}
Expand Down