Skip to content

Instantly share code, notes, and snippets.

@brson
Created November 21, 2020 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brson/f5b90ed7a70043d09a069725fda853e4 to your computer and use it in GitHub Desktop.
Save brson/f5b90ed7a70043d09a069725fda853e4 to your computer and use it in GitHub Desktop.
#![feature(prelude_import)]
#![no_std]
#[prelude_import]
use core::prelude::v1::*;
#[macro_use]
extern crate core;
#[macro_use]
extern crate compiler_builtins;
use ink_lang as ink;
mod flipper {
impl ::ink_lang::ContractEnv for Flipper {
type Env = ::ink_env::DefaultEnvironment;
}
type Environment = <Flipper as ::ink_lang::ContractEnv>::Env;
type AccountId =
<<Flipper as ::ink_lang::ContractEnv>::Env as ::ink_env::Environment>::AccountId;
type Balance = <<Flipper as ::ink_lang::ContractEnv>::Env as ::ink_env::Environment>::Balance;
type Hash = <<Flipper as ::ink_lang::ContractEnv>::Env as ::ink_env::Environment>::Hash;
type Timestamp =
<<Flipper as ::ink_lang::ContractEnv>::Env as ::ink_env::Environment>::Timestamp;
type BlockNumber =
<<Flipper as ::ink_lang::ContractEnv>::Env as ::ink_env::Environment>::BlockNumber;
#[cfg(not(feature = "ink-as-dependency"))]
const _: () = {
impl<'a> ::ink_lang::Env for &'a Flipper {
type EnvAccess = ::ink_lang::EnvAccess<'a, <Flipper as ::ink_lang::ContractEnv>::Env>;
fn env(self) -> Self::EnvAccess {
Default::default()
}
}
impl<'a> ::ink_lang::StaticEnv for Flipper {
type EnvAccess =
::ink_lang::EnvAccess<'static, <Flipper as ::ink_lang::ContractEnv>::Env>;
fn env() -> Self::EnvAccess {
Default::default()
}
}
};
#[cfg(not(feature = "ink-as-dependency"))]
/// Defines the storage of your contract.
/// Add new fields to the below struct in order
/// to add new static storage fields to your contract.
pub struct Flipper {
/// Stores a single `bool` value on the storage.
value: bool,
}
const _: () = {
impl ::ink_storage::traits::SpreadLayout for Flipper {
#[allow(unused_comparisons)]
const FOOTPRINT: u64 = [
(0u64 + <bool as ::ink_storage::traits::SpreadLayout>::FOOTPRINT),
0u64,
][((0u64 + <bool as ::ink_storage::traits::SpreadLayout>::FOOTPRINT) < 0u64) as usize];
const REQUIRES_DEEP_CLEAN_UP: bool = (false
|| (false
|| <bool as ::ink_storage::traits::SpreadLayout>::REQUIRES_DEEP_CLEAN_UP));
fn pull_spread(__key_ptr: &mut ::ink_storage::traits::KeyPtr) -> Self {
Flipper {
value: <bool as ::ink_storage::traits::SpreadLayout>::pull_spread(__key_ptr),
}
}
fn push_spread(&self, __key_ptr: &mut ::ink_storage::traits::KeyPtr) {
match self {
Flipper { value: __binding_0 } => {
::ink_storage::traits::SpreadLayout::push_spread(__binding_0, __key_ptr);
}
}
}
fn clear_spread(&self, __key_ptr: &mut ::ink_storage::traits::KeyPtr) {
match self {
Flipper { value: __binding_0 } => {
::ink_storage::traits::SpreadLayout::clear_spread(__binding_0, __key_ptr);
}
}
}
}
};
#[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(
<Flipper as ::ink_lang::DispatchUsingMode>::dispatch_using_mode(
::ink_lang::DispatchMode::Instantiate,
),
)
.to_u32()
}
#[cfg(not(test))]
#[no_mangle]
fn call() -> u32 {
if true {
::ink_lang::deny_payment::<<Flipper as ::ink_lang::ContractEnv>::Env>()
.expect("caller transferred value even though all ink! message deny payments")
}
::ink_lang::DispatchRetCode::from(
<Flipper as ::ink_lang::DispatchUsingMode>::dispatch_using_mode(
::ink_lang::DispatchMode::Call,
),
)
.to_u32()
}
impl ::ink_lang::DispatchUsingMode for Flipper {
#[allow(unused_parens)]
fn dispatch_using_mode(
mode: ::ink_lang::DispatchMode,
) -> core::result::Result<(), ::ink_lang::DispatchError> {
match mode { :: ink_lang :: DispatchMode :: Instantiate => { < < Flipper as :: ink_lang :: ConstructorDispatcher > :: Type as :: ink_lang :: Execute > :: execute (:: ink_env :: decode_input :: < < Flipper as :: ink_lang :: ConstructorDispatcher > :: Type > () . map_err (| _ | :: ink_lang :: DispatchError :: CouldNotReadInput) ?) } :: ink_lang :: DispatchMode :: Call => { < < Flipper as :: ink_lang :: MessageDispatcher > :: Type as :: ink_lang :: Execute > :: execute (:: ink_env :: decode_input :: < < Flipper 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<[(); 4087715520usize]> {
type Input = ();
}
impl ::ink_lang::FnSelector for __ink_Msg<[(); 4087715520usize]> {
const SELECTOR: ::ink_env::call::Selector =
::ink_env::call::Selector::new([192u8, 150u8, 165u8, 243u8]);
}
impl ::ink_lang::FnState for __ink_Msg<[(); 4087715520usize]> {
type State = Flipper;
}
impl ::ink_lang::FnOutput for __ink_Msg<[(); 4087715520usize]> {
#[allow(unused_parens)]
type Output = ();
}
impl ::ink_lang::MessageMut for __ink_Msg<[(); 4087715520usize]> {
const CALLABLE: fn(
&mut <Self as ::ink_lang::FnState>::State,
<Self as ::ink_lang::FnInput>::Input,
) -> <Self as ::ink_lang::FnOutput>::Output = |state, _| <Flipper>::flip(state);
}
impl ::ink_lang::FnInput for __ink_Msg<[(); 1453612062usize]> {
type Input = ();
}
impl ::ink_lang::FnSelector for __ink_Msg<[(); 1453612062usize]> {
const SELECTOR: ::ink_env::call::Selector =
::ink_env::call::Selector::new([30u8, 92u8, 164u8, 86u8]);
}
impl ::ink_lang::FnState for __ink_Msg<[(); 1453612062usize]> {
type State = Flipper;
}
impl ::ink_lang::FnOutput for __ink_Msg<[(); 1453612062usize]> {
#[allow(unused_parens)]
type Output = bool;
}
impl ::ink_lang::MessageRef for __ink_Msg<[(); 1453612062usize]> {
const CALLABLE: fn(
&<Self as ::ink_lang::FnState>::State,
<Self as ::ink_lang::FnInput>::Input,
) -> <Self as ::ink_lang::FnOutput>::Output = |state, _| <Flipper>::get(state);
}
impl ::ink_lang::FnInput for __ink_Constr<[(); 726762449usize]> {
type Input = bool;
}
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 = Flipper;
}
impl ::ink_lang::Constructor for __ink_Constr<[(); 726762449usize]> {
const CALLABLE: fn(
<Self as ::ink_lang::FnInput>::Input,
) -> <Self as ::ink_lang::FnState>::State =
|__ink_binding_0| <Flipper>::new(__ink_binding_0);
}
impl ::ink_lang::FnInput for __ink_Constr<[(); 3792844650usize]> {
type Input = ();
}
impl ::ink_lang::FnSelector for __ink_Constr<[(); 3792844650usize]> {
const SELECTOR: ::ink_env::call::Selector =
::ink_env::call::Selector::new([106u8, 55u8, 18u8, 226u8]);
}
impl ::ink_lang::FnState for __ink_Constr<[(); 3792844650usize]> {
type State = Flipper;
}
impl ::ink_lang::Constructor for __ink_Constr<[(); 3792844650usize]> {
const CALLABLE: fn(
<Self as ::ink_lang::FnInput>::Input,
) -> <Self as ::ink_lang::FnState>::State = |_| <Flipper>::default();
}
const _: () = {
#[doc(hidden)]
pub enum __ink_MessageDispatchEnum {
__ink_Message_0xC096A5F3(),
__ink_Message_0x1E5CA456(),
}
impl ::ink_lang::MessageDispatcher for Flipper {
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)? {
[192u8, 150u8, 165u8, 243u8] => Ok(Self::__ink_Message_0xC096A5F3()),
[30u8, 92u8, 164u8, 86u8] => Ok(Self::__ink_Message_0x1E5CA456()),
_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_0xC096A5F3() => ::ink_lang::execute_message_mut::<
<Flipper as ::ink_lang::ContractEnv>::Env,
__ink_Msg<[(); 4087715520usize]>,
_,
>(
::ink_lang::AcceptsPayments(true),
::ink_lang::EnablesDynamicStorageAllocator(false),
move |state: &mut Flipper| {
< __ink_Msg < [() ; 4087715520usize] > as :: ink_lang :: MessageMut > :: CALLABLE (state , ())
},
),
Self::__ink_Message_0x1E5CA456() => ::ink_lang::execute_message::<
<Flipper as ::ink_lang::ContractEnv>::Env,
__ink_Msg<[(); 1453612062usize]>,
_,
>(
::ink_lang::AcceptsPayments(true),
::ink_lang::EnablesDynamicStorageAllocator(false),
move |state: &Flipper| {
< __ink_Msg < [() ; 1453612062usize] > as :: ink_lang :: MessageRef > :: CALLABLE (state , ())
},
),
}
}
}
};
const _: () = {
#[doc(hidden)]
pub enum __ink_ConstructorDispatchEnum {
__ink_Constructor_0xD183512B(bool),
__ink_Constructor_0x6A3712E2(),
}
impl ::ink_lang::ConstructorDispatcher for Flipper {
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(
<bool as ::scale::Decode>::decode(input)?,
)),
[106u8, 55u8, 18u8, 226u8] => Ok(Self::__ink_Constructor_0x6A3712E2()),
_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(init_value) => {
::ink_lang::execute_constructor::<__ink_Constr<[(); 726762449usize]>, _>(
::ink_lang::EnablesDynamicStorageAllocator(false),
move || {
< __ink_Constr < [() ; 726762449usize] > as :: ink_lang :: Constructor > :: CALLABLE (init_value)
},
)
}
Self::__ink_Constructor_0x6A3712E2() => {
::ink_lang::execute_constructor::<__ink_Constr<[(); 3792844650usize]>, _>(
::ink_lang::EnablesDynamicStorageAllocator(false),
move || {
< __ink_Constr < [() ; 3792844650usize] > 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 :: < Flipper , Flipper > () ; } } ; impl Flipper { # [doc = " Constructor that initializes the `bool` value to the given `init_value`."] pub fn new (init_value : bool) -> Self { Self { value : init_value , } } # [doc = " Constructor that initializes the `bool` value to `false`."] # [doc = ""] # [doc = " Constructors can delegate to other constructors."] pub fn default () -> Self { Self :: new (Default :: default ()) } # [doc = " A message that can be called on instantiated contracts."] # [doc = " This one flips the value of the stored `bool` from `true`"] # [doc = " to `false` and vice versa."] pub fn flip (& mut self) { self . value = ! self . value ; } # [doc = " Simply returns the current value of our `bool`."] pub fn get (& self) -> bool { self . value } } };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment