GithubHelp home page GithubHelp logo

pinax-network / antelope.rs Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 98 KB

Antelope Standard Library for Rust

Home Page: https://docs.rs/antelope

License: Apache License 2.0

Rust 100.00%
antelope blockchain eosio rust

antelope.rs's People

Contributors

deniscarriere avatar yaroshkvorets avatar

Watchers

 avatar  avatar  avatar  avatar

antelope.rs's Issues

๐Ÿ›  [TYPE] - Asset

Reference URL

https://github.com/AntelopeIO/cdt/blob/main/libraries/eosiolib/core/eosio/asset.hpp

Constructors

  • new()
  • from_amount()

Methods

  • is_amount_within_range()
  • is_valid()
  • set_amount()
  • to_string() (via Display trait)

Traits

  • Default (derived)
  • Copy (derived)
  • Clone (derived)
  • Eq (derived)
  • AsRef
  • Display
  • From<&str>

Operators

  • PartialEq
    • expr != expr
    • expr == expr
    • expr!
  • PartialOrd
    • expr < expr
    • expr > expr
    • expr <= expr
    • expr >= expr
  • Neg
    • - expr
  • Sub
    • expr - expr
  • SubAssign
    • var -= expr
  • Add
    • expr + expr
  • AddAssign
    • var += expr
  • Mul
    • expr * expr
  • MulAssign
    • var *= expr
  • Div
    • expr / expr
  • DivAssign
    • var /= expr

๐Ÿ›  [TYPE] - Symbol

Reference URL

https://github.com/AntelopeIO/cdt/blob/main/libraries/eosiolib/core/eosio/symbol.hpp

Custom Antelope Types

  • code() => SymbolCode
  • is_valid => code().is_valid()
  • raw
  • precision() uint8
  • to_string(show_precision = true)

Standard Rust Types

  • new
  • as_ref
  • AsBool
    • as_bool
  • std::marker::Copy
    • Copy
  • std::clone
    • Clone
  • std::fmt
    • {Result, Formatter, Display}
  • std::convert::From
    • From<u64>
    • From<String>
    • From<&str>
    • From<MyType> for bool

Operators Rust Types

  • PartialEq
    • expr != expr
    • expr == expr
  • Not
    • expr!
  • PartialOrd (partial_cmp & cmp)
    • expr < expr
    • expr > expr
    • expr <= expr
    • expr >= expr

๐Ÿ›  [TYPE] - TimePoint

Reference URL

https://github.com/AntelopeIO/cdt/blob/main/libraries/eosiolib/core/eosio/time.hpp

Constructors

  • new()
  • default()
  • from()

Custom Antelope Methods

  • from_iso_string()
  • to_string()
  • time_since_epoch()
  • sec_since_epoch()

Common Rust Traits

  • AsRef
  • Copy
  • Clone
  • Display

Operators

  • PartialEq
    • Self != Self
    • Self == Self
  • PartialOrd (partial_cmp & cmp)
    • Self < Self
    • expr > Self
    • Self <= Self
    • Self >= Self
  • Sub
    • Self - Self
    • Self - Microseconds
  • SubAssign
    • Self -= Microseconds
  • Add
    • Self + Self
    • Self + Microseconds
  • AddAssign
    • Self += Microseconds

EOSIO Rust SymbolCode issue

Using example Rust EOSIO library, doesn't produce the right SymbolCode

use eosio::*;

#[test]
fn test_symbol_code() {
    assert_eq!(SymbolCode::new(5197638).to_string(), "FOO");
    assert_eq!(Name::from_str("........dxboa").unwrap().as_u64(), 5197638);
}

โŒ Failure

failures:

---- abi::test_symbol_code stdout ----
thread 'abi::test_symbol_code' panicked at 'assertion failed: `(left == right)`
  left: `"SOE"`,
 right: `"EOS"`', substreams/eosio.token/src/abi.rs:208:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected Output

$ eosc tools  names FOO

  from \ to    hex               hex_be            hex_rev_u32  name           uint64   symbol  symbol_code
  ---------    ---               ------            -----------  ----           ------   ------  -----------  
  name         0000000000000000  0000000000000000  ffffffff                    0        0,      -            
  symbol_code  464f4f0000000000  00000000004f4f46  ffb0b0b9     ........dxboa  5197638  70,OO   FOO          

๐Ÿ›  [TYPE] - TimePointSec

Reference URL

https://github.com/AntelopeIO/cdt/blob/main/libraries/eosiolib/core/eosio/time.hpp#L106

Constructors

  • new()
  • default()
  • from()

Custom Antelope Methods

  • to_string()
  • maximum()
  • min()
  • from_iso_string()
  • sec_since_epoch()

Common Rust Traits

  • AsRef
  • Copy
  • Clone
  • Display
  • From<u32>

Operators

  • PartialEq
    • self != self
    • self == self
  • PartialOrd (partial_cmp & cmp)
    • self < self
    • self > self
    • self <= self
    • self >= self
  • Sub
    • self - self
    • self - u32
    • self - Microseconds
  • SubAssign
    • self -= u32
    • self -= Microseconds
    • self -= self
  • Add
    • self + self
    • self + u32
    • self + Microseconds
  • AddAssign
    • self += u32
    • self += Microseconds
    • self += self

๐Ÿ’ก Implement infallible conversions from &str

Start Date

No response

Implementation PR

No response

Reference Issues

No response

Summary

In some cases we can't just panic when parsing invalid types on chain, due to nodeos bugs.
For example this trx: https://eos.eosq.eosnation.io/tx/ab8690feb4486a030cc16cec6e815108325b292d460b47b8c88b4a75c1959bad

image

Need a way to parse it into Result.

Basic Example

In addition to Asset::from() -> Self add Asset::from_str() -> Result<Self, Err>

Drawbacks

N/A

Unresolved questions

No response

๐Ÿ› [BUG] - panics on assets with long precision

Description

Turns out nodeos allows symbols with > 18 precision when insantiated from smart contract.

Example trx: 328fb8765ae167a709390303bc37fa9a0ce5442a29c503f8e8df59ec1c2e2cba

Panic when converting asset into string:

{"severity":"ERROR","timestamp":"2024-03-20T15:38:22.337901079Z","logger":"sink-sql","message":"stream invalid: rpc error: code = InvalidArgument desc = rpc error: code = InvalidArgument desc = step new irr: handler step new: execute modules: running executor \"antelope_tokens:map_accounts\": execute: maps wasm call: block 18777680: module \"antelope_tokens:map_accounts\": general wasm execution panicked: wasm execution failed deterministically: panic in the wasm: \"attempt to divide by zero\" at /Users/work/.cargo/registry/src/index.crates.io-6f17d22bba15001f/antelope-0.1.5/src/asset.rs:86:24","logging.googleapis.com/labels":{},"serviceContext":{"service":"unknown"}}

Reproduction URL

n/a

Reproduction steps

assert_eq!(
            Asset::from_amount(10000000000000, Symbol::from("69,JIAYOUY")),
            Asset::from("0.000000000000000000000000000000000000000000000000000000010000000000000 JIAYOUY")
        );


### Screenshots

```bash
![DESCRIPTION](LINK.png)

Logs

No response

Browsers

No response

OS

No response

๐Ÿ›  [TYPE] - Microseconds

Reference URL

https://github.com/AntelopeIO/cdt/blob/fb549b6cc3569b8d3f61e5e9ad1a992f2b23dbb4/libraries/eosiolib/core/eosio/time.hpp#L19

Constructors

  • new()
  • default()
  • from(i64)
  • from(Microseconds)

Custom Antelope Methods

  • maximum()
  • count()
  • to_seconds()
  • Static functions
    • milliseconds()
    • seconds()
    • minutes()
    • hours()
    • days()

Common Rust Traits

  • AsRef
  • AsBool
  • Copy
  • Clone
  • Display
    • From<u64>
    • From<&str>

Operators

  • PartialEq
    • expr != expr
    • expr == expr
  • PartialOrd (partial_cmp & cmp)
    • expr < expr
    • expr > expr
    • expr <= expr
    • expr >= expr
  • Neg
    • - expr
  • Sub
    • expr - expr
  • SubAssign
    • var -= expr
  • Add
    • expr + expr
  • AddAssign
    • var += expr
  • Mul
    • expr * expr
  • MulAssign
    • var *= expr
  • Div
    • expr / expr
  • DivAssign
    • var /= expr

๐Ÿ›  [TYPE] - ExtendedAsset

Reference URL

https://github.com/AntelopeIO/cdt/blob/main/libraries/eosiolib/core/eosio/asset.hpp#L392

Constructors

  • new()
  • from_amount()
  • from_asset()

Methods

  • get_extended_symbol()
  • is_valid()
  • to_string() (via Display trait)

Traits

  • Default (derived)
  • Copy (derived)
  • Clone (derived)
  • Eq (derived)
  • AsRef
  • Display
  • From<&str>

Operators

  • PartialEq
    • expr != expr
    • expr == expr
  • PartialOrd
    • expr < expr
    • expr > expr
    • expr <= expr
    • expr >= expr
  • Neg
    • - expr
  • Sub
    • expr - expr
  • SubAssign
    • var -= expr
  • Add
    • expr + expr
  • AddAssign
    • var += expr
  • Mul
    • expr * expr
  • MulAssign
    • var *= expr
  • Div
    • expr / expr
  • DivAssign
    • var /= expr

Remove `chrono` dependency

Substreams WASM engine doesn't support some things from chrono

Error: rpc error: code = Internal desc = error building pipeline WASM: new wasm module: creating new instance: unknown import: `__wbindgen_placeholder__::__wbindgen_describe` has not been defined

Comes from the chrono dependency in Antelope.rs

chrono = { version = "0.4", features = ["serde"] }

use chrono::{TimeZone, Utc};

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.