[−][src]Crate solid
Basic usage of the crate without the "deser" nor "derive" features would be using Builder
and Selector
.
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.
#[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.
#[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.
#[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.
#[derive(Encode)] #[solid(constructor)] struct Contract { creator: String, }
Re-exports
pub use solid_derive as derive; |
Modules
bytesfix | Container for all |
decode | |
encode | |
int | Container for all |
into_type |
Structs
Address | Simple wrapper for the Solidity type |
Builder | Function call builder |
Bytes | Solidity Type |
Function | Simple wrapper for the Solidity type |
Selector | Function signature builder |
Enums
Error | Crate level error type |
Functions
from_bytes | Function to call to decode a Solidity response into a struct that implements |
to_bytes | Function to call to encode a struct that implements |
Type Definitions
Result | Simple wrapper around |
Derive Macros
Decode | |
Encode |