From dd8ed2c2480e8c0c0dd115ef8f52f5e2ba69ca22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjam=C3=ADn=20Nogal?= Date: Sat, 25 Jan 2020 14:39:04 +0100 Subject: [PATCH] Horizon v0.24.0 added a `fee_charged` and `max_fee` object with information about max bid and actual fee paid for each transaction. --- src/responses/feestatsresponse.cpp | 116 ++++++++++++++++------ src/responses/feestatsresponse.h | 81 +++++++++------ test/responses/feestatsdeserializertest.h | 99 ++++++++++++------ 3 files changed, 209 insertions(+), 87 deletions(-) diff --git a/src/responses/feestatsresponse.cpp b/src/responses/feestatsresponse.cpp index 568c72f..284a53b 100644 --- a/src/responses/feestatsresponse.cpp +++ b/src/responses/feestatsresponse.cpp @@ -2,7 +2,44 @@ FeeStatsResponse::FeeStatsResponse(QNetworkReply* reply) :Response(reply) - ,m_min(0) + ,m_ledgerCapacityUsage(0) + ,m_lastLedgerBaseFee(0) + ,m_lastLedger(0) +{ + +} + + +FeeStatsResponse::~FeeStatsResponse(){} + + + +float FeeStatsResponse::getLedgerCapacityUsage() const { + return m_ledgerCapacityUsage; +} + +qint64 FeeStatsResponse::getLastLedgerBaseFee() const +{ + return m_lastLedgerBaseFee; +} + +qint64 FeeStatsResponse::getLastLedger() const +{ + return m_lastLedger; +} + +FeeDistribution FeeStatsResponse::getFeeCharged() const +{ + return m_feeCharged; +} + +FeeDistribution FeeStatsResponse::getMaxFee() const{ + return m_maxFee; +} + +FeeDistribution::FeeDistribution() + :m_min(0) + ,m_max(0) ,m_mode(0) ,m_p10(0) ,m_p20(0) @@ -15,79 +52,102 @@ FeeStatsResponse::FeeStatsResponse(QNetworkReply* reply) ,m_p90(0) ,m_p95(0) ,m_p99(0) - ,m_ledgerCapacityUsage(0) - ,m_lastLedgerBaseFee(0) - ,m_lastLedger(0) { } -FeeStatsResponse::~FeeStatsResponse(){} -qint64 FeeStatsResponse::getMin() const +qint64 FeeDistribution::getMin() const { return m_min; } -qint64 FeeStatsResponse::getMode() const +qint64 FeeDistribution::getMax() const +{ + return m_max; +} + +qint64 FeeDistribution::getMode() const { return m_mode; } -qint64 FeeStatsResponse::getP10() const{ +qint64 FeeDistribution::getP10() const{ return m_p10; } -qint64 FeeStatsResponse::getP20() const{ +qint64 FeeDistribution::getP20() const{ return m_p20; } -qint64 FeeStatsResponse::getP30() const{ +qint64 FeeDistribution::getP30() const{ return m_p30; } -qint64 FeeStatsResponse::getP40() const{ +qint64 FeeDistribution::getP40() const{ return m_p40; } -qint64 FeeStatsResponse::getP50() const{ +qint64 FeeDistribution::getP50() const{ return m_p50; } -qint64 FeeStatsResponse::getP60() const{ +qint64 FeeDistribution::getP60() const{ return m_p60; } -qint64 FeeStatsResponse::getP70() const{ +qint64 FeeDistribution::getP70() const{ return m_p70; } -qint64 FeeStatsResponse::getP80() const{ +qint64 FeeDistribution::getP80() const{ return m_p80; } -qint64 FeeStatsResponse::getP90() const{ +qint64 FeeDistribution::getP90() const{ return m_p90; } -qint64 FeeStatsResponse::getP95() const{ +qint64 FeeDistribution::getP95() const{ return m_p95; } -qint64 FeeStatsResponse::getP99() const{ +qint64 FeeDistribution::getP99() const{ return m_p99; } -float FeeStatsResponse::getLedgerCapacityUsage() const { - return m_ledgerCapacityUsage; -} - -qint64 FeeStatsResponse::getLastLedgerBaseFee() const +bool FeeDistribution::operator !=(FeeDistribution &feeDistribution) { - return m_lastLedgerBaseFee; -} - -qint64 FeeStatsResponse::getLastLedger() const + return (m_min != feeDistribution.m_min) || + (m_max != feeDistribution.m_max) || + (m_mode != feeDistribution.m_mode) || + (m_p10 != feeDistribution.m_p10) || + (m_p20 != feeDistribution.m_p20) || + (m_p30 != feeDistribution.m_p30) || + (m_p40 != feeDistribution.m_p40) || + (m_p50 != feeDistribution.m_p50) || + (m_p60 != feeDistribution.m_p60) || + (m_p70 != feeDistribution.m_p70) || + (m_p80 != feeDistribution.m_p80) || + (m_p90 != feeDistribution.m_p90) || + (m_p95 != feeDistribution.m_p95) || + (m_p99 != feeDistribution.m_p99); +} + +bool FeeDistribution::operator ==(FeeDistribution &feeDistribution) { - return m_lastLedger; + return (m_min == feeDistribution.m_min) && + (m_max == feeDistribution.m_max) && + (m_mode == feeDistribution.m_mode) && + (m_p10 == feeDistribution.m_p10) && + (m_p20 == feeDistribution.m_p20) && + (m_p30 == feeDistribution.m_p30) && + (m_p40 == feeDistribution.m_p40) && + (m_p50 == feeDistribution.m_p50) && + (m_p60 == feeDistribution.m_p60) && + (m_p70 == feeDistribution.m_p70) && + (m_p80 == feeDistribution.m_p80) && + (m_p90 == feeDistribution.m_p90) && + (m_p95 == feeDistribution.m_p95) && + (m_p99 == feeDistribution.m_p99); } diff --git a/src/responses/feestatsresponse.h b/src/responses/feestatsresponse.h index 1caf38d..0e83cf1 100644 --- a/src/responses/feestatsresponse.h +++ b/src/responses/feestatsresponse.h @@ -3,27 +3,26 @@ #include "response.h" -class FeeStatsResponse : public Response +class FeeDistribution { - Q_OBJECT - Q_PROPERTY(qint64 min_accepted_fee MEMBER m_min) - Q_PROPERTY(qint64 mode_accepted_fee MEMBER m_mode) - - Q_PROPERTY(qint64 p10_accepted_fee MEMBER m_p10) - Q_PROPERTY(qint64 p20_accepted_fee MEMBER m_p20) - Q_PROPERTY(qint64 p30_accepted_fee MEMBER m_p30) - Q_PROPERTY(qint64 p40_accepted_fee MEMBER m_p40) - Q_PROPERTY(qint64 p50_accepted_fee MEMBER m_p50) - Q_PROPERTY(qint64 p60_accepted_fee MEMBER m_p60) - Q_PROPERTY(qint64 p70_accepted_fee MEMBER m_p70) - Q_PROPERTY(qint64 p80_accepted_fee MEMBER m_p80) - Q_PROPERTY(qint64 p90_accepted_fee MEMBER m_p90) - Q_PROPERTY(qint64 p95_accepted_fee MEMBER m_p95) - Q_PROPERTY(qint64 p99_accepted_fee MEMBER m_p99) - Q_PROPERTY(float ledger_capacity_usage MEMBER m_ledgerCapacityUsage) - Q_PROPERTY(qint64 last_ledger_base_fee MEMBER m_lastLedgerBaseFee) - Q_PROPERTY(qint64 last_ledger MEMBER m_lastLedger) + Q_GADGET + Q_PROPERTY(qint64 min MEMBER m_min) + Q_PROPERTY(qint64 max MEMBER m_max) + Q_PROPERTY(qint64 mode MEMBER m_mode) + + Q_PROPERTY(qint64 p10 MEMBER m_p10) + Q_PROPERTY(qint64 p20 MEMBER m_p20) + Q_PROPERTY(qint64 p30 MEMBER m_p30) + Q_PROPERTY(qint64 p40 MEMBER m_p40) + Q_PROPERTY(qint64 p50 MEMBER m_p50) + Q_PROPERTY(qint64 p60 MEMBER m_p60) + Q_PROPERTY(qint64 p70 MEMBER m_p70) + Q_PROPERTY(qint64 p80 MEMBER m_p80) + Q_PROPERTY(qint64 p90 MEMBER m_p90) + Q_PROPERTY(qint64 p95 MEMBER m_p95) + Q_PROPERTY(qint64 p99 MEMBER m_p99) qint64 m_min; + qint64 m_max; qint64 m_mode; qint64 m_p10; @@ -37,18 +36,12 @@ class FeeStatsResponse : public Response qint64 m_p90; qint64 m_p95; qint64 m_p99; - float m_ledgerCapacityUsage; - - - qint64 m_lastLedgerBaseFee; - qint64 m_lastLedger; - public: - Q_INVOKABLE explicit FeeStatsResponse(QNetworkReply* reply=nullptr); - virtual ~FeeStatsResponse(); - + FeeDistribution(); qint64 getMin() const; + qint64 getMax() const; + qint64 getMode() const; qint64 getP10() const; @@ -73,14 +66,46 @@ class FeeStatsResponse : public Response qint64 getP99() const; + bool operator !=(FeeDistribution& feeDistribution); + bool operator ==(FeeDistribution& feeDistribution); +}; + +class FeeStatsResponse : public Response +{ + Q_OBJECT + Q_PROPERTY(float ledger_capacity_usage MEMBER m_ledgerCapacityUsage) + Q_PROPERTY(qint64 last_ledger_base_fee MEMBER m_lastLedgerBaseFee) + Q_PROPERTY(qint64 last_ledger MEMBER m_lastLedger) + Q_PROPERTY(FeeDistribution fee_charged MEMBER m_feeCharged) + Q_PROPERTY(FeeDistribution max_fee MEMBER m_maxFee) + + float m_ledgerCapacityUsage; + + + qint64 m_lastLedgerBaseFee; + qint64 m_lastLedger; + FeeDistribution m_feeCharged; + FeeDistribution m_maxFee; + +public: + Q_INVOKABLE explicit FeeStatsResponse(QNetworkReply* reply=nullptr); + virtual ~FeeStatsResponse(); + + float getLedgerCapacityUsage() const; qint64 getLastLedgerBaseFee() const; qint64 getLastLedger() const; + FeeDistribution getFeeCharged() const; + + FeeDistribution getMaxFee() const; + }; +Q_DECLARE_METATYPE(FeeDistribution) + #endif // FEESTATSRESPONSE_H diff --git a/test/responses/feestatsdeserializertest.h b/test/responses/feestatsdeserializertest.h index 24f0732..4db241d 100644 --- a/test/responses/feestatsdeserializertest.h +++ b/test/responses/feestatsdeserializertest.h @@ -9,23 +9,42 @@ class FeeStatsDeserializerTest: public QObject { Q_OBJECT const QByteArray json = "{\n" - " \"last_ledger\": \"20882791\",\n" - " \"last_ledger_base_fee\": \"100\",\n" - " \"ledger_capacity_usage\": \"0.97\",\n" - " \"min_accepted_fee\": \"101\",\n" - " \"mode_accepted_fee\": \"102\",\n" - " \"p10_accepted_fee\": \"103\",\n" - " \"p20_accepted_fee\": \"104\",\n" - " \"p30_accepted_fee\": \"105\",\n" - " \"p40_accepted_fee\": \"106\",\n" - " \"p50_accepted_fee\": \"107\",\n" - " \"p60_accepted_fee\": \"108\",\n" - " \"p70_accepted_fee\": \"109\",\n" - " \"p80_accepted_fee\": \"110\",\n" - " \"p90_accepted_fee\": \"111\",\n" - " \"p95_accepted_fee\": \"112\",\n" - " \"p99_accepted_fee\": \"113\"" - "}"; + " \"last_ledger\": \"22606298\",\n" + " \"last_ledger_base_fee\": \"100\",\n" + " \"ledger_capacity_usage\": \"0.97\",\n" + " \"max_fee\": {\n" + " \"min\": \"130\",\n" + " \"max\": \"8000\",\n" + " \"mode\": \"250\",\n" + " \"p10\": \"150\",\n" + " \"p20\": \"200\",\n" + " \"p30\": \"300\",\n" + " \"p40\": \"400\",\n" + " \"p50\": \"500\",\n" + " \"p60\": \"1000\",\n" + " \"p70\": \"2000\",\n" + " \"p80\": \"3000\",\n" + " \"p90\": \"4000\",\n" + " \"p95\": \"5000\",\n" + " \"p99\": \"8000\"\n" + " },\n" + " \"fee_charged\": {\n" + " \"min\": \"100\",\n" + " \"max\": \"102\",\n" + " \"mode\": \"101\",\n" + " \"p10\": \"103\",\n" + " \"p20\": \"104\",\n" + " \"p30\": \"105\",\n" + " \"p40\": \"106\",\n" + " \"p50\": \"107\",\n" + " \"p60\": \"108\",\n" + " \"p70\": \"109\",\n" + " \"p80\": \"110\",\n" + " \"p90\": \"111\",\n" + " \"p95\": \"112\",\n" + " \"p99\": \"113\"\n" + " }\n" + "}"; public: @@ -41,22 +60,40 @@ private slots: void testDeserialize() { FeeStatsResponse stats; stats.loadFromJson(json); - QCOMPARE(stats.getLastLedger(),20882791); + QCOMPARE(stats.getLastLedger(),22606298); QCOMPARE(stats.getLastLedgerBaseFee(),100); QCOMPARE(stats.getLedgerCapacityUsage(),0.97f); - QCOMPARE(stats.getMin(),101); - QCOMPARE(stats.getMode(),102); - QCOMPARE(stats.getP10(),103); - QCOMPARE(stats.getP20(),104); - QCOMPARE(stats.getP30(),105); - QCOMPARE(stats.getP40(),106); - QCOMPARE(stats.getP50(),107); - QCOMPARE(stats.getP60(),108); - QCOMPARE(stats.getP70(),109); - QCOMPARE(stats.getP80(),110); - QCOMPARE(stats.getP90(),111); - QCOMPARE(stats.getP95(),112); - QCOMPARE(stats.getP99(),113); + FeeDistribution maxFee = stats.getMaxFee(); + QCOMPARE(maxFee.getMin(),130); + QCOMPARE(maxFee.getMax(),8000); + QCOMPARE(maxFee.getMode(),250); + QCOMPARE(maxFee.getP10(),150); + QCOMPARE(maxFee.getP20(),200); + QCOMPARE(maxFee.getP30(),300); + QCOMPARE(maxFee.getP40(),400); + QCOMPARE(maxFee.getP50(),500); + QCOMPARE(maxFee.getP60(),1000); + QCOMPARE(maxFee.getP70(),2000); + QCOMPARE(maxFee.getP80(),3000); + QCOMPARE(maxFee.getP90(),4000); + QCOMPARE(maxFee.getP95(),5000); + QCOMPARE(maxFee.getP99(),8000); + + FeeDistribution feeCharged = stats.getFeeCharged(); + QCOMPARE(feeCharged.getMin(),100); + QCOMPARE(feeCharged.getMax(),102); + QCOMPARE(feeCharged.getMode(),101); + QCOMPARE(feeCharged.getP10(),103); + QCOMPARE(feeCharged.getP20(),104); + QCOMPARE(feeCharged.getP30(),105); + QCOMPARE(feeCharged.getP40(),106); + QCOMPARE(feeCharged.getP50(),107); + QCOMPARE(feeCharged.getP60(),108); + QCOMPARE(feeCharged.getP70(),109); + QCOMPARE(feeCharged.getP80(),110); + QCOMPARE(feeCharged.getP90(),111); + QCOMPARE(feeCharged.getP95(),112); + QCOMPARE(feeCharged.getP99(),113); } };