Contract

Struct Contract 

Source
pub struct Contract { /* private fields */ }

Implementations§

Source§

impl Contract

Source

pub fn from_address(web3: &CPCWeb3, address: &Address, abi_json: &[u8]) -> Self

Source

pub fn event_sig(&self, event: &str) -> Option<H256>

Source

pub fn deploy<'a>(web3: &'a CPCWeb3, abi_json: &'a [u8]) -> Deployer<'a>

Deploy smart contract e.g.

let bytecode = include_str!("../../fixtures/contracts/Metacoin.bin").trim_end();
let web3 = CPCWeb3::new("https://civilian.cpchain.io").unwrap();
let account = load_account();
assert_eq!(
    account.address.to_checksum(),
    "0x6CBea203F4061855247cea3843E2e5957C4CD428"
);
let balance = web3.balance(&account.address).await.unwrap();
println!("balance: {:?}", balance);
let c = Contract::deploy(
    &web3,
    include_bytes!("../../fixtures/contracts/Metacoin.abi"),
)
.options(Options::with(|opt| {
    opt.value = Some(0.into());
    opt.gas_price = Some((180_000_000_000 as u64).into());
    opt.gas = Some(300_000.into());
}))
.sign_with_key_and_execute(bytecode, (), &account, 337.into())
.await
.unwrap();
println!("Address: {:?}", c.address());
Source

pub fn address(&self) -> Address

Get address of this contract

Source

pub fn query<R, A, B, P>( &self, func: &str, params: P, from: A, options: Options, block: B, ) -> impl Future<Output = Result<R>> + '_

Call query methods of the smart contract e.g.

let web3 = CPCWeb3::new("https://civilian.cpchain.io").unwrap();
let account = load_account();
let c = Contract::from_address(
    &web3,
    &Address::from_str("0x8b3b22339466a3c8fd9b78c309aebfbf0bb95a9a").unwrap(),
    include_bytes!("../../fixtures/contracts/Metacoin.abi"),
);
let r = c.query(
        "getBalance",
    (account.address.h160,),
    None,
    Options::default(),
    None,
);
let balance: U256 = r.await.unwrap();
println!("balance: {:?}", balance);
Source

pub async fn signed_call( &self, web3: &CPCWeb3, chain_id: u32, func: &str, params: impl Tokenize, options: Options, account: &Account, ) -> Result<H256>

Call functions of this contract

Source

pub async fn logs( &self, web3: &CPCWeb3, event_name: &str, from_block: Option<u64>, to_block: Option<u64>, ) -> Result<Vec<Log>, StdError>

Source

pub async fn events( &self, web3: &CPCWeb3, event_name: &str, from_block: Option<u64>, to_block: Option<u64>, ) -> Result<Vec<Event>, StdError>

Source

pub fn parse_log( abi_json: &[u8], event_name: &str, log: &TransactionLog, ) -> Result<Event, StdError>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> JsonSchemaMaybe for T