thor_devkit/
lib.rs

1#![doc(html_root_url = "https://docs.rs/thor-devkit/0.1.0")]
2#![warn(rust_2018_idioms, missing_docs)]
3#![deny(dead_code, unused_imports, unused_mut)]
4
5//! Rust library to aid coding with VeChain: wallets, transactions signing,
6//! encoding and verification, smart contract ABI interfacing, etc.
7//!
8//! This library acts primary as a proxy to several underlying libraries,
9//! with the addition of some VeChain-specific toolchain components.
10//!
11//! ## Usage
12//!
13//! One of possible use cases can be transaction creation and signing.
14//!
15//! Here is how you may approach it. Let's transfer a few VET to another account.
16//!
17//! To do so, we need to create a transaction and encode it into broadcastable bytes.
18//!
19//! ```rust
20//! use thor_devkit::transactions::{Transaction, Clause};
21//! use thor_devkit::hdnode::{Mnemonic, Language, HDNode};
22//!
23//! let transaction = Transaction {
24//!     chain_tag: 1,
25//!     block_ref: 0xaabbccdd,
26//!     expiration: 32,
27//!     clauses: vec![
28//!         Clause {
29//!             to: Some(
30//!                 "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed"
31//!                     .parse()
32//!                     .unwrap(),
33//!             ),
34//!             value: 10000.into(),
35//!             data: b"\x00\x00\x00\x60\x60\x60".to_vec().into(),
36//!         },
37//!     ],
38//!     gas_price_coef: 128,
39//!     gas: 21000,
40//!     depends_on: None,
41//!     nonce: 0xbc614e,
42//!     reserved: None,
43//!     signature: None,
44//! };
45//! let mnemonic = Mnemonic::from_phrase(
46//!     "ignore empty bird silly journey junior ripple have guard waste between tenant",
47//!     Language::English
48//! ).expect("Must be correct");
49//! let wallet = HDNode::build().mnemonic(mnemonic).build().expect("Builds");
50//! let signed = transaction.sign(&wallet.private_key().expect("Must be non-restricted").private_key());
51//! println!("{:02x?}", signed.to_broadcastable_bytes());
52//! ```
53//!
54//! ## Examples
55//!
56//! You can check out sample usage of this crate in the [examples/](https://github.com/sterliakov/thor-devkit.rs/tree/master/examples)
57//! folder in the project repo on GitHub.
58//!
59//! ## Readme Docs
60//!
61//! You can find the crate's readme documentation on the
62//! [crates.io] page, or alternatively in the [`README.md`] file on the GitHub project repo.
63//!
64//! [crates.io]: https://crates.io/crates/thor-devkit
65//! [`README.md`]: https://github.com/sterliakov/thor-devkit.rs
66//!
67//! ### MSRV
68//!
69//! `thor-devkit` promises to maintain a reasonable MSRV policy. MSRV will not be
70//! bumped unless necessary, and such MSRV bumps will only happen in minor or major
71//! releases as soon as the first non-beta release goes live. The required version
72//! will never be newer than 6 months.
73//!
74//! Currently it requires rust `1.81.0` or higher to build.
75//!
76//! ## Contributing
77//!
78//! Contributions are welcome! Open a pull request to fix a bug, or [open an issue][]
79//! to discuss a new feature or change.
80//!
81//! Check out the [Contributing][] section in the docs for more info.
82//!
83//! [Contributing]: https://github.com/sterliakov/thor-devkit.rs/blob/master/CONTRIBUTING.md
84//! [open an issue]: https://github.com/sterliakov/thor-devkit.rs/issues
85//!
86//! ## License
87//!
88//! This project is proudly licensed under the Lesser GNU General Public License v3 ([LICENSE](https://github.com/sterliakov/thor-devkit.rs/blob/master/LICENSE)).
89//!
90//! `thor-devkit` can be distributed according to the Lesser GNU General Public License v3. Contributions
91//! will be accepted under the same license.
92
93mod address;
94pub use address::{Address, AddressConvertible, PrivateKey, PublicKey};
95pub mod hdnode;
96#[cfg(feature = "http")]
97pub mod network;
98pub mod rlp;
99#[cfg(feature = "http")]
100mod transaction_builder;
101pub mod transactions;
102mod utils;
103pub use ethereum_types::U256;
104pub use rustc_hex::FromHexError as AddressValidationError;
105pub use utils::{blake2_256, keccak};