MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / cli_get_info_string_to_dict

Function cli_get_info_string_to_dict

test/functional/interface_bitcoin_cli.py:42–73  ·  view source on GitHub ↗

Helper method to convert human-readable -getinfo into a dictionary

(cli_get_info_string)

Source from the content-addressed store, hash-verified

40
41
42def cli_get_info_string_to_dict(cli_get_info_string):
43 """Helper method to convert human-readable -getinfo into a dictionary"""
44 cli_get_info = {}
45 lines = cli_get_info_string.splitlines()
46 line_idx = 0
47 ansi_escape = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]')
48 while line_idx < len(lines):
49 # Remove ansi colour code
50 line = ansi_escape.sub('', lines[line_idx])
51 if "Balances" in line:
52 # When "Balances" appears in a line, all of the following lines contain "balance: wallet" until an empty line
53 cli_get_info["Balances"] = {}
54 while line_idx < len(lines) and not (lines[line_idx + 1] == ''):
55 line_idx += 1
56 balance, wallet = lines[line_idx].strip().split(" ")
57 # Remove right justification padding
58 wallet = wallet.strip()
59 if wallet == '""':
60 # Set default wallet("") to empty string
61 wallet = ''
62 cli_get_info["Balances"][wallet] = balance.strip()
63 elif ": " in line:
64 key, value = line.split(": ")
65 if key == 'Wallet' and value == '""':
66 # Set default wallet("") to empty string
67 value = ''
68 if key == "Proxies" and value == "n/a":
69 # Set N/A to empty string to represent no proxy
70 value = ''
71 cli_get_info[key.strip()] = value.strip()
72 line_idx += 1
73 return cli_get_info
74
75
76class TestBitcoinCli(BitcoinTestFramework):

Callers 1

run_testMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected