Skip to content

Instantly share code, notes, and snippets.

@axelchalon
Last active February 16, 2018 15:19
Show Gist options
  • Save axelchalon/8649a3ed8fe89db5731272b456809e62 to your computer and use it in GitHub Desktop.
Save axelchalon/8649a3ed8fe89db5731272b456809e62 to your computer and use it in GitHub Desktop.
eip20_file.rs
use ethabi;
const INTERNAL_ERR: &'static str = "`ethabi_derive` internal error";
#[doc = r" Contract"]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct Eip20 {}
impl Eip20 {}
pub mod events {
use ethabi;
use ethabi::ParseLog;
#[derive(Debug, Clone, PartialEq)]
pub struct Approval {
event: ethabi::Event,
}
impl Default for Approval {
fn default() -> Self {
Approval {
event: ethabi::Event {
name: "Approval".to_owned(),
inputs: vec![
ethabi::EventParam {
name: "owner".to_owned(),
kind: ethabi::ParamType::Address,
indexed: true,
},
ethabi::EventParam {
name: "spender".to_owned(),
kind: ethabi::ParamType::Address,
indexed: true,
},
ethabi::EventParam {
name: "value".to_owned(),
kind: ethabi::ParamType::Uint(256usize),
indexed: false,
},
],
anonymous: false,
},
}
}
}
impl ParseLog for Approval {
type Log = super::logs::Approval;
#[doc = r" Parses log."]
fn parse_log(&self, log: ethabi::RawLog) -> ethabi::Result<Self::Log> {
let mut log = self.event.parse_log(log)?.params.into_iter();
let result = super::logs::Approval {
owner: log.next()
.expect(super::INTERNAL_ERR)
.value
.to_address()
.expect(super::INTERNAL_ERR),
spender: log.next()
.expect(super::INTERNAL_ERR)
.value
.to_address()
.expect(super::INTERNAL_ERR),
value: log.next()
.expect(super::INTERNAL_ERR)
.value
.to_uint()
.expect(super::INTERNAL_ERR),
};
Ok(result)
}
}
impl Approval {
#[doc = r" Creates topic filter."]
pub fn create_filter<
T0: Into<ethabi::Topic<ethabi::Address>>,
T1: Into<ethabi::Topic<ethabi::Address>>,
>(
&self,
owner: T0,
spender: T1,
) -> ethabi::TopicFilter {
let raw = ethabi::RawTopicFilter {
topic0: owner.into().map(|i| ethabi::Token::Address(i)),
topic1: spender.into().map(|i| ethabi::Token::Address(i)),
..Default::default()
};
self.event.create_filter(raw).expect(super::INTERNAL_ERR)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Transfer {
event: ethabi::Event,
}
impl Default for Transfer {
fn default() -> Self {
Transfer {
event: ethabi::Event {
name: "Transfer".to_owned(),
inputs: vec![
ethabi::EventParam {
name: "from".to_owned(),
kind: ethabi::ParamType::Address,
indexed: true,
},
ethabi::EventParam {
name: "to".to_owned(),
kind: ethabi::ParamType::Address,
indexed: true,
},
ethabi::EventParam {
name: "value".to_owned(),
kind: ethabi::ParamType::Uint(256usize),
indexed: false,
},
],
anonymous: false,
},
}
}
}
impl ParseLog for Transfer {
type Log = super::logs::Transfer;
#[doc = r" Parses log."]
fn parse_log(&self, log: ethabi::RawLog) -> ethabi::Result<Self::Log> {
let mut log = self.event.parse_log(log)?.params.into_iter();
let result = super::logs::Transfer {
from: log.next()
.expect(super::INTERNAL_ERR)
.value
.to_address()
.expect(super::INTERNAL_ERR),
to: log.next()
.expect(super::INTERNAL_ERR)
.value
.to_address()
.expect(super::INTERNAL_ERR),
value: log.next()
.expect(super::INTERNAL_ERR)
.value
.to_uint()
.expect(super::INTERNAL_ERR),
};
Ok(result)
}
}
impl Transfer {
#[doc = r" Creates topic filter."]
pub fn create_filter<
T0: Into<ethabi::Topic<ethabi::Address>>,
T1: Into<ethabi::Topic<ethabi::Address>>,
>(
&self,
from: T0,
to: T1,
) -> ethabi::TopicFilter {
let raw = ethabi::RawTopicFilter {
topic0: from.into().map(|i| ethabi::Token::Address(i)),
topic1: to.into().map(|i| ethabi::Token::Address(i)),
..Default::default()
};
self.event.create_filter(raw).expect(super::INTERNAL_ERR)
}
}
}
pub mod logs {
use ethabi;
#[derive(Debug, Clone, PartialEq)]
pub struct Approval {
pub owner: ethabi::Address,
pub spender: ethabi::Address,
pub value: ethabi::Uint,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Transfer {
pub from: ethabi::Address,
pub to: ethabi::Address,
pub value: ethabi::Uint,
}
}
#[doc = r" Contract events"]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct Eip20Events {}
impl Eip20Events {
pub fn approval(&self) -> events::Approval {
events::Approval::default()
}
pub fn transfer(&self) -> events::Transfer {
events::Transfer::default()
}
}
impl Eip20 {
#[doc = r" Get contract events"]
pub fn events(&self) -> Eip20Events {
Eip20Events {}
}
}
#[doc = r" Contract functions (for decoding output)"]
pub struct Outputs {}
impl Outputs {
#[doc = r" Returns the decoded output for this contract function"]
pub fn total_supply(&self, output_bytes: &[u8]) -> ethabi::Result<ethabi::Uint> {
functions::TotalSupply::default().decode_output(&output_bytes)
}
#[doc = r" Returns the decoded output for this contract function"]
pub fn transfer_from(&self, output_bytes: &[u8]) -> ethabi::Result<bool> {
functions::TransferFrom::default().decode_output(&output_bytes)
}
#[doc = r" Returns the decoded output for this contract function"]
pub fn approve(&self, output_bytes: &[u8]) -> ethabi::Result<bool> {
functions::Approve::default().decode_output(&output_bytes)
}
#[doc = r" Returns the decoded output for this contract function"]
pub fn balance_of(&self, output_bytes: &[u8]) -> ethabi::Result<ethabi::Uint> {
functions::BalanceOf::default().decode_output(&output_bytes)
}
#[doc = r" Returns the decoded output for this contract function"]
pub fn allowance(&self, output_bytes: &[u8]) -> ethabi::Result<ethabi::Uint> {
functions::Allowance::default().decode_output(&output_bytes)
}
#[doc = r" Returns the decoded output for this contract function"]
pub fn transfer(&self, output_bytes: &[u8]) -> ethabi::Result<bool> {
functions::Transfer::default().decode_output(&output_bytes)
}
}
impl Eip20 {
#[doc = r" Gets contract functions (for decoding output)"]
pub fn outputs(&self) -> Outputs {
Outputs {}
}
}
pub mod functions {
use ethabi;
#[derive(Debug, Clone, PartialEq)]
pub struct TotalSupply {
function: ethabi::Function,
}
impl Default for TotalSupply {
fn default() -> Self {
TotalSupply {
function: ethabi::Function {
name: "totalSupply".to_owned(),
inputs: vec![],
outputs: vec![
ethabi::Param {
name: "total".to_owned(),
kind: ethabi::ParamType::Uint(256usize),
},
],
constant: true,
},
}
}
}
impl TotalSupply {
#[allow(unused_variables)]
pub fn decode_output(&self, output: &[u8]) -> ethabi::Result<ethabi::Uint> {
let out = self.function
.decode_output(output)?
.into_iter()
.next()
.expect(super::INTERNAL_ERR);
Ok(out.to_uint().expect(super::INTERNAL_ERR))
}
pub fn encode_input(&self, tokens: &[ethabi::Token]) -> ethabi::Result<ethabi::Bytes> {
self.function.encode_input(tokens)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct TransferFrom {
function: ethabi::Function,
}
impl Default for TransferFrom {
fn default() -> Self {
TransferFrom {
function: ethabi::Function {
name: "transferFrom".to_owned(),
inputs: vec![
ethabi::Param {
name: "_from".to_owned(),
kind: ethabi::ParamType::Address,
},
ethabi::Param {
name: "_to".to_owned(),
kind: ethabi::ParamType::Address,
},
ethabi::Param {
name: "_value".to_owned(),
kind: ethabi::ParamType::Uint(256usize),
},
],
outputs: vec![
ethabi::Param {
name: "success".to_owned(),
kind: ethabi::ParamType::Bool,
},
],
constant: false,
},
}
}
}
impl TransferFrom {
#[allow(unused_variables)]
pub fn decode_output(&self, output: &[u8]) -> ethabi::Result<bool> {
let out = self.function
.decode_output(output)?
.into_iter()
.next()
.expect(super::INTERNAL_ERR);
Ok(out.to_bool().expect(super::INTERNAL_ERR))
}
pub fn encode_input(&self, tokens: &[ethabi::Token]) -> ethabi::Result<ethabi::Bytes> {
self.function.encode_input(tokens)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Approve {
function: ethabi::Function,
}
impl Default for Approve {
fn default() -> Self {
Approve {
function: ethabi::Function {
name: "approve".to_owned(),
inputs: vec![
ethabi::Param {
name: "_spender".to_owned(),
kind: ethabi::ParamType::Address,
},
ethabi::Param {
name: "_value".to_owned(),
kind: ethabi::ParamType::Uint(256usize),
},
],
outputs: vec![
ethabi::Param {
name: "success".to_owned(),
kind: ethabi::ParamType::Bool,
},
],
constant: false,
},
}
}
}
impl Approve {
#[allow(unused_variables)]
pub fn decode_output(&self, output: &[u8]) -> ethabi::Result<bool> {
let out = self.function
.decode_output(output)?
.into_iter()
.next()
.expect(super::INTERNAL_ERR);
Ok(out.to_bool().expect(super::INTERNAL_ERR))
}
pub fn encode_input(&self, tokens: &[ethabi::Token]) -> ethabi::Result<ethabi::Bytes> {
self.function.encode_input(tokens)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct BalanceOf {
function: ethabi::Function,
}
impl Default for BalanceOf {
fn default() -> Self {
BalanceOf {
function: ethabi::Function {
name: "balanceOf".to_owned(),
inputs: vec![
ethabi::Param {
name: "_owner".to_owned(),
kind: ethabi::ParamType::Address,
},
],
outputs: vec![
ethabi::Param {
name: "balance".to_owned(),
kind: ethabi::ParamType::Uint(256usize),
},
],
constant: true,
},
}
}
}
impl BalanceOf {
#[allow(unused_variables)]
pub fn decode_output(&self, output: &[u8]) -> ethabi::Result<ethabi::Uint> {
let out = self.function
.decode_output(output)?
.into_iter()
.next()
.expect(super::INTERNAL_ERR);
Ok(out.to_uint().expect(super::INTERNAL_ERR))
}
pub fn encode_input(&self, tokens: &[ethabi::Token]) -> ethabi::Result<ethabi::Bytes> {
self.function.encode_input(tokens)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Allowance {
function: ethabi::Function,
}
impl Default for Allowance {
fn default() -> Self {
Allowance {
function: ethabi::Function {
name: "allowance".to_owned(),
inputs: vec![
ethabi::Param {
name: "_owner".to_owned(),
kind: ethabi::ParamType::Address,
},
ethabi::Param {
name: "_spender".to_owned(),
kind: ethabi::ParamType::Address,
},
],
outputs: vec![
ethabi::Param {
name: "remaining".to_owned(),
kind: ethabi::ParamType::Uint(256usize),
},
],
constant: true,
},
}
}
}
impl Allowance {
#[allow(unused_variables)]
pub fn decode_output(&self, output: &[u8]) -> ethabi::Result<ethabi::Uint> {
let out = self.function
.decode_output(output)?
.into_iter()
.next()
.expect(super::INTERNAL_ERR);
Ok(out.to_uint().expect(super::INTERNAL_ERR))
}
pub fn encode_input(&self, tokens: &[ethabi::Token]) -> ethabi::Result<ethabi::Bytes> {
self.function.encode_input(tokens)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Transfer {
function: ethabi::Function,
}
impl Default for Transfer {
fn default() -> Self {
Transfer {
function: ethabi::Function {
name: "transfer".to_owned(),
inputs: vec![
ethabi::Param {
name: "_to".to_owned(),
kind: ethabi::ParamType::Address,
},
ethabi::Param {
name: "_value".to_owned(),
kind: ethabi::ParamType::Uint(256usize),
},
],
outputs: vec![
ethabi::Param {
name: "success".to_owned(),
kind: ethabi::ParamType::Bool,
},
],
constant: false,
},
}
}
}
impl Transfer {
#[allow(unused_variables)]
pub fn decode_output(&self, output: &[u8]) -> ethabi::Result<bool> {
let out = self.function
.decode_output(output)?
.into_iter()
.next()
.expect(super::INTERNAL_ERR);
Ok(out.to_bool().expect(super::INTERNAL_ERR))
}
pub fn encode_input(&self, tokens: &[ethabi::Token]) -> ethabi::Result<ethabi::Bytes> {
self.function.encode_input(tokens)
}
}
}
#[doc = r" Contract function with already defined input values"]
pub struct TotalSupplyWithInput {
encoded_input: ethabi::Bytes,
}
impl ethabi::ContractFunction for TotalSupplyWithInput {
type Output = ethabi::Uint;
fn encoded(&self) -> ethabi::Bytes {
self.encoded_input.clone()
}
fn output(&self, _output_bytes: ethabi::Bytes) -> ethabi::Result<Self::Output> {
functions::TotalSupply::default().decode_output(&_output_bytes)
}
}
impl TotalSupplyWithInput {
#[doc(hidden)]
pub fn new(v: Vec<ethabi::Token>) -> Self {
let encoded_input: ethabi::Bytes = functions::TotalSupply::default()
.encode_input(&v)
.expect(INTERNAL_ERR);
TotalSupplyWithInput { encoded_input: encoded_input }
}
}
#[doc = r" Contract function with already defined input values"]
pub struct TransferFromWithInput {
encoded_input: ethabi::Bytes,
}
impl ethabi::ContractFunction for TransferFromWithInput {
type Output = ();
fn encoded(&self) -> ethabi::Bytes {
self.encoded_input.clone()
}
fn output(&self, _output_bytes: ethabi::Bytes) -> ethabi::Result<Self::Output> {
Ok(())
}
}
impl TransferFromWithInput {
#[doc(hidden)]
pub fn new(v: Vec<ethabi::Token>) -> Self {
let encoded_input: ethabi::Bytes = functions::TransferFrom::default()
.encode_input(&v)
.expect(INTERNAL_ERR);
TransferFromWithInput { encoded_input: encoded_input }
}
}
#[doc = r" Contract function with already defined input values"]
pub struct ApproveWithInput {
encoded_input: ethabi::Bytes,
}
impl ethabi::ContractFunction for ApproveWithInput {
type Output = ();
fn encoded(&self) -> ethabi::Bytes {
self.encoded_input.clone()
}
fn output(&self, _output_bytes: ethabi::Bytes) -> ethabi::Result<Self::Output> {
Ok(())
}
}
impl ApproveWithInput {
#[doc(hidden)]
pub fn new(v: Vec<ethabi::Token>) -> Self {
let encoded_input: ethabi::Bytes = functions::Approve::default().encode_input(&v).expect(
INTERNAL_ERR,
);
ApproveWithInput { encoded_input: encoded_input }
}
}
#[doc = r" Contract function with already defined input values"]
pub struct BalanceOfWithInput {
encoded_input: ethabi::Bytes,
}
impl ethabi::ContractFunction for BalanceOfWithInput {
type Output = ethabi::Uint;
fn encoded(&self) -> ethabi::Bytes {
self.encoded_input.clone()
}
fn output(&self, _output_bytes: ethabi::Bytes) -> ethabi::Result<Self::Output> {
functions::BalanceOf::default().decode_output(&_output_bytes)
}
}
impl BalanceOfWithInput {
#[doc(hidden)]
pub fn new(v: Vec<ethabi::Token>) -> Self {
let encoded_input: ethabi::Bytes = functions::BalanceOf::default()
.encode_input(&v)
.expect(INTERNAL_ERR);
BalanceOfWithInput { encoded_input: encoded_input }
}
}
#[doc = r" Contract function with already defined input values"]
pub struct AllowanceWithInput {
encoded_input: ethabi::Bytes,
}
impl ethabi::ContractFunction for AllowanceWithInput {
type Output = ethabi::Uint;
fn encoded(&self) -> ethabi::Bytes {
self.encoded_input.clone()
}
fn output(&self, _output_bytes: ethabi::Bytes) -> ethabi::Result<Self::Output> {
functions::Allowance::default().decode_output(&_output_bytes)
}
}
impl AllowanceWithInput {
#[doc(hidden)]
pub fn new(v: Vec<ethabi::Token>) -> Self {
let encoded_input: ethabi::Bytes = functions::Allowance::default()
.encode_input(&v)
.expect(INTERNAL_ERR);
AllowanceWithInput { encoded_input: encoded_input }
}
}
#[doc = r" Contract function with already defined input values"]
pub struct TransferWithInput {
encoded_input: ethabi::Bytes,
}
impl ethabi::ContractFunction for TransferWithInput {
type Output = ();
fn encoded(&self) -> ethabi::Bytes {
self.encoded_input.clone()
}
fn output(&self, _output_bytes: ethabi::Bytes) -> ethabi::Result<Self::Output> {
Ok(())
}
}
impl TransferWithInput {
#[doc(hidden)]
pub fn new(v: Vec<ethabi::Token>) -> Self {
let encoded_input: ethabi::Bytes = functions::Transfer::default().encode_input(&v).expect(
INTERNAL_ERR,
);
TransferWithInput { encoded_input: encoded_input }
}
}
#[doc = r" Contract functions (for encoding input, making calls, transactions)"]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct Eip20Functions {}
impl Eip20Functions {
#[doc = r" Sets the input (arguments) for this contract function"]
pub fn total_supply(&self) -> TotalSupplyWithInput {
let v: Vec<ethabi::Token> = vec![];
TotalSupplyWithInput::new(v)
}
#[doc = r" Sets the input (arguments) for this contract function"]
pub fn transfer_from<
T0: Into<ethabi::Address>,
T1: Into<ethabi::Address>,
T2: Into<ethabi::Uint>,
>(
&self,
from: T0,
to: T1,
value: T2,
) -> TransferFromWithInput {
let v: Vec<ethabi::Token> = vec![
ethabi::Token::Address(from.into()),
ethabi::Token::Address(to.into()),
ethabi::Token::Uint(value.into()),
];
TransferFromWithInput::new(v)
}
#[doc = r" Sets the input (arguments) for this contract function"]
pub fn approve<T0: Into<ethabi::Address>, T1: Into<ethabi::Uint>>(
&self,
spender: T0,
value: T1,
) -> ApproveWithInput {
let v: Vec<ethabi::Token> = vec![
ethabi::Token::Address(spender.into()),
ethabi::Token::Uint(value.into()),
];
ApproveWithInput::new(v)
}
#[doc = r" Sets the input (arguments) for this contract function"]
pub fn balance_of<T0: Into<ethabi::Address>>(&self, owner: T0) -> BalanceOfWithInput {
let v: Vec<ethabi::Token> = vec![ethabi::Token::Address(owner.into())];
BalanceOfWithInput::new(v)
}
#[doc = r" Sets the input (arguments) for this contract function"]
pub fn allowance<T0: Into<ethabi::Address>, T1: Into<ethabi::Address>>(
&self,
owner: T0,
spender: T1,
) -> AllowanceWithInput {
let v: Vec<ethabi::Token> = vec![
ethabi::Token::Address(owner.into()),
ethabi::Token::Address(spender.into()),
];
AllowanceWithInput::new(v)
}
#[doc = r" Sets the input (arguments) for this contract function"]
pub fn transfer<T0: Into<ethabi::Address>, T1: Into<ethabi::Uint>>(
&self,
to: T0,
value: T1,
) -> TransferWithInput {
let v: Vec<ethabi::Token> = vec![
ethabi::Token::Address(to.into()),
ethabi::Token::Uint(value.into()),
];
TransferWithInput::new(v)
}
}
impl Eip20 {
#[doc = r" Gets contract functions (for encoding input, making calls, transactions)"]
pub fn functions(&self) -> Eip20Functions {
Eip20Functions {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment