|
|
|
|
@ -1,18 +1,20 @@
|
|
|
|
|
from __future__ import print_function |
|
|
|
|
from __future__ import (absolute_import, division, |
|
|
|
|
print_function, unicode_literals) |
|
|
|
|
from builtins import * # noqa: F401 |
|
|
|
|
""" |
|
|
|
|
Commands defining client-server (daemon) |
|
|
|
|
messaging protocol (*not* Joinmarket p2p protocol). |
|
|
|
|
Used for AMP asynchronous messages. |
|
|
|
|
""" |
|
|
|
|
from twisted.protocols.amp import Boolean, Command, Integer, String |
|
|
|
|
from bigstring import BigString |
|
|
|
|
from twisted.protocols.amp import Boolean, Command, Integer, Unicode |
|
|
|
|
from .bigstring import BigString |
|
|
|
|
|
|
|
|
|
class DaemonNotReady(Exception): |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
class JMCommand(Command): |
|
|
|
|
#a default response type |
|
|
|
|
response = [('accepted', Boolean())] |
|
|
|
|
response = [(b'accepted', Boolean())] |
|
|
|
|
|
|
|
|
|
"""COMMANDS FROM CLIENT TO DAEMON |
|
|
|
|
================================= |
|
|
|
|
@ -27,44 +29,44 @@ class JMInit(JMCommand):
|
|
|
|
|
Blockchain source is communicated only as a naming |
|
|
|
|
tag for messagechannels (currently IRC 'realname' field). |
|
|
|
|
""" |
|
|
|
|
arguments = [('bcsource', String()), |
|
|
|
|
('network', String()), |
|
|
|
|
('irc_configs', String()), |
|
|
|
|
('minmakers', Integer()), |
|
|
|
|
('maker_timeout_sec', Integer())] |
|
|
|
|
errors = {DaemonNotReady: 'daemon is not ready'} |
|
|
|
|
arguments = [(b'bcsource', Unicode()), |
|
|
|
|
(b'network', Unicode()), |
|
|
|
|
(b'irc_configs', Unicode()), |
|
|
|
|
(b'minmakers', Integer()), |
|
|
|
|
(b'maker_timeout_sec', Integer())] |
|
|
|
|
errors = {DaemonNotReady: b'daemon is not ready'} |
|
|
|
|
|
|
|
|
|
class JMStartMC(JMCommand): |
|
|
|
|
"""Will restart message channel connections if config |
|
|
|
|
has changed; otherwise will only change nym/nick on MCs. |
|
|
|
|
""" |
|
|
|
|
arguments = [('nick', String())] |
|
|
|
|
arguments = [(b'nick', Unicode())] |
|
|
|
|
|
|
|
|
|
class JMSetup(JMCommand): |
|
|
|
|
"""Communicates which of "MAKER" or "TAKER" |
|
|
|
|
roles are to be taken by this client; for MAKER |
|
|
|
|
role, passes initial offers for announcement (for TAKER, this data is "none") |
|
|
|
|
""" |
|
|
|
|
arguments = [('role', String()), |
|
|
|
|
('initdata', String())] |
|
|
|
|
arguments = [(b'role', Unicode()), |
|
|
|
|
(b'initdata', Unicode())] |
|
|
|
|
|
|
|
|
|
class JMMsgSignature(JMCommand): |
|
|
|
|
"""A response to a request for a bitcoin signature |
|
|
|
|
on a message-channel layer message from the daemon |
|
|
|
|
""" |
|
|
|
|
arguments = [('nick', String()), |
|
|
|
|
('cmd', String()), |
|
|
|
|
('msg_to_return', String()), |
|
|
|
|
('hostid', String())] |
|
|
|
|
arguments = [(b'nick', Unicode()), |
|
|
|
|
(b'cmd', Unicode()), |
|
|
|
|
(b'msg_to_return', Unicode()), |
|
|
|
|
(b'hostid', Unicode())] |
|
|
|
|
|
|
|
|
|
class JMMsgSignatureVerify(JMCommand): |
|
|
|
|
"""A response to a request to verify the bitcoin signature |
|
|
|
|
of a message-channel layer message from the daemon |
|
|
|
|
""" |
|
|
|
|
arguments = [('verif_result', Boolean()), |
|
|
|
|
('nick', String()), |
|
|
|
|
('fullmsg', String()), |
|
|
|
|
('hostid', String())] |
|
|
|
|
arguments = [(b'verif_result', Boolean()), |
|
|
|
|
(b'nick', Unicode()), |
|
|
|
|
(b'fullmsg', Unicode()), |
|
|
|
|
(b'hostid', Unicode())] |
|
|
|
|
|
|
|
|
|
"""TAKER specific commands |
|
|
|
|
""" |
|
|
|
|
@ -77,24 +79,24 @@ class JMRequestOffers(JMCommand):
|
|
|
|
|
class JMFill(JMCommand): |
|
|
|
|
"""Fill an offer/order |
|
|
|
|
""" |
|
|
|
|
arguments = [('amount', Integer()), |
|
|
|
|
('commitment', String()), |
|
|
|
|
('revelation', String()), |
|
|
|
|
('filled_offers', String())] |
|
|
|
|
arguments = [(b'amount', Integer()), |
|
|
|
|
(b'commitment', Unicode()), |
|
|
|
|
(b'revelation', Unicode()), |
|
|
|
|
(b'filled_offers', Unicode())] |
|
|
|
|
|
|
|
|
|
class JMMakeTx(JMCommand): |
|
|
|
|
"""Send a hex encoded raw bitcoin transaction |
|
|
|
|
to a set of counterparties |
|
|
|
|
""" |
|
|
|
|
arguments = [('nick_list', String()), |
|
|
|
|
('txhex', String())] |
|
|
|
|
arguments = [(b'nick_list', Unicode()), |
|
|
|
|
(b'txhex', Unicode())] |
|
|
|
|
|
|
|
|
|
class JMPushTx(JMCommand): |
|
|
|
|
"""Pass a raw hex transaction to a specific |
|
|
|
|
counterparty (maker) for pushing (anonymity feature in JM) |
|
|
|
|
""" |
|
|
|
|
arguments = [('nick', String()), |
|
|
|
|
('txhex', String())] |
|
|
|
|
arguments = [(b'nick', Unicode()), |
|
|
|
|
(b'txhex', Unicode())] |
|
|
|
|
|
|
|
|
|
"""MAKER specific commands |
|
|
|
|
""" |
|
|
|
|
@ -104,27 +106,27 @@ class JMAnnounceOffers(JMCommand):
|
|
|
|
|
to the daemon, along with new announcement |
|
|
|
|
and cancellation lists (deltas). |
|
|
|
|
""" |
|
|
|
|
arguments = [('to_announce', String()), |
|
|
|
|
('to_cancel', String()), |
|
|
|
|
('offerlist', String())] |
|
|
|
|
arguments = [(b'to_announce', Unicode()), |
|
|
|
|
(b'to_cancel', Unicode()), |
|
|
|
|
(b'offerlist', Unicode())] |
|
|
|
|
|
|
|
|
|
class JMIOAuth(JMCommand): |
|
|
|
|
"""Send contents of !ioauth message after |
|
|
|
|
verifying Taker's auth message |
|
|
|
|
""" |
|
|
|
|
arguments = [('nick', String()), |
|
|
|
|
('utxolist', String()), |
|
|
|
|
('pubkey', String()), |
|
|
|
|
('cjaddr', String()), |
|
|
|
|
('changeaddr', String()), |
|
|
|
|
('pubkeysig', String())] |
|
|
|
|
arguments = [(b'nick', Unicode()), |
|
|
|
|
(b'utxolist', Unicode()), |
|
|
|
|
(b'pubkey', Unicode()), |
|
|
|
|
(b'cjaddr', Unicode()), |
|
|
|
|
(b'changeaddr', Unicode()), |
|
|
|
|
(b'pubkeysig', Unicode())] |
|
|
|
|
|
|
|
|
|
class JMTXSigs(JMCommand): |
|
|
|
|
"""Send signatures on the bitcoin transaction |
|
|
|
|
sent by TAKER |
|
|
|
|
""" |
|
|
|
|
arguments = [('nick', String()), |
|
|
|
|
('sigs', String())] |
|
|
|
|
arguments = [(b'nick', Unicode()), |
|
|
|
|
(b'sigs', Unicode())] |
|
|
|
|
|
|
|
|
|
"""COMMANDS FROM DAEMON TO CLIENT |
|
|
|
|
================================= |
|
|
|
|
@ -137,10 +139,10 @@ class JMInitProto(JMCommand):
|
|
|
|
|
(that key being controlled by the client; the daemon knows nothing |
|
|
|
|
about bitcoin). |
|
|
|
|
""" |
|
|
|
|
arguments = [('nick_hash_length', Integer()), |
|
|
|
|
('nick_max_encoded', Integer()), |
|
|
|
|
('joinmarket_nick_header', String()), |
|
|
|
|
('joinmarket_version', Integer())] |
|
|
|
|
arguments = [(b'nick_hash_length', Integer()), |
|
|
|
|
(b'nick_max_encoded', Integer()), |
|
|
|
|
(b'joinmarket_nick_header', Unicode()), |
|
|
|
|
(b'joinmarket_version', Integer())] |
|
|
|
|
|
|
|
|
|
class JMUp(JMCommand): |
|
|
|
|
"""Used to signal readiness of message channels to client. |
|
|
|
|
@ -157,47 +159,46 @@ class JMRequestMsgSig(JMCommand):
|
|
|
|
|
"""Request the client to sign a message-channel |
|
|
|
|
layer message with the bitcoin key for the nick |
|
|
|
|
""" |
|
|
|
|
arguments = [('nick', String()), |
|
|
|
|
('cmd', String()), |
|
|
|
|
('msg', String()), |
|
|
|
|
('msg_to_be_signed', String()), |
|
|
|
|
('hostid', String())] |
|
|
|
|
arguments = [(b'nick', Unicode()), |
|
|
|
|
(b'cmd', Unicode()), |
|
|
|
|
(b'msg', Unicode()), |
|
|
|
|
(b'msg_to_be_signed', Unicode()), |
|
|
|
|
(b'hostid', Unicode())] |
|
|
|
|
|
|
|
|
|
class JMRequestMsgSigVerify(JMCommand): |
|
|
|
|
"""Request the client to verify a counterparty's |
|
|
|
|
message-channel layer message against the provided nick |
|
|
|
|
""" |
|
|
|
|
arguments = [('msg', String()), |
|
|
|
|
('fullmsg', String()), |
|
|
|
|
('sig', String()), |
|
|
|
|
('pubkey', String()), |
|
|
|
|
('nick', String()), |
|
|
|
|
('hashlen', Integer()), |
|
|
|
|
('max_encoded', Integer()), |
|
|
|
|
('hostid', String())] |
|
|
|
|
arguments = [(b'msg', Unicode()), |
|
|
|
|
(b'fullmsg', Unicode()), |
|
|
|
|
(b'sig', Unicode()), |
|
|
|
|
(b'pubkey', Unicode()), |
|
|
|
|
(b'nick', Unicode()), |
|
|
|
|
(b'hashlen', Integer()), |
|
|
|
|
(b'max_encoded', Integer()), |
|
|
|
|
(b'hostid', Unicode())] |
|
|
|
|
|
|
|
|
|
""" TAKER-specific commands |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
class JMOffers(JMCommand): |
|
|
|
|
"""Return the entire contents of the |
|
|
|
|
orderbook to TAKER, as a json-ified dict; |
|
|
|
|
note uses BigString because can be very large |
|
|
|
|
orderbook to TAKER, as a json-ified dict. |
|
|
|
|
""" |
|
|
|
|
arguments = [('orderbook', BigString())] |
|
|
|
|
arguments = [(b'orderbook', BigString())] |
|
|
|
|
|
|
|
|
|
class JMFillResponse(JMCommand): |
|
|
|
|
"""Returns ioauth data from MAKER if successful. |
|
|
|
|
""" |
|
|
|
|
arguments = [('success', Boolean()), |
|
|
|
|
('ioauth_data', String())] |
|
|
|
|
arguments = [(b'success', Boolean()), |
|
|
|
|
(b'ioauth_data', Unicode())] |
|
|
|
|
|
|
|
|
|
class JMSigReceived(JMCommand): |
|
|
|
|
"""Returns an individual bitcoin transaction signature |
|
|
|
|
from a MAKER |
|
|
|
|
""" |
|
|
|
|
arguments = [('nick', String()), |
|
|
|
|
('sig', String())] |
|
|
|
|
arguments = [(b'nick', Unicode()), |
|
|
|
|
(b'sig', Unicode())] |
|
|
|
|
|
|
|
|
|
"""MAKER-specific commands |
|
|
|
|
""" |
|
|
|
|
@ -208,17 +209,17 @@ class JMAuthReceived(JMCommand):
|
|
|
|
|
allowing the MAKER to verify against btc library |
|
|
|
|
before setting up encryption and continuing. |
|
|
|
|
""" |
|
|
|
|
arguments = [('nick', String()), |
|
|
|
|
('offer', String()), |
|
|
|
|
('commitment', String()), |
|
|
|
|
('revelation', String()), |
|
|
|
|
('amount', Integer()), |
|
|
|
|
('kphex', String())] |
|
|
|
|
arguments = [(b'nick', Unicode()), |
|
|
|
|
(b'offer', Unicode()), |
|
|
|
|
(b'commitment', Unicode()), |
|
|
|
|
(b'revelation', Unicode()), |
|
|
|
|
(b'amount', Integer()), |
|
|
|
|
(b'kphex', Unicode())] |
|
|
|
|
|
|
|
|
|
class JMTXReceived(JMCommand): |
|
|
|
|
"""Send back transaction template provided |
|
|
|
|
by TAKER, along with offerdata to verify fees. |
|
|
|
|
""" |
|
|
|
|
arguments = [('nick', String()), |
|
|
|
|
('txhex', String()), |
|
|
|
|
('offer', String())] |
|
|
|
|
arguments = [(b'nick', Unicode()), |
|
|
|
|
(b'txhex', Unicode()), |
|
|
|
|
(b'offer', Unicode())] |
|
|
|
|
|