Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yield generator can be launched in Qt #487

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions jmbase/jmbase/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ class JMMsgSignatureVerify(JMCommand):
(b'fullmsg', Unicode()),
(b'hostid', Unicode())]

class JMShutdown(JMCommand):
""" Requests shutdown of the current
message channel connections (to be used
when the client is shutting down).
"""
arguments = []

"""TAKER specific commands
"""

Expand Down
2 changes: 1 addition & 1 deletion jmclient/jmclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
wallet_change_passphrase)
from .wallet_service import WalletService
from .maker import Maker
from .yieldgenerator import YieldGenerator, YieldGeneratorBasic, ygmain
from .yieldgenerator import YieldGenerator, YieldGeneratorBasic, ygmain, ygstart
from .snicker_receiver import SNICKERError, SNICKERReceiver
from .payjoin import (parse_payjoin_setup, send_payjoin, PayjoinServer,
JMBIP78ReceiverManager)
Expand Down
9 changes: 9 additions & 0 deletions jmclient/jmclient/client_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ def make_tx(self, nick_list, txhex):
txhex=txhex)
self.defaultCallbacks(d)

def request_mc_shutdown(self):
""" To ensure that lingering message channel
connections are shut down when the client itself
is shutting down.
"""
d = self.callRemote(commands.JMShutdown)
self.defaultCallbacks(d)
return {'accepted': True}

class JMMakerClientProtocol(JMClientProtocol):
def __init__(self, factory, maker, nick_priv=None):
self.factory = factory
Expand Down
38 changes: 23 additions & 15 deletions jmclient/jmclient/yieldgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import time
import abc
import sys
from twisted.python.log import startLogging
from optparse import OptionParser
from jmbase import get_log
Expand All @@ -17,6 +18,19 @@

MAX_MIX_DEPTH = 5

def get_yg_ordertype(wallet_service, ordertype):
txtype = wallet_service.get_txtype()
if txtype == "p2wpkh":
prefix = "sw0"
elif txtype == "p2sh-p2wpkh":
prefix = "sw"
elif txtype == "p2pkh":
prefix = ""
else:
jlog.error("Unsupported wallet type for yieldgenerator: " + txtype)
sys.exit(EXIT_ARGERROR)
return prefix + ordertype

class YieldGenerator(Maker):
"""A maker for the purposes of generating a yield from held
bitcoins, offering from the maximum mixdepth and trying to offer
Expand Down Expand Up @@ -256,22 +270,15 @@ def ygmain(ygclass, txfee=1000, cjfee_a=200, cjfee_r=0.002, ordertype='reloffer'
wallet_service.sync_wallet(fast=not options.recoversync)
wallet_service.startService()

txtype = wallet_service.get_txtype()
if txtype == "p2wpkh":
prefix = "sw0"
elif txtype == "p2sh-p2wpkh":
prefix = "sw"
elif txtype == "p2pkh":
prefix = ""
else:
jlog.error("Unsupported wallet type for yieldgenerator: " + txtype)
sys.exit(EXIT_ARGERROR)
ygstart(wallet_service, options.txfee, cjfee_a, cjfee_r,
ordertype, options.minsize, ygclass=ygclass)

ordertype = prefix + ordertype
def ygstart(wallet_service, txfee, cjfee_a, cjfee_r, ordertype, minsize,
rs=True, ygclass=YieldGeneratorBasic):
# translate from user-interface "reloffer/absoffer" to wallet specific string:
ordertype = get_yg_ordertype(wallet_service, ordertype)
jlog.debug("Set the offer type string to: " + ordertype)

maker = ygclass(wallet_service, [options.txfee, cjfee_a, cjfee_r,
ordertype, options.minsize])
maker = ygclass(wallet_service, [txfee, cjfee_a, cjfee_r, ordertype, minsize])
jlog.info('starting yield generator')
clientfactory = JMClientProtocolFactory(maker, proto_type="MAKER")

Expand All @@ -281,4 +288,5 @@ def ygmain(ygclass, txfee=1000, cjfee_a=200, cjfee_r=0.002, ordertype='reloffer'
startLogging(sys.stdout)
start_reactor(jm_single().config.get("DAEMON", "daemon_host"),
jm_single().config.getint("DAEMON", "daemon_port"),
clientfactory, daemon=daemon)
clientfactory, rs=rs, daemon=daemon)
return clientfactory
5 changes: 5 additions & 0 deletions jmdaemon/jmdaemon/daemon_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ def on_JM_MSGSIGNATURE_VERIFY(self, verif_result, nick, fullmsg, hostid):
self.mcc.on_verified_privmsg(nick, fullmsg, hostid)
return {'accepted': True}

@JMShutdown.responder
def on_JM_SHUTDOWN(self):
self.mc_shutdown()
self.jm_state = 0
return {'accepted': True}
"""Taker specific responders
"""

Expand Down
12 changes: 9 additions & 3 deletions jmdaemon/jmdaemon/irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ def __init__(self,
self.tx_irc_client = None
#TODO can be configuration var, how long between reconnect attempts:
self.reconnect_interval = 10

# service is used to wrap endpoint for Tor connections:
self.reconnecting_service = None

#implementation of abstract base class methods;
#these are mostly but not exclusively acting as pass through
#to the wrapped twisted IRC client protocol
Expand All @@ -113,6 +117,8 @@ def run(self):
def shutdown(self):
self.tx_irc_client.quit()
self.give_up = True
if self.reconnecting_service:
self.reconnecting_service.stopService()

def _pubmsg(self, msg):
self.tx_irc_client._pubmsg(msg)
Expand Down Expand Up @@ -155,8 +161,8 @@ def build_irc(self):
use_tls = False
ircEndpoint = TorSocksEndpoint(torEndpoint, self.serverport[0],
self.serverport[1], tls=use_tls)
myRS = ClientService(ircEndpoint, factory)
myRS.startService()
self.reconnecting_service = ClientService(ircEndpoint, factory)
self.reconnecting_service.startService()
else:
try:
factory = TxIRCFactory(self)
Expand Down Expand Up @@ -201,7 +207,7 @@ def connectionMade(self):
def connectionLost(self, reason=protocol.connectionDone):
wlog("INFO", "Lost IRC connection to: " + str(self.hostname)
+ " . Should reconnect automatically soon.")
if self.wrapper.on_disconnect:
if not self.wrapper.give_up and self.wrapper.on_disconnect:
reactor.callLater(0.0, self.wrapper.on_disconnect, self.wrapper)
return irc.IRCClient.connectionLost(self, reason)

Expand Down
Binary file added scripts/icons/greencircle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added scripts/icons/reddiamond.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading