mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-20 19:55:54 +00:00
Build a wallet tutorial: draft steps 1-3
1. wxPython app that shows XRPL data (once) 2. threaded app monitoring XRPL in background 3. Decode address & watch for balance
This commit is contained in:
46
content/_code-samples/build-a-wallet/py/1_hello.py
Normal file
46
content/_code-samples/build-a-wallet/py/1_hello.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# "Build a Wallet" tutorial, step 1: slightly more than "Hello World"
|
||||
|
||||
import xrpl
|
||||
import wx
|
||||
|
||||
class TWaXLFrame(wx.Frame):
|
||||
"""
|
||||
Tutorial Wallet for the XRP Ledger (TWaXL)
|
||||
user interface, main frame.
|
||||
"""
|
||||
def __init__(self, url):
|
||||
super(TWaXLFrame, self).__init__(None, title="TWaXL")
|
||||
|
||||
self.client = xrpl.clients.JsonRpcClient(url)
|
||||
|
||||
main_panel = wx.Panel(self)
|
||||
main_sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
main_panel.SetSizer(main_sizer)
|
||||
|
||||
st = wx.StaticText(main_panel, label=self.get_validated_ledger())
|
||||
main_sizer.Add(st, wx.SizerFlags().Border(wx.TOP|wx.LEFT, 25))
|
||||
|
||||
def get_validated_ledger(self):
|
||||
try:
|
||||
response = self.client.request(xrpl.models.requests.Ledger(
|
||||
ledger_index="validated"
|
||||
))
|
||||
except Exception as e:
|
||||
return f"Failed to get validated ledger from server. ({e})"
|
||||
|
||||
if response.is_successful():
|
||||
return f"Latest validated ledger: {response.result['ledger_index']}"
|
||||
else:
|
||||
# Connected to the server, but the request failed. This can
|
||||
# happen if, for example, the server isn't synced to the network
|
||||
# so it doesn't have the latest validated ledger.
|
||||
return f"Server returned an error: {response.result['error_message']}"
|
||||
|
||||
if __name__ == "__main__":
|
||||
JSON_RPC_URL = "https://s.altnet.rippletest.net:51234/"
|
||||
#JSON_RPC_URL = "http://localhost:5005/"
|
||||
|
||||
app = wx.App()
|
||||
frame = TWaXLFrame(JSON_RPC_URL)
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
Reference in New Issue
Block a user