Exemple #1
0
    def __init__(self, loop, syncer, config):
        self.host = config['rpc']['host']
        self.port = config['rpc']['port']
        self.loop = loop
        self.syncer = syncer
        self.global_message_queue = self.syncer.queues['RPCManager']
        #self.allowed_clients
        self.requests = {}
        self.up = True
        self.logger = logging.getLogger("RPCManager")

        rpc_manager_location = __file__
        web_wallet_dir = join(
            path_split(rpc_manager_location)[0], "web_wallet")
        self.app = web.Application(loop=self.loop)

        self.app.router.add_static('/', web_wallet_dir)
        self.app.router.add_route('*', '/rpc', self.handle)
        self.server = self.loop.create_server(self.app.make_handler(),
                                              self.host, self.port)
        asyncio.ensure_future(self.server, loop=loop)
        asyncio.ensure_future(self.check_queue())

        methods.add(self.ping)
        methods.add(self.getconnectioncount)
        methods.add(self.getheight)
        methods.add(self.getblocktemplate)
        methods.add(self.validatesolution)
        methods.add(self.getbalancestats)
        methods.add(self.getbalancelist)
        methods.add(self.getbalance)
        methods.add(self.sendtoaddress)
        methods.add(self.getnewaddress)
        methods.add(self.dumpprivkey)
        methods.add(self.importprivkey)
        methods.add(self.getsyncstatus)
Exemple #2
0
 async def start(self):
     app = web.Application()
     app.router.add_post('/', self._handle)
     runner = web.AppRunner(app)
     await runner.setup()
     methods.add(self.echo)
     methods.add(self.help)
     methods.add(self.estimatefee)
     methods.add(self.estimatesmartfee)
     methods.add(self.getbestblockhash)
     methods.add(self.getblockchaininfo)
     methods.add(self.getblockheader)
     methods.add(self.getblockhash)
     methods.add(self.getblock)
     methods.add(self.getblockcount)
     methods.add(self.getrawtransaction)
     methods.add(self.gettxout)
     methods.add(self.getpeerinfo)
     methods.add(self.sendrawtransaction)
     methods.add(self.stop)
     methods.add(self.getmempoolinfo)
     methods.add(self.getchaintxstats)
     methods.add(self.getmininginfo)
     methods.add(self.getrawmempool)
     methods.add(self.getnetworkinfo)
     methods.add(self.uptime)
     methods.add(self.getnettotals)
     methods.add(self.validateaddress)
     methods.add(self.dev_memorysummary, name="dev-gc-stats")
     methods.add(self.dev_collect, name="dev-gc-collect")
     return await web.TCPSite(runner, host=self.host,
                              port=self.port).start()
from jsonrpcserver.aio import methods
from jsonrpcserver.async_request import AsyncRequest


def async_test(f):
    def wrapper(*args, **kwargs):
        if inspect.iscoroutinefunction(f):
            future = f(*args, **kwargs)
        else:
            coroutine = asyncio.coroutine(f)
            future = coroutine(*args, **kwargs)
        asyncio.get_event_loop().run_until_complete(future)

    return wrapper


class MyMethods:
    async def foo(self):
        return "bar"


methods.add(MyMethods().foo)


class TestCall(TestCase):
    @async_test
    async def test_request(self):
        req = AsyncRequest({"jsonrpc": "2.0", "method": "foo", "id": 1})
        response = await req.call(methods)
        self.assertEqual("bar", response["result"])
Exemple #4
0
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

from hive.db.methods import (db_head_state, get_followers, get_following,
                             following_count, follower_count, get_user_feed,
                             get_blog_feed, get_discussions_by_sort_and_tag,
                             get_related_posts, payouts_total,
                             payouts_last_24h)

jrpc_methods = (db_head_state, get_followers, get_following, following_count,
                follower_count, get_user_feed, get_blog_feed,
                get_discussions_by_sort_and_tag, get_related_posts,
                payouts_total, payouts_last_24h)

for m in jrpc_methods:
    methods.add(m)

app = web.Application()
app['config'] = dict()

app['config']['hive.MAX_BLOCK_NUM_DIFF'] = 10
app['config']['hive.MAX_DB_ROW_RESULTS'] = 100000
app['config'][
    'hive.DB_QUERY_LIMIT'] = app['config']['hive.MAX_DB_ROW_RESULTS'] + 1
app['config']['hive.logger'] = logger


async def init_db(app):
    args = app['config']['args']
    db = make_url(args.database_url)
    engine = await create_engine(user=db.username,
Exemple #5
0
    def __init__(self, loop, syncer, config):
        self.host = config['rpc']['host']
        self.port = config['rpc']['port']
        self.loop = loop
        self.syncer = syncer
        self.global_message_queue = self.syncer.queues['RPCManager']
        #self.allowed_clients
        self.requests = {}
        self.up = True
        self.logger = logging.getLogger("RPCManager")
        default_log_level = logging.INFO
        if "logging" in config:  #debug, info, warning, error, critical
            loglevels = {
                "debug": logging.DEBUG,
                "info": logging.INFO,
                "warning": logging.WARNING,
                "error": logging.ERROR,
                "critical": logging.CRITICAL
            }
            if "base" in config["logging"] and config["logging"][
                    "base"] in loglevels:
                self.logger.setLevel(loglevels[config["logging"]["base"]])
            if "rpc" in config["logging"] and config["logging"][
                    "rpc"] in loglevels:
                #its ok to rewrite
                self.logger.setLevel(loglevels[config["logging"]["rpc"]])

        rpc_manager_location = __file__
        web_wallet_dir = join(
            path_split(rpc_manager_location)[0], "web_wallet")
        self.app = web.Application(loop=self.loop)
        self.loop.run_until_complete(
            setup(
                self.app,
                BasicAuth(config['rpc']['login'],
                          config['rpc']['password'],
                          "realm",
                          white_paths=['/'])))

        self.app.router.add_route('*', '/rpc', self.handle)
        self.app.router.add_route('*', '/', self.handle_root)
        self.app.router.add_static('/', web_wallet_dir)
        self.server = self.loop.create_server(self.app.make_handler(),
                                              self.host, self.port)
        asyncio.ensure_future(self.server, loop=loop)
        asyncio.ensure_future(self.check_queue())

        methods.add(self.ping)
        methods.add(self.getconnectioncount)
        methods.add(self.getheight)
        methods.add(self.getblocktemplate)
        methods.add(self.getwork)
        methods.add(self.submitwork)
        methods.add(self.validatesolution)
        methods.add(self.getbalancestats)
        methods.add(self.getbalancelist)
        methods.add(self.getbalance)
        methods.add(self.sendtoaddress)
        methods.add(self.getnewaddress)
        methods.add(self.dumpprivkey)
        methods.add(self.importprivkey)
        methods.add(self.getsyncstatus)
        methods.add(self.getblock)
        methods.add(self.getnodes)
        methods.add(self.connecttonode)
        methods.add(self.gettransactions)
        methods.add(self.getversion)
        methods.add(self.shutdown)

        methods.add(self.eth_getWork)
        methods.add(self.eth_submitWork)
        methods.add(self.eth_getBlockByNumber)
        self.no_auth_methods = [
            "eth_getWork", "eth_submitWork", "eth_getBlockByNumber"
        ]
Exemple #6
0
    async def start(self):
        """ Start remote admin server """
        methods.add(self.exec)
        methods.add(self.channels)
        methods.add(self.stop_channel)
        methods.add(self.start_channel)
        methods.add(self.list_msg)
        methods.add(self.replay_msg)
        methods.add(self.push_msg)

        start_server = websockets.serve(
            self.command,
            host=self.host,
            port=self.port,
            ssl=self.ssl,
            loop=self.loop
        )
        await start_server
Exemple #7
0
 def __missing__(self, key):
     methods.add(self.d.create_passthrough(key), key)
     return self[key]