CKB Pulse

All lessons · Rust scripts and ckb-std · Start here · Glossary

Iterating group inputs and outputs with ckb-std until IndexOutOfBoundWorkingFrom one fix

From one fix · Check: right · Checked 2026-11-19

In a ckb-std script, walk the cells of a source with the high-level loaders, for example load_cell_type_hash(i, Source::GroupInput) or load_cell_lock_hash(j, Source::Output), in an index loop. Break on Err(SysError::IndexOutOfBound), and return a script error code for any other SysError. Accumulate the u64 capacities you load in a u128 so that a sum over many cells cannot overflow.

Why it matters: Without the IndexOutOfBound break the loop has no clean end condition, and treating every load error as the end of the list would hide real syscall failures.

Pattern

Prefer
Err(SysError::IndexOutOfBound) => break,

Taken from the commit, shortened.

A test changed in the same commit

It sits next to the fix. We did not run it.

Concepts
Capacity and cell size, Cell deps and script lookup
Evidence
From one fix: from one project, checked against its commit
First seen
2026-11-08
Last changed
2026-11-08
Last checked
2026-11-19
Check against the commit
right: the lesson follows from its commit and still holds in the code today

Sources (1)

More about Rust scripts and ckb-std

All 35 in this topic

Do you maintain a project this lesson came from? Confirm or correct it

Cite this lesson
LusoCryptoLabs, "Iterating group inputs and outputs with ckb-std until IndexOutOfBound", CKB lessons, https://pulse.lusocryptolabs.com/learned/scripts/iterating-group-inputs-and-outputs-with-ckb-std-until-indexo, CC BY 4.0, last changed 2026-11-08.

Drawn from public commits and checked against the commit each one came from and the project's code today. Read the source before you rely on one. Text under CC BY 4.0: credit LusoCryptoLabs, CKB lessons, with a link to the lesson. Want a lesson changed or removed? Open an issue.