SmartContractInputs

Struct SmartContractInputs 

Source
pub struct SmartContractInputs {
    pub version: i32,
    pub account_info: AccountInfo,
    pub protocol_input: ProtocolInputs,
    pub contract_input: ContractInputs,
}
Expand description

SmartContractInputs represents the entire bundle of inputs sent into a Versatus smart contract. It is a collection of input data from a variety of locations, including the contract caller, and the protocol accounts database.

Fields§

§version: i32

Version of the compute stack and API/ABI

§account_info: AccountInfo

Account info as provided by the protocol

§protocol_input: ProtocolInputs

Protocol inputs as provided by the protocol

§contract_input: ContractInputs

Application inputs as provided by the application via the protocol

Implementations§

Source§

impl SmartContractInputs

Source

pub fn gather() -> Result<Self>

Read JSON data on stdin and deserialise it to a set of Rust data structures.

Source

pub fn account_info(&self) -> AccountInfo

Returns a copy of the associated account information

Source

pub fn account_addr(&self) -> Address

Returns the address of the associated account

Examples found in repository?
examples/erc20.rs (line 48)
45    fn transfer(&self, to: Address, value: U256) -> Result<Erc20TransferEvent> {
46        let addr: Address;
47        if let Some(input) = &self.inputs {
48            addr = input.account_addr();
49        } else {
50            // Shouldn't be reachable.
51            return Err(anyhow!("Input data missing"));
52        }
53        Ok(Erc20TransferEvent {
54            from: addr,
55            to,
56            value,
57        })
58    }
59
60    fn transfer_from(&self, from: Address, to: Address, value: U256) -> Result<Erc20TransferEvent> {
61        Ok(Erc20TransferEvent { from, to, value })
62    }
63
64    fn approve(&self, spender: Address, value: U256) -> Result<Erc20ApprovalEvent> {
65        let owner: Address;
66        if let Some(input) = &self.inputs {
67            owner = input.account_addr();
68        } else {
69            // Shouldn't be reachable.
70            return Err(anyhow!("Input data missing"));
71        }
72        Ok(Erc20ApprovalEvent {
73            owner,
74            spender,
75            value,
76        })
77    }

Trait Implementations§

Source§

impl Clone for SmartContractInputs

Source§

fn clone(&self) -> SmartContractInputs

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SmartContractInputs

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for SmartContractInputs

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for SmartContractInputs

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,