Crates.io | hooks-rs |
lib.rs | hooks-rs |
version | |
source | src |
created_at | 2023-10-13 13:58:33.226795 |
updated_at | 2025-01-29 14:33:28.534985 |
description | Hooks in Rust for Xahau |
homepage | |
repository | https://github.com/9oelm/hooks-rs/ |
max_upload_size | |
id | 1002328 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Xahau hooks in Rust and CLI to build and deploy hooks.
[!WARNING] Only MacOS and Linux are supported for now. Windows is not supported.
Before anything, install deno.
deno install --allow-all --allow-scripts --global jsr:@hooks-rs/cli --name hooks # install the CLI as "hooks"
hooks # see help
hooks up # install binary dependencies
hooks new hooks-example # init new project called "hooks-example"
cd hooks-example
hooks account # create a new account for deployment
hooks build # build hook
hooks deploy --hook-on INVOKE # deploy the hook
new <projectName> - Initializes a new hooks-rs template in a new folder in the current working
directory
up - Installs all prerequisite binaries
check - Checks if all prerequisite binaries are installed and available in PATH
account - Create a new testnet account stored in account.json
build - Compile and preprocess a hook
deploy - Build and deploy a hook to Xahau network
uninstall - Uninstall all prerequisite binaries installed by 'up' command.
test - Run tests for the project
This is the most basic accept.rs hook, and it looks like this:
#![no_std]
#![no_main]
use hooks_rs::*;
#[no_mangle]
pub extern "C" fn cbak(_: u32) -> i64 {
0
}
#[no_mangle]
pub extern "C" fn hook(_: u32) -> i64 {
// Every hook needs to import guard function
// and use it at least once
max_iter(1);
// Log it to the debug stream, which can be inspected on the website or via wss connection
let _ = trace(b"accept.rs: Called.", b"", DataRepr::AsUTF8);
// Accept all
accept(b"accept.rs: Finished.", line!().into());
}
Other examples are under /examples
directory. Check them out!.
Most implementations are thoroughly documented. Please check out the book and crate docs.
Still, a lot of functions are WIP. Contributions are welcome.
Control
accept
rollback
Utilities
util_raddr
util_accid
util_verify
util_sha512h
util_keylet
Serialization
sto_subfield
sto_subarray
sto_emplace
sto_erase
sto_validate
Emitted transaction
etxn_burden
etxn_details
etxn_fee_base
etxn_nonce
etxn_reserve
etxn_generation
emit
Float
float_set
float_multiply
float_mulratio
float_negate
float_compare
float_sum
float_sto
float_sto_set
float_invert
float_divide
float_one
float_exponent
float_mantissa
float_sign
float_int
float_root
float_log
Ledger
fee_base
ledger_seq
ledger_last_hash
ledger_last_time
ledger_nonce
ledger_keylet
Hook context
hook_account
hook_hash
hook_param
hook_param_set
hook_skip
hook_pos
hook_again
Slot
slot
slot_clear
slot_count
slot_set
slot_size
slot_subarray
slot_subfield
slot_type
xpop_slot
slot_float
State
state
state_set
state_foreign
state_foreign_set
Trace
trace
trace_num
trace_float
Originating transaction
otxn_burden
otxn_field
otxn_generation
otxn_id
otxn_type
otxn_slot
otxn_param
meta_slot
The latest header files can be found at https://github.com/XRPLF/hook-macros
There are still many parts of the C API that are not supported yet. The first priority for now would be to get all of them working.
If you have all checkboxes below ticked, you can proceed to create a PR:
/tests
folder to see the existing integration test examples. Currently, each integration test would cover the smallest unit of testable 'chunk', because hooks is impossible to be tested without a live connection with an actual XRPL node, no matter if it is on local docker or is one of the testnet nodes. Therefore, an integration test is somewhat like an unit test but still connects to an actual XRPL node to run the hook to see if it actually works. Make sure the all of the state changes caused by the hook are correctly asserted, before and after the execution of the hook./examples
folder. The example hook file should contain the most minimal example of how the feature that you have added can be used. Use this example as a documentation for the function as well, so that it can appear in the generated documentation.Remember that this repository is a novel combination of two amazing concepts: Rust and Hooks. And neither of these are easy nor familiar with the general audience. If you are not sure where to start, probably start with the book, which will give you some idea to start with.