Giter Site home page Giter Site logo

abi's Introduction

SaaS3 protocol ABI

This library allows to encode and decode different types of data during interaction between SaaS3 protocol and Ethereum smart contracts

Parameters from contract event logs are consumed as Vec<U256>, which avoids reading random raw bytes and provides guarantee of a proper data alignment on input.

Second parameter of decoding is strict flag, which defines whether decoding could be done into extended types (String32,Bool,Date) that are actually represented as Bytes32 on a protocol level.

decoding example

use abi::ABI;
use primitive_types::U256;
use hex_literal::hex;

fn main() {
    let data: Vec<U256> = vec![
        hex!("3162000000000000000000000000000000000000000000000000000000000000").into(),
        hex!("54657374427974657333324e616d650000000000000000000000000000000000").into(),
        hex!("536f6d6520627974657333322076616c75650000000000000000000000000000").into(),
    ];
    let res: ABI = ABI::decode(&data, true).unwrap();
    println!("{:#?}", res);
}

encoding example

use abi::{ABI, Param};
use primitive_types::U256;

fn main() {
    let param = Param::String {
        name: "hello".to_owned(),
        value: "world".to_owned(),
    };
    let res: Vec<U256> = ABI::new(vec![param]).encode().unwrap();
    println!("{:#?}", res);
}

Please see more examples for each type of the parameter in unit tests.

Contribute

Run cargo +nightly no-std-check --manifest-path Cargo.toml when you introduce new deps

License

MIT

abi's People

Contributors

songtianyi avatar

Watchers

 avatar Steven Wong avatar  avatar

Forkers

cryptobuks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.