Run bitcoin-cli command. Deserializes returned string as python object.
(self, command=None, *args, **kwargs)
| 723 | return results |
| 724 | |
| 725 | def send_cli(self, command=None, *args, **kwargs): |
| 726 | """Run bitcoin-cli command. Deserializes returned string as python object.""" |
| 727 | pos_args = [arg_to_cli(arg) for arg in args] |
| 728 | named_args = [str(key) + "=" + arg_to_cli(value) for (key, value) in kwargs.items()] |
| 729 | assert not (pos_args and named_args), "Cannot use positional arguments and named arguments in the same bitcoin-cli call" |
| 730 | p_args = [self.binary, "-datadir=" + self.datadir, "-chain=" + self.chain] + self.options |
| 731 | if named_args: |
| 732 | p_args += ["-named"] |
| 733 | if command is not None: |
| 734 | p_args += [command] |
| 735 | p_args += pos_args + named_args |
| 736 | self.log.debug("Running bitcoin-cli {}".format(p_args[2:])) |
| 737 | process = subprocess.Popen(p_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) |
| 738 | cli_stdout, cli_stderr = process.communicate(input=self.input) |
| 739 | returncode = process.poll() |
| 740 | if returncode: |
| 741 | match = re.match(r'error code: ([-0-9]+)\nerror message:\n(.*)', cli_stderr) |
| 742 | if match: |
| 743 | code, message = match.groups() |
| 744 | raise JSONRPCException(dict(code=int(code), message=message)) |
| 745 | # Ignore cli_stdout, raise with cli_stderr |
| 746 | raise subprocess.CalledProcessError(returncode, self.binary, output=cli_stderr) |
| 747 | try: |
| 748 | return json.loads(cli_stdout, parse_float=decimal.Decimal) |
| 749 | except (json.JSONDecodeError, decimal.InvalidOperation): |
| 750 | return cli_stdout.rstrip("\n") |
| 751 | |
| 752 | class RPCOverloadWrapper(): |
| 753 | def __init__(self, rpc, cli=False, descriptors=False): |
no test coverage detected