automatically give LBC to users on the first run and update RUNNING.md for prompt interface

This commit is contained in:
Jimmy Kiselak 2015-11-11 15:06:14 -05:00
parent 0891b0d294
commit 6252f903ee
6 changed files with 178 additions and 60 deletions

View file

@ -8,7 +8,7 @@ Download the file https://raw.githubusercontent.com/lbryio/lbry-setup/master/lbr
Once it's done building, type:
./lbrycrd/src/lbrycrdd -server -daemon -gen
./lbrycrd/src/lbrycrdd -server -daemon
lbrynet-gui
@ -91,12 +91,13 @@ In order to use lbrynet-console or lbrynet-gui, lbyrcrdd must be running.
If you ran the easy install script, the lbrycrd folder will be in the directory you ran lbry_setup.sh from. Otherwise it is the root of the cloned lbrycrd repository. Go to that directory.
./src/lbrycrdd -server -daemon
If you want to mine LBC, also use the flag '-gen', so:
./src/lbrycrdd -server -daemon -gen
It will take a few minutes for your client to download the whole block chain.
Once it has caught up, it will start mining coins.
If you don't want to mine, leave off the '-gen' flag.
lbrycrdd must be running in order for lbrynet to function.
@ -112,19 +113,15 @@ In your terminal:
lbrynet-console
You should now be presented with a list of options.
You should be presented with a prompt.
Watch It's a Wonderful Life via LBRY
Choose the option labeled Add a stream from a short name by typing the number next to it and pressing the enter key.
Type into the prompt:
You will be prompted for a name. Type in "wonderfullife" and hit enter. After a few seconds, you will prompted to choose what you want to do with the file. Select the option labeled Stream.
get wonderfullife
You will be shown some options related to the file which you do not care about. Type 'n' and hit enter.
You will be prompted to choose if you really want to download this file. Type 'y' and hit enter.
To shut it down, type ctrl-c at any time or enter the option to shut down from the main menu.
To shut it down, type ctrl-c at any time or enter 'exit' into the prompt.
### Option 2) Running lbrynet-gui

View file

@ -312,7 +312,7 @@ class LBRYcrdWallet(object):
def get_name_and_validity_for_sd_hash(self, sd_hash):
d = self._get_claim_metadata_for_sd_hash(sd_hash)
d.addCallback(lambda name_txid: self._get_status_of_claim(name_txid[1], name_txid[0], sd_hash) if name_txid is not None else None)
d.addCallback(lambda name_txid: threads.deferToThread(self._get_status_of_claim, name_txid[1], name_txid[0], sd_hash) if name_txid is not None else None)
return d
def get_available_balance(self):
@ -321,6 +321,15 @@ class LBRYcrdWallet(object):
def get_new_address(self):
return threads.deferToThread(self._get_new_address)
def check_first_run(self):
d = threads.deferToThread(self._get_wallet_balance)
d.addCallback(lambda bal: threads.deferToThread(self._get_num_addresses) if bal == 0 else 2)
d.addCallback(lambda num_addresses: True if num_addresses <= 1 else False)
return d
def get_most_recent_blocktime(self):
return threads.deferToThread(self._get_best_block_time)
def get_rpc_conf(self):
settings = {"username": "rpcuser",
"password": "rpcpassword",
@ -509,6 +518,20 @@ class LBRYcrdWallet(object):
return name, "unconfirmed"
return None
@_catch_connection_error
def _get_num_addresses(self):
rpc_conn = self._get_rpc_conn()
return len(rpc_conn.getaddressesbyaccount(""))
@_catch_connection_error
def _get_best_block_time(self):
rpc_conn = self._get_rpc_conn()
best_block_hash = rpc_conn.getbestblockhash()
block = rpc_conn.getblock(best_block_hash)
if 'time' in block:
return block['time']
raise ValueError("Could not get a block time")
@_catch_connection_error
def _rpc_stop(self):

View file

@ -12,6 +12,7 @@ from lbrynet.core.Error import UnknownNameError, InvalidBlobHashError, Insuffici
from lbrynet.core.Error import InvalidStreamInfoError
from lbrynet.core.utils import is_valid_blobhash
from twisted.internet import defer, threads
import datetime
import os
@ -2350,3 +2351,49 @@ class StatusFactory(CommandHandlerFactory):
"or have been downloaded, and give the option to " \
"toggle whether the file is actively downloading or " \
"to remove the file."
class BlockchainStatus(CommandHandler):
def __init__(self, console, wallet=None):
CommandHandler.__init__(self, console)
self.wallet = wallet
def start(self):
d = self.wallet.get_most_recent_blocktime()
d.addCallbacks(self._show_time_behind_blockchain, self._show_error)
d.chainDeferred(self.finished_deferred)
return d
def _show_time_behind_blockchain(self, best_block_time):
best_time = datetime.datetime.utcfromtimestamp(best_block_time)
diff = datetime.datetime.utcnow() - best_time
unit = None
val = None
if diff.days > 0:
if diff.days >= 7:
val = diff.days // 7
unit = "week"
else:
val = diff.days
unit = "day"
elif diff.seconds >= 60 * 90:
if diff.seconds >= 60 * 60:
val = diff.seconds // (60 * 60)
unit = "hour"
if unit is not None:
if val != 1:
unit += "s"
self.console.sendLine("This application is %d %s behind the LBC blockchain." % (val, unit))
else:
self.console.sendLine("This application is up to date with the LBC blockchain.")
def _show_error(self, err):
logging.error(err.getTraceback())
self.console.sendLine("Unable to determine the status of the blockchain.")
class BlockchainStatusFactory(CommandHandlerFactory):
control_handler_class = BlockchainStatus
command = "get-blockchain-status"
short_help = "Show whether this application has caught up with the LBC blockchain"
full_help = "Show whether this applications has caught up with the LBC blockchain"

View file

@ -2,6 +2,8 @@ import logging
from lbrynet.core.Session import LBRYSession
import os.path
import argparse
import requests
import locale
from yapsy.PluginManager import PluginManager
from twisted.internet import defer, threads, stdio, task, error
from lbrynet.lbrynet_console.ConsoleControl import ConsoleControl
@ -33,6 +35,7 @@ from lbrynet.lbrynet_console.ControlHandlers import ClaimNameFactory, GetNewWall
from lbrynet.lbrynet_console.ControlHandlers import ShowServerStatusFactory, ModifyServerSettingsFactory
from lbrynet.lbrynet_console.ControlHandlers import ModifyLBRYFileOptionsChooserFactory, StatusFactory
from lbrynet.lbrynet_console.ControlHandlers import PeerStatsAndSettingsChooserFactory, PublishFactory
from lbrynet.lbrynet_console.ControlHandlers import BlockchainStatusFactory
from lbrynet.core.LBRYcrdWallet import LBRYcrdWallet
@ -234,7 +237,8 @@ class LBRYConsole():
if not lbrycrdd_path:
lbrycrdd_path = self.default_lbrycrdd_path
d = defer.succeed(LBRYcrdWallet(self.db_dir, wallet_dir=self.lbrycrd_dir,
wallet_conf=self.lbrycrd_conf, lbrycrdd_path=lbrycrdd_path))
wallet_conf=self.lbrycrd_conf,
lbrycrdd_path=lbrycrdd_path))
else:
d = defer.succeed(PTCWallet(self.db_dir))
d.addCallback(lambda wallet: {"wallet": wallet})
@ -267,8 +271,51 @@ class LBRYConsole():
dl.addCallback(lambda _: self.session.setup())
dl.addCallback(lambda _: self.check_first_run())
dl.addCallback(self._show_first_run_result)
return dl
def check_first_run(self):
d = self.session.wallet.check_first_run()
d.addCallback(lambda is_first_run: self._do_first_run() if is_first_run else 0.0)
return d
def _do_first_run(self):
d = self.session.wallet.get_new_address()
def send_request(url, data):
r = requests.post(url, json=data)
if r.status_code == 200:
return r.json()['credits_sent']
return 0.0
def log_error(err):
log.warning("unable to request free credits. %s", err.getErrorMessage())
return 0.0
def request_credits(address):
url = "http://credreq.lbry.io/requestcredits"
data = {"address": address}
d = threads.deferToThread(send_request, url, data)
d.addErrback(log_error)
return d
d.addCallback(request_credits)
return d
@staticmethod
def _show_first_run_result(credits_received):
if credits_received != 0.0:
points_string = locale.format_string("%.2f LBC", (round(credits_received, 2),),
grouping=True)
alert.info("Thank you for using LBRY! You have been given %s for free because we "
"love you. Please give them a few minutes to show up while you catch up "
"with our blockchain.\nTo check whether you've caught up with the blockchain, "
"use the command 'get-blockchain-status'.\nDownloading some files "
"may not work until you have downloaded the LBC blockchain.", points_string)
def _setup_lbry_file_manager(self):
self.lbry_file_metadata_manager = DBLBRYFileMetadataManager(self.db_dir)
d = self.lbry_file_metadata_manager.setup()
@ -321,7 +368,8 @@ class LBRYConsole():
ClaimNameFactory(self.session.wallet, self.lbry_file_manager,
self.session.blob_manager),
GetNewWalletAddressFactory(self.session.wallet),
PublishFactory(self.session, self.lbry_file_manager, self.session.wallet)
PublishFactory(self.session, self.lbry_file_manager, self.session.wallet),
BlockchainStatusFactory(self.session.wallet)
]
self.add_control_handlers(lbrycrd_handlers)
if self.peer_port is not None:

View file

@ -226,7 +226,7 @@ class DownloaderApp(object):
def _start_downloader(self):
self.downloader = LBRYDownloader()
d = self.downloader.start()
d.addCallback(lambda _: self.downloader.do_first_run())
d.addCallback(lambda _: self.downloader.check_first_run())
d.addCallback(self._show_welcome_message)
return d

View file

@ -32,8 +32,6 @@ class LBRYDownloader(object):
self.known_dht_nodes = [('104.236.42.182', 4000)]
self.db_dir = os.path.join(os.path.expanduser("~"), ".lbrydownloader")
self.blobfile_dir = os.path.join(self.db_dir, "blobfiles")
self.wallet_dir = os.path.join(os.path.expanduser("~"), ".lbrycrd")
self.wallet_conf = os.path.join(self.wallet_dir, "lbrycrd.conf")
self.peer_port = 3333
self.dht_node_port = 4444
self.run_server = True
@ -42,8 +40,10 @@ class LBRYDownloader(object):
if os.name == "nt":
from lbrynet.winhelpers.knownpaths import get_path, FOLDERID, UserHandle
self.download_directory = get_path(FOLDERID.Downloads, UserHandle.current)
self.wallet_dir = os.path.join(get_path(FOLDERID.RoamingAppData, UserHandle.current), "lbrycrd")
else:
self.download_directory = os.getcwd()
self.wallet_conf = os.path.join(self.wallet_dir, "lbrycrd.conf")
self.wallet_user = None
self.wallet_password = None
self.sd_identifier = StreamDescriptorIdentifier()
@ -267,6 +267,7 @@ class LBRYDownloader(object):
if not os.path.exists(self.blobfile_dir):
os.makedirs(self.blobfile_dir)
log.debug("Created the data directory: %s", str(self.blobfile_dir))
if os.name == "nt":
if not os.path.exists(self.wallet_dir):
os.makedirs(self.wallet_dir)
if not os.path.exists(self.wallet_conf):
@ -277,7 +278,6 @@ class LBRYDownloader(object):
lbrycrd_conf.write("rpcpassword=%s\n" % self.wallet_password)
lbrycrd_conf.write("server=1\n")
lbrycrd_conf.close()
self.first_run = True
else:
lbrycrd_conf = open(self.wallet_conf)
for l in lbrycrd_conf:
@ -349,8 +349,12 @@ class LBRYDownloader(object):
self.session.wallet)
self.sd_identifier.add_stream_downloader_factory(LBRYFileStreamType, file_opener_factory)
def do_first_run(self):
if self.first_run is True:
def check_first_run(self):
d = self.session.wallet.check_first_run()
d.addCallback(lambda is_first_run: self._do_first_run() if is_first_run else 0.0)
return d
def _do_first_run(self):
d = self.session.wallet.get_new_address()
def send_request(url, data):
@ -372,7 +376,6 @@ class LBRYDownloader(object):
d.addCallback(request_credits)
return d
return defer.succeed(0.0)
def _resolve_name(self, uri):
return self.session.wallet.get_stream_info_for_name(uri)