Created
December 16, 2020 23:42
-
-
Save Aimeedeer/dbca32662ed4c63c363b5994cac90a42 to your computer and use it in GitHub Desktop.
cargo expand --no-default-features --target=wasm32-unknown-unknown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(prelude_import)] | |
//! A smart contract which demonstrates behavior of the `self.env().transfer()` function. | |
//! It transfers some of it's balance to the caller. | |
#![no_std] | |
#![allow(clippy::new_without_default)] | |
#[prelude_import] | |
use core::prelude::v1::*; | |
#[macro_use] | |
extern crate core; | |
#[macro_use] | |
extern crate compiler_builtins; | |
use ink_lang as ink; | |
pub mod give_me { | |
impl ::ink_lang::ContractEnv for GiveMe { | |
type Env = ::ink_env::DefaultEnvironment; | |
} | |
type Environment = <GiveMe as ::ink_lang::ContractEnv>::Env; | |
type AccountId = | |
<<GiveMe as ::ink_lang::ContractEnv>::Env as ::ink_env::Environment>::AccountId; | |
type Balance = <<GiveMe as ::ink_lang::ContractEnv>::Env as ::ink_env::Environment>::Balance; | |
type Hash = <<GiveMe as ::ink_lang::ContractEnv>::Env as ::ink_env::Environment>::Hash; | |
type Timestamp = | |
<<GiveMe as ::ink_lang::ContractEnv>::Env as ::ink_env::Environment>::Timestamp; | |
type BlockNumber = | |
<<GiveMe as ::ink_lang::ContractEnv>::Env as ::ink_env::Environment>::BlockNumber; | |
#[cfg(not(feature = "ink-as-dependency"))] | |
const _: () = { | |
impl<'a> ::ink_lang::Env for &'a GiveMe { | |
type EnvAccess = ::ink_lang::EnvAccess<'a, <GiveMe as ::ink_lang::ContractEnv>::Env>; | |
fn env(self) -> Self::EnvAccess { | |
Default::default() | |
} | |
} | |
impl<'a> ::ink_lang::StaticEnv for GiveMe { | |
type EnvAccess = | |
::ink_lang::EnvAccess<'static, <GiveMe as ::ink_lang::ContractEnv>::Env>; | |
fn env() -> Self::EnvAccess { | |
Default::default() | |
} | |
} | |
}; | |
#[cfg(not(feature = "ink-as-dependency"))] | |
/// No storage is needed for this simple contract. | |
pub struct GiveMe {} | |
const _: () = { | |
impl ::ink_storage::traits::SpreadLayout for GiveMe { | |
#[allow(unused_comparisons)] | |
const FOOTPRINT: u64 = [0u64, 0u64][(0u64 < 0u64) as usize]; | |
const REQUIRES_DEEP_CLEAN_UP: bool = (false || false); | |
fn pull_spread(__key_ptr: &mut ::ink_storage::traits::KeyPtr) -> Self { | |
GiveMe {} | |
} | |
fn push_spread(&self, __key_ptr: &mut ::ink_storage::traits::KeyPtr) { | |
match self { | |
GiveMe {} => {} | |
} | |
} | |
fn clear_spread(&self, __key_ptr: &mut ::ink_storage::traits::KeyPtr) { | |
match self { | |
GiveMe {} => {} | |
} | |
} | |
} | |
}; | |
#[cfg(not(feature = "ink-as-dependency"))] | |
const _: () = { | |
#[allow(unused_imports)] | |
use ::ink_lang::{Env as _, StaticEnv as _}; | |
}; | |
#[cfg(not(test))] | |
#[cfg(not(feature = "ink-as-dependency"))] | |
const _: () = { | |
#[cfg(not(test))] | |
#[no_mangle] | |
fn deploy() -> u32 { | |
::ink_lang::DispatchRetCode::from( | |
<GiveMe as ::ink_lang::DispatchUsingMode>::dispatch_using_mode( | |
::ink_lang::DispatchMode::Instantiate, | |
), | |
) | |
.to_u32() | |
} | |
#[cfg(not(test))] | |
#[no_mangle] | |
fn call() -> u32 { | |
if false { | |
::ink_lang::deny_payment::<<GiveMe as ::ink_lang::ContractEnv>::Env>() | |
.expect("caller transferred value even though all ink! message deny payments") | |
} | |
::ink_lang::DispatchRetCode::from( | |
<GiveMe as ::ink_lang::DispatchUsingMode>::dispatch_using_mode( | |
::ink_lang::DispatchMode::Call, | |
), | |
) | |
.to_u32() | |
} | |
impl ::ink_lang::DispatchUsingMode for GiveMe { | |
#[allow(unused_parens)] | |
fn dispatch_using_mode( | |
mode: ::ink_lang::DispatchMode, | |
) -> core::result::Result<(), ::ink_lang::DispatchError> { | |
match mode { :: ink_lang :: DispatchMode :: Instantiate => { < < GiveMe as :: ink_lang :: ConstructorDispatcher > :: Type as :: ink_lang :: Execute > :: execute (:: ink_env :: decode_input :: < < GiveMe as :: ink_lang :: ConstructorDispatcher > :: Type > () . map_err (| _ | :: ink_lang :: DispatchError :: CouldNotReadInput) ?) } :: ink_lang :: DispatchMode :: Call => { < < GiveMe as :: ink_lang :: MessageDispatcher > :: Type as :: ink_lang :: Execute > :: execute (:: ink_env :: decode_input :: < < GiveMe as :: ink_lang :: MessageDispatcher > :: Type > () . map_err (| _ | :: ink_lang :: DispatchError :: CouldNotReadInput) ?) } } | |
} | |
} | |
#[doc(hidden)] | |
pub struct __ink_Msg<S> { | |
marker: core::marker::PhantomData<fn() -> S>, | |
} | |
#[doc(hidden)] | |
pub struct __ink_Constr<S> { | |
marker: core::marker::PhantomData<fn() -> S>, | |
} | |
impl ::ink_lang::FnInput for __ink_Msg<[(); 2566918985usize]> { | |
type Input = Balance; | |
} | |
impl ::ink_lang::FnSelector for __ink_Msg<[(); 2566918985usize]> { | |
const SELECTOR: ::ink_env::call::Selector = | |
::ink_env::call::Selector::new([73u8, 19u8, 0u8, 153u8]); | |
} | |
impl ::ink_lang::FnState for __ink_Msg<[(); 2566918985usize]> { | |
type State = GiveMe; | |
} | |
impl ::ink_lang::FnOutput for __ink_Msg<[(); 2566918985usize]> { | |
#[allow(unused_parens)] | |
type Output = Result<(), Error>; | |
} | |
impl ::ink_lang::MessageMut for __ink_Msg<[(); 2566918985usize]> { | |
const CALLABLE: fn( | |
&mut <Self as ::ink_lang::FnState>::State, | |
<Self as ::ink_lang::FnInput>::Input, | |
) -> <Self as ::ink_lang::FnOutput>::Output = | |
|state, __ink_binding_0| <GiveMe>::give_me(state, __ink_binding_0); | |
} | |
impl ::ink_lang::FnInput for __ink_Msg<[(); 3199925962usize]> { | |
type Input = (); | |
} | |
impl ::ink_lang::FnSelector for __ink_Msg<[(); 3199925962usize]> { | |
const SELECTOR: ::ink_env::call::Selector = | |
::ink_env::call::Selector::new([202u8, 254u8, 186u8, 190u8]); | |
} | |
impl ::ink_lang::FnState for __ink_Msg<[(); 3199925962usize]> { | |
type State = GiveMe; | |
} | |
impl ::ink_lang::FnOutput for __ink_Msg<[(); 3199925962usize]> { | |
#[allow(unused_parens)] | |
type Output = bool; | |
} | |
impl ::ink_lang::MessageRef for __ink_Msg<[(); 3199925962usize]> { | |
const CALLABLE: fn( | |
&<Self as ::ink_lang::FnState>::State, | |
<Self as ::ink_lang::FnInput>::Input, | |
) -> <Self as ::ink_lang::FnOutput>::Output = |state, _| <GiveMe>::was_it_ten(state); | |
} | |
impl ::ink_lang::FnInput for __ink_Constr<[(); 726762449usize]> { | |
type Input = (); | |
} | |
impl ::ink_lang::FnSelector for __ink_Constr<[(); 726762449usize]> { | |
const SELECTOR: ::ink_env::call::Selector = | |
::ink_env::call::Selector::new([209u8, 131u8, 81u8, 43u8]); | |
} | |
impl ::ink_lang::FnState for __ink_Constr<[(); 726762449usize]> { | |
type State = GiveMe; | |
} | |
impl ::ink_lang::Constructor for __ink_Constr<[(); 726762449usize]> { | |
const CALLABLE: fn( | |
<Self as ::ink_lang::FnInput>::Input, | |
) -> <Self as ::ink_lang::FnState>::State = |_| <GiveMe>::new(); | |
} | |
const _: () = { | |
#[doc(hidden)] | |
pub enum __ink_MessageDispatchEnum { | |
__ink_Message_0x49130099(Balance), | |
__ink_Message_0xCAFEBABE(), | |
} | |
impl ::ink_lang::MessageDispatcher for GiveMe { | |
type Type = __ink_MessageDispatchEnum; | |
} | |
impl ::scale::Decode for __ink_MessageDispatchEnum { | |
fn decode<I: ::scale::Input>( | |
input: &mut I, | |
) -> ::core::result::Result<Self, ::scale::Error> { | |
match <[u8; 4] as ::scale::Decode>::decode(input)? { | |
[73u8, 19u8, 0u8, 153u8] => Ok(Self::__ink_Message_0x49130099( | |
<Balance as ::scale::Decode>::decode(input)?, | |
)), | |
[202u8, 254u8, 186u8, 190u8] => Ok(Self::__ink_Message_0xCAFEBABE()), | |
_invalid => Err(::scale::Error::from( | |
"encountered unknown ink! message selector", | |
)), | |
} | |
} | |
} | |
impl ::ink_lang::Execute for __ink_MessageDispatchEnum { | |
fn execute(self) -> ::core::result::Result<(), ::ink_lang::DispatchError> { | |
match self { | |
Self::__ink_Message_0x49130099(value) => ::ink_lang::execute_message_mut::< | |
<GiveMe as ::ink_lang::ContractEnv>::Env, | |
__ink_Msg<[(); 2566918985usize]>, | |
_, | |
>( | |
::ink_lang::AcceptsPayments(false), | |
::ink_lang::EnablesDynamicStorageAllocator(false), | |
move |state: &mut GiveMe| { | |
< __ink_Msg < [() ; 2566918985usize] > as :: ink_lang :: MessageMut > :: CALLABLE (state , value) | |
}, | |
), | |
Self::__ink_Message_0xCAFEBABE() => ::ink_lang::execute_message::< | |
<GiveMe as ::ink_lang::ContractEnv>::Env, | |
__ink_Msg<[(); 3199925962usize]>, | |
_, | |
>( | |
::ink_lang::AcceptsPayments(true), | |
::ink_lang::EnablesDynamicStorageAllocator(false), | |
move |state: &GiveMe| { | |
< __ink_Msg < [() ; 3199925962usize] > as :: ink_lang :: MessageRef > :: CALLABLE (state , ()) | |
}, | |
), | |
} | |
} | |
} | |
}; | |
const _: () = { | |
#[doc(hidden)] | |
pub enum __ink_ConstructorDispatchEnum { | |
__ink_Constructor_0xD183512B(), | |
} | |
impl ::ink_lang::ConstructorDispatcher for GiveMe { | |
type Type = __ink_ConstructorDispatchEnum; | |
} | |
impl ::scale::Decode for __ink_ConstructorDispatchEnum { | |
fn decode<I: ::scale::Input>( | |
input: &mut I, | |
) -> ::core::result::Result<Self, ::scale::Error> { | |
match <[u8; 4] as ::scale::Decode>::decode(input)? { | |
[209u8, 131u8, 81u8, 43u8] => Ok(Self::__ink_Constructor_0xD183512B()), | |
_invalid => Err(::scale::Error::from( | |
"encountered unknown ink! constructor selector", | |
)), | |
} | |
} | |
} | |
impl ::ink_lang::Execute for __ink_ConstructorDispatchEnum { | |
fn execute(self) -> ::core::result::Result<(), ::ink_lang::DispatchError> { | |
match self { | |
Self::__ink_Constructor_0xD183512B() => { | |
::ink_lang::execute_constructor::<__ink_Constr<[(); 726762449usize]>, _>( | |
::ink_lang::EnablesDynamicStorageAllocator(false), | |
move || { | |
< __ink_Constr < [() ; 726762449usize] > as :: ink_lang :: Constructor > :: CALLABLE (()) | |
}, | |
) | |
} | |
} | |
} | |
} | |
}; | |
}; | |
#[cfg(not(feature = "ink-as-dependency"))] | |
const _: () = { use :: ink_lang :: { Env , EmitEvent , StaticEnv } ; const _ : fn () = | | { { trait TypeEq { type This : ? Sized ; } impl < T : ? Sized > TypeEq for T { type This = Self ; } fn assert_type_eq_all < T , U > () where T : ? Sized + TypeEq < This = U > , U : ? Sized { } assert_type_eq_all :: < GiveMe , GiveMe > () ; } } ; impl GiveMe { # [doc = " Creates a new instance of this contract."] pub fn new () -> Self { Self { } } # [doc = " Transfers `value` amount of tokens to the caller."] # [doc = ""] # [doc = " # Errors"] # [doc = ""] # [doc = " - Returns `Error::InsufficientFunds` in case the requested transfer of"] # [doc = " `value` exceeds the contracts balance."] # [doc = " - Returns `Error::BelowSubsistenceThreshold` in case the requested transfer"] # [doc = " of `value` would have brought the contract\'s balance below the subsistence"] # [doc = " threshold."] # [doc = " - Returns `Error::TransferFailed` in case the transfer failed for another"] # [doc = " reason."] pub fn give_me (& mut self , value : Balance) -> Result < () , Error > { if value > self . env () . balance () { return Err (Error :: InsufficientFunds) } self . env () . transfer (self . env () . caller () , value) . map_err (| err | { match err { ink_env :: Error :: BelowSubsistenceThreshold => { Error :: BelowSubsistenceThreshold } _ => Error :: TransferFailed , } }) } # [doc = " Returns `true` if the token amount which the contract received"] # [doc = " with this call is exactly `10`."] # [doc = ""] # [doc = " # Note"] # [doc = ""] # [doc = " The method needs to be annotated with `payable`; only then it is"] # [doc = " allowed to receive value as part of the call."] pub fn was_it_ten (& self) -> bool { self . env () . transferred_balance () == 10 } } }; | |
/// The error types. | |
pub enum Error { | |
/// Returned if the transfer failed. | |
TransferFailed, | |
/// Insufficient funds to execute transfer. | |
InsufficientFunds, | |
/// Transfer failed because it would have brought the contract's | |
/// balance below the subsistence threshold. | |
/// This is necessary to keep enough funds in the contract to | |
/// allow for a tombstone to be created. | |
BelowSubsistenceThreshold, | |
} | |
#[automatically_derived] | |
#[allow(unused_qualifications)] | |
impl ::core::fmt::Debug for Error { | |
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { | |
match (&*self,) { | |
(&Error::TransferFailed,) => { | |
let mut debug_trait_builder = f.debug_tuple("TransferFailed"); | |
debug_trait_builder.finish() | |
} | |
(&Error::InsufficientFunds,) => { | |
let mut debug_trait_builder = f.debug_tuple("InsufficientFunds"); | |
debug_trait_builder.finish() | |
} | |
(&Error::BelowSubsistenceThreshold,) => { | |
let mut debug_trait_builder = f.debug_tuple("BelowSubsistenceThreshold"); | |
debug_trait_builder.finish() | |
} | |
} | |
} | |
} | |
impl ::core::marker::StructuralPartialEq for Error {} | |
#[automatically_derived] | |
#[allow(unused_qualifications)] | |
impl ::core::cmp::PartialEq for Error { | |
#[inline] | |
fn eq(&self, other: &Error) -> bool { | |
{ | |
let __self_vi = ::core::intrinsics::discriminant_value(&*self); | |
let __arg_1_vi = ::core::intrinsics::discriminant_value(&*other); | |
if true && __self_vi == __arg_1_vi { | |
match (&*self, &*other) { | |
_ => true, | |
} | |
} else { | |
false | |
} | |
} | |
} | |
} | |
impl ::core::marker::StructuralEq for Error {} | |
#[automatically_derived] | |
#[allow(unused_qualifications)] | |
impl ::core::cmp::Eq for Error { | |
#[inline] | |
#[doc(hidden)] | |
fn assert_receiver_is_total_eq(&self) -> () { | |
{} | |
} | |
} | |
const _: () = { | |
#[allow(unknown_lints)] | |
#[allow(rust_2018_idioms)] | |
extern crate scale as _parity_scale_codec; | |
impl _parity_scale_codec::Encode for Error { | |
fn encode_to<__CodecOutputEdqy: _parity_scale_codec::Output>( | |
&self, | |
__codec_dest_edqy: &mut __CodecOutputEdqy, | |
) { | |
match *self { | |
Error::TransferFailed => { | |
__codec_dest_edqy.push_byte(0usize as u8); | |
} | |
Error::InsufficientFunds => { | |
__codec_dest_edqy.push_byte(1usize as u8); | |
} | |
Error::BelowSubsistenceThreshold => { | |
__codec_dest_edqy.push_byte(2usize as u8); | |
} | |
_ => (), | |
} | |
} | |
} | |
impl _parity_scale_codec::EncodeLike for Error {} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment