Files

87 lines
2.8 KiB
C++
Raw Permalink Normal View History

2019-12-09 14:57:21 +01:00
/*
* This file is part of the Flowee project
2021-02-16 17:31:57 +01:00
* Copyright (C) 2019-2021 Tom Zander <tom@flowee.org>
2019-12-09 14:57:21 +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/>.
*/
2019-11-29 22:12:08 +01:00
#ifndef FLOWEE_H
#define FLOWEE_H
#include <napi.h>
#include <Blockchain.h>
namespace Flowee {
2019-12-09 14:57:21 +01:00
struct Callback {
2021-02-17 21:02:06 +01:00
Callback(Napi::ThreadSafeFunction && function)
: f(std::move(function)){}
Callback() {}
2021-02-16 17:31:57 +01:00
~Callback() { free(); }
2021-02-17 21:02:06 +01:00
inline bool acquire() {
if (!acquired)
acquired = f.Acquire() == napi_ok;
return acquired;
2021-02-16 17:31:57 +01:00
}
void free() {
2021-02-17 23:34:27 +01:00
if (acquired) {
f.Release();
acquired = false;
}
2019-12-09 14:57:21 +01:00
}
bool acquired = false;
Napi::ThreadSafeFunction f;
};
struct PromiseCallback {
PromiseCallback(Napi::Env env);
void resolve(Napi::Value value);
Napi::Promise promise(Napi::Env env);
inline void resolve(Napi::Env env, const std::string &string) {
resolve(Napi::String::New(env, string));
}
void reject(Napi::Value value);
inline void reject(Napi::Env env, const std::string &string) {
reject(Napi::String::New(env, string));
}
2019-12-09 14:57:21 +01:00
Napi::Promise::Deferred p;
bool present = false;
};
2021-02-12 14:35:56 +01:00
Napi::Object populateTransaction(Napi::Env env, const Blockchain::Transaction &transaction, bool binaryHash);
2019-11-30 19:46:30 +01:00
Napi::Uint8Array wrap(Napi::Env env, const Streaming::ConstBuffer &buffer);
2019-12-08 23:20:41 +01:00
Napi::String hashToString(Napi::Env env, const Streaming::ConstBuffer &buffer);
2019-12-30 17:13:29 +01:00
2021-02-18 09:47:42 +01:00
// return a pool for the current thread;
Streaming::BufferPool &globalPool(int reserveSize);
2019-12-30 17:13:29 +01:00
/*
* Create a buffer of the raw data we get from a hex-string.
* /param hash string of hex characters (not case sensitive).
*/
Streaming::ConstBuffer hexStringToBuffer(const std::string &hash);
2021-02-26 19:37:16 +01:00
constexpr const char *CashAddressMainnet = "bitcoincash";
constexpr const char *CashAddressTestnet = "bchtest";
2019-12-30 17:13:29 +01:00
/*
* Create a sha256 hash from the user input.
*/
2021-02-26 19:37:16 +01:00
Streaming::ConstBuffer parseAddress(const Napi::String &string, std::string *prefix = nullptr, bool *isHash = nullptr);
2019-11-29 22:12:08 +01:00
}
#endif