Struct Calldata

Source
pub struct Calldata { /* private fields */ }

Implementations§

Source§

impl Calldata

Source

pub fn bytes(&self) -> &[u8]

Source

pub fn hex(&self) -> String

Source

pub fn len(&self) -> usize

Source

pub fn from_bytes(bytes: &[u8]) -> Self

Source

pub fn from_hex(string: &str) -> Self

Examples found in repository?
examples/v2mod.rs (line 74)
72fn main() {
73    let string     = "0x791ac94700000000000000000000000000000000000000000000000000000000004c3f88000000000000000000000000000000000000000000000000000ac2d7237640f900000000000000000000000000000000000000000000000000000000000000a000000000000000000000000013a48c3e0a403b6cf1a59fbd600e284e620b37ed0000000000000000000000000000000000000000000000000000000065211d050000000000000000000000000000000000000000000000000000000000000002000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc800000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1";
74    let mut view   = View::new(Calldata::from_hex(string), WithSig::True);
75    
76    print!("[>] Before:\n"); 
77    print(&view, AMOUNT_MIN_SLOT);
78    print(&view, TIME_LIMIT_SLOT);  
79    
80    zero_amount_min(&mut view);
81    replace_deadline(&mut view);
82    print!("[>] After:\n");
83    print(&view, AMOUNT_MIN_SLOT);
84    print(&view, TIME_LIMIT_SLOT);  
85    print!("[>] Hex 0x:\n");
86    hex_0x(&view);
87    //quick_sum(&view);
88  }
More examples
Hide additional examples
examples/basic_stream.rs (line 23)
5fn build_basic_stream() {
6  /*
7
8     Basic stream creation, otherwise known as concat with extra steps.
9     Obviously when we know our stream and our calls are working, we create
10     dedicated functions for this. But when debugging streams for our
11     contracts or troubleshooting the composition of streams for others,
12     having a visual segmentation while still retaining a granular control 
13     can be useful. Kawala `View`s provide an easy interface for this.
14
15  */
16
17  let command1  = "01"; // command byte
18  let command2  = "FF"; // command byte
19  let address   = "2791Bca1f2de4661ED88A30C99A7a9449Aa84174"; // address
20  let amount    = "08E8925E5C2E7DE78EEA"; // value 42069123456789876543210
21
22  // we can start from a single byte view
23  let mut view = View::new(Calldata::from_hex(command1), WithSig::False);
24  view.summary();
25  /* Sig: 
26     Data:  01 
27     View:  ["01"] 
28     Count: 1    */
29  // we can append following words
30  [command2, amount, address] . map(|x| view.append(x));
31
32  view.summary();
33  /* Sig: 
34     Data:  01ff08e8925e5c2e7de78eea2791bca1f2de4661ed88a30c99a7a9449aa84174 
35     View:  ["01", "ff", "08e8925e5c2e7de78eea", "2791bca1f2de4661ed88a30c99a7a9449aa84174"] 
36     Count: 4
37     Can see we already have our stream above if we just call the data() method
38     but for the sake of keeping it simple while exploring functionality let's 
39     build it from the elements */
40
41  // we can pad the words to the desired side..
42
43  // to reflect abi encoding
44  view.left_pad(3); 
45  //"0000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa84174"
46  
47  // or position where we need it
48  view.right_pad(2);
49  // "08e8925e5c2e7de78eea00000000000000000000000000000000000000000000",
50  
51  view.right_pad(1);
52  // "ff00000000000000000000000000000000000000000000000000000000000000"
53  
54  view.right_pad(0); 
55  // "0100000000000000000000000000000000000000000000000000000000000000"
56
57  // we can then shift our bytes left or right to fine tune their positioning
58  view.right_shift(1,1);
59  // "00ff000000000000000000000000000000000000000000000000000000000000"
60  
61
62  view.right_shift(2,2);
63  //"000008e8925e5c2e7de78eea0000000000000000000000000000000000000000"
64  
65  // we'll go into more uses for the log ops, but for now we can simply 
66  // xor_fold_all(), to perform an exclusive or on the 2 tail elements 
67  // consuming the last until we are left with a single 32 byte word. 
68  view.xor_fold_all();
69
70  view.summary();
71  /* Sig: 
72     Data:  01ff08e8925e5c2e7de78eea2791bca1f2de4661ed88a30c99a7a9449aa84174 
73     View:  ["01ff08e8925e5c2e7de78eea2791bca1f2de4661ed88a30c99a7a9449aa84174"] 
74     Count: 1  */
75  
76  // we have essentially concatonated our strings
77  let desired = command1.to_owned() + command2 + amount + address;
78  assert_eq!(view.data(), desired.to_lowercase());
79
80}
Source

pub fn hex_0x(&self) -> String

Trait Implementations§

Source§

impl Debug for Calldata

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Calldata

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.