123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- #####################################################################
- # #
- # THIS IS A SOURCE CODE FILE FROM A PROGRAM TO INTERACT WITH THE #
- # LBRY PROTOCOL ( lbry.com ). IT WILL USE THE LBRY SDK ( lbrynet ) #
- # FROM THEIR REPOSITORY ( https://github.com/lbryio/lbry-sdk ) #
- # WHICH I GONNA PRESENT TO YOU AS A BINARY. SINCE I DID NOT DEVELOP #
- # IT AND I'M LAZY TO INTEGRATE IN A MORE SMART WAY. THE SOURCE CODE #
- # OF THE SDK IS AVAILABLE IN THE REPOSITORY MENTIONED ABOVE. #
- # #
- # ALL THE CODE IN THIS REPOSITORY INCLUDING THIS FILE IS #
- # (C) J.Y.Amihud and Other Contributors 2021. EXCEPT THE LBRY SDK. #
- # YOU CAN USE THIS FILE AND ANY OTHER FILE IN THIS REPOSITORY UNDER #
- # THE TERMS OF GNU GENERAL PUBLIC LICENSE VERSION 3 OR ANY LATER #
- # VERSION. TO FIND THE FULL TEXT OF THE LICENSE GO TO THE GNU.ORG #
- # WEBSITE AT ( https://www.gnu.org/licenses/gpl-3.0.html ). #
- # #
- # THE LBRY SDK IS UNFORTUNATELY UNDER THE MIT LICENSE. IF YOU ARE #
- # NOT INTENDING TO USE MY CODE AND JUST THE SDK. YOU CAN FIND IT ON #
- # THEIR OFFICIAL REPOSITORY ABOVE. THEIR LICENSE CHOICE DOES NOT #
- # SPREAD ONTO THIS PROJECT. DON'T GET A FALSE ASSUMPTION THAT SINCE #
- # THEY USE A PUSH-OVER LICENSE, I GONNA DO THE SAME. I'M NOT. #
- # #
- # THE LICENSE CHOSEN FOR THIS PROJECT WILL PROTECT THE 4 ESSENTIAL #
- # FREEDOMS OF THE USER FURTHER, BY NOT ALLOWING ANY WHO TO CHANGE #
- # THE LICENSE AT WILL. SO NO PROPRIETARY SOFTWARE DEVELOPER COULD #
- # TAKE THIS CODE AND MAKE THEIR USER-SUBJUGATING SOFTWARE FROM IT. #
- # #
- #####################################################################
- # This file will perform a simple search on the LBRY network.
- from subprocess import *
- import json
- from flbry import url
- from flbry import settings
- from flbry import markdown
- from flbry import channel
- from flbry.variables import *
- def history():
- # This function will output wallet history.
- # So instead we are going to request only the first 20 and let
- # the user load more.
- w, h = tsize()
-
- page_size = h - 6
- page = 1
- balance = check_output(["flbry/lbrynet",
- "wallet", "balance"])
- try:
- balance = json.loads(balance)
- except:
- print(" Connect to LBRY first.")
- return
- balance = balance["available"]
-
- while True:
- # Printing the search query and page number
- center("WALLET HISTORY. PAGE: "+str(page))
- center("AVAILABLE BALANCE: "+balance+" LBC")
-
- out = check_output(["flbry/lbrynet",
- "transaction", "list",
- '--page='+str(page),
- '--page_size='+str(page_size)])
- # Now we want to parse the json
- try:
- out = json.loads(out)
- except:
- print(" Connect to LBRY first.")
- return
-
- d = {"categories":["CONFORMATIONS", "AMOUNT", "IS TIP", "PUBLICATION"],
- "size":[1,1,1,3],
- "data":[]}
-
- try:
-
- # List what we found
- for n, i in enumerate(out["items"]):
- confirm = i["confirmations"]
- amount = i["value"]
- tip = " "
- publication = " "
- try:
- if i["support_info"][0]["is_tip"]:
- if i["support_info"][0]["is_spent"]:
- tip = "[v]"
- else:
- tip = "[ ]"
- publication = i["support_info"][0]["claim_name"]
- except:
- tip = " "
- publication = " "
-
-
- d["data"].append([confirm, amount, tip, publication])
- table(d)
- # Tell the user that he might want to load more
- center(" ---type 'more' to load more---")
- page = page +1
- # Error messages
- except Exception as e:
- if "code" in out:
- print(" Error code: ", out["code"] )
- if out["code"] == -32500:
- print(" SDK is still starting. Patience!")
- else:
- raise()
- print(" Error :", e)
- return
- # Making sure that we stop every time a new page is reached
- c = input(typing_dots())
- if c != "more":
- break
- try:
- c = int(c)
-
- except:
- return
- while True:
- try:
- url.get(out["items"][c]["support_info"][0]["claim_name"]+"#"+out["items"][c]["support_info"][0]["claim_id"])
- except:
- pass
- c = input(typing_dots())
- if not c:
- break
- try:
- c = int(c)
- except:
- return
- def balance():
- # Prints all wallet balance information
- balance = check_output(["flbry/lbrynet",
- "wallet", "balance"])
- try:
- balance = json.loads(balance)
- except:
- print(" Connect to LBRY first.")
- return
- # Get the variables
- total = balance["total"]
- available = balance["available"]
- reserved = balance["reserved"]
- claims = balance["reserved_subtotals"]["claims"]
- supports = balance["reserved_subtotals"]["supports"]
- tips = balance["reserved_subtotals"]["tips"]
- # Show the total, available, and reserved amounts in a table
- center("Balance Information")
- d = {"categories":["total", "available", "reserved"],
- "size":[1,1,1],
- "data":[]}
- d["data"].append([total, available, reserved])
- table(d, False)
- # Show the sources of the reserved balance in a table
- center("Reserved Balance Information")
- d = {"categories":["claims", "supports", "tips"],
- "size":[1,1,1],
- "data":[]}
- d["data"].append([claims, supports, tips])
- table(d, False)
- # Here because it looks out of place without it
- center("--- for wallet transaction history type 'wallet' ---")
- def support(claim_id, tip=False):
- # Dialog to send support or tip to claim_id
- d = {"categories": ["Amount", "Channel", "Comment"],
- "size": [1,3,5],
- "data": []}
- amount = float(settings.get("default_tip"))
- channel_name = "[anonymous]"
- channel_id = ""
- comment = None
- complete([
- "amount",
- "channel",
- "send",
- "comment"
- ])
- while True:
- # Just setting data directly wasn't working, so we clear it then append to it
- d["data"] = []
- # f'amount:.5f}' shows the amount in decimal notation with 5 places after the decimal
- d["data"].append([f'{amount:.5f}', channel_name, str(comment)])
- table(d, False)
- center("---type 'help' for support commands---")
- c = input(typing_dots())
- if not c:
- break
- if c == "amount":
- amount = float(input(" Amount: "))
- elif c == "channel":
- channel_name, channel_id = channel.select("Select the signing channel.", claim_id=True)
- elif c == "help":
- markdown.draw("help/support.md", "Support Help")
- elif c.startswith("comment"):
- c = c + ' '
- a = c[c.find(" "):]
- if len(a) > 1:
- comment = file_or_editor(a, "Type the comment here. Don't forget to save. Then return to FastLBRY.")
- else:
- comment = input(" Comment: ")
- elif c == "send":
- args = [
- "flbry/lbrynet",
- "support", "create",
- "--claim_id="+claim_id,
- "--amount="+f'{amount:.5f}'
- ]
- if channel_id:
- args.append("--channel_id="+channel_id)
- if comment:
- args.append("--comment="+comment)
- if tip:
- args.append("--tip")
- try:
- x = check_output(args)
- center("Supported with "+f'{amount:.5f}'+" LBC", "bdgr")
- except Exception as e:
- center("Error sending support: "+str(e), "bdrd")
- break
- def addresses():
- w, h = tsize()
- page_size = h - 5
- # TODO: At the time of writing, pagination in this command is not working, so we only get the first page.
- # When this gets fixed, please add pagination here.
- out = check_output(["flbry/lbrynet",
- "address", "list",
- "--page_size="+str(page_size)])
- out = json.loads(out)
- try:
- data_print = {"categories":["Address"],
- "size":[1],
- "data":[]}
- # List what we found
- for n, i in enumerate(out["items"]):
- data_print["data"].append([i["address"]])
- table(data_print)
- center("")
- # Error messages
- except Exception as e:
- if "code" in out:
- print(" Error code: ", out["code"] )
- if out["code"] == -32500:
- print(" SDK is still starting. Patience!")
- else:
- print(" Error :", e)
- return
- def address_send(amount="", address=""):
- if not amount:
- amount = input(" Amount to send: ")
- if not address:
- address = input(" Address to send to: ")
- out = check_output(["flbry/lbrynet",
- "wallet",
- "send",
- str(amount),
- address])
- out = json.loads(out)
- if "message" in out:
- center(" Error sending to address: "+out["message"], "bdrd")
- else:
- center(" Successfully sent "+str(amount)+" to "+address, "bdgr")
|