From 0902acf633bade50dc5041ca5aeaccfd660be629 Mon Sep 17 00:00:00 2001 From: Sander Ferdinand Date: Sat, 20 Oct 2018 13:28:01 +0200 Subject: [PATCH 1/7] Faster incoming/outgoing transaction checking --- funding/cache.py | 2 +- funding/orm/orm.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/funding/cache.py b/funding/cache.py index 1878a9e..b5c308f 100644 --- a/funding/cache.py +++ b/funding/cache.py @@ -57,5 +57,5 @@ class WowCache: except: return {} - def set(self, key: str, data: dict, expiry = 300): + def set(self, key: str, data: dict, expiry=300): self._cache.set(key, json.dumps(data, default=json_encoder), ex=expiry) diff --git a/funding/orm/orm.py b/funding/orm/orm.py index 6ccc5a7..3114397 100644 --- a/funding/orm/orm.py +++ b/funding/orm/orm.py @@ -196,7 +196,7 @@ class Proposal(base): if not isinstance(data, dict): print('error; get_transfers_in; %d' % self.id) return rtn - cache.set(cache_key, data=data, expiry=300) + cache.set(cache_key, data=data, expiry=60) except Exception as ex: print('error; get_transfers_in; %d' % self.id) return rtn @@ -241,7 +241,7 @@ class Proposal(base): if not isinstance(data, dict): print('error; get_transfers_out; %d' % self.id) return rtn - cache.set(cache_key, data=data, expiry=300) + cache.set(cache_key, data=data, expiry=60) except: print('error; get_transfers_out; %d' % self.id) return rtn From 7b177679af2d71caf4b7537b44d794c9a4ab9536 Mon Sep 17 00:00:00 2001 From: Sander Ferdinand Date: Sat, 20 Oct 2018 14:52:45 +0200 Subject: [PATCH 2/7] Faster exchange rates updates --- funding/bin/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/funding/bin/utils.py b/funding/bin/utils.py index 3ba8672..0602b91 100644 --- a/funding/bin/utils.py +++ b/funding/bin/utils.py @@ -30,7 +30,7 @@ class Summary: 'coin-btc': coin_btc_value(), 'btc-usd': price_cmc_btc_usd() } - cache.set(cache_key, data=data, expiry=7200) + cache.set(cache_key, data=data, expiry=1200) g.coin_prices = data return data From 03db09423c1a80a61af9d27c6ac36410a305cf5b Mon Sep 17 00:00:00 2001 From: Sander Ferdinand Date: Sat, 20 Oct 2018 14:57:22 +0200 Subject: [PATCH 3/7] Fetch txs from pool --- funding/bin/daemon.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/funding/bin/daemon.py b/funding/bin/daemon.py index f21ffee..efd9ea1 100644 --- a/funding/bin/daemon.py +++ b/funding/bin/daemon.py @@ -102,7 +102,8 @@ class Daemon: } data = self._make_request(data) - data = data['result'].get('in', []) + data = data['result'] + data = data.get('in', []) + data.get('pool', []) # filter by current proposal txs = [tx for tx in data if tx.get('address') == address['address']] @@ -136,7 +137,8 @@ class Daemon: } data = self._make_request(data) - data = data['result'].get('out', []) + data = data['result'] + data = data.get('out', []) + data.get('pool', []) # filter by current proposal txs = [tx for tx in data if tx.get('address') == address['address']] From fe64d300fe8444dd7549ab60cfd2b7dbaf5565b8 Mon Sep 17 00:00:00 2001 From: Sander Ferdinand Date: Sat, 20 Oct 2018 15:07:33 +0200 Subject: [PATCH 4/7] Dont look in pool for outgoing transactions --- funding/bin/daemon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/funding/bin/daemon.py b/funding/bin/daemon.py index efd9ea1..6cd7e71 100644 --- a/funding/bin/daemon.py +++ b/funding/bin/daemon.py @@ -131,7 +131,7 @@ class Daemon: data = { "method": "get_transfers", - "params": {"pool": True, "out": True, "account_index": index}, + "params": {"pool": False, "out": True, "account_index": index}, "jsonrpc": "2.0", "id": "0", } From 1a997aace6bc8e46481213b3a82a5658122c2a62 Mon Sep 17 00:00:00 2001 From: Sander Ferdinand Date: Sat, 20 Oct 2018 16:25:42 +0200 Subject: [PATCH 5/7] Some templating changes --- funding/static/css/wow.css | 12 ++++++++---- funding/templates/proposal/macros/table.html | 2 +- funding/templates/proposal/proposal.html | 4 +--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/funding/static/css/wow.css b/funding/static/css/wow.css index b1944a6..50151aa 100644 --- a/funding/static/css/wow.css +++ b/funding/static/css/wow.css @@ -135,12 +135,12 @@ body { } .table-hover tbody tr:hover { - background-color: rgba(0,0,0,.075); + background-color: rgba(0,0,0,.055); } .table th, .table td { - border-top: 1px solid #008926; - padding-top: .3rem; + border-top: 1px solid #00000029; + padding-top: .65rem; } .table-tilted{ @@ -169,7 +169,7 @@ body { } .table thead th { - border-bottom: 1px solid #008926 !important; + border-bottom: 1px solid #00000029 !important; border-top: none; font-size: 14px; } @@ -612,4 +612,8 @@ ul.b { .proposal_qr{ margin-top:8px; margin-bottom:8px; +} + +.table-proposal tr { + background: #00000005; } \ No newline at end of file diff --git a/funding/templates/proposal/macros/table.html b/funding/templates/proposal/macros/table.html index 5d1c372..8efc515 100644 --- a/funding/templates/proposal/macros/table.html +++ b/funding/templates/proposal/macros/table.html @@ -2,7 +2,7 @@ - + {% if _proposals and _proposals[0].status >= 2 %} diff --git a/funding/templates/proposal/proposal.html b/funding/templates/proposal/proposal.html index 05a82cc..1ea297b 100644 --- a/funding/templates/proposal/proposal.html +++ b/funding/templates/proposal/proposal.html @@ -51,7 +51,6 @@ {% endif %}

-
{% if proposal.status in [2,3] %}
@@ -124,12 +123,11 @@
-

-
+
Donation address:
{% if proposal.addr_donation %}{{ proposal.addr_donation }}{% else %}None generated yet{% endif %}
From 470173db636dc8afb4daad021eb301172a11493d Mon Sep 17 00:00:00 2001 From: Sander Ferdinand Date: Sat, 20 Oct 2018 16:26:54 +0200 Subject: [PATCH 6/7] Refactor Daemon._make_request() --- funding/bin/daemon.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/funding/bin/daemon.py b/funding/bin/daemon.py index 6cd7e71..cc89bbc 100644 --- a/funding/bin/daemon.py +++ b/funding/bin/daemon.py @@ -152,10 +152,10 @@ class Daemon: } def _make_request(self, data): - if self.username: - if self.password: - r = requests.post(self.url, auth=HTTPDigestAuth(settings.RPC_USERNAME, settings.RPC_PASSWORD), json=data, headers=self.headers) - else: - r = requests.post(self.url, json=data, headers=self.headers) + options = {'json': data, 'headers': self.headers} + if self.username and self.password: + options['auth'] = HTTPDigestAuth(settings.RPC_USERNAME, settings.RPC_PASSWORD) + + r = requests.post(self.url, **options) r.raise_for_status() - return r.json() \ No newline at end of file + return r.json() From 92eac2ee20e0343e5fa76fc6e813c8977f1b282a Mon Sep 17 00:00:00 2001 From: Sander Ferdinand Date: Sat, 20 Oct 2018 18:25:58 +0200 Subject: [PATCH 7/7] Some template changes --- funding/orm/orm.py | 10 ++-- funding/templates/comments.html | 63 ++------------------- funding/templates/proposal/proposal.html | 72 +++++++++++++++--------- 3 files changed, 56 insertions(+), 89 deletions(-) diff --git a/funding/orm/orm.py b/funding/orm/orm.py index 3114397..66af310 100644 --- a/funding/orm/orm.py +++ b/funding/orm/orm.py @@ -246,7 +246,9 @@ class Proposal(base): print('error; get_transfers_out; %d' % self.id) return rtn + data['remaining_pct'] = 0.0 prices = Summary.fetch_prices() + for tx in data['txs']: if prices: tx['amount_usd'] = coin_to_usd(amt=tx['amount_human'], btc_per_coin=prices['coin-btc'], usd_per_btc=prices['btc-usd']) @@ -259,10 +261,10 @@ class Proposal(base): data['pct'] = 0.0 data['spent'] = 0.0 - if data['spent']: - data['remaining_pct'] = 100 / float(data['sum'] / data['spent']) - else: - data['remaining_pct'] = 0.0 + cache_key_in = 'coin_balance_pid_%d' % self.id + data_in = cache.get(cache_key_in) + if data_in and data['spent']: + data['remaining_pct'] = 100 / float(data_in['sum'] / data['spent']) return data diff --git a/funding/templates/comments.html b/funding/templates/comments.html index a502051..a1bd5de 100644 --- a/funding/templates/comments.html +++ b/funding/templates/comments.html @@ -1,3 +1,5 @@ +{% from 'proposal/macros/comment.html' import comment_entry %} +
@@ -18,69 +20,14 @@ {% else %} - You need to be logged in to comment. + You need to be logged in to comment.
{% endif %}
- {% for c in proposal._comments %} - - + {% for c in proposal._comments if not c.automated %} + {{ comment_entry(c, proposal) }} {% endfor %}
diff --git a/funding/templates/proposal/proposal.html b/funding/templates/proposal/proposal.html index 1ea297b..bcd7cec 100644 --- a/funding/templates/proposal/proposal.html +++ b/funding/templates/proposal/proposal.html @@ -95,11 +95,14 @@
{{proposal.balance['available']|round(3) or 0 }} WOW Raised - {% if (proposal.funds_target-proposal.balance['available']|float|round(3)) > 0 %} - ({{ (proposal.funds_target-proposal.balance['available']|float|round(3)|int) }} WOW until goal) - {% else %} + {% set remaining = proposal.funds_target - proposal.balance['available']|float|round(3) %} + + {% if remaining > 0 %} + ({{ (proposal.funds_target - proposal.balance['available']|float|round(3)|int) }} WOW until goal) + {% elif remaining < 0 %} ({{ (proposal.balance['available']-proposal.funds_target|float|round(3)|int) }} WOW past goal!) {% endif %} +
@@ -112,7 +115,7 @@
{{proposal.spends['spent']|round(3) or 0}} WOW Paid out
-
+

@@ -201,36 +204,51 @@ {% endif %} -{% if proposal.spends['txs'] %} + {% if proposal.spends['txs'] %} +
+
+
+
Outgoing transactions ({{proposal.spends['txs']|length}})
+
+
    + {% for tx in proposal.spends['txs'] %} +
  • + {{tx['datetime'].strftime('%Y-%m-%d %H:%M')}} + Blockheight: {{tx['height']}} +
    + {{tx['txid'][:32]}}... + + - {{tx['amount_human']|round(3)}} WOW + {% if 'amount_usd' in tx %} + + ➞ $ {{tx['amount_usd']}} + + {% endif %} + +
  • + {% endfor %} +
+
+
+
+
+ + {% endif %} + + {% from 'proposal/macros/comment.html' import comment_entry %} +
-
Outgoing transactions ({{proposal.spends['txs']|length}})
-
-
    - {% for tx in proposal.spends['txs'] %} -
  • - {{tx['datetime'].strftime('%Y-%m-%d %H:%M')}} - Blockheight: {{tx['height']}} -
    - {{tx['txid'][:32]}}... - - - {{tx['amount_human']|round(3)}} WOW - {% if 'amount_usd' in tx %} - - ➞ $ {{tx['amount_usd']}} - - {% endif %} - -
  • - {% endfor %} -
+
Events
+
+ {% for c in proposal._comments if c.automated %} + {{ comment_entry(c, proposal) }} + {% endfor %}
- - {% endif %}
{{title}}{{title}} Username Date