Add basic high-level methods
Closed this issue · 1 comments
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.
fields type explanation Sources:
- ...
-
-
Every function has a client
argument. Its type is always only one of WebsocketClient
and AsyncWebsocketClient
. When writing sync high-level methods use WebsocketClient
, when writing async use AsyncWebsocketClient
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.
fields type explanation account &str
An accounts classic address. client WebsocketClient
/AsyncWebsocketClient
A websocket client object. ledger_index Option<&str>
A ledger index. Must be one of "validated", "current", "closed", or an integer as 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.
fields type explanation account &str
An accounts classic address. client WebsocketClient
/AsyncWebsocketClient
A websocket client object. ledger_index Option<&str>
A ledger index. Must be one of: "validated", "current", "closed", integer as 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.
fields type explanation account &str
An accounts classic address. client WebsocketClient
/AsyncWebsocketClient
A websocket client object. ledger_index Optional<&str>
A ledger index. Must be one of: "validated", "current", "closed", integer as 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.
fields type explanation account &str
An accounts classic address. client WebsocketClient
/AsyncWebsocketClient
A websocket client object. ledger_index Optional<&str>
A ledger index. Must be one of: "validated", "current", "closed", integer as 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.
fields type explanation account &str
An accounts classic address. client WebsocketClient
/AsyncWebsocketClient
A websocket client object. ledger_index Option<&str>
A ledger index. Must be one of: "validated", "current", "closed", integer as 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 #17, if the tick is already set.
The user can choose which ledger he wants to query using theledger_index
argument. If noledger_index
is defined (: None
) the default is "validated". If a Ledger Index is defined edit theAccountInfo
request as wished.
fields type explanation account &str
An accounts classic address. client WebsocketClient
/AsyncWebsocketClient
A websocket client object. ledger_index Option<&str>
A ledger index. Must be one of: "validated", "current", "closed", integer as 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 #17, if the tick is already set.
To receive an account's latest transaction define request:AccountTx { command: RequestMethod::AccountTx, // maybe obsolete; check if `<https://github.com/sephynox/xrpl-rust/issues/19)>` is closed. account: account, id: None, ledger_hash: None, ledger_index: None, binary: None, forward: None, ledger_index_min: None, ledger_index_max: -1, limit: 1, marker: None }
fields type explanation account &str
An accounts classic address. client WebsocketClient
/AsyncWebsocketClient
A websocket client object. 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.
fields type explanation account &str
An accounts classic address. client WebsocketClient
/AsyncWebsocketClient
A websocket client object. marker u32
The Marker to request the next batch of transactions. 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
.
fields type explanation account &str
An accounts classic address. client WebsocketClient
/AsyncWebsocketClient
A websocket client object. marker u32
The Marker to request the next batch of transactions. 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.
fields type explanation client WebsocketClient
/AsyncWebsocketClient
A websocket client object. max_fee Option<u32>
The max fee the user want to spend as drops. fee_type Option<&str>
The type of fee to return. Must be one of: "open", "minimum", "dynamic" 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
field -
The
ledger_index
field must be set to "validated".
fields type explanation client WebsocketClient
/AsyncWebsocketClient
A websocket client object. 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
field -
The
ledger_index
field must be set to "open".
fields type explanation client WebsocketClient
/AsyncWebsocketClient
A websocket client object. 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
.
fields type explanation txn_hash &str
The transaction hash. client WebsocketClient
/AsyncWebsocketClient
A websocket client object. binary Option<bool>
A boolean to determine wether to return the transaction as binary serialized to hexadecimal strings or as JSON. min_ledger Option<u32>
A Ledger Index to begin search. max_ledger Option<u32>
A Ledger Index to search up to. Sources:
-
-
sign_transaction
-
Signs a transaction locally.
-
If
check_fee
isNone
,check_fee
is True.
fields type explanation transaction Transaction
The transaction that needs to get signed wallet Wallet
The wallet used to sign the transaction. check_fee Option<bool>
Bool if the provided fee defined in the transaction could be lower. -
-
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
.
fields type explanation transaction Transaction
The transaction that needs to get signed wallet Wallet
The wallet used to sign the transaction. check_fee Option<bool>
Bool if the provided fee defined in the transaction could be lower. client WebsocketClient
/AsyncWebsocketClient
A websocket client object. -
-
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
.
fields type explanation transaction Transaction
The transaction that needs to get signed wallet Wallet
The wallet used to sign the transaction. client WebsocketClient
/AsyncWebsocketClient
A websocket client object. fee_type Option<FeeType>
A enum to determine the fee calculation type. -
-
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
.
fields type explanation transaction Transaction
The transaction that needs to get signed client WebsocketClient
/AsyncWebsocketClient
A websocket client object. 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.
fields type explanation transaction Transaction
The transaction that needs to get signed client WebsocketClient
/AsyncWebsocketClient
A websocket client object. 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.
fields type explanation client WebsocketClient
/AsyncWebsocketClient
A websocket client object. wallet Option<Wallet>
A wallet object to fund. custom_faucet_host Option<&str>
A custom faucet network to use. Sources:
-
-
All these functions should be async. But we should have sync functions which simply call the async ones.
For clarity reasons, every topic (account, ledger, …) gets its own issue.