wallet.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. w, h = tsize()
  39. page_size = h - 5
  40. page = 1
  41. while True:
  42. # Printing the search query and page number
  43. center("WALLET HISTORY. PAGE: "+str(page))
  44. out = check_output(["flbry/lbrynet",
  45. "transaction", "list",
  46. '--page='+str(page),
  47. '--page_size='+str(page_size)])
  48. # Now we want to parse the json
  49. try:
  50. out = json.loads(out)
  51. except:
  52. print(" Connect to LBRY first.")
  53. return
  54. d = {"categories":["CONFORMATIONS", "AMOUNT", "IS TIP", "PUBLICATION"],
  55. "size":[1,1,1,3],
  56. "data":[]}
  57. try:
  58. # List what we found
  59. for n, i in enumerate(out["items"]):
  60. confirm = i["confirmations"]
  61. amount = i["value"]
  62. try:
  63. if i["support_info"][0]["is_tip"]:
  64. if i["support_info"][0]["is_spent"]:
  65. tip = "[v]"
  66. else:
  67. tip = "[ ]"
  68. publication = i["support_info"][0]["claim_name"]
  69. except:
  70. tip = " "
  71. publication = " "
  72. d["data"].append([confirm, amount, tip, publication])
  73. table(d)
  74. # Tell the user that he might want to load more
  75. center(" ---type 'more' to load more---")
  76. page = page +1
  77. # Error messages
  78. except Exception as e:
  79. if "code" in out:
  80. print(" Error code: ", out["code"] )
  81. if out["code"] == -32500:
  82. print(" SDK is still starting. Patience!")
  83. else:
  84. raise()
  85. print(" Error :", e)
  86. return
  87. # Making sure that we stop every time a new page is reached
  88. c = input(typing_dots())
  89. if c != "more":
  90. break
  91. try:
  92. c = int(c)
  93. except:
  94. return
  95. while True:
  96. try:
  97. url.get(out["items"][c]["support_info"][0]["claim_name"]+"#"+out["items"][c]["support_info"][0]["claim_id"])
  98. except:
  99. pass
  100. c = input(typing_dots())
  101. if not c:
  102. break
  103. try:
  104. c = int(c)
  105. except:
  106. return