wallet.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #####################################################################
  2. # #
  3. # THIS IS A SOURCE CODE FILE FROM A PROGRAM TO INTERACT WITH THE #
  4. # LBRY PROTOCOL ( lbry.com ). IT WILL USE THE LBRY SDK ( lbrynet ) #
  5. # FROM THEIR REPOSITORY ( https://github.com/lbryio/lbry-sdk ) #
  6. # WHICH I GONNA PRESENT TO YOU AS A BINARY. SINCE I DID NOT DEVELOP #
  7. # IT AND I'M LAZY TO INTEGRATE IN A MORE SMART WAY. THE SOURCE CODE #
  8. # OF THE SDK IS AVAILABLE IN THE REPOSITORY MENTIONED ABOVE. #
  9. # #
  10. # ALL THE CODE IN THIS REPOSITORY INCLUDING THIS FILE IS #
  11. # (C) J.Y.Amihud and Other Contributors 2021. EXCEPT THE LBRY SDK. #
  12. # YOU CAN USE THIS FILE AND ANY OTHER FILE IN THIS REPOSITORY UNDER #
  13. # THE TERMS OF GNU GENERAL PUBLIC LICENSE VERSION 3 OR ANY LATER #
  14. # VERSION. TO FIND THE FULL TEXT OF THE LICENSE GO TO THE GNU.ORG #
  15. # WEBSITE AT ( https://www.gnu.org/licenses/gpl-3.0.html ). #
  16. # #
  17. # THE LBRY SDK IS UNFORTUNATELY UNDER THE MIT LICENSE. IF YOU ARE #
  18. # NOT INTENDING TO USE MY CODE AND JUST THE SDK. YOU CAN FIND IT ON #
  19. # THEIR OFFICIAL REPOSITORY ABOVE. THEIR LICENSE CHOICE DOES NOT #
  20. # SPREAD ONTO THIS PROJECT. DON'T GET A FALSE ASSUMPTION THAT SINCE #
  21. # THEY USE A PUSH-OVER LICENSE, I GONNA DO THE SAME. I'M NOT. #
  22. # #
  23. # THE LICENSE CHOSEN FOR THIS PROJECT WILL PROTECT THE 4 ESSENTIAL #
  24. # FREEDOMS OF THE USER FURTHER, BY NOT ALLOWING ANY WHO TO CHANGE #
  25. # THE LICENSE AT WILL. SO NO PROPRIETARY SOFTWARE DEVELOPER COULD #
  26. # TAKE THIS CODE AND MAKE THEIR USER-SUBJUGATING SOFTWARE FROM IT. #
  27. # #
  28. #####################################################################
  29. # This file will perform a simple search on the LBRY network.
  30. from subprocess import *
  31. import json
  32. from flbry import url
  33. from flbry.variables import *
  34. def history():
  35. # This function will output wallet history.
  36. # So instead we are going to request only the first 20 and let
  37. # the user load more.
  38. page_size = 20
  39. page = 1
  40. while True:
  41. # Printing the search query and page number
  42. print(" "+clr["bold"]+clr["bdma"], " WALLET HISTORY",
  43. wdth(" ", 19), " PAGE :",
  44. wdth(page, 3),
  45. wdth(" ", 32)+clr["norm"])
  46. out = check_output(["flbry/lbrynet",
  47. "transaction", "list",
  48. '--page='+str(page),
  49. '--page_size='+str(page_size)])
  50. # Now we want to parse the json
  51. try:
  52. out = json.loads(out)
  53. except:
  54. print(" Connect to LBRY first.")
  55. return
  56. # Print the categories
  57. print(" "+clr["bold"]+clr["bdma"],wdth(" ", 3),
  58. "", wdth("CONFIRMED", 10),
  59. "", wdth("AMOUNT", 10),
  60. "", wdth("TIP", 9),
  61. "", wdth("PUBLICATION", 17)+wdth(" ", 31)+clr["norm"])
  62. try:
  63. # List what we found
  64. for n, i in enumerate(out["items"]):
  65. # This will make each new line a different shade
  66. if n % 2:
  67. b = "d"
  68. else:
  69. b = "b"
  70. value = i["value"]
  71. if int(i["confirmations"]) < 10:
  72. concol = "tbrd"
  73. elif int(i["confirmations"]) < 100:
  74. concol = "tbyl"
  75. elif int(i["confirmations"]) < 500:
  76. concol = "tbgr"
  77. else:
  78. concol = "tbwh"
  79. conf = clr["norm"]+clr["bold"]+clr["tbwh"]+clr["b"+b+"bu"]+clr[concol]+\
  80. " "+wdth(i["confirmations"], 10)+" "
  81. s = " "+clr["bold"]+clr["b"+b+"ma"]+" "+\
  82. wdth(n, 3)+" "+\
  83. conf+" "+\
  84. clr["norm"]+clr["bold"]+clr["b"+b+"bu"]+\
  85. wdth(value, 12)+" LBC "
  86. try:
  87. if i["support_info"][0]["is_tip"]:
  88. if i["support_info"][0]["is_spent"]:
  89. s = s + " [v] "
  90. else:
  91. s = s + " [ ] "
  92. s = s + wdth(i["support_info"][0]["claim_name"], 48)
  93. except:
  94. s = s + wdth(" ", 53)
  95. print(s+" "+clr["norm"])
  96. # Tell the user that he might want to load more
  97. print(" "+clr["bold"]+clr["bdma"],
  98. " ---type more to load more---",
  99. wdth(" ",40)+clr["norm"])
  100. page = page +1
  101. # Error messages
  102. except Exception as e:
  103. if "code" in out:
  104. print(" Error code: ", out["code"] )
  105. if out["code"] == -32500:
  106. print(" SDK is still starting. Patience!")
  107. else:
  108. raise()
  109. print(" Error :", e)
  110. return
  111. # Making sure that we stop every time a new page is reached
  112. c = input(" :: ")
  113. if c != "more":
  114. break
  115. try:
  116. c = int(c)
  117. except:
  118. return
  119. while True:
  120. try:
  121. url.get(out["items"][c]["support_info"][0]["claim_name"]+"#"+out["items"][c]["support_info"][0]["claim_id"])
  122. except:
  123. pass
  124. c = input(" :: ")
  125. if not c:
  126. break
  127. try:
  128. c = int(c)
  129. except:
  130. return