1#![deny(warnings)]
4#![deny(missing_docs)]
5
6#[macro_use]
7extern crate serde_derive;
8
9mod abi;
11pub mod client;
13pub mod crypto;
15pub mod error;
17mod new_token;
19pub mod protos;
21pub mod rpctypes;
23
24pub use crate::abi::{decode_input, decode_logs, decode_params, encode_input, encode_params};
25pub use crate::client::{parse_url, remove_0x, TransactionOptions};
26pub use crate::crypto::{
27 pubkey_to_address, secp256k1_sign, sign, sm2_sign, CreateKey, Encryption, Hashable, KeyPair,
28 Message, PrivateKey, PubKey, Secp256k1KeyPair, Secp256k1PrivKey, Secp256k1PubKey, Signature,
29 Sm2KeyPair, Sm2Privkey, Sm2Pubkey, Sm2Signature,
30};
31pub use crate::error::ToolError;
32pub use crate::protos::{Crypto, SignedTransaction, Transaction, UnverifiedTransaction};
33pub use crate::rpctypes::{JsonRpcParams, JsonRpcResponse, ParamsValue, ResponseValue};
34pub use hex::{decode, encode};
35pub use protobuf::Message as ProtoMessage;
36pub use types::{Address, H128, H160, H256, H264, H32, H512, H520, H64};
37pub use types::{U256, U512, U64};
38
39pub trait LowerHex {
41 fn lower_hex(&self) -> String;
43 fn completed_lower_hex(&self) -> String;
45 fn completed_lower_hex_with_0x(&self) -> String;
47 fn lower_hex_with_0x(&self) -> String;
49}
50
51macro_rules! add_funcs {
52 ([$( ($name:ident) ),+ ,]) => {
53 add_funcs!([ $( ($name) ),+ ]);
54 };
55
56 ([$( ($name:ident) ),+]) => {
57 $( add_funcs!($name); )+
58 };
59
60 ($name:ident) => {
61 impl LowerHex for $name {
62 #[inline]
63 fn lower_hex(&self) -> String {
64 format!("{:x}", self)
65 }
66
67 #[inline]
68 fn completed_lower_hex(&self) -> String {
69 let len = stringify!($name)[1..].parse::<usize>().unwrap() / 4;
70 format!("{:0>width$}", self.lower_hex(), width=len)
71 }
72
73 fn completed_lower_hex_with_0x(&self) -> String {
74 let len = stringify!($name)[1..].parse::<usize>().unwrap() / 4;
75 format!("0x{:0>width$}", self.lower_hex(), width=len)
76 }
77
78 #[inline]
79 fn lower_hex_with_0x(&self) -> String {
80 format!("{:#x}", self)
81 }
82 }
83 }
84}
85
86add_funcs!([
87 (H32),
88 (H64),
89 (H128),
90 (H160),
91 (H256),
92 (H264),
93 (H512),
94 (H520),
95 (U64),
96 (U256),
97 (U512),
98]);