Merge pull request #7 from skftn/camthegeek-pr
[Release] showing love for the wownerosupdate-readme
@ -0,0 +1,159 @@
|
||||
import settings
|
||||
import requests
|
||||
from requests.auth import HTTPDigestAuth
|
||||
|
||||
from funding.orm.orm import User
|
||||
|
||||
|
||||
class Daemon:
|
||||
def __init__(self):
|
||||
self.url = settings.RPC_LOCATION
|
||||
self.username = settings.RPC_USERNAME
|
||||
self.password = settings.RPC_PASSWORD
|
||||
self.headers = {"User-Agent": "Mozilla"}
|
||||
|
||||
def create_address(self, account_index, label_name):
|
||||
data = {
|
||||
'method': 'create_address',
|
||||
'params': {'account_index': account_index, 'label': 'p_%s' % label_name},
|
||||
'jsonrpc': '2.0',
|
||||
'id': '0'
|
||||
}
|
||||
|
||||
try:
|
||||
result = self._make_request(data)
|
||||
return result['result']
|
||||
except:
|
||||
return
|
||||
|
||||
def create_account(self, pid):
|
||||
data = {
|
||||
'method': 'create_account',
|
||||
'params': {'label': 'p_%s' % pid},
|
||||
'jsonrpc': '2.0',
|
||||
'id': '0'
|
||||
}
|
||||
try:
|
||||
result = self._make_request(data)
|
||||
return result['result']
|
||||
except:
|
||||
return
|
||||
|
||||
def get_accounts(self, proposal_id:int = None):
|
||||
data = {
|
||||
'method': 'get_accounts',
|
||||
'jsonrpc': '2.0',
|
||||
'id': '0'
|
||||
}
|
||||
try:
|
||||
result = self._make_request(data)
|
||||
result = result['result']
|
||||
|
||||
if isinstance(proposal_id, int):
|
||||
account_user = [acc for acc in result.get('subaddress_accounts', []) if acc['label'] == 'p_%d' % proposal_id]
|
||||
if account_user:
|
||||
return account_user[0]
|
||||
else:
|
||||
return
|
||||
|
||||
return result
|
||||
except Exception as ex:
|
||||
return
|
||||
|
||||
def get_address(self, account_index: int, proposal_id: int = None):
|
||||
data = {
|
||||
'method': 'getaddress',
|
||||
'params': {'account_index': account_index},
|
||||
'jsonrpc': '2.0',
|
||||
'id': '0'
|
||||
}
|
||||
try:
|
||||
result = self._make_request(data)
|
||||
addresses = result['result']['addresses']
|
||||
|
||||
if isinstance(proposal_id, int):
|
||||
address = [addy for addy in addresses if addy['label'] == 'p_%d' % proposal_id]
|
||||
if address:
|
||||
return address[0]
|
||||
else:
|
||||
return
|
||||
return addresses
|
||||
except:
|
||||
return
|
||||
|
||||
def get_transfers_in(self, proposal):
|
||||
daemon = Daemon()
|
||||
|
||||
account = daemon.get_accounts(proposal.id)
|
||||
if not account:
|
||||
raise Exception('wallet error; pid not found found')
|
||||
index = account['account_index']
|
||||
|
||||
address = daemon.get_address(index, proposal_id=proposal.id)
|
||||
if not address:
|
||||
print('Could not fetch transfers_in for proposal id %d' % proposal.id)
|
||||
return {'sum': [], 'txs': []}
|
||||
|
||||
data = {
|
||||
"method": "get_transfers",
|
||||
"params": {"pool": True, "in": True, "account_index": index},
|
||||
"jsonrpc": "2.0",
|
||||
"id": "0",
|
||||
}
|
||||
|
||||
data = self._make_request(data)
|
||||
data = data['result'].get('in', [])
|
||||
|
||||
# filter by current proposal
|
||||
txs = [tx for tx in data if tx.get('address') == address['address']]
|
||||
|
||||
for d in txs:
|
||||
d['amount_human'] = float(d['amount'])/1e11
|
||||
|
||||
return {
|
||||
'sum': sum([float(z['amount'])/1e11 for z in txs]),
|
||||
'txs': txs
|
||||
}
|
||||
|
||||
def get_transfers_out(self, proposal):
|
||||
daemon = Daemon()
|
||||
|
||||
account = daemon.get_accounts(proposal.id)
|
||||
if not account:
|
||||
raise Exception('wallet error; pid not found found')
|
||||
index = account['account_index']
|
||||
|
||||
address = daemon.get_address(index, proposal_id=proposal.id)
|
||||
if not address:
|
||||
print('Could not fetch transfers_in for proposal id %d' % proposal.id)
|
||||
return {'sum': [], 'txs': []}
|
||||
|
||||
data = {
|
||||
"method": "get_transfers",
|
||||
"params": {"pool": True, "out": True, "account_index": index},
|
||||
"jsonrpc": "2.0",
|
||||
"id": "0",
|
||||
}
|
||||
|
||||
data = self._make_request(data)
|
||||
data = data['result'].get('out', [])
|
||||
|
||||
# filter by current proposal
|
||||
txs = [tx for tx in data if tx.get('address') == address['address']]
|
||||
|
||||
for d in txs:
|
||||
d['amount_human'] = float(d['amount'])/1e11
|
||||
|
||||
return {
|
||||
'sum': sum([float(z['amount'])/1e11 for z in txs]),
|
||||
'txs': txs
|
||||
}
|
||||
|
||||
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)
|
||||
r.raise_for_status()
|
||||
return r.json()
|
Before Width: | Height: | Size: 89 KiB After Width: | Height: | Size: 89 KiB |
Before Width: | Height: | Size: 182 KiB After Width: | Height: | Size: 182 KiB |
Before Width: | Height: | Size: 7.7 KiB After Width: | Height: | Size: 7.7 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 111 B After Width: | Height: | Size: 111 B |
Before Width: | Height: | Size: 175 KiB After Width: | Height: | Size: 175 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 67 KiB After Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 180 KiB After Width: | Height: | Size: 180 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
@ -0,0 +1,70 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
|
||||
{% if user %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<span class="form-text text-muted" style="margin-top: -2px;">
|
||||
Proposals made by '{{user.username}}'
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
{% if user.proposals %}
|
||||
<table class="table table-proposal table-hover" style="margin-bottom:6px;">
|
||||
<tbody>
|
||||
<th>Proposal</th>
|
||||
<th>Category</th>
|
||||
<th>Target Amount</th>
|
||||
<th>Amount Raised</th>
|
||||
<th>Date</th>
|
||||
{% for p in user.proposals | sort(attribute='date_added', reverse=True) %}
|
||||
<tr>
|
||||
<td><b><a href="/proposal/{{ p.id }}">{{ p.headline | truncate(42)}}</a></b></td>
|
||||
<td><a href="/proposals?cat={{ p.category }}">{{ p.category |capitalize}}</a></td>
|
||||
<td>{{p.funds_target}}</td>
|
||||
<td>{{p.funds_progress | round(3, 'floor')}}%</td>
|
||||
<td>{{ p.date_added.strftime('%Y-%m-%d') }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
This user has not submitted any proposals yet.
|
||||
{% endif %}
|
||||
<hr>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
Comments made by {{user.username}}
|
||||
{% if user.comments %}
|
||||
<table class="table table-proposal table-hover" style="margin-bottom:6px;">
|
||||
<tbody>
|
||||
<th>Comment</th>
|
||||
<th>Proposal</th>
|
||||
<th>Date</th>
|
||||
{% for y in user.comments | sort(attribute='date_added', reverse=True) %}
|
||||
<tr>
|
||||
<td><b><a href="/proposal/{{y.proposal.id}}#comment-{{ y.id }}">{{ y.message | truncate(32)}}</a></b></td>
|
||||
<td><a href="/proposal/{{y.proposal.id}}">#{{y.proposal.id }} {{ y.proposal.headline | truncate(32) }}</a></td>
|
||||
<td>{{ y.date_added.strftime('%Y-%m-%d') }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
This user has not submitted any proposals yet.
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
|
||||
</div>
|
||||
{% else %}
|
||||
No user found by that name.
|
||||
{% endif %}
|
||||
<!-- /.container -->
|
||||
{% endblock %}
|
@ -1,52 +0,0 @@
|
||||
import settings
|
||||
import requests
|
||||
|
||||
|
||||
class WowneroDaemon:
|
||||
def __init__(self):
|
||||
self.url = settings.RPC_LOCATION
|
||||
self.headers = {"User-Agent": "Mozilla"}
|
||||
|
||||
def create_address(self, label_name):
|
||||
data = {
|
||||
'method': 'create_address',
|
||||
'params': {'account_index': 0, 'label': label_name},
|
||||
'jsonrpc': '2.0',
|
||||
'id': '0'
|
||||
}
|
||||
return self._make_request(data)
|
||||
|
||||
def get_address(self, index):
|
||||
data = {
|
||||
'method': 'get_address',
|
||||
'params': {'address_index': [index], 'account_index': 0},
|
||||
'jsonrpc': '2.0',
|
||||
'id': '0'
|
||||
}
|
||||
try:
|
||||
result = self._make_request(data)
|
||||
return next(z for z in result['result']['addresses'] if z['address_index'] == index)
|
||||
except:
|
||||
return
|
||||
|
||||
def get_transfers_in(self, index):
|
||||
data = {
|
||||
"method":"get_transfers",
|
||||
"params": {"pool": True, "in": True, "account_index": 0, "subaddr_indices": [index]},
|
||||
"jsonrpc": "2.0",
|
||||
"id": "0",
|
||||
}
|
||||
data = self._make_request(data)
|
||||
data = data['result'].get('in', [])
|
||||
for d in data:
|
||||
d['amount_human'] = float(d['amount'])/1e11
|
||||
|
||||
return {
|
||||
'sum': sum([float(z['amount'])/1e11 for z in data]),
|
||||
'txs': data
|
||||
}
|
||||
|
||||
def _make_request(self, data):
|
||||
r = requests.post(self.url, json=data, headers=self.headers)
|
||||
r.raise_for_status()
|
||||
return r.json()
|
@ -1,43 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
|
||||
{% if user %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-lg-8">
|
||||
<span class="form-text text-muted" style="margin-top: -2px;">
|
||||
Details for '{{user.username}}'
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-8">
|
||||
{% if user.proposals %}
|
||||
<table class="table table-proposal table-hover" style="margin-bottom:6px;">
|
||||
<tbody>
|
||||
{% for p in user.proposals %}
|
||||
<tr>
|
||||
<td><b><a href="/proposal/{{ p.id }}">{{ p.headline }}</a></b></td>
|
||||
<td><a href="/user/{{ p.user.username }}">{{ p.user.username }}</a></td>
|
||||
<td>{{ p.date_added.strftime('%Y-%m-%d') }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
This user did not submit any proposals yet.
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% include 'sidebar.html' %}
|
||||
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
</div>
|
||||
{% else %}
|
||||
No user found by that name.
|
||||
{% endif %}
|
||||
<!-- /.container -->
|
||||
{% endblock %}
|