Contracts expose pallet-xcm (#1248)

This PR introduces:
- XCM  host functions `xcm_send`, `xcm_execute`
- An Xcm trait into the config. that proxy these functions to to
`pallet_xcm`, or disable their usage by using `()`.
- A mock_network and xcm_test files to test the newly added xcm-related
functions.

---------

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
Co-authored-by: command-bot <>
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
This commit is contained in:
PG Herveou
2023-11-14 21:32:14 +01:00
committed by GitHub
parent fc12f435e3
commit f517900a48
23 changed files with 1797 additions and 15 deletions
@@ -0,0 +1,52 @@
;; This passes its input to `seal_xcm_execute` and returns the return value to its caller.
(module
(import "seal0" "xcm_execute" (func $xcm_execute (param i32 i32 i32) (result i32)))
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
(import "env" "memory" (memory 1 1))
;; 0x1000 = 4k in little endian
;; Size of input buffer
(data (i32.const 0) "\00\10")
(func $assert (param i32)
(block $ok
(br_if $ok
(get_local 0)
)
(unreachable)
)
)
(func (export "call")
;; Receive the encoded call
(call $seal_input
(i32.const 4) ;; Pointer to the input buffer
(i32.const 0) ;; Pointer to the buffer length (before call) and to the copied data length (after call)
)
;; Input data layout.
;; [0..4) - size of the call
;; [4..) - message
;; Call xcm_execute with provided input.
(call $assert
(i32.eq
(call $xcm_execute
(i32.const 4) ;; Pointer where the message is stored
(i32.load (i32.const 0)) ;; Size of the message
(i32.const 100) ;; Pointer to the where the outcome is stored
)
(i32.const 0)
)
)
(call $seal_return
(i32.const 0) ;; flags
(i32.const 100) ;; Pointer to returned value
(i32.const 10) ;; length of returned value
)
)
(func (export "deploy"))
)