Add basic high-level methods #21
Labels
3rd month
Planned to be worked on in the third month. Estimate budget: 10,000 $
duplicate
This issue or pull request already exists
enhancement
New feature or request
XRPL Grants
This issue is planned to get resoled as part of the XRPL Grants program (within 8 months)
Need to be done:
#17
AsyncWebsocketClient
Response
We should have high-level methods that predefine often used functions in combination with the public XRP Ledger Server API methods.
Structure
Topic
function, structure, addition, removal, ...
Short explanation of the change.
Short explanation how the change works.
Some particularities.
Sources:
Every function has a
client
argument. Its type is always only one ofWebsocketClient
andAsyncWebsocketClient
. When writing sync high-level methods useWebsocketClient
, when writing async useAsyncWebsocketClient
as type.account:
does_account_exist -> bool
Queries a ledger and checks if an account exists.
The function simply calls the
get_account_info
function. If theResult
is no error the account exists.&str
WebsocketClient
/AsyncWebsocketClient
Option<&str>
Sources:
get_next_valid_account_seq_number -> u32
Queries the ledger for an account to its next valid sequence number.
The function simply calls the
get_account_root
function and returns the AccountRoot object'sSequence
field.&str
WebsocketClient
/AsyncWebsocketClient
Option<&str>
Sources:
get_account_xrp_balance -> Currency
Queries the Ledger for an account's XRP balance.
The function simply calls the
get_account_root
function and returns the AccountRoot object'sBalance
field.Use
drops_to_xrp
to convert the drops amount into a XRP amount.&str
WebsocketClient
/AsyncWebsocketClient
Optional<&str>
Sources:
get_account_balances -> Vec<Currency>
Queries the Ledger for all balances (XRP and Token) a given account holds.
The function calls the
get_account_xrp_balance
and theAccountLines
request method and brings the balances in an easy-to-use format.&str
WebsocketClient
/AsyncWebsocketClient
Optional<&str>
Sources:
get_account_root -> AccountRoot
Queries the ledger for an AccountRoot object of a given address.
The function simply calls the
get_account_info
function and returns the result'saccount_data
field.The return type
AccountRoot
may not be defined yet.&str
WebsocketClient
/AsyncWebsocketClient
Option<&str>
Sources:
get_account_info -> Response
Queries the ledger for account info of an account's address.
The function calls the
AccountInfo
request method using theWebsocketClient
/AsyncWebsocketClient
.The returning
Response
struct may not have been added yet. Keep a look at Add clients #17, if the tick is already set.The user can choose which ledger he wants to query using the
ledger_index
argument. If noledger_index
is defined (: None
) the default is "validated". If a Ledger Index is defined edit theAccountInfo
request as wished.&str
WebsocketClient
/AsyncWebsocketClient
Option<&str>
Sources:
get_latest_transaction -> Response
Queries the Ledger for the last transaction a given account has sent.
The function calls the
AccountTx
request method using theWebsocketClient
/AsyncWebsocketClient
.The returning
Response
struct may not have been added yet. Keep a look at Add clients #17, if the tick is already set.To receive an account's latest transaction define request:
&str
WebsocketClient
/AsyncWebsocketClient
Sources:
get_account_transactions
Queries the Ledger for transactions sent by a given address.
The function calls the
AccountTx
request method using theWebsocketClient
/AsyncWebsocketClient
.If an account has send too many transactions for the node to send, the node sends as many transactions as it can and includes a
marker
field to tell you to how many Ledgers it looked back. You can define themarker
field inAccountTx
to receive the next batch of transactions.&str
WebsocketClient
/AsyncWebsocketClient
u32
Sources:
get_account_payment_transactions
Queries the Ledger for transactions sent by a given address with the
TransactionType
Payment
.The function simply calls the
get_account_transactions
function and filters the list of transactions for transactions withTransactionType
Payment
.&str
WebsocketClient
/AsyncWebsocketClient
u32
Sources:
ledger:
get_fee
Queries the Ledger for the current transaction fee.
The function calls the
Fee
request method using theWebsocketClient
/AsyncWebsocketClient
.The user can decide what type of fee to get. "open" would return the
open_ledger_fee
field; "minimum" would return theminimum_fee
field; "dynamic" would return a calculated fee based on the node's transaction queue size.WebsocketClient
/AsyncWebsocketClient
Option<u32>
Option<&str>
Sources:
get_latest_validated_ledger_sequence
Queries the Ledger for the sequence number of the last validated Ledger.
The function simply calls the
Ledger
request method and returns the resultsledger_index
fieldThe
ledger_index
field must be set to "validated".WebsocketClient
/AsyncWebsocketClient
Sources:
get_latest_open_ledger_sequence
Queries the Ledger for the sequence number of the last open Ledger.
The function simply calls the
Ledger
request method and returns the resultsledger_index
fieldThe
ledger_index
field must be set to "open".WebsocketClient
/AsyncWebsocketClient
Sources:
transaction:
get_transaction_from_hash
Queries the Ledger for a transaction using the given transaction hash.
The function simply calls the
Tx
request method using theWebsocketClient
/AsyncWebsocketClient
.&str
WebsocketClient
/AsyncWebsocketClient
Option<bool>
Option<u32>
Option<u32>
Sources:
sign_transaction
Signs a transaction locally.
If
check_fee
isNone
,check_fee
is True.Transaction
Wallet
Option<bool>
sign_and_submit_transaction
Signs a transaction locally and submits it to the network.
Simply calls the
sign_transaction
function and uses thesubmit
request method to submit the transaction to the network using theWebsocketClient
/AsyncWebsocketClient
.Transaction
Wallet
Option<bool>
WebsocketClient
/AsyncWebsocketClient
autofill_and_sign_transaction
Autofills and locally signs a transaction.
Autofills fields like
fee
and signs the given transaction locally by callingsign_transaction
.The method should have a parameter to choose the
get_fee
calculation type. This Parameter should be optional. IfNone
the default value should beFeeType::Open
.Transaction
Wallet
WebsocketClient
/AsyncWebsocketClient
Option<FeeType>
submit_transaction -> Response
Submits a signed transaction to the XRP Ledger.
Turns a transaction into a transaction blob and uses the
SubmitOnly
request method to submit it using theclient
.Transaction
WebsocketClient
/AsyncWebsocketClient
Sources:
send_reliable_submission -> Response
Submits a transaction to the XRP Ledger and waits until it got a result from the Ledger back.
Calls the
submit_transaction
and waits untilget_transaction_from_hash
returns a validated transaction.Transaction
WebsocketClient
/AsyncWebsocketClient
Sources:
wallet:
generate_faucet_wallet
Generates a random wallet and funds it with some amount of XRP (usually 1000 XRP).
The function uses the
destination
field to tell what account to fund.WebsocketClient
/AsyncWebsocketClient
Option<Wallet>
Option<&str>
Sources:
All these functions should be async. But we should have sync functions which simply call the async ones.
The text was updated successfully, but these errors were encountered: