Sets up an RPC connection to the bitcoind process. Returns False if unable to connect.
(self)
| 166 | self.log.debug("bitcoind started, waiting for RPC to come up") |
| 167 | |
| 168 | def wait_for_rpc_connection(self): |
| 169 | """Sets up an RPC connection to the bitcoind process. Returns False if unable to connect.""" |
| 170 | # Poll at a rate of four times per second |
| 171 | poll_per_s = 4 |
| 172 | for _ in range(poll_per_s * self.rpc_timeout): |
| 173 | if self.process.poll() is not None: |
| 174 | raise FailedToStartError(self._node_msg( |
| 175 | 'bitcoind exited with status {} during initialization'.format(self.process.returncode))) |
| 176 | try: |
| 177 | self.rpc = get_rpc_proxy(rpc_url(self.datadir, self.index, self.rpchost), self.index, timeout=self.rpc_timeout, coveragedir=self.coverage_dir) |
| 178 | self.rpc.getblockcount() |
| 179 | # If the call to getblockcount() succeeds then the RPC connection is up |
| 180 | self.rpc_connected = True |
| 181 | self.url = self.rpc.url |
| 182 | self.log.debug("RPC successfully started") |
| 183 | return |
| 184 | except IOError as e: |
| 185 | if e.errno != errno.ECONNREFUSED: # Port not yet open? |
| 186 | raise # unknown IO error |
| 187 | except JSONRPCException as e: # Initialization phase |
| 188 | if e.error['code'] != -28: # RPC in warmup? |
| 189 | raise # unknown JSON RPC exception |
| 190 | except ValueError as e: # cookie file not found and no rpcuser or rpcassword. bitcoind still starting |
| 191 | if "No RPC credentials" not in str(e): |
| 192 | raise |
| 193 | time.sleep(1.0 / poll_per_s) |
| 194 | self._raise_assertion_error("Unable to connect to bitcoind") |
| 195 | |
| 196 | def get_wallet_rpc(self, wallet_name): |
| 197 | if self.use_cli: |
no test coverage detected