def __getattr__(self, name): if name.startswith('__') and name.endswith('__'): # Python internal stuff raise AttributeError # Create a callable to do the actual call f = lambda *args: BitcoinProxy(self.url)._call(name, *args) # Make debuggers show <function bitcoin.rpc.name> rather than <function # bitcoin.rpc.<lambda>> f.__name__ = name return f
def _handle_request(self, r): conf_file = os.path.join(self.bitcoin_dir, 'bitcoin.conf') brpc = BitcoinProxy(btc_conf_file=conf_file) method = r['method'] # If we have set a mock for this method reply with that instead of # forwarding the request. if method in self.mocks and type(method) == dict: return self.mocks[method] elif method in self.mocks and callable(self.mocks[method]): return self.mocks[method](r) try: reply = { "result": brpc._call(r['method'], *r.get('params', [])), "error": None, "id": r['id'] } except JSONRPCError as e: reply = {"error": e.error, "id": r['id']} return reply
def _handle_request(self, r): brpc = BitcoinProxy(btc_conf_file=self.bitcoind.conf_file) method = r['method'] # If we have set a mock for this method reply with that instead of # forwarding the request. if method in self.mocks and type(method) == dict: self.mock_counts[method] += 1 return self.mocks[method] elif method in self.mocks and callable(self.mocks[method]): self.mock_counts[method] += 1 return self.mocks[method](r) try: reply = { "result": brpc._call(r['method'], *r['params']), "error": None, "id": r['id'] } except JSONRPCError as e: reply = {"error": e.error, "code": -32603, "id": r['id']} self.request_count += 1 return reply
def __getattr__(self, name): if name.startswith("__") and name.endswith("__"): # Python internal stuff raise AttributeError # We want to hit the per-wallet API and python-bitcoinlib will not read # the cookie if we specify a custom URL.. with open(self.__cookie_path) as fd: authpair = fd.read() service_url = (f"http://{authpair}@localhost:{self.__port}/wallet" f"/{self.wallet_name}") # Create a callable to do the actual call proxy = BitcoinProxy(btc_conf_file=self.__btc_conf_file__, service_url=service_url) def f(*args): return proxy._call(name, *args) # Make debuggers show <function bitcoin.rpc.name> rather than <function # bitcoin.rpc.<lambda>> f.__name__ = name return f
def callback(*args): return BitcoinProxy(self.url)._call(name, *args)