|
| 1 | +;; Call chain extension by passing through input and output of this contract |
| 2 | +(module |
| 3 | + (import "seal0" "seal_call_chain_extension" |
| 4 | + (func $seal_call_chain_extension (param i32 i32 i32 i32 i32) (result i32)) |
| 5 | + ) |
| 6 | + (import "seal0" "seal_input" (func $seal_input (param i32 i32))) |
| 7 | + (import "seal0" "seal_return" (func $seal_return (param i32 i32 i32))) |
| 8 | + (import "env" "memory" (memory 16 16)) |
| 9 | + |
| 10 | + (func $assert (param i32) |
| 11 | + (block $ok |
| 12 | + (br_if $ok (get_local 0)) |
| 13 | + (unreachable) |
| 14 | + ) |
| 15 | + ) |
| 16 | + |
| 17 | + ;; [0, 4) len of input output |
| 18 | + (data (i32.const 0) "\02") |
| 19 | + |
| 20 | + ;; [4, 12) buffer for input |
| 21 | + |
| 22 | + ;; [12, 16) len of output buffer |
| 23 | + (data (i32.const 12) "\02") |
| 24 | + |
| 25 | + ;; [16, inf) buffer for output |
| 26 | + |
| 27 | + (func (export "deploy")) |
| 28 | + |
| 29 | + (func (export "call") |
| 30 | + (call $seal_input (i32.const 4) (i32.const 0)) |
| 31 | + |
| 32 | + ;; the chain extension passes through the input and returns it as output |
| 33 | + (call $seal_call_chain_extension |
| 34 | + (i32.load8_u (i32.const 4)) ;; func_id |
| 35 | + (i32.const 4) ;; input_ptr |
| 36 | + (i32.load (i32.const 0)) ;; input_len |
| 37 | + (i32.const 16) ;; output_ptr |
| 38 | + (i32.const 12) ;; output_len_ptr |
| 39 | + ) |
| 40 | + |
| 41 | + ;; the chain extension passes through the func_id |
| 42 | + (call $assert (i32.eq (i32.load8_u (i32.const 4)))) |
| 43 | + |
| 44 | + (call $seal_return (i32.const 0) (i32.const 16) (i32.load (i32.const 12))) |
| 45 | + ) |
| 46 | +) |
0 commit comments