mirror of
https://git.wownero.com/wownero/wownero-funding-system.git
synced 2024-08-15 00:53:45 +00:00
aeonfunding update for wownero
a lot more generic; a lot more configurable; UI goodness with accounting; wallet account support for ezmode
This commit is contained in:
parent
f473a4234e
commit
955de2544e
19 changed files with 361 additions and 173 deletions
|
@ -207,4 +207,4 @@ def such_xss(inp):
|
|||
line = '>%s' % line
|
||||
_lines.append(line)
|
||||
|
||||
return "\n".join(_lines)
|
||||
return "\n".join(_lines)
|
|
@ -1,10 +1,12 @@
|
|||
import settings
|
||||
import requests
|
||||
from requests.auth import HTTPDigestAuth
|
||||
|
||||
|
||||
class WowneroDaemon:
|
||||
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, label_name):
|
||||
|
@ -16,37 +18,65 @@ class WowneroDaemon:
|
|||
}
|
||||
return self._make_request(data)
|
||||
|
||||
def get_address(self, index):
|
||||
def create_account(self, pid):
|
||||
data = {
|
||||
'method': 'get_address',
|
||||
'params': {'address_index': [index], 'account_index': 0},
|
||||
'method': 'create_account',
|
||||
'params': {'label': '%s' % pid},
|
||||
'jsonrpc': '2.0',
|
||||
'id': '0'
|
||||
}
|
||||
return self._make_request(data)
|
||||
|
||||
def get_address(self, index, proposal_id):
|
||||
data = {
|
||||
'method': 'getaddress',
|
||||
'params': {'account_index': proposal_id, 'address_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)
|
||||
return result['result']
|
||||
except:
|
||||
return
|
||||
|
||||
def get_transfers_in(self, index):
|
||||
def get_transfers_in(self, index, proposal_id):
|
||||
data = {
|
||||
"method":"get_transfers",
|
||||
"params": {"pool": True, "in": True, "account_index": 0, "subaddr_indices": [index]},
|
||||
"params": {"pool": True, "in": True, "account_index": proposal_id},
|
||||
"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
|
||||
|
||||
d['amount_human'] = float(d['amount'])/1e12
|
||||
return {
|
||||
'sum': sum([float(z['amount'])/1e11 for z in data]),
|
||||
'sum': sum([float(z['amount'])/1e12 for z in data]),
|
||||
'txs': data
|
||||
}
|
||||
|
||||
def get_transfers_out(self, index, proposal_id):
|
||||
data = {
|
||||
"method":"get_transfers",
|
||||
"params": {"pool": True, "out": True, "account_index": proposal_id},
|
||||
"jsonrpc": "2.0",
|
||||
"id": "0",
|
||||
}
|
||||
data = self._make_request(data)
|
||||
data = data['result'].get('out', [])
|
||||
for d in data:
|
||||
d['amount_human'] = float(d['amount'])/1e12
|
||||
return {
|
||||
'sum': sum([float(z['amount'])/1e12 for z in data]),
|
||||
'txs': data
|
||||
}
|
||||
|
||||
def _make_request(self, data):
|
||||
r = requests.post(self.url, json=data, headers=self.headers)
|
||||
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()
|
||||
return r.json()
|
|
@ -1,44 +1,39 @@
|
|||
from datetime import datetime, date
|
||||
|
||||
import requests
|
||||
from flask import g
|
||||
from flask.json import JSONEncoder
|
||||
|
||||
import json
|
||||
import settings
|
||||
|
||||
|
||||
def json_encoder(obj):
|
||||
if isinstance(obj, (datetime, date)):
|
||||
return obj.isoformat()
|
||||
raise TypeError ("Type %s not serializable" % type(obj))
|
||||
|
||||
|
||||
class Summary:
|
||||
@staticmethod
|
||||
def fetch_prices():
|
||||
if hasattr(g, 'wowfunding_prices') and g.wow_prices:
|
||||
return g.wow_prices
|
||||
|
||||
from wowfunding.factory import cache
|
||||
cache_key = 'wowfunding_prices'
|
||||
if hasattr(g, 'funding_prices') and g.coin_prices:
|
||||
return g.coin_prices
|
||||
from funding.factory import cache
|
||||
cache_key = 'funding_prices'
|
||||
data = cache.get(cache_key)
|
||||
if data:
|
||||
return data
|
||||
data = {
|
||||
'wow-btc': price_tradeogre_wow_btc(),
|
||||
'coin-btc': coin_btc_value(),
|
||||
'btc-usd': price_cmc_btc_usd()
|
||||
}
|
||||
|
||||
cache.set(cache_key, data=data, expiry=7200)
|
||||
g.wow_prices = data
|
||||
g.coin_prices = data
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
def fetch_stats(purge=False):
|
||||
from wowfunding.factory import db_session
|
||||
from wowfunding.orm.orm import Proposal, User, Comment
|
||||
from wowfunding.factory import cache
|
||||
cache_key = 'wowfunding_stats'
|
||||
from funding.factory import db_session
|
||||
from funding.orm.orm import Proposal, User, Comment
|
||||
from funding.factory import cache
|
||||
cache_key = 'funding_stats'
|
||||
data = cache.get(cache_key)
|
||||
if data and not purge:
|
||||
return data
|
||||
|
@ -65,7 +60,6 @@ class Summary:
|
|||
cache.set(cache_key, data=data, expiry=300)
|
||||
return data
|
||||
|
||||
|
||||
def price_cmc_btc_usd():
|
||||
headers = {'User-Agent': 'Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0'}
|
||||
try:
|
||||
|
@ -75,8 +69,7 @@ def price_cmc_btc_usd():
|
|||
except:
|
||||
return
|
||||
|
||||
|
||||
def price_tradeogre_wow_btc():
|
||||
def coin_btc_value():
|
||||
headers = {'User-Agent': 'Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0'}
|
||||
try:
|
||||
r = requests.get('https://tradeogre.com/api/v1/ticker/BTC-WOW', headers=headers)
|
||||
|
@ -85,9 +78,8 @@ def price_tradeogre_wow_btc():
|
|||
except:
|
||||
return
|
||||
|
||||
|
||||
def wow_to_usd(wows: float, usd_per_btc: float, btc_per_wow: float):
|
||||
def coin_to_usd(amt: float, usd_per_btc: float, btc_per_coin: float):
|
||||
try:
|
||||
return round(usd_per_btc / (1.0 / (wows * btc_per_wow)), 2)
|
||||
return round(usd_per_btc / (1.0 / (amt * btc_per_coin)), 2)
|
||||
except:
|
||||
pass
|
|
@ -1,34 +1,32 @@
|
|||
from datetime import datetime
|
||||
from flask import session, g
|
||||
|
||||
import settings
|
||||
from wowfunding.bin.utils import Summary
|
||||
from wowfunding.factory import app, db_session
|
||||
from wowfunding.orm.orm import Proposal, User, Comment
|
||||
|
||||
from funding.bin.utils import Summary
|
||||
from funding.factory import app, db_session
|
||||
from funding.orm.orm import Proposal, User, Comment
|
||||
|
||||
@app.context_processor
|
||||
def templating():
|
||||
from flask.ext.login import current_user
|
||||
recent_comments = db_session.query(Comment).filter(Comment.automated == False).order_by(Comment.date_added.desc()).limit(10).all()
|
||||
recent_comments = db_session.query(Comment).filter(Comment.automated == False).order_by(Comment.date_added.desc()).limit(8).all()
|
||||
summary_data = Summary.fetch_stats()
|
||||
newest_users = db_session.query(User).filter(User.admin == False).order_by(User.registered_on.desc()).limit(5).all()
|
||||
return dict(logged_in=current_user.is_authenticated,
|
||||
current_user=current_user,
|
||||
funding_categories=settings.FUNDING_CATEGORIES,
|
||||
funding_statuses=settings.FUNDING_STATUSES,
|
||||
summary_data=summary_data,
|
||||
recent_comments=recent_comments)
|
||||
|
||||
recent_comments=recent_comments,
|
||||
newest_users=newest_users)
|
||||
|
||||
@app.before_request
|
||||
def before_request():
|
||||
pass
|
||||
|
||||
|
||||
@app.after_request
|
||||
def after_request(res):
|
||||
if hasattr(g, 'wowfunding_prices'):
|
||||
delattr(g, 'wowfunding_prices')
|
||||
if hasattr(g, 'funding_prices'):
|
||||
delattr(g, 'funding_prices')
|
||||
res.headers.add('Accept-Ranges', 'bytes')
|
||||
if settings.DEBUG:
|
||||
res.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
|
||||
|
@ -37,12 +35,10 @@ def after_request(res):
|
|||
res.headers['Cache-Control'] = 'public, max-age=0'
|
||||
return res
|
||||
|
||||
|
||||
@app.teardown_appcontext
|
||||
def shutdown_session(**kwargs):
|
||||
db_session.remove()
|
||||
|
||||
|
||||
@app.errorhandler(404)
|
||||
def error(err):
|
||||
return 'Error', 404
|
||||
return 'Error', 404
|
Loading…
Add table
Add a link
Reference in a new issue