1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
//! ### Basic usage of the crate without the "deser" nor "derive" features would be using `Builder` and `Selector`. //! //! ```rust //! # use solid::{ //! # bytesfix::Bytes10, //! # Builder, //! # }; //! # //! let function = Builder::new() //! .name("transfer") //! .push("daniel") //! .push(10u128) //! .push(Bytes10([1u8; 10])) //! .build(); //! ``` //! //! ### Usage with the "derive" feature would look like. //! //! Use `#[solid(contstructor)]` if you're constructing a contract. //! Otherwise the name of the struct and the field types will be used //! to derive the function signature. //! //! ```rust //! # use solid::{ //! # Address, //! # Bytes, //! # Encode, //! # Decode, //! # int::Uint256, //! # }; //! # //! #[derive(Encode)] //! #[solid(rename = "random_function")] //! struct ContractCallComposite<'a> { //! to: (&'a str, u128), //! memos: &'a [&'a str], //! matrix: &'a [&'a [&'a [u8]]], //! } //! //! #[derive(Decode)] //! struct ContractCallResponse<'a> { //! int: Uint256, //! bytes: Bytes<'a>, //! memo: &'a str, //! address: Address, //! } //! ``` //! //! ### Usage with the "deser" feature would look like. //! //! ```rust //! # use solid::Bytes; //! # use serde::{Serialize, Deserialize}; //! # //! #[derive(Serialize)] //! struct ContractCallComposite<'a> { //! to: (&'a str, u128), //! memos: &'a [&'a str], //! matrix: &'a [&'a [&'a [u8]]], //! } //! //! #[derive(Deserialize)] //! struct ContractCallResponse<'a> { //! // Uint256 is not supported. //! // int: Uint256, //! int: u128, //! //! #[serde(borrow)] //! bytes: Bytes<'a>, //! // You can also do the following because //! // serde treats `&'a [u8]` as bytes //! // bytes: &'a [u8], //! // //! // However, note that if you want to get `uint8[]` using serde you'll need to use a vec //! // uint8array: Vec<u8>, //! //! memo: &'a str, //! // Address is not supported. //! // address: Address, //! } //! ``` //! //! ### Supported attribute key/value pairs for `Encode`: //! //! "rename": must have a value associated with it indicating the function name. //! If this is key is not used, then the struct identifier is used as the function name. //! //! ```rust //! # use solid::Bytes; //! # use solid::Encode; //! # //! #[derive(Encode)] //! #[solid(rename = "random_function")] //! struct RandomFunction<'a> { //! memo: String, //! data: Bytes<'a> //! } //! ``` //! //! "constructor": This indicates the function that is being called is a constructor and hence //! should not have the function signature encoded in the buffer. //! Note: The function signature in solidity is 4 bytes hash in the beginning of the buffer. //! //! ```rust //! # use solid::Encode; //! # //! #[derive(Encode)] //! #[solid(constructor)] //! struct Contract { //! creator: String, //! } //! ``` #[cfg(feature = "derive")] pub use solid_derive as derive; #[cfg(feature = "derive")] pub use solid_derive::{ Decode, Encode, }; pub use solid_core::{ address::Address, builder::Builder, bytes::Bytes, bytesfix, decode, encode, error::{ Error, Result, }, function::Function, int, into_type, selector::Selector, }; #[cfg(feature = "deser")] pub use solid_core::derive::{ from_bytes, to_bytes, };