diff --git a/jmbase/test/test_commands.py b/jmbase/test/test_commands.py index dafda0f..d3d2863 100644 --- a/jmbase/test/test_commands.py +++ b/jmbase/test/test_commands.py @@ -92,26 +92,26 @@ class JMTestServerProtocol(JMBaseProtocol): def on_JM_MAKE_TX(self, nick_list, txhex): show_receipt("JMMAKETX", nick_list, txhex) d = self.callRemote(JMSigReceived, - nick="dummynick", - sig="xxxsig") + nick="dummynick", + sig="xxxsig") self.defaultCallbacks(d) #add dummy calls to check message sign and message verify d2 = self.callRemote(JMRequestMsgSig, - nick="dummynickforsign", - cmd="command1", - msg="msgforsign", - msg_to_be_signed="fullmsgforsign", - hostid="hostid1") + nick="dummynickforsign", + cmd="command1", + msg="msgforsign", + msg_to_be_signed="fullmsgforsign", + hostid="hostid1") self.defaultCallbacks(d2) d3 = self.callRemote(JMRequestMsgSigVerify, - msg="msgforverify", - fullmsg="fullmsgforverify", - sig="xxxsigforverify", - pubkey="pubkey1", - nick="dummynickforverify", - hashlen=4, - max_encoded=5, - hostid="hostid2") + msg="msgforverify", + fullmsg="fullmsgforverify", + sig="xxxsigforverify", + pubkey="pubkey1", + nick="dummynickforverify", + hashlen=4, + max_encoded=5, + hostid="hostid2") self.defaultCallbacks(d3) d4 = self.callRemote(JMTXBroadcast, tx=b"deadbeef") self.defaultCallbacks(d4) diff --git a/jmclient/jmclient/client_protocol.py b/jmclient/jmclient/client_protocol.py index dd50184..9969b73 100644 --- a/jmclient/jmclient/client_protocol.py +++ b/jmclient/jmclient/client_protocol.py @@ -443,7 +443,7 @@ class JMMakerClientProtocol(JMClientProtocol): def on_JM_AUTH_RECEIVED(self, nick, offer, commitment, revelation, amount, kphex): retval = self.client.on_auth_received(nick, offer, - commitment, revelation, amount, kphex) + commitment, revelation, amount, kphex) if not retval[0]: jlog.info("Maker refuses to continue on receiving auth.") else: @@ -512,7 +512,7 @@ class JMMakerClientProtocol(JMClientProtocol): return {"accepted": True} def tx_match(self, txd): - for k,v in self.finalized_offers.items(): + for k, v in self.finalized_offers.items(): # Tx considered defined by its output set if v["txd"].vout == txd.vout: offerinfo = v diff --git a/jmclient/test/test_client_protocol.py b/jmclient/test/test_client_protocol.py index 0d4a6ba..cb37a16 100644 --- a/jmclient/test/test_client_protocol.py +++ b/jmclient/test/test_client_protocol.py @@ -199,8 +199,8 @@ class JMTestServerProtocol(JMBaseProtocol): orderbook = ["aaaa" for _ in range(15)] fidelitybonds = ["bbbb" for _ in range(15)] d = self.callRemote(JMOffers, - orderbook=json.dumps(orderbook), - fidelitybonds=json.dumps(fidelitybonds)) + orderbook=json.dumps(orderbook), + fidelitybonds=json.dumps(fidelitybonds)) self.defaultCallbacks(d) return {'accepted': True} @@ -217,16 +217,16 @@ class JMTestServerProtocol(JMBaseProtocol): def on_JM_MAKE_TX(self, nick_list, txhex): show_receipt("JMMAKETX", nick_list, txhex) d = self.callRemote(JMSigReceived, - nick="dummynick", - sig="xxxsig") + nick="dummynick", + sig="xxxsig") self.defaultCallbacks(d) #add dummy calls to check message sign and message verify d2 = self.callRemote(JMRequestMsgSig, - nick="dummynickforsign", - cmd="command1", - msg="msgforsign", - msg_to_be_signed="fullmsgforsign", - hostid="hostid1") + nick="dummynickforsign", + cmd="command1", + msg="msgforsign", + msg_to_be_signed="fullmsgforsign", + hostid="hostid1") self.defaultCallbacks(d2) #To test, this must include a valid ecdsa sig fullmsg = "fullmsgforverify" @@ -234,18 +234,18 @@ class JMTestServerProtocol(JMBaseProtocol): pub = bintohex(bitcoin.privkey_to_pubkey(priv)) sig = bitcoin.ecdsa_sign(fullmsg, priv) d3 = self.callRemote(JMRequestMsgSigVerify, - msg="msgforverify", - fullmsg=fullmsg, - sig=sig, - pubkey=pub, - nick="dummynickforverify", - hashlen=4, - max_encoded=5, - hostid="hostid2") + msg="msgforverify", + fullmsg=fullmsg, + sig=sig, + pubkey=pub, + nick="dummynickforverify", + hashlen=4, + max_encoded=5, + hostid="hostid2") self.defaultCallbacks(d3) d4 = self.callRemote(JMSigReceived, - nick="dummynick", - sig="dummysig") + nick="dummynick", + sig="dummysig") self.defaultCallbacks(d4) return {'accepted': True} diff --git a/jmdaemon/jmdaemon/daemon_protocol.py b/jmdaemon/jmdaemon/daemon_protocol.py index 7ae1868..64d3f1c 100644 --- a/jmdaemon/jmdaemon/daemon_protocol.py +++ b/jmdaemon/jmdaemon/daemon_protocol.py @@ -100,11 +100,11 @@ class BIP78ReceiverResource(JMHTTPResource): def __init__(self, info_callback, shutdown_callback, post_request_handler): """ The POST request handling callback has function signature: - args: (request-body-content-in-bytes,) - returns: (errormsg, errcode, httpcode, response-in-bytes) - If the request was successful, errormsg should be true and response - should be in bytes, to be sent in the return value of render_POST(). - """ + args: (request-body-content-in-bytes,) + returns: (errormsg, errcode, httpcode, response-in-bytes) + If the request was successful, errormsg should be true and response + should be in bytes, to be sent in the return value of render_POST(). + """ self.post_request_handler = post_request_handler super().__init__(info_callback, shutdown_callback) @@ -157,6 +157,7 @@ class BIP78ReceiverResource(JMHTTPResource): self.info_callback("Shutting down, payjoin negotiation failed.") self.shutdown_callback() + class HTTPPassThrough(amp.AMP): """ This class supports passing through requests over HTTPS or over a socks proxy to a remote @@ -204,9 +205,9 @@ class HTTPPassThrough(amp.AMP): def getRequest(self, server, success_callback, url=None, headers=None): """ Make GET request to server server, if response received OK, - passed to success_callback, which must have function signature + passed to success_callback, which must have function signature (response, server). - """ + """ agent, destination_url = self.getAgentDestination(server) if url: destination_url = destination_url + url @@ -228,7 +229,7 @@ class HTTPPassThrough(amp.AMP): def postRequest(self, body, server, success_callback, url=None, params=None, headers=None): """ Pass body of post request as string, will be encoded here. - """ + """ agent, destination_url = self.getAgentDestination(server, params=params) if url: @@ -301,25 +302,25 @@ class BIP78ServerProtocol(HTTPPassThrough): def info_callback(self, msg): """ Informational messages are all passed - to the client. TODO makes sense to log locally - too, in case daemon is isolated?. - """ + to the client. TODO makes sense to log locally + too, in case daemon is isolated?. + """ d = self.callRemote(BIP78InfoMsg, infomsg=msg) self.defaultCallbacks(d) def onion_hostname_callback(self, hostname): """ On successful start of HS, we pass hostname - to client, who can use this to build the full URI. - """ + to client, who can use this to build the full URI. + """ d = self.callRemote(BIP78ReceiverUp, hostname=hostname) self.defaultCallbacks(d) def post_request_handler(self, request, body, params): """ Fired when a sender has sent a POST request - to our hidden service. Argument `body` should be a base64 + to our hidden service. Argument `body` should be a base64 string and params should be a dict. - """ + """ self.post_request = request d = self.callRemote(BIP78ReceiverOriginalPSBT, body=body, params=bdict_sdict_convert(params)) @@ -381,8 +382,8 @@ class SNICKERDaemonServerProtocol(HTTPPassThrough): @SNICKERProposerPostProposals.responder def on_SNICKER_PROPOSER_POST_PROPOSALS(self, proposals, server): """ Receives a list of proposals to be posted to a specific - server. - """ + server. + """ self.postRequest(proposals, server, self.receive_proposals_response) return {"accepted": True} @@ -418,7 +419,7 @@ class SNICKERDaemonServerProtocol(HTTPPassThrough): def receive_proposals_from_server(self, response, server): """ Parses the response from one server. - """ + """ # if the response code is not 200 OK, we must let the client # know that this server is not responding as expected. if int(response.code) != 200: @@ -484,7 +485,7 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch): def defaultErrback(self, failure): """TODO better network error handling. - """ + """ failure.trap(ConnectionAborted, ConnectionClosed, ConnectionDone, ConnectionLost) @@ -630,8 +631,8 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch): @JMMakeTx.responder def on_JM_MAKE_TX(self, nick_list, txhex): """Taker sends the prepared unsigned transaction - to all the Makers in nick_list - """ + to all the Makers in nick_list + """ if not self.jm_state == 4: log.msg("Make tx was called in wrong state, rejecting") return {'accepted': False} @@ -649,9 +650,9 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch): @JMAnnounceOffers.responder def on_JM_ANNOUNCE_OFFERS(self, to_announce, to_cancel, offerlist): """Called by Maker to reset his current offerlist; - Daemon decides what messages (cancel, announce) to - send to the message channel. - """ + Daemon decides what messages (cancel, announce) to + send to the message channel. + """ if self.role != "MAKER": return self.offerlist = offerlist @@ -670,9 +671,9 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch): @JMIOAuth.responder def on_JM_IOAUTH(self, nick, utxolist, pubkey, cjaddr, changeaddr, pubkeysig): """Daemon constructs full !ioauth message to be sent on message - channel based on data from Maker. Relevant data (utxos, addresses) - are stored in the active_orders dict keyed by the nick of the Taker. - """ + channel based on data from Maker. Relevant data (utxos, addresses) + are stored in the active_orders dict keyed by the nick of the Taker. + """ if not self.role == "MAKER": return if nick not in self.active_orders: @@ -791,7 +792,7 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch): """ if nick not in self.active_orders: return - ao =self.active_orders[nick] + ao = self.active_orders[nick] #ask the client to validate the commitment and prepare the utxo data d = self.callRemote(JMAuthReceived, nick=nick, @@ -805,8 +806,8 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch): @maker_only def on_commitment_seen(self, nick, commitment): """Triggered when we see a commitment for blacklisting - appear in the public pit channel. - """ + appear in the public pit channel. + """ #just add if necessary, ignore return value. check_utxo_blacklist(commitment, persist=True) log.msg("Received commitment broadcast by other maker: " + str( @@ -815,10 +816,10 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch): @maker_only def on_commitment_transferred(self, nick, commitment): """Triggered when a privmsg is received from another maker - with a commitment to announce in public (obfuscation of source). + with a commitment to announce in public (obfuscation of source). We simply post it in public (not affected by whether we ourselves are *accepting* commitment broadcasts. - """ + """ self.mcc.pubmsg("!hp2 " + commitment) @maker_only @@ -831,8 +832,8 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch): @maker_only def on_seen_tx(self, nick, tx): """Passes the txhex to the Maker for verification - and signing. Note the security checks occur in Maker. - """ + and signing. Note the security checks occur in Maker. + """ if nick not in self.active_orders: return #we send a copy of the entire "active_orders" entry except the cryptobox, @@ -900,11 +901,11 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch): """ with self.sig_lock: d = self.callRemote(JMRequestMsgSig, - nick=str(nick), - cmd=str(cmd), - msg=str(msg), - msg_to_be_signed=str(msg_to_be_signed), - hostid=str(hostid)) + nick=str(nick), + cmd=str(cmd), + msg=str(msg), + msg_to_be_signed=str(msg_to_be_signed), + hostid=str(hostid)) self.defaultCallbacks(d) def request_signature_verify(self, msg, fullmsg, sig, pubkey, nick, hashlen, @@ -939,8 +940,8 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch): def transfer_commitment(self, commit): """Send this commitment via privmsg to one (random) - other maker. - """ + other maker. + """ crow = self.db.execute( 'SELECT DISTINCT counterparty FROM orderbook ORDER BY ' + 'RANDOM() LIMIT 1;' diff --git a/jmdaemon/test/test_daemon_protocol.py b/jmdaemon/test/test_daemon_protocol.py index 22a5298..059cb4a 100644 --- a/jmdaemon/test/test_daemon_protocol.py +++ b/jmdaemon/test/test_daemon_protocol.py @@ -101,7 +101,7 @@ class JMTestClientProtocol(JMBaseProtocol): show_receipt("JMFILLRESPONSE", success, ioauth_data) reactor.callLater(1, self.maketx, ioauth_data) return {'accepted': True} - + def maketx(self, ioauth_data): nl = list(ioauth_data) d = self.callRemote(JMMakeTx, @@ -118,18 +118,18 @@ class JMTestClientProtocol(JMBaseProtocol): nick = str(list(t_chosen_orders.keys())[0]) b64tx = base64.b64encode(b"deadbeef").decode('ascii') d1 = self.callRemote(JMMsgSignatureVerify, - verif_result=True, - nick=nick, - fullmsg="!push " + b64tx + " abc def", - hostid="dummy") + verif_result=True, + nick=nick, + fullmsg="!push " + b64tx + " abc def", + hostid="dummy") self.defaultCallbacks(d1) #unverified d2 = self.callRemote(JMMsgSignatureVerify, - verif_result=False, - nick=nick, - fullmsg="!push " + b64tx + " abc def", - hostid="dummy") - self.defaultCallbacks(d2) + verif_result=False, + nick=nick, + fullmsg="!push " + b64tx + " abc def", + hostid="dummy") + self.defaultCallbacks(d2) d = self.callRemote(JMFill, amount=100, commitment="dummycommitment", @@ -173,7 +173,7 @@ class JMTestClientProtocol(JMBaseProtocol): class JMTestClientProtocolFactory(protocol.ClientFactory): protocol = JMTestClientProtocol - + def show_receipt(name, *args): tmsg("Received msgtype: " + name + ", args: " + ",".join([str(x) for x in args])) @@ -209,7 +209,7 @@ class JMDaemonTestServerProtocol(JMDaemonServerProtocol): o["minsize"], o["maxsize"], o["txfee"], o["cjfee"]) return super().on_JM_REQUEST_OFFERS() - + @JMInit.responder def on_JM_INIT(self, bcsource, network, irc_configs, minmakers, maker_timeout_sec, dust_threshold): @@ -226,14 +226,14 @@ class JMDaemonTestServerProtocol(JMDaemonServerProtocol): OrderbookWatch.set_msgchan(self, self.mcc) #register taker-specific msgchan callbacks here self.mcc.register_taker_callbacks(self.on_error, self.on_pubkey, - self.on_ioauth, self.on_sig) + self.on_ioauth, self.on_sig) self.mcc.set_daemon(self) self.restart_mc_required = True d = self.callRemote(JMInitProto, - nick_hash_length=NICK_HASH_LENGTH, - nick_max_encoded=NICK_MAX_ENCODED, - joinmarket_nick_header=JOINMARKET_NICK_HEADER, - joinmarket_version=JM_VERSION) + nick_hash_length=NICK_HASH_LENGTH, + nick_max_encoded=NICK_MAX_ENCODED, + joinmarket_nick_header=JOINMARKET_NICK_HEADER, + joinmarket_version=JM_VERSION) self.defaultCallbacks(d) return {'accepted': True} @@ -267,7 +267,7 @@ class JMDaemonTestServerProtocol(JMDaemonServerProtocol): class JMDaemonTestServerProtocolFactory(ServerFactory): protocol = JMDaemonTestServerProtocol - + def buildProtocol(self, addr): return JMDaemonTestServerProtocol(self)