2019-11-28 23:58:56 +01:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
2021-02-17 21:02:06 +01:00
|
|
|
* Copyright (C) 2019-2021 Tom Zander <tom@flowee.org>
|
2019-11-28 23:58:56 +01:00
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef SEARCH_H
|
|
|
|
|
#define SEARCH_H
|
|
|
|
|
|
2019-12-09 15:06:55 +01:00
|
|
|
#include "Flowee.h"
|
|
|
|
|
|
2019-11-28 23:58:56 +01:00
|
|
|
#include <Blockchain.h>
|
|
|
|
|
#include <napi.h>
|
|
|
|
|
|
|
|
|
|
class Search : public Blockchain::Search
|
|
|
|
|
{
|
|
|
|
|
public:
|
2019-11-29 20:12:16 +01:00
|
|
|
static Search *create(Napi::Object requestObject);
|
2019-11-28 23:58:56 +01:00
|
|
|
|
2019-11-29 22:12:08 +01:00
|
|
|
// Blockchain::Search interface
|
|
|
|
|
void finished(int unfinishedJobs) override;
|
2020-09-19 23:53:39 +02:00
|
|
|
void transactionAdded(const Blockchain::Transaction &transaction, int answerIndex) override;
|
2019-11-29 22:12:08 +01:00
|
|
|
void txIdResolved(int jobId, int blockHeight, int offsetInBlock) override;
|
|
|
|
|
void spentOutputResolved(int jobId, int blockHeight, int offsetInBlock) override;
|
|
|
|
|
void addressUsedInOutput(int blockHeight, int offsetInBlock, int outIndex) override;
|
2019-11-30 19:46:30 +01:00
|
|
|
void utxoLookup(int jobId, int blockHeight, int offsetInBlock, int outIndex, bool unspent, int64_t amount, Streaming::ConstBuffer outputScript) override;
|
2020-09-19 23:53:39 +02:00
|
|
|
void aborted(const Blockchain::ServiceUnavailableException&) override;
|
2019-11-28 23:58:56 +01:00
|
|
|
|
2019-12-09 15:06:55 +01:00
|
|
|
inline Napi::Promise promise(Napi::Env env) {
|
|
|
|
|
return m_promise.promise(env);
|
2019-11-29 20:12:16 +01:00
|
|
|
}
|
2019-12-08 19:01:24 +01:00
|
|
|
inline void finishupPromise() {
|
2019-12-09 15:06:55 +01:00
|
|
|
m_promise.resolve(mainObject());
|
2019-12-08 19:01:24 +01:00
|
|
|
}
|
2019-11-29 20:12:16 +01:00
|
|
|
|
2019-12-08 21:22:24 +01:00
|
|
|
// set jobs on mainObject. No validation will be done.
|
|
|
|
|
void setJobs(Napi::Array jobs);
|
2019-11-30 19:46:30 +01:00
|
|
|
// append job object to job-list. No validation will be done.
|
|
|
|
|
void addJsJobObject(Napi::Object job);
|
|
|
|
|
|
|
|
|
|
void addJsCallbackScheduled();
|
2019-12-08 21:22:24 +01:00
|
|
|
void jsCallbackFinished(Napi::Env env);
|
|
|
|
|
|
|
|
|
|
void copyResults(Napi::Env env);
|
2019-11-30 19:46:30 +01:00
|
|
|
|
|
|
|
|
inline Napi::Object mainObject() const {
|
|
|
|
|
return m_me.Value();
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-08 23:20:41 +01:00
|
|
|
bool useBinaryHashes() const;
|
|
|
|
|
void setUseBinaryHashes(bool useBinaryHashes);
|
|
|
|
|
|
2019-11-28 23:58:56 +01:00
|
|
|
protected:
|
2019-11-29 20:12:16 +01:00
|
|
|
Search(Napi::Env env);
|
2019-11-28 23:58:56 +01:00
|
|
|
|
|
|
|
|
private:
|
2021-02-17 21:02:06 +01:00
|
|
|
std::unique_ptr<Flowee::Callback> m_onFinished;
|
|
|
|
|
std::unique_ptr<Flowee::Callback> m_onTxAdded;
|
|
|
|
|
std::unique_ptr<Flowee::Callback> m_onTxIdResolved;
|
|
|
|
|
std::unique_ptr<Flowee::Callback> m_onSpentOutputResolved;
|
|
|
|
|
std::unique_ptr<Flowee::Callback> m_onAddressUsedInOutput;
|
|
|
|
|
std::unique_ptr<Flowee::Callback> m_onUtxoLookup;
|
2019-11-29 20:12:16 +01:00
|
|
|
|
2019-12-09 15:06:55 +01:00
|
|
|
Flowee::PromiseCallback m_promise;
|
2021-02-17 21:02:06 +01:00
|
|
|
std::unique_ptr<Flowee::Callback> m_promiseFinished;
|
2019-11-29 22:12:08 +01:00
|
|
|
Napi::ObjectReference m_me; // javascript version of 'me'.
|
2019-11-30 19:46:30 +01:00
|
|
|
|
|
|
|
|
std::atomic<int> m_calls;
|
2019-12-08 23:20:41 +01:00
|
|
|
bool m_useBinaryHashes = false;
|
2020-07-27 20:52:38 +02:00
|
|
|
bool m_done = false;
|
2019-11-28 23:58:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|