def connect_to_local(filename=None): """ Connect to default kimocoin instance owned by this user, on this machine. Returns a :class:`~kimocoinrpc.connection.BitcoinConnection` object. Arguments: - `filename`: Path to a configuration file in a non-standard location (optional) """ from kimocoinrpc.connection import BitcoinConnection from kimocoinrpc.config import read_default_config cfg = read_default_config(filename) if cfg is None: cfg = {} port = int(cfg.get('rpcport', '11988' if cfg.get('testnet') else '1988')) rpcuser = cfg.get('rpcuser', '') rpcpassword = cfg.get('rpcpassword', '') return BitcoinConnection(rpcuser, rpcpassword, 'localhost', port)
parser = argparse.ArgumentParser() parser.add_argument("--config", help="Specify configuration file") parser.add_argument("--nolocal", help="Don't use connect_to_local", action="store_true") parser.add_argument("--noremote", help="Don't use connect_to_remote", action="store_true") args = parser.parse_args() if __name__ == "__main__": if args.config: from kimocoinrpc.config import read_config_file cfg = read_config_file(args.config) else: from kimocoinrpc.config import read_default_config cfg = read_default_config(None) port = int(cfg.get("rpcport", "11988" if cfg.get("testnet") else "1988")) rpcuser = cfg.get("rpcuser", "") connections = [] if not args.nolocal: local_conn = kimocoinrpc.connect_to_local() # will use read_default_config connections.append(local_conn) for conn in connections: assert type(conn.getconnectioncount()) is int assert type(conn.getdifficulty()) is Decimal assert type(conn.getgenerate()) is bool conn.setgenerate(True) conn.setgenerate(True, 2)