Skip to content

Instantly share code, notes, and snippets.

View valstu's full-sized avatar

Valtteri Karesto valstu

View GitHub Profile
import {
accept,
emit,
etxn_details,
etxn_fee_base,
etxn_reserve,
hook_account,
ledger_seq,
otxn_field,
rollback,
import {
accept,
emit,
etxn_details,
etxn_fee_base,
etxn_reserve,
hook_account,
ledger_seq,
otxn_field,
rollback,

Carbon

Carbon hook sends a percentage of outgoing payments to a dedicated account.

The beneficiary account is hard-coded, so while the default version of carbon.c works, it works with an account that cannot be imported into Hooks Builder (unless you know its secret key). See later examples for how to parametrize a hook.

to test:

  • make sure Hooks Builder has at least 3 accounts: Alice, Bob and Carol
  • in carbon.c, change hardcoded beneficiary to Carol account
  • compile carbon.c and deploy it to Alice account
@external("env", "_g")
export declare function GUARD(id: i32, maxiter: i32): i32
@external("env", "accept")
export declare function ACCEPT(read_ptr: string, read_len: i32, err: i64): i64
@external("env", "trace")
export declare function TRACE(mread_ptr: string, mread_len: i32, dread_ptr: string, dread_len: i32, as_hex: i32): i64
////////////////////
@external("env", "_g")
export declare function _g(id: i32, maxiter: i32): i64
@external("env", "accept")
export declare function accept(read_ptr: string, read_len: i32, err: i64): i64
@external("env", "trace")
export declare function TRACE(mread_ptr: string, mread_len: i32, dread_ptr: string, dread_len: i32, as_hex: i32): i64
////////////////////////
import lib from "https://esm.sh/xrpl-accountlib?bundle";
import bin from "https://esm.sh/ripple-binary-codec?bundle";
import { XrplClient } from "https://esm.sh/xrpl-client?bundle";
// Alice
const notary_account = '{{ notary_account }}';
// Bob
const proposer_secret = '{{ proposer_secret }}';
const proposer_account = '{{ proposer_account }}';
<html>
<head>
<script type="module">
import lib from "https://esm.sh/xrpl-accountlib?bundle";
import bin from "https://esm.sh/ripple-binary-codec?bundle";
import { XrplClient } from "https://esm.sh/xrpl-client?bundle";
// Alice
@valstu
valstu / aa
Last active June 3, 2022 13:15
// oj
/**
* This hook just accepts any transaction coming through it
*/
#include "hookapi.h"
int64_t cbak(uint32_t reserved) {
return 0;
}