Contracts: Stabilize APIs (#3384)

Remove `#[unstable]` on `call_v2`, `instantiate_v2`,
`lock_delegate_dependency` and `unlock_delegate_dependency`.
See ink! integrations: 
- call_v2: https://github.com/paritytech/ink/pull/2077
- instantiate_v2: <TODO>
- lock/unlock dependency: https://github.com/paritytech/ink/pull/2076
This commit is contained in:
PG Herveou
2024-02-20 15:28:05 +01:00
committed by GitHub
parent e89d0fca35
commit d250a6e427
26 changed files with 137 additions and 140 deletions
@@ -35,11 +35,13 @@ pub extern "C" fn call() {
);
// Call the callee
api::call_v1(
api::call_v2(
uapi::CallFlags::empty(),
callee_addr,
0u64, // How much gas to devote for the execution. 0 = all.
&0u64.to_le_bytes(), // value transferred to the contract.
0u64, // How much ref_time to devote for the execution. 0 = all.
0u64, // How much proof_size to devote for the execution. 0 = all.
None, // No deposit limit.
&0u64.to_le_bytes(), // Value transferred to the contract.
callee_input,
None,
)
@@ -38,11 +38,13 @@ pub extern "C" fn call() {
);
// Call the callee
let err_code = match api::call_v1(
let err_code = match api::call_v2(
uapi::CallFlags::empty(),
callee_addr,
0u64, // How much gas to devote for the execution. 0 = all.
&100u64.to_le_bytes(), // value transferred to the contract.
0u64, // How much ref_time to devote for the execution. 0 = all.
0u64, // How much proof_size to devote for the execution. 0 = all.
None, // No deposit limit.
&100u64.to_le_bytes(), // Value transferred to the contract.
input,
None,
) {
@@ -39,11 +39,13 @@ pub extern "C" fn call() {
api::call_runtime(call).unwrap();
// Call the callee
api::call_v1(
api::call_v2(
uapi::CallFlags::empty(),
callee_addr,
0u64, // How much gas to devote for the execution. 0 = all.
&0u64.to_le_bytes(), // value transferred to the contract.
0u64, // How much ref_time to devote for the execution. 0 = all.
0u64, // How much proof_size to devote for the execution. 0 = all.
None, // No deposit limit.
&0u64.to_le_bytes(), // Value transferred to the contract.
callee_input,
None,
)
@@ -38,7 +38,6 @@ pub extern "C" fn call() {
forwarded_input: [u8],
);
#[allow(deprecated)]
api::call_v2(
uapi::CallFlags::empty(),
callee_addr,
@@ -40,7 +40,6 @@ pub extern "C" fn call() {
let reverted_input = [1u8, 34, 51, 68, 85, 102, 119];
// Fail to deploy the contract since it returns a non-zero exit status.
#[allow(deprecated)]
let res = api::instantiate_v2(
code_hash,
0u64, // How much ref_time weight to devote for the execution. 0 = all.
@@ -55,7 +54,6 @@ pub extern "C" fn call() {
assert!(matches!(res, Err(ReturnErrorCode::CalleeReverted)));
// Fail to deploy the contract due to insufficient ref_time weight.
#[allow(deprecated)]
let res = api::instantiate_v2(
code_hash, 1u64, // too little ref_time weight
0u64, // How much proof_size weight to devote for the execution. 0 = all.
@@ -65,7 +63,6 @@ pub extern "C" fn call() {
assert!(matches!(res, Err(ReturnErrorCode::CalleeTrapped)));
// Fail to deploy the contract due to insufficient proof_size weight.
#[allow(deprecated)]
let res = api::instantiate_v2(
code_hash, 0u64, // How much ref_time weight to devote for the execution. 0 = all.
1u64, // Too little proof_size weight
@@ -78,7 +75,6 @@ pub extern "C" fn call() {
let mut callee = [0u8; 32];
let callee = &mut &mut callee[..];
#[allow(deprecated)]
api::instantiate_v2(
code_hash,
0u64, // How much ref_time weight to devote for the execution. 0 = all.
@@ -94,7 +90,6 @@ pub extern "C" fn call() {
assert_eq!(callee.len(), 32);
// Call the new contract and expect it to return failing exit code.
#[allow(deprecated)]
let res = api::call_v2(
uapi::CallFlags::empty(),
callee,
@@ -108,11 +103,10 @@ pub extern "C" fn call() {
assert!(matches!(res, Err(ReturnErrorCode::CalleeReverted)));
// Fail to call the contract due to insufficient ref_time weight.
#[allow(deprecated)]
let res = api::call_v2(
uapi::CallFlags::empty(),
callee,
1u64, // too little ref_time weight
1u64, // Too little ref_time weight.
0u64, // How much proof_size weight to devote for the execution. 0 = all.
None, // No deposit limit.
&value,
@@ -122,7 +116,6 @@ pub extern "C" fn call() {
assert!(matches!(res, Err(ReturnErrorCode::CalleeTrapped)));
// Fail to call the contract due to insufficient proof_size weight.
#[allow(deprecated)]
let res = api::call_v2(
uapi::CallFlags::empty(),
callee,
@@ -137,7 +130,6 @@ pub extern "C" fn call() {
// Call the contract successfully.
let mut output = [0u8; 4];
#[allow(deprecated)]
api::call_v2(
uapi::CallFlags::empty(),
callee,
@@ -50,11 +50,13 @@ pub extern "C" fn call() {
output!(addr, [0u8; 32], api::address,);
// call self
api::call_v1(
api::call_v2(
uapi::CallFlags::ALLOW_REENTRY,
addr,
0u64, // How much gas to devote for the execution. 0 = all.
&0u64.to_le_bytes(), // value transferred to the contract.
0u64, // How much ref_time to devote for the execution. 0 = all.
0u64, // How much proof_size to devote for the execution. 0 = all.
None, // No deposit limit.
&0u64.to_le_bytes(), // Value transferred to the contract.
input,
None,
)
@@ -40,14 +40,13 @@ pub extern "C" fn call() {
api::set_storage(buffer, &[1u8; 4]);
// Call the callee
#[allow(deprecated)]
api::call_v2(
uapi::CallFlags::empty(),
callee,
0u64, // How much ref_time weight to devote for the execution. 0 = all.
0u64, // How much proof_size weight to devote for the execution. 0 = all.
Some(deposit_limit),
&0u64.to_le_bytes(), // value transferred to the contract.
&0u64.to_le_bytes(), // Value transferred to the contract.
input,
None,
)
@@ -40,7 +40,6 @@ pub extern "C" fn call() {
let mut address = [0u8; 32];
let address = &mut &mut address[..];
#[allow(deprecated)]
api::instantiate_v2(
code_hash,
0u64, // How much ref_time weight to devote for the execution. 0 = all.
@@ -34,7 +34,6 @@ pub extern "C" fn deploy() {
let address = &mut &mut address[..];
let salt = [71u8, 17u8];
#[allow(deprecated)]
api::instantiate_v2(
code_hash,
0u64, // How much ref_time weight to devote for the execution. 0 = all.
@@ -60,7 +59,6 @@ pub extern "C" fn call() {
api::get_storage(&ADDRESS_KEY, callee_addr).unwrap();
// Calling the destination contract with non-empty input data should fail.
#[allow(deprecated)]
let res = api::call_v2(
uapi::CallFlags::empty(),
callee_addr,
@@ -74,7 +72,6 @@ pub extern "C" fn call() {
assert!(matches!(res, Err(uapi::ReturnErrorCode::CalleeTrapped)));
// Call the destination contract regularly, forcing it to self-destruct.
#[allow(deprecated)]
api::call_v2(
uapi::CallFlags::empty(),
callee_addr,
@@ -31,7 +31,6 @@ pub extern "C" fn call() {
input!(buffer, 36, code_hash: [u8; 32],);
let input = &buffer[32..];
#[allow(deprecated)]
let err_code = match api::instantiate_v2(
code_hash,
0u64, // How much ref_time weight to devote for the execution. 0 = all.
@@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! This contract tests the behavior of adding / removing delegate_dependencies when delegate
//! This contract tests the behavior of locking / unlocking delegate_dependencies when delegate
//! calling into a contract.
#![no_std]
#![no_main]
@@ -34,15 +34,13 @@ fn load_input(delegate_call: bool) {
);
match action {
// 1 = Add delegate dependency
// 1 = Lock delegate dependency
1 => {
#[allow(deprecated)]
api::add_delegate_dependency(code_hash);
api::lock_delegate_dependency(code_hash);
},
// 2 = Remove delegate dependency
// 2 = Unlock delegate dependency
2 => {
#[allow(deprecated)]
api::remove_delegate_dependency(code_hash);
api::unlock_delegate_dependency(code_hash);
},
// 3 = Terminate
3 => {
@@ -42,11 +42,13 @@ pub extern "C" fn call() {
if expected_reentrance_count != 5 {
let count = (expected_reentrance_count + 1).to_le_bytes();
api::call_v1(
api::call_v2(
uapi::CallFlags::ALLOW_REENTRY,
addr,
0u64, // How much gas to devote for the execution. 0 = all.
&0u64.to_le_bytes(), // value transferred to the contract.
0u64, // How much ref_time to devote for the execution. 0 = all.
0u64, // How much proof_size to devote for the execution. 0 = all.
None, // No deposit limit.
&0u64.to_le_bytes(), // Value transferred to the contract.
&count,
None,
)
@@ -37,10 +37,12 @@ pub extern "C" fn call() {
if !input.is_empty() {
output!(addr, [0u8; 32], api::address,);
api::call_v1(
api::call_v2(
uapi::CallFlags::ALLOW_REENTRY,
addr,
0u64, // How much gas to devote for the execution. 0 = all.
0u64, // How much ref_time to devote for the execution. 0 = all.
0u64, // How much proof_size to devote for the execution. 0 = all.
None, // No deposit limit.
&0u64.to_le_bytes(), // Value to transfer.
&[0u8; 0],
None,