|
| 1 | +// This file is part of Substrate. |
| 2 | + |
| 3 | +// Copyright (C) Parity Technologies (UK) Ltd. |
| 4 | +// SPDX-License-Identifier: Apache-2.0 |
| 5 | + |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | + |
| 18 | +#![no_std] |
| 19 | +#![no_main] |
| 20 | +include!("../panic_handler.rs"); |
| 21 | + |
| 22 | +use uapi::{u64_output, HostFn, HostFnImpl as api, ReturnFlags}; |
| 23 | + |
| 24 | +fn decide_my_fate() -> ! { |
| 25 | + match u64_output!(api::value_transferred,) { |
| 26 | + 0 => api::consume_all_gas(), |
| 27 | + 1 => api::return_value(ReturnFlags::REVERT, &[]), |
| 28 | + _ => api::return_value(ReturnFlags::empty(), &[]), |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +#[no_mangle] |
| 33 | +#[polkavm_derive::polkavm_export] |
| 34 | +pub extern "C" fn deploy() { |
| 35 | + decide_my_fate(); |
| 36 | +} |
| 37 | + |
| 38 | +#[no_mangle] |
| 39 | +#[polkavm_derive::polkavm_export] |
| 40 | +pub extern "C" fn call() { |
| 41 | + decide_my_fate(); |
| 42 | +} |
0 commit comments