From 21836f16533cdf0c48bfe8cc0a35e0a743fd53d1 Mon Sep 17 00:00:00 2001 From: TomZ Date: Thu, 18 Mar 2021 12:32:59 +0100 Subject: [PATCH] Support fetching fees for a transaction directly Only on a Hub that enabled it, though --- ContextData.cpp | 11 ++++++----- Flowee.cpp | 4 +++- examples/transaction.js | 5 +++-- lib/index.js | 1 + 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/ContextData.cpp b/ContextData.cpp index 55a5c45..06ffcc8 100644 --- a/ContextData.cpp +++ b/ContextData.cpp @@ -575,15 +575,16 @@ void ContextData::setupBindings(Napi::Env env, Napi::Object exports) auto enum7 = Napi::PropertyDescriptor::Value("IncludeOutputScripts", Napi::Value::From(env, int(Blockchain::IncludeOutputScripts))); auto enum8 = Napi::PropertyDescriptor::Value("IncludeOutputAddresses", Napi::Value::From(env, int(Blockchain::IncludeOutputAddresses))); auto enum9 = Napi::PropertyDescriptor::Value("IncludeOutputScriptHash", Napi::Value::From(env, int(Blockchain::IncludeOutputScriptHash))); - auto enum10 = Napi::PropertyDescriptor::Value("InfoLevel", Napi::Value::From(env, int(Log::InfoLevel))); - auto enum11 = Napi::PropertyDescriptor::Value("WarningLevel", Napi::Value::From(env, int(Log::WarningLevel))); - auto enum12 = Napi::PropertyDescriptor::Value("QuietLevel", Napi::Value::From(env, int(Log::CriticalLevel))); - auto enum13 = Napi::PropertyDescriptor::Value("SilentLevel", Napi::Value::From(env, int(Log::FatalLevel))); + auto enum10 = Napi::PropertyDescriptor::Value("IncludeTxFees", Napi::Value::From(env, int(Blockchain::IncludeTxFees))); + auto enum11 = Napi::PropertyDescriptor::Value("InfoLevel", Napi::Value::From(env, int(Log::InfoLevel))); + auto enum12 = Napi::PropertyDescriptor::Value("WarningLevel", Napi::Value::From(env, int(Log::WarningLevel))); + auto enum13 = Napi::PropertyDescriptor::Value("QuietLevel", Napi::Value::From(env, int(Log::CriticalLevel))); + auto enum14 = Napi::PropertyDescriptor::Value("SilentLevel", Napi::Value::From(env, int(Log::FatalLevel))); exports.DefineProperties({m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, p1, p2, p3, p4, p5, p6, enum1, enum2, enum3, enum4, enum5, enum6, enum7, enum8, - enum9, enum10, enum11, enum12, enum13, + enum9, enum10, enum11, enum12, enum13, enum14, }); Napi::Object jobEnum = Napi::Object::New(env); diff --git a/Flowee.cpp b/Flowee.cpp index 7957833..14f15f1 100644 --- a/Flowee.cpp +++ b/Flowee.cpp @@ -1,6 +1,6 @@ /* * This file is part of the Flowee project - * Copyright (C) 2019 Tom Zander + * Copyright (C) 2019-2021 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 @@ -118,6 +118,8 @@ Napi::Object Flowee::populateTransaction(Napi::Env env, const Blockchain::Transa tx.Set("fullTxData", wrap(env, transaction.fullTxData)); tx.Set("txid", binaryHash ? wrap(env, transaction.txid) : hashToString(env, transaction.txid)); + if (transaction.fees != -1) + tx.Set("fees", Napi::Number::From(env, transaction.fees)); Napi::Array inputs = Napi::Array::New(env, transaction.inputs.size()); for (size_t i = 0 ; i < transaction.inputs.size(); ++i) { diff --git a/examples/transaction.js b/examples/transaction.js index 9fbbc53..b011186 100644 --- a/examples/transaction.js +++ b/examples/transaction.js @@ -14,7 +14,7 @@ var Flowee = new FloweeServices(); if (process.argv.length <= 2) { console.log("Fetch transaction\nUsage node transaction.js [txid]"); - console.log("Example address: b39fa6c39b99683ac8f456721b270786c627ecb246700888315991877024b983\n"); + console.log("Example txid: 2c0b2784bae08449e651f3718029cb09a12eb00d5c3a6adc326ba31819892880\n"); process.exit(); } @@ -23,7 +23,7 @@ function detailTx(txid) { jobs: [{ value: txid, type: Flowee.Job.FetchTx, - txFilter: [ Flowee.IncludeInputs, Flowee.IncludeOutputs ] + txFilter: [ Flowee.IncludeInputs, Flowee.IncludeOutputs , Flowee.IncludeTxFees] }], onTxAdded: function(transaction) { @@ -65,6 +65,7 @@ Flowee.connect().then(async function() { console.log(" script: " + output.script); console.log(" }"); } + console.log(" fees: " + tx.fees); const header = result[`block${tx.blockHeight}`]; console.log(" block: " + header.height); diff --git a/lib/index.js b/lib/index.js index f97b026..3478c98 100644 --- a/lib/index.js +++ b/lib/index.js @@ -78,6 +78,7 @@ class Flowee { this.IncludeOutputScripts = this.network.IncludeOutputScripts; this.IncludeOutputAddresses = this.network.IncludeOutputAddresses; this.IncludeOutputScriptHash = this.network.IncludeOutputScriptHash; + this.IncludeTxFees = this.network.IncludeTxFees; this.InfoLevel = this.network.InfoLevel; this.WarningLevel = this.network.WarningLevel; this.QuietLevel = this.network.QuietLevel;