Browse Source

remove unneeded hex encoding/decoding from sent_tx + push_tx

master
undeath 5 years ago committed by Adam Gibson
parent
commit
e082c3c451
  1. 4
      jmbase/jmbase/commands.py
  2. 6
      jmbase/test/test_commands.py
  3. 17
      jmclient/jmclient/client_protocol.py
  4. 4
      jmclient/jmclient/taker.py
  5. 7
      jmclient/test/test_client_protocol.py
  6. 6
      jmclient/test/test_coinjoin.py
  7. 8
      jmdaemon/jmdaemon/daemon_protocol.py
  8. 17
      jmdaemon/jmdaemon/message_channel.py
  9. 6
      jmdaemon/test/test_daemon_protocol.py
  10. 8
      jmdaemon/test/test_message_channel.py

4
jmbase/jmbase/commands.py

@ -91,14 +91,14 @@ class JMMakeTx(JMCommand):
to a set of counterparties
"""
arguments = [(b'nick_list', ListOf(Unicode())),
(b'txhex', Unicode())]
(b'tx', String())]
class JMPushTx(JMCommand):
"""Pass a raw hex transaction to a specific
counterparty (maker) for pushing (anonymity feature in JM)
"""
arguments = [(b'nick', Unicode()),
(b'txhex', Unicode())]
(b'tx', String())]
"""MAKER specific commands
"""

6
jmbase/test/test_commands.py

@ -89,8 +89,8 @@ class JMTestServerProtocol(JMBaseProtocol):
return {'accepted': True}
@JMMakeTx.responder
def on_JM_MAKE_TX(self, nick_list, txhex):
show_receipt("JMMAKETX", nick_list, txhex)
def on_JM_MAKE_TX(self, nick_list, tx):
show_receipt("JMMAKETX", nick_list, tx)
d = self.callRemote(JMSigReceived,
nick="dummynick",
sig="xxxsig")
@ -175,7 +175,7 @@ class JMTestClientProtocol(JMBaseProtocol):
show_receipt("JMFILLRESPONSE", success, ioauth_data)
d = self.callRemote(JMMakeTx,
nick_list=['nick1', 'nick2', 'nick3'],
txhex="deadbeef")
tx=b"deadbeef")
self.defaultCallbacks(d)
return {'accepted': True}

17
jmclient/jmclient/client_protocol.py

@ -360,10 +360,10 @@ class JMClientProtocol(BaseClientProtocol):
self.defaultCallbacks(d)
return {'accepted': True}
def make_tx(self, nick_list, txhex):
def make_tx(self, nick_list, tx):
d = self.callRemote(commands.JMMakeTx,
nick_list=nick_list,
txhex=txhex)
tx=tx)
self.defaultCallbacks(d)
class JMMakerClientProtocol(JMClientProtocol):
@ -677,8 +677,8 @@ class JMTakerClientProtocol(JMClientProtocol):
self.client.on_finished_callback(False, False, 0.0)
return {'accepted': False}
else:
nick_list, txhex = retval[1:]
reactor.callLater(0, self.make_tx, nick_list, txhex)
nick_list, tx = retval[1:]
reactor.callLater(0, self.make_tx, nick_list, tx)
return {'accepted': True}
@commands.JMOffers.responder
@ -716,17 +716,16 @@ class JMTakerClientProtocol(JMClientProtocol):
def on_JM_SIG_RECEIVED(self, nick, sig):
retval = self.client.on_sig(nick, sig)
if retval:
nick_to_use, txhex = retval
self.push_tx(nick_to_use, txhex)
nick_to_use, tx = retval
self.push_tx(nick_to_use, tx)
return {'accepted': True}
def get_offers(self):
d = self.callRemote(commands.JMRequestOffers)
self.defaultCallbacks(d)
def push_tx(self, nick_to_push, txhex_to_push):
d = self.callRemote(commands.JMPushTx, nick=str(nick_to_push),
txhex=str(txhex_to_push))
def push_tx(self, nick_to_push, tx):
d = self.callRemote(commands.JMPushTx, nick=str(nick_to_push), tx=tx)
self.defaultCallbacks(d)
class SNICKERClientProtocolFactory(protocol.ClientFactory):

4
jmclient/jmclient/taker.py

@ -524,7 +524,7 @@ class Taker(object):
self.taker_info_callback("INFO", "Built tx, sending to counterparties.")
return (True, list(self.maker_utxo_data.keys()),
bintohex(self.latest_tx.serialize()))
self.latest_tx.serialize())
def _verify_ioauth_data(self, ioauth_data):
verified_data = []
@ -943,7 +943,7 @@ class Taker(object):
self.on_finished_callback(False, fromtx=True)
else:
if nick_to_use:
return (nick_to_use, bintohex(self.latest_tx.serialize()))
return (nick_to_use, self.latest_tx.serialize())
#if push was not successful, return None
def self_sign_and_push(self):

7
jmclient/test/test_client_protocol.py

@ -65,7 +65,8 @@ class DummyTaker(Taker):
if self.failutxos:
return (False, "dummyreason")
else:
return (True, [x*64 + ":01" for x in ["a", "b", "c"]], t_raw_signed_tx)
return (True, [x*64 + ":01" for x in ["a", "b", "c"]],
base64.b16decode(t_raw_signed_tx, casefold=True))
def on_sig(self, nick, sigb64):
@ -214,8 +215,8 @@ class JMTestServerProtocol(JMBaseProtocol):
return {'accepted': True}
@JMMakeTx.responder
def on_JM_MAKE_TX(self, nick_list, txhex):
show_receipt("JMMAKETX", nick_list, txhex)
def on_JM_MAKE_TX(self, nick_list, tx):
show_receipt("JMMAKETX", nick_list, tx)
d = self.callRemote(JMSigReceived,
nick="dummynick",
sig="xxxsig")

6
jmclient/test/test_coinjoin.py

@ -9,7 +9,7 @@ import pytest
import copy
from twisted.internet import reactor
from jmbase import get_log, hextobin
from jmbase import get_log
from jmclient import load_test_config, jm_single,\
YieldGeneratorBasic, Taker, LegacyWallet, SegwitLegacyWallet, SegwitWallet,\
NO_ROUNDING
@ -206,7 +206,7 @@ def test_coinjoin_mixdepth_wrap_taker(monkeypatch, tmpdir, setup_cj):
taker_final_result = do_tx_signing(taker, makers, active_orders, txdata)
assert taker_final_result is not False
tx = btc.CMutableTransaction.deserialize(hextobin(txdata[2]))
tx = btc.CMutableTransaction.deserialize(txdata[2])
wallet_service = wallet_services[-1]
# TODO change for new tx monitoring:
@ -261,7 +261,7 @@ def test_coinjoin_mixdepth_wrap_maker(monkeypatch, tmpdir, setup_cj):
taker_final_result = do_tx_signing(taker, makers, active_orders, txdata)
assert taker_final_result is not False
tx = btc.CMutableTransaction.deserialize(hextobin(txdata[2]))
tx = btc.CMutableTransaction.deserialize(txdata[2])
for i in range(MAKER_NUM):
wallet_service = wallet_services[i]

8
jmdaemon/jmdaemon/daemon_protocol.py

@ -629,19 +629,19 @@ class JMDaemonServerProtocol(amp.AMP, OrderbookWatch):
return {'accepted': True}
@JMMakeTx.responder
def on_JM_MAKE_TX(self, nick_list, txhex):
def on_JM_MAKE_TX(self, nick_list, tx):
"""Taker sends the prepared unsigned transaction
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}
self.mcc.send_tx(nick_list, txhex)
self.mcc.send_tx(nick_list, tx)
return {'accepted': True}
@JMPushTx.responder
def on_JM_PushTx(self, nick, txhex):
self.mcc.push_tx(nick, txhex)
def on_JM_PushTx(self, nick, tx):
self.mcc.push_tx(nick, tx)
return {'accepted': True}
"""Maker specific responders

17
jmdaemon/jmdaemon/message_channel.py

@ -1,7 +1,6 @@
#! /usr/bin/env python
import abc
import base64
import binascii
import threading
from twisted.internet import reactor
from jmdaemon import encrypt_encode, decode_decrypt, COMMAND_PREFIX,\
@ -351,14 +350,14 @@ class MessageChannelCollection(object):
self.prepare_privmsg(nick, "error", errormsg)
@check_privmsg
def push_tx(self, nick, txhex):
def push_tx(self, nick, tx):
#TODO supporting sending to arbitrary nicks
#adds quite a bit of complexity, not supported
#initially; will fail if nick is not part of TX
txb64 = base64.b64encode(binascii.unhexlify(txhex)).decode('ascii')
txb64 = base64.b64encode(tx).decode('ascii')
self.prepare_privmsg(nick, "push", txb64)
def send_tx(self, nick_list, txhex):
def send_tx(self, nick_list, tx):
"""Push out the transaction to nicks
in groups by their message channel.
"""
@ -376,10 +375,10 @@ class MessageChannelCollection(object):
else:
tx_nick_sets[self.active_channels[nick]].append(nick)
for mc, nl in tx_nick_sets.items():
self.prepare_send_tx(mc, nl, txhex)
self.prepare_send_tx(mc, nl, tx)
def prepare_send_tx(self, mc, nick_list, txhex):
txb64 = base64.b64encode(binascii.unhexlify(txhex)).decode('ascii')
def prepare_send_tx(self, mc, nick_list, tx):
txb64 = base64.b64encode(tx).decode('ascii')
for nick in nick_list:
self.prepare_privmsg(nick, "tx", txb64, mc=mc)
@ -853,10 +852,10 @@ class MessageChannel(object):
msg += ' ' + commitment
self.privmsg(c, 'fill', msg)
def push_tx(self, nick, txhex):
def push_tx(self, nick, tx):
#Note: not currently used; will require prepare_privmsg call so
#not in this class (see send_error)
txb64 = base64.b64encode(binascii.unhexlify(txhex)).decode('ascii')
txb64 = base64.b64encode(tx).decode('ascii')
self.privmsg(nick, 'push', txb64)
def send_error(self, nick, errormsg):

6
jmdaemon/test/test_daemon_protocol.py

@ -106,7 +106,7 @@ class JMTestClientProtocol(JMBaseProtocol):
nl = list(ioauth_data)
d = self.callRemote(JMMakeTx,
nick_list=nl,
txhex="deadbeef")
tx=b"deadbeef")
self.defaultCallbacks(d)
@JMOffers.responder
@ -258,10 +258,10 @@ class JMDaemonTestServerProtocol(JMDaemonServerProtocol):
return super().on_JM_FILL(amount, commitment, revelation, filled_offers)
@JMMakeTx.responder
def on_JM_MAKE_TX(self, nick_list, txhex):
def on_JM_MAKE_TX(self, nick_list, tx):
for n in nick_list:
reactor.callLater(1, self.on_sig, n, "dummytxsig")
return super().on_JM_MAKE_TX(nick_list, txhex)
return super().on_JM_MAKE_TX(nick_list, tx)

8
jmdaemon/test/test_message_channel.py

@ -160,7 +160,7 @@ def test_setup_mc():
mcc.privmsg(cp1+"XXX", "fill", "0")
#trigger check_privmsg decorator
mcc.send_error(cp1, "errormsg")
mcc.push_tx(cp1, "deadbeef")
mcc.push_tx(cp1, b"deadbeef")
#kill the chan on which the cp is marked active;
#note dummychannel has no actual shutdown (call it anyway),
#so change its status manually.
@ -215,13 +215,13 @@ def test_setup_mc():
mcc.fill_orders(new_offers, 1000, "dummypubkey", "dummycommit")
#now send a dummy transaction to this same set.
#first fails with no crypto box.
mcc.send_tx(cps, "deadbeef")
mcc.send_tx(cps, b"deadbeef")
#Now initialize the boxes
for c in cps:
dummydaemon.crypto_boxes[c] = ["a", DummyBox()]
mcc.send_tx(cps, "deadbeef")
mcc.send_tx(cps, b"deadbeef")
#try to send the transaction to a wrong cp:
mcc.send_tx(["notrealcp"], "deadbeef")
mcc.send_tx(["notrealcp"], b"deadbeef")
#At this stage, dmcs0,2 should be "up" and 1 should be "down":
assert mcc.mc_status[dmcs[0]] == 1

Loading…
Cancel
Save