-
Notifications
You must be signed in to change notification settings - Fork 415
/
sys.rs
127 lines (107 loc) · 4.42 KB
/
sys.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright 2018-2019 Parity Technologies (UK) Ltd.
// This file is part of ink!.
//
// ink! is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ink! is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ink!. If not, see <http://www.gnu.org/licenses/>.
//! External C API to communicate with substrate contracts runtime module.
//!
//! Refer to substrate SRML contract module for more documentation.
extern "C" {
/// Creates a new smart contract account.
#[allow(unused)]
pub fn ext_create(
init_code_ptr: u32,
init_code_len: u32,
gas: u64,
value_ptr: u32,
value_len: u32,
input_data_ptr: u32,
input_data_len: u32,
) -> u32;
/// Calls a remote smart contract.
#[allow(unused)]
pub fn ext_call(
callee_ptr: u32,
callee_len: u32,
gas: u64,
value_ptr: u32,
value_len: u32,
input_data_ptr: u32,
input_data_len: u32,
) -> u32;
/// Tells the execution environment to load the raw byte
/// representation of the caller into the scratch buffer.
pub fn ext_caller();
/// Prints the contents of `str_ptr` to the console.
///
/// # Note
///
/// This must only be used in `--dev` chain environments!
pub fn ext_println(str_ptr: u32, str_len: u32);
/// Deposits raw event data through the Contracts module.
pub fn ext_deposit_event(
topics_ptr: u32,
topics_len: u32,
data_ptr: u32,
data_len: u32,
);
/// Writes the contents of the buffer at `value_ptr` into the
/// storage slot associated with the given key or clears the
/// associated slot if `value_non_null` is `0`.
pub fn ext_set_storage(
key_ptr: u32,
value_non_null: u32,
value_ptr: u32,
value_len: u32,
);
/// Dispatches a Call into the runtime, for invocation of substrate modules
///
/// Call data is written to the scratch buffer, and it MUST be decodable into the host chain
/// runtime `Call` type.
pub fn ext_dispatch_call(call_ptr: u32, call_len: u32);
/// Tells the execution environment to load the contents
/// stored at the given key into the scratch buffer.
pub fn ext_get_storage(key_ptr: u32) -> u32;
/// Returns the length in bytes of the scratch buffer.
pub fn ext_scratch_size() -> u32;
/// Reads the contents of the scratch buffer at the host site starting at `offset` and writes them to the
/// buffer starting at `dst_ptr` with length `len` on the smart contract site.
pub fn ext_scratch_read(dst_ptr: u32, offset: u32, len: u32);
/// Immediately returns contract execution to the caller
/// with the provided data at `data_ptr`.
pub fn ext_return(data_ptr: u32, data_len: u32) -> !;
/// Stores the address of the current contract into the scratch buffer.
pub fn ext_address();
/// Stores the balance of the current account into the scratch buffer.
///
/// The data is encoded as T::Balance. The current contents of the scratch buffer are overwritten.
pub fn ext_balance();
/// Stores the gas price for the current transaction into the scratch buffer.
///
/// The data is encoded as T::Balance. The current contents of the scratch buffer are overwritten.
pub fn ext_gas_price();
/// Stores the amount of gas left into the scratch buffer.
///
/// The data is encoded as T::Balance. The current contents of the scratch buffer are overwritten.
pub fn ext_gas_left();
/// Stores the value transferred along with this call or as endowment into the scratch buffer.
///
/// The data is encoded as T::Balance. The current contents of the scratch buffer are overwritten.
pub fn ext_value_transferred();
/// Load the latest block RNG seed into the scratch buffer.
pub fn ext_random_seed();
/// Load the latest block timestamp into the scratch buffer.
pub fn ext_now();
/// Load the latest block number into the scratch buffer.
pub fn ext_block_number();
}