Apply suggestions from code review

Co-authored-by: tequ <git@tequ.dev>
This commit is contained in:
Thomas Silkjær
2025-11-18 13:49:35 +01:00
committed by GitHub
parent 0d215df7d9
commit c07613ee1f
18 changed files with 28 additions and 28 deletions

View File

@@ -73,7 +73,7 @@ const phash = [ 0x19, 0xFE, 0x69, 0xF1, 0x53, 0x66, 0x4E, 0x8C,
0x97, 0xF4, 0x4C, 0x5C, 0x3C, 0x65, 0x63, 0x79,
0xC2, 0xD0, 0x26, 0xE7, 0x90, 0xEF, 0x38, 0xF7,
0xED, 0x73, 0xE9, 0xCE, 0x9C, 0x9D, 0xBF, 0x03 ]
const result = hook_param_set(str2hex(./pvalue), str2hex(./pname), phash)
const result = hook_param_set(str2hex(pvalue), str2hex(pname), phash)
```
</TabItem>
</Tabs>

View File

@@ -13,7 +13,7 @@ import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs>
<TabItem label="C">
```c
int64_t hook_pos(./void);
int64_t hook_pos(void);
```
</TabItem>
<TabItem label="JavaScript">

View File

@@ -10,7 +10,7 @@ import { Tabs, TabItem } from '@astrojs/starlight/components';
<TabItem label="C">
* Read a 34 byte Keylet from the `lread_ptr`
* Read a 32 byte Keylet from the `hread_ptr`
* Search the ledger for the first (./lowest) Keylet of this type in this range.
* Search the ledger for the first (lowest) Keylet of this type in this range.
* If any matching Keylet is found, write it to `write_ptr`.
</TabItem>

View File

@@ -56,7 +56,7 @@ int64_t value_len =
<TabItem label="JavaScript">
```javascript
const pname = [0xCA, 0xFE]
const pvalue = otxn_param(./pname)
const pvalue = otxn_param(pname)
```
</TabItem>
</Tabs>

View File

@@ -50,7 +50,7 @@ Some Hook APIs may only write or may only read from memory, and some might not d
</TabItem>
<TabItem label="JavaScript">
All parameters passed to a Hook API must be one of: `string, number[], bigint(./xfl), object(./json)`. Typically these are pointers and lengths of buffers within the Hook's stack frame. Sometimes they are [Integer Encoded Floating Point Numbers (XFL)](/docs/hooks/concepts/floating-point-numbers-xfl) or other data.
All parameters passed to a Hook API must be one of: `string, number[], bigint(xfl), object(json)`. Typically these are pointers and lengths of buffers within the Hook's stack frame. Sometimes they are [Integer Encoded Floating Point Numbers (XFL)](/docs/hooks/concepts/floating-point-numbers-xfl) or other data.
The parameters to a Hook API are always in the following order:

View File

@@ -3,7 +3,7 @@ title: Return Codes
---
### Return code design
Web assembly allows for exceptions (./traps) however this language feature is not used for Hooks. Instead there is only one way to return from any Hook API (you may think of every Hook API as being `noexcept`).
Web assembly allows for exceptions (traps) however this language feature is not used for Hooks. Instead there is only one way to return from any Hook API (you may think of every Hook API as being `noexcept`).
To provide for efficient error handling:

View File

@@ -72,7 +72,7 @@ function sto_emplace(
uint8_t tx_out[1024];
int64_t tx_len =
sto_emplace(tx_out, sizeof(./tx_out),
sto_emplace(tx_out, sizeof(tx_out),
tx_in, tx_len,
sequence_field, 5, sfSequence);
@@ -106,7 +106,7 @@ if (typeof tx_out === 'number')
| sread_len | uint32_t | The Length of the source object |
| fread_ptr | uint32_t | The buffer to read the field to be emplaced/injected from |
| fread_len | uint32_t | The length of the field to be emplaced/injected |
| field_id | uint32_t | The `sf` code (./location) to form the emplacement. If this already exists in the source object then the existing field is overriden. If it doesn't exist it is inserted. |
| field_id | uint32_t | The `sf` code (location) to form the emplacement. If this already exists in the source object then the existing field is overriden. If it doesn't exist it is inserted. |
</TabItem>

View File

@@ -61,7 +61,7 @@ function sto_erase(
<TabItem label="C">
```c
int64_t result =
sto_erase(tx_out, sizeof(./tx_out),
sto_erase(tx_out, sizeof(tx_out),
tx_in, tx_len, sfSigners);
if (tx_len <= 0)
@@ -93,7 +93,7 @@ if (typeof tx_out === 'number')
| write_len | uint32_t | The length of the output buffer |
| read_ptr | uint32_t | The buffer to read the source STObject from |
| read_len | uint32_t | The Length of the source object |
| field_id | uint32_t | The `sf` code (./location) to erase |
| field_id | uint32_t | The `sf` code (location) to erase |
</TabItem>

View File

@@ -78,8 +78,8 @@ if (memo_lookup < 0)
else
{
// 0th index of the STArray was found and its location is as follows:
uint8_t* memo_ptr = SUB_OFFSET(./memo_lookup) + memos;
uint32_t memo_len = SUB_LENGTH(./memo_lookup);
uint8_t* memo_ptr = SUB_OFFSET(memo_lookup) + memos;
uint32_t memo_len = SUB_LENGTH(memo_lookup);
}
```
@@ -102,8 +102,8 @@ if (typeof memo_lookup === 'number')
else
{
// 0th index of the STArray was found and its location is as follows:
const memo_start = SUB_OFFSET(./memo_lookup)
const memo_len = SUB_LENGTH(./memo_lookup)
const memo_start = SUB_OFFSET(memo_lookup)
const memo_len = SUB_LENGTH(memo_lookup)
const memo = memos.slice(memo_start, memo_len)
}
```

View File

@@ -79,8 +79,8 @@ if (memos_lookup < 0)
else
{
// sfMemos was found and its location is as follows:
uint8_t* memos_ptr = SUB_OFFSET(./memos_lookup) + memos_ptr;
int64_t memos_len = SUB_LENGTH(./memos_lookup);
uint8_t* memos_ptr = SUB_OFFSET(memos_lookup) + memos_ptr;
int64_t memos_len = SUB_LENGTH(memos_lookup);
}
```
@@ -101,8 +101,8 @@ if (typeof memos_lookup === 'number')
else
{
// sfMemos was found and its location is as follows:
const memo_start = SUB_OFFSET(./memos_lookup)
const memo_len = SUB_LENGTH(./memos_lookup)
const memo_start = SUB_OFFSET(memos_lookup)
const memo_len = SUB_LENGTH(memos_lookup)
const memo = txn.slice(memo_start, memo_len)
}
```

View File

@@ -53,7 +53,7 @@ function sto_validate(blob: ByteArray | HexString): ErrorCode | number
<TabItem label="C">
```c
int64_t result =
sto_validate(tx_out, sizeof(./tx_out));
sto_validate(tx_out, sizeof(tx_out));
if (tx_len <= 0)
rollback("Invalid STO.", 12, 1);

View File

@@ -81,8 +81,8 @@ To delete the state use `state_set(null, key);`.
<TabItem label="C">
| Name | Type | Description |
| ---------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| read_ptr | uint32_t | <p>Pointer to the data (./value) to write into Hook State.<br />If this is <code>0</code> (./null) then delete the data at this key. <em>May be null.</em></p> |
| read_len | uint32_t | <p>The length of the data.<br />If this is <code>0</code> (./null) then delete the data at this key. <em>May be null.</em></p> |
| read_ptr | uint32_t | <p>Pointer to the data (value) to write into Hook State.<br />If this is <code>0</code> (null) then delete the data at this key. <em>May be null.</em></p> |
| read_len | uint32_t | <p>The length of the data.<br />If this is <code>0</code> (null) then delete the data at this key. <em>May be null.</em></p> |
| kread_ptr | uint32_t | A pointer to the Hook State key at which to store the value. |
| kread_len | uint32_t | The length of the key. (Should always be 32.) |

View File

@@ -43,8 +43,8 @@ function trace(
<Tabs>
<TabItem label="C">
```c
#define SBUF(./str) (uint32_t)(./str), sizeof(./str)
trace(SBUF("Buffer conatained"), SBUF(./some_buffer), 1);
#define SBUF(str) (uint32_t)(str), sizeof(str)
trace(SBUF("Buffer conatained"), SBUF(some_buffer), 1);
```
</TabItem>

View File

@@ -29,7 +29,7 @@ int64_t trace_float (
<Tabs>
<TabItem label="C">
```c
#define SBUF(./str) (uint32_t)(./str), sizeof(./str)
#define SBUF(str) (uint32_t)(str), sizeof(str)
trace_float(SBUF("This is a float"), float_one());
```
</TabItem>

View File

@@ -29,7 +29,7 @@ int64_t trace_num (
<Tabs>
<TabItem label="C">
```c
#define SBUF(./str) (uint32_t)(./str), sizeof(./str)
#define SBUF(str) (uint32_t)(str), sizeof(str)
trace_num(SBUF("This is an integer"), 10);
```
</TabItem>

View File

@@ -54,7 +54,7 @@ uint8_t accid_out[20];
uint8_t raddr_in[] = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh";
int64_t bytes_written =
util_accid(accid_out, 20, raddr_in, sizeof(./raddr_in)-1);
util_accid(accid_out, 20, raddr_in, sizeof(raddr_in)-1);
// NB: if specified as a c-string as above, account for the nul char
```

View File

@@ -113,7 +113,7 @@ if (util_keylet(
| <p>KEYLET_UNCHECKED<br />KEYLET_CHILD<br />KEYLET_EMITTED_TXN</p> | <p><code>a</code> points to a key.<br /><code>b</code> is the length of the key (should be 32.)<br /><code>c</code>, <code>d</code>, <code>e</code>, <code>f</code> must both be zero</p> |
| <p>KEYLET_OWNER_DIR<br />KEYLET_SIGNERS<br />KEYLET_ACCOUNT<br />KEYLET_HOOK</p> | <p><code>a</code> points to an Account ID.<br /><code>b</code> is the length (should be 20.)<br /><code>c</code>, <code>d</code>, <code>e</code>, <code>f</code> must all be zero.</p> |
| KEYLET_PAGE | <p><code>a</code> points to a key.<br /><code>b</code> is the length of the key (should be 32.)<br /><code>c</code> is the high 32 bits of the uint64 to pass<br /><code>d</code> is the low 32 bits of the uint64 to pass<br /><code>e</code>, <code>f</code> must both be zero</p> |
| <p>KEYLET_OFFER<br />KEYLET_CHECK<br />KEYLET_ESCROW<br />KEYLET_NFT_OFFER</p> | <p><code>a</code> points to an Account ID.<br /><code>b</code> is the length (should be 20.)<br />And Either:<br /><code>c</code> is a 32bit unsigned integer (./sequence)<br /><code>d</code> is 0<br />Or:<br /><code>c</code> points to a 32 byte key<br /><code>d</code> is the length of the key (32).<br />In both cases:<br /><code>e</code> and <code>f</code> must be 0.</p> |
| <p>KEYLET_OFFER<br />KEYLET_CHECK<br />KEYLET_ESCROW<br />KEYLET_NFT_OFFER</p> | <p><code>a</code> points to an Account ID.<br /><code>b</code> is the length (should be 20.)<br />And Either:<br /><code>c</code> is a 32bit unsigned integer (sequence)<br /><code>d</code> is 0<br />Or:<br /><code>c</code> points to a 32 byte key<br /><code>d</code> is the length of the key (32).<br />In both cases:<br /><code>e</code> and <code>f</code> must be 0.</p> |
| KEYLET_PAYCHAN | <p><code>a</code> points to an Account ID<br /><code>b</code> is the length (should be 20)<br /><code>c</code> points to an Account ID<br /><code>d</code> is the length (should be 20)<br />And Either:<br /><code>e</code> 32bit unsigned int to pass<br /><code>f</code> is zero<br />Or:<br /><code>e</code> points to a 32 byte key<br /><code>f</code> is the length of the key (32)</p> |

View File

@@ -54,7 +54,7 @@ uint8_t acc_id[20] =
0x35U, 0x91U, 0x4U, 0x7bU, 0xfaU, 0x1eU, 0xeU
};
int64_t bytes_written =
util_raddr(raddr_out, sizeof(./raddr_out), acc_id, 20);
util_raddr(raddr_out, sizeof(raddr_out), acc_id, 20);
```