Files
pezkuwi-subxt/substrate/frame/contracts/fixtures/self_destruct.wat
T
Alexander Theißen 25de5b5c78 seal: Rework contracts API (#6573)
* Transition getter functions to not use scratch buffer

* Remove scratch buffer from ext_get_storage

* Remove scratch buffer from ext_call

* Remove scratch buffer from ext_instantiate

* Add ext_input and remove scratch buffer

* Rework error handling (changes RPC exposed data)

* ext_return passes a flags field instead of a return code
	* Flags is only for seal and not for the caller
	* flags: u32 replaced status_code: u8 in RPC exposed type
* API functions use a unified error type (ReturnCode)
* ext_transfer now traps on error to be consistent with call and instantiate

* Remove the no longer used `Dispatched` event

* Updated inline documentation

* Prevent skipping of copying the output for getter API

* Return gas_consumed from the RPC contracts call interface

* Updated COMPLEXTITY.md

* Rename ext_gas_price to ext_weight_to_fee

* Align comments with spaces

* Removed no longer used `ExecError`

* Remove possible panic in `from_typed_value`

* Use a struct as associated data for SpecialTrap::Return

* Fix nits in COMPLEXITY.md

* Renamed SpecialTrap to TrapReason

* Fix test

* Finish renaming special_trap -> trap_reason

* Remove no longer used get_runtime_storage

* fixup! Remove no longer used get_runtime_storage

* Removed tabs for comment aligment
2020-07-09 13:07:02 +00:00

81 lines
2.3 KiB
WebAssembly Text Format

(module
(import "env" "ext_input" (func $ext_input (param i32 i32)))
(import "env" "ext_address" (func $ext_address (param i32 i32)))
(import "env" "ext_call" (func $ext_call (param i32 i32 i64 i32 i32 i32 i32 i32 i32) (result i32)))
(import "env" "ext_terminate" (func $ext_terminate (param i32 i32)))
(import "env" "memory" (memory 1 1))
;; [0, 8) reserved for $ext_address output
;; [8, 16) length of the buffer
(data (i32.const 8) "\08")
;; [16, 24) Address of django
(data (i32.const 16) "\04\00\00\00\00\00\00\00")
;; [24, 32) reserved for output of $ext_input
;; [32, 36) length of the buffer
(data (i32.const 32) "\04")
;; [36, inf) zero initialized
(func $assert (param i32)
(block $ok
(br_if $ok
(get_local 0)
)
(unreachable)
)
)
(func (export "deploy"))
(func (export "call")
;; If the input data is not empty, then recursively call self with empty input data.
;; This should trap instead of self-destructing since a contract cannot be removed live in
;; the execution stack cannot be removed. If the recursive call traps, then trap here as
;; well.
(call $ext_input (i32.const 24) (i32.const 32))
(if (i32.load (i32.const 32))
(then
(call $ext_address (i32.const 0) (i32.const 8))
;; Expect address to be 8 bytes.
(call $assert
(i32.eq
(i32.load (i32.const 8))
(i32.const 8)
)
)
;; Recursively call self with empty input data.
(call $assert
(i32.eq
(call $ext_call
(i32.const 0) ;; Pointer to own address
(i32.const 8) ;; Length of own address
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
(i32.const 36) ;; Pointer to the buffer with value to transfer
(i32.const 8) ;; Length of the buffer with value to transfer
(i32.const 0) ;; Pointer to input data buffer address
(i32.const 0) ;; Length of input data buffer
(i32.const 4294967295) ;; u32 max sentinel value: do not copy output
(i32.const 0) ;; Length is ignored in this case
)
(i32.const 0)
)
)
)
(else
;; Try to terminate and give balance to django.
(call $ext_terminate
(i32.const 16) ;; Pointer to beneficiary address
(i32.const 8) ;; Length of beneficiary address
)
(unreachable) ;; ext_terminate never returns
)
)
)
)