parity-common/README.md

50 lines
1.2 KiB
Markdown
Raw Normal View History

2018-09-02 11:45:45 -07:00
# Ethereum primitives
2016-12-22 03:07:45 -08:00
2017-11-03 08:39:09 -07:00
[![Build Status](https://travis-ci.org/paritytech/primitives.svg?branch=master)](https://travis-ci.org/paritytech/primitives)
2017-06-21 20:23:26 -07:00
2018-09-02 11:45:45 -07:00
Fixed-sized integer arithmetic (ethereum-types) and bloom filter (ethbloom)
2016-12-22 03:07:45 -08:00
2018-09-02 11:45:45 -07:00
To add this crate to your project, add the following in `Cargo.toml`
2017-09-22 02:01:31 -07:00
2017-09-22 02:02:06 -07:00
```toml
2017-09-22 02:01:31 -07:00
[dependencies]
ethereum-types = "0.4"
2018-09-02 11:45:45 -07:00
ethbloom = "0.5"
2017-09-22 02:02:06 -07:00
```
2017-09-22 02:01:31 -07:00
2018-09-02 11:45:45 -07:00
A basic example how to use this crate:
2017-09-22 02:01:31 -07:00
2016-12-22 03:07:45 -08:00
```rust
2017-11-03 08:39:09 -07:00
extern crate ethereum_types;
2018-09-02 11:45:45 -07:00
extern crate ethbloom;
2017-11-03 08:39:09 -07:00
use ethereum_types::U256;
2018-09-02 11:45:45 -07:00
use ethbloom::{Bloom, Input};
2016-12-22 03:07:45 -08:00
fn main() {
2017-04-11 05:44:32 -07:00
let mut val: U256 = 1023.into();
2018-02-13 00:40:05 -08:00
for _ in 0..200 { val = val * 2u32 }
2017-04-11 05:44:32 -07:00
assert_eq!(
2018-02-04 03:53:35 -08:00
&format!("{}", val),
2017-04-11 05:44:32 -07:00
"1643897619276947051879427220465009342380213662639797070513307648"
);
2018-09-02 11:45:45 -07:00
let address = [0_u8; 32];
let mut my_bloom = Bloom::default();
assert!(!my_bloom.contains_input(Input::Raw(&address)));
my_bloom.accrue(Input::Raw(&address));
2016-12-22 03:07:45 -08:00
}
2018-09-02 11:45:45 -07:00
2017-08-14 07:31:00 -07:00
```
2017-08-14 07:30:50 -07:00
### `no_std` crates
This crate has a feature, `std`, that is enabled by default. To use this crate
in a `no_std` context, add the following to your `Cargo.toml`:
```toml
[dependencies]
ethereum-types = { version = "0.4", default-features = false }
2018-09-02 11:45:45 -07:00
ethbloom = { version = "0.5", default-features = false }
2017-08-14 07:30:50 -07:00
```