Skip to content

Latest commit

 

History

History
36 lines (26 loc) · 2.83 KB

README.js.md

File metadata and controls

36 lines (26 loc) · 2.83 KB

Custom Script Example - Lumos (JavaScript)

Full Example

To add new scripts, Lumos provides registerCustomLockScriptInfos. For each lock script, a LockScriptInfo object is mandatory.

Inside LockScriptInfo.lockScriptInfo, the lock script must implement following interfaces:

  • The CellCollector must be a constructor function or class and is used by Lumos to locate live cells for transaction inputs. For each address and registered lock script, Lumos will create an instance of CellCollector. The responsibility of filtering out cells that do not match the lock script lies with the CellCollector; Lumos does not perform this check. The initialized object's mandatory interface is async *collect(), an async generator.
  • When a live cell is found by the CellCollector instance, Lumos invokes the setupInputCell method within the corresponding LockScriptInfo. This method is responsible for adding the input to the transaction and including a matching output cell. This is necessary since Lumos searches for the available balance of an address in the outputs during transaction building.
  • The prepareSigningEntries method serves as a callback in lumos.commons.common.prepareSigningEntries. Its purpose is to add signing entries for each input that requires storing a signature in the witness. A singing entry has 3 fields:
    • index: the witness index where the signature is stored
    • message: this refers to the message waiting for signature.
    • type: the one available value is witness_args_lock. This value specifies that the witness is a serialized WitnessArgs, and its lock field contains the signature of the lock script.

Summary

  • Live Cells Collector: Script is responsible for live cells filtering via CellCollector
  • Dep Cell: Via setupInputCell
  • Pre-fill Witness: Required, via setupInputCell
  • Signing: Via prepareSigningEntries and an external helper to generate signatures from signing entries.
  • Extra Data
    • Has access to input cells
    • Cannot access dep headers
    • LockScriptInfo cannot receive extra data from client.

Issues

  • LockScriptInfo lacks documentations about the interfaces.
  • Lumos imposes many implict requirements on the implementation of setupInputCell.
  • Setting up a script requires a significant amount of bootstrap code. Compared to the Java example, it took over 100 lines of code more.