/* * This file is part of the Flowee project * Copyright (C) 2019 Tom Zander * * 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 . */ #ifndef FLOWEE_H #define FLOWEE_H #include #include namespace Flowee { struct Callback { inline void acquire() { if (present && !acquired) present = f.Acquire() == napi_ok; } bool present = false; 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)); } Napi::Promise::Deferred p; bool present = false; }; Napi::Object populateTransaction(Napi::Env env, const Blockchain::Transaction *transaction, bool binaryHash); Napi::Uint8Array wrap(Napi::Env env, const Streaming::ConstBuffer &buffer); Napi::String hashToString(Napi::Env env, const Streaming::ConstBuffer &buffer); /* * 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); /* * Create a sha256 hash from the user input. */ Streaming::ConstBuffer parseAddress(const Napi::String &string, bool *isHash = nullptr); } #endif