add auto_renew_claim_height_delta to configuration and auto renew after startup if necessary

This commit is contained in:
Kay Kurokawa 2017-11-28 13:47:44 -05:00 committed by Jack Robison
parent 1ea8c1ad29
commit e4e60ebe9b
No known key found for this signature in database
GPG key ID: 284699E7404E3CFF
2 changed files with 24 additions and 0 deletions

View file

@ -242,6 +242,10 @@ ADJUSTABLE_SETTINGS = {
# all of your credits.
'api_host': (str, 'localhost'),
'api_port': (int, 5279),
# claims set to expire within this many blocks will be
# automatically renewed after startup (if set to 0, renews
# will not be made automatically)
'auto_renew_claim_height_delta': (int, 0),
'cache_time': (int, 150),
'data_dir': (str, default_data_dir),
'data_rate': (float, .0001), # points/megabyte

View file

@ -188,6 +188,8 @@ class Daemon(AuthJSONRPCServer):
self.reflector_port = conf.settings['reflector_port']
self.dht_node_port = conf.settings['dht_node_port']
self.use_upnp = conf.settings['use_upnp']
self.auto_renew_claim_height_delta = conf.settings['auto_renew_claim_height_delta']
self.startup_status = STARTUP_STAGES[0]
self.connected_to_internet = True
@ -255,6 +257,7 @@ class Daemon(AuthJSONRPCServer):
yield self._setup_server()
log.info("Starting balance: " + str(self.session.wallet.get_balance()))
yield _announce_startup()
self._auto_renew()
def _get_platform(self):
if self.platform is None:
@ -290,6 +293,23 @@ class Daemon(AuthJSONRPCServer):
if not self.connected_to_internet:
self.connection_status_code = CONNECTION_STATUS_NETWORK
@defer.inlineCallbacks
def _auto_renew(self):
# automatically renew claims
# auto renew is turned off if 0 or some negative number
if self.auto_renew_claim_height_delta < 1:
return
log.debug("Renewing claim")
h = self.session.wallet.network.get_local_height() + self.auto_renew_claim_height_delta
results = yield self.session.wallet.claim_renew_all_before_expiration(h)
for outpoint, result in results.iteritems():
if result['success']:
log.info("Renewed claim at outpoint:%s claim ID:%s, paid fee:%s",
outpoint, result['claim_id'], result['fee'])
else:
log.info("Failed to renew claim at outpoint:%s, reason:%s",
outpoint, result['reason'])
def _start_server(self):
if self.peer_port is not None:
server_factory = ServerProtocolFactory(self.session.rate_limiter,