Add ext_transfer call (#5169)

* contracts: Add ext_transfer call

This call allows contracts to send balance to any account
contract or not. Previously, the only way to do that was
though ext_call.

* Apply suggestions from code review

Co-Authored-By: Nikolay Volf <nikvolf@gmail.com>

* The define_env! macro does not allow for trailing comma

* Update frame/contracts/src/exec.rs

Co-Authored-By: Nikolay Volf <nikvolf@gmail.com>

* Bump spec version

* Do not use nested gas meter

* Use explicit 0 or 1 as return value

* Remove superflous intermediate binding

Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
This commit is contained in:
Alexander Theißen
2020-03-14 12:49:22 +01:00
committed by GitHub
parent 7e2cd0edee
commit b817763ea9
5 changed files with 158 additions and 4 deletions
+15
View File
@@ -291,6 +291,21 @@ performed. Moreover, the DB read has to be synchronous and no progress can be ma
**complexity**: The memory and computing complexity is proportional to the size of the fetched value. This function performs a
DB read.
## ext_transfer
This function receives the following arguments:
- `account` buffer of a marshaled `AccountId`,
- `value` buffer of a marshaled `Balance`,
It consists of the following steps:
1. Loading `account` buffer from the sandbox memory (see sandboxing memory get) and then decoding it.
2. Loading `value` buffer from the sandbox memory and then decoding it.
4. Invoking the executive function `transfer`.
Loading of `account` and `value` buffers should be charged. This is because the sizes of buffers are specified by the calling code, even though marshaled representations are, essentially, of constant size. This can be fixed by assigning an upper bound for sizes of `AccountId` and `Balance`.
## ext_call
This function receives the following arguments: