def test_prepareLogging(tmp_path): path = tmp_path / "test.log" helpers.prepareLogging(filepath=path) logger = helpers.getLogger("1") logger1 = logger assert logger.getEffectiveLevel() == logging.INFO logger.info("something") assert path.is_file() helpers.prepareLogging(filepath=path, logLvl=logging.DEBUG) logger = helpers.getLogger("2") assert logger.getEffectiveLevel() == logging.DEBUG helpers.prepareLogging( filepath=path, logLvl=logging.INFO, lvlMap={ "1": logging.NOTSET, "3": logging.WARNING }, ) logger = helpers.getLogger("3") assert logger.getEffectiveLevel() == logging.WARNING assert logger1.getEffectiveLevel() == logging.NOTSET
def initLogging(self): """ Initialize logging for the entire app. """ logDir = os.path.join(config.DATA_DIR, "logs") helpers.mkdir(logDir) logFilePath = os.path.join(logDir, "tinydecred.log") helpers.prepareLogging( logFilePath, logLvl=self.cfg.logLevel, lvlMap=self.cfg.moduleLevels ) log = helpers.getLogger("APP") log.info("configuration file at %s" % config.CONFIG_PATH) log.info("data directory at %s" % config.DATA_DIR) return log
from decred.util.encode import ByteArray from flask import Flask, abort, jsonify, render_template, request from challenges import SockAddr from tcp import ConnectionPool MEDIA_ROOT = Path("./static") ChallengeServerPort = 54345 MebiByte = 1024 * 1024 MaxChallengesPerRequest = 20 log = helpers.getLogger("WINATOMS") app = Flask(__name__) if "WINATOMS_RELOAD_TEMPLATES" in os.environ: print( "WARNING: Running with template auto-reload enabled. Disable this feature in production" ) app.config['TEMPLATES_AUTO_RELOAD'] = True users = {} backlog = deque(maxlen=10) pool = ConnectionPool(SockAddr)
import calendar import json import time from urllib.parse import urlencode, urljoin, urlsplit, urlunsplit from decred import DecredError from decred.crypto import crypto from decred.dcr import addrlib from decred.util import database, tinyhttp, ws from decred.util.encode import ByteArray from decred.util.helpers import formatTraceback, getLogger, makeWebsocketURL from . import account, agenda, txscript from .wire import msgblock, msgtx, wire log = getLogger("DCRDATA") VERSION = "0.0.1" GET_HEADERS = {"User-Agent": "PyDcrData/%s" % VERSION} POST_HEADERS = { "User-Agent": "tinydecred/%s" % VERSION, "Content-Type": "application/json; charset=utf-8", } WS_DONE = object() # These two come from dcrdata, and are potentially subject to change, though # unlikely. MaxInsightAddrsTxns = 250 AddrsPerRequest = 25
""" Copyright (c) 2020, the Decred developers """ import time from decred.dcr import addrlib, rpc from decred.dcr.wire.msgblock import BlockHeader from decred.util import database, helpers from decred.util.encode import ByteArray log = helpers.getLogger("blockchain") class LocalNode: """ LocalNode is a Blockchain based on an authenticated dcrd websocket connection. """ def __init__(self, netParams, dbPath, url, user, pw, certPath=None): """ Args: netParams (module): The network parameters. dbPath (str or Path): A path to a database file for use by the LocalNode. url (str): The URL for the local node, with protocol. user (str): The user name for authenticating the connection. pw (str): The password for authenticating the connection. certPath (str or Path): A filepath to the dcrd TLS certificate. """
import redis from base58 import b58encode from decred.crypto import crypto, opcode from decred.crypto.secp256k1.curve import generateKey from decred.dcr import nets, txscript from decred.dcr.addrlib import AddressScriptHash, decodeAddress from decred.dcr.dcrdata import WS_DONE, DcrdataBlockchain from decred.dcr.wire import msgtx from decred.util import helpers from decred.util.encode import ByteArray import tcp FEED_CHANNEL = "winatoms-feed" log = helpers.getLogger("CHALLENGES") DummyHash = ByteArray("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef") MinDisplayFunding = 1e7 # 0.1 DCR of funding before display. # Standard network fee rate. feeRate = 10 # DCR / byte SockAddr = "/tmp/challenge.sock" _addrIDs = { nets.mainnet.Name: ByteArray("0786"), # Dw nets.testnet.Name: ByteArray("0fab"), # Tw nets.simnet.Name: ByteArray("0f17"), # Sw }
import asyncio import logging import asyncio_redis from decred.util import helpers from flask import Flask, jsonify, render_template from flask_uwsgi_websocket import AsyncioWebSocket from challenges import FEED_CHANNEL app = Flask(__name__) ws = AsyncioWebSocket(app) helpers.prepareLogging(logLvl=logging.DEBUG) log = helpers.getLogger("WS") @ws.route('/ws') async def feed(ws): # yield from ws.send("sup") asyncio.get_event_loop().create_task(redis_subscribe(ws, FEED_CHANNEL)) await asyncio_redis.Connection.create() while True: msg = await ws.receive() if msg is not None: log.warn( f"received unexpected message from websocket client: {msg}") else: break
import atexit import subprocess import sys from decred.dcr import nets from decred.util import helpers from challenges import ChallengeManager helpers.prepareLogging() log = helpers.getLogger("SERVER") netParams = nets.mainnet if "--testnet" in sys.argv: netParams = nets.testnet if "--simnet" in sys.argv: netParams = nets.simnet def runWSGI_http(): return subprocess.Popen([ "uwsgi", "--master", "--wsgi=winatoms:app", "--socket=/tmp/winatoms.sock", "--chmod-socket=666", "--vacuum", "--python-autoreload=1", "--die-on-term" ]) def runWSGI_ws(): return subprocess.Popen([ "uwsgi", "--http-websockets", "--asyncio=100", "--greenlet", "--master", "--wsgi=ws:app", "--socket=/tmp/ws.sock",
""" Copyright (c) 2019, Brian Stafford Copyright (c) 2019, the Decred developers See LICENSE for detail PyQt5 utilities. """ import re from PyQt5 import QtCore, QtGui, QtWidgets from decred.util import helpers log = helpers.getLogger("QUTIL") # Some colors, QT_WHITE = QtGui.QColor("white") WHITE_PALETTE = QtGui.QPalette(QT_WHITE) # Alignments, ALIGN_LEFT = QtCore.Qt.AlignLeft ALIGN_CENTER = QtCore.Qt.AlignCenter ALIGN_RIGHT = QtCore.Qt.AlignRight ALIGN_TOP = QtCore.Qt.AlignTop ALIGN_BOTTOM = QtCore.Qt.AlignBottom # Layout directions. HORIZONTAL = "horizontal" VERTICAL = "vertical" GRID = "grid"
Copyright (c) 2019-2020, The Decred developers See LICENSE for details """ from pathlib import Path from decred import DecredError from decred.crypto import crypto, mnemonic, rando from decred.dcr import nets from decred.dcr.dcrdata import DcrdataBlockchain from decred.util import chains, database, encode, helpers from decred.util.helpers import mkdir from . import accounts log = helpers.getLogger("WLLT") BipIDs = chains.BipIDs class DBKeys: cryptoKey = "cryptoKey".encode("utf-8") root = "root".encode("utf-8") keyParams = "keyParams".encode("utf-8") class Wallet: """ Wallet is a wallet. An application would use a Wallet to create and manager addresses and funds and to interact with various blockchains. Ideally, blockchain interactions are always handled through interfaces