def get_mchannels(self, mode): """ A transparent wrapper that allows override, so that a script can return a customised set of message channel configs; currently used for testing multiple bots on regtest. """ return get_mchannels(mode)
def getmc(nick): dm = DummyDaemon() mc = DummyMC(get_mchannels()[0], nick, dm) mc.register_orderbookwatch_callbacks(on_order_seen=on_order_seen) mc.register_taker_callbacks(on_pubkey=on_pubkey) mc.on_connect = on_connect mc.on_disconnect = on_disconnect mc.on_welcome = on_welcome mcc = MessageChannelCollection([mc]) return dm, mc, mcc
def get_ob(): load_test_config() dm = DummyDaemon() mc = DummyMC(get_mchannels()[0], "test", dm) ob = OrderbookWatch() ob.on_welcome = on_welcome ob.set_msgchan(mc) # would usually be set in JMInit; we use # a fake small value to allow small orders: ob.dust_threshold = 2 return ob
def clientStart(self): self.sigs_received = 0 chan_configs = [get_mchannels()[0]] d = self.callRemote(JMInit, bcsource="dummyblockchain", network="dummynetwork", chan_configs=chan_configs, minmakers=2, maker_timeout_sec=3, dust_threshold=27300, blacklist_location=".") self.defaultCallbacks(d)
def setUp(self): load_test_config() print(get_mchannels()[0]) jm_single().maker_timeout_sec = 1 dm, mc, mcc = getmc("irc_publisher") dm2, mc2, mcc2 = getmc("irc_receiver") mcc.run() mcc2.run() def cb(m): #don't try to reconnect m.give_up = True m.tcp_connector.disconnect() self.addCleanup(cb, mc) self.addCleanup(cb, mc2) #test_junk_messages() print("Got here")
def main(): global bond_exponent parser = OptionParser( usage='usage: %prog [options]', description='Runs a webservice which shows the orderbook.') add_base_options(parser) parser.add_option('-H', '--host', action='store', type='string', dest='host', default='localhost', help='hostname or IP to bind to, default=localhost') parser.add_option('-p', '--port', action='store', type='int', dest='port', help='port to listen on, default=62601', default=62601) (options, args) = parser.parse_args() load_program_config(config_path=options.datadir) # needed to display notional units of FB valuation bond_exponent = jm_single().config.get("POLICY", "bond_value_exponent") try: float(bond_exponent) except ValueError: log.error("Invalid entry for bond_value_exponent, should be decimal " "number: {}".format(bond_exponent)) sys.exit(EXIT_FAILURE) check_and_start_tor() hostport = (options.host, options.port) mcs = [] chan_configs = get_mchannels(mode="PASSIVE") for c in chan_configs: if "type" in c and c["type"] == "onion": mcs.append(OnionMessageChannel(c)) else: # default is IRC; TODO allow others mcs.append(IRCMessageChannel(c)) IRCMessageChannel.on_privmsg = on_privmsg OnionMessageChannel.on_privmsg = on_privmsg mcc = MessageChannelCollection(mcs) mcc.set_nick(get_dummy_nick()) taker = ObBasic(mcc, hostport) log.info("Starting ob-watcher") mcc.run()
def get_mchannels(self, mode="TAKER"): # swaps out any existing onionmc configs # in the config settings on startup, for one # that's indexed to the regtest counter var: default_chans = get_mchannels(mode=mode) new_chans = [] onion_found = False hsd = "" for c in default_chans: if "type" in c and c["type"] == "onion": onion_found = True if c["hidden_service_dir"] != "": hsd = c["hidden_service_dir"] continue else: new_chans.append(c) if onion_found: new_chans.append(get_onion_messaging_config_regtest( self.i, self.dns, hsd, mode=mode)) return new_chans
def main(): parser = OptionParser( usage='usage: %prog [options]', description='Runs a webservice which shows the orderbook.') add_base_options(parser) parser.add_option('-H', '--host', action='store', type='string', dest='host', default='localhost', help='hostname or IP to bind to, default=localhost') parser.add_option('-p', '--port', action='store', type='int', dest='port', help='port to listen on, default=62601', default=62601) (options, args) = parser.parse_args() load_program_config(config_path=options.datadir) check_and_start_tor() hostport = (options.host, options.port) mcs = [] chan_configs = get_mchannels(mode="PASSIVE") for c in chan_configs: if "type" in c and c["type"] == "onion": mcs.append(OnionMessageChannel(c)) else: # default is IRC; TODO allow others mcs.append(IRCMessageChannel(c)) IRCMessageChannel.on_privmsg = on_privmsg OnionMessageChannel.on_privmsg = on_privmsg mcc = MessageChannelCollection(mcs) mcc.set_nick(get_dummy_nick()) taker = ObBasic(mcc, hostport) log.info("Starting ob-watcher") mcc.run()
def directory_node_startup(): parser = OptionParser(usage='usage: %prog [options]') add_base_options(parser) (options, args) = parser.parse_args() # for string access, convert to dict: options = vars(options) if len(args) != 1: parser.error( 'One argument required: string to be published in the MOTD of the directory node.' ) sys.exit(EXIT_ARGERROR) operator_message = args[0] # It's possible to set `no-blockchain` in the config file, but this just # makes it easier for the user: load_program_config(config_path=options["datadir"], bs="no-blockchain") # note: you *must* only have the onionmc, no IRC, for this to work, # and of course you must only have your own d-node configured here: mchan_config = get_mchannels()[0] node_location = mchan_config["directory_nodes"] # before starting, patch the server handshake default to include our MOTD customization # default acceptance false; code must switch it on: jmdaemon.onionmc.server_handshake_json[ "motd"] = "DIRECTORY NODE: {}\nJOINMARKET VERSION: {}\n{}".format( node_location, JM_CORE_VERSION, operator_message) maker = DNMaker() jlog.info('starting directory node') clientfactory = DNJMClientProtocolFactory(maker, proto_type="MAKER") nodaemon = jm_single().config.getint("DAEMON", "no_daemon") daemon = bool(nodaemon) if jm_single().config.get("BLOCKCHAIN", "network") in ["regtest", "testnet", "signet"]: startLogging(sys.stdout) start_reactor(jm_single().config.get("DAEMON", "daemon_host"), jm_single().config.getint("DAEMON", "daemon_port"), clientfactory, daemon=daemon)