-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/github_actions/deps-2a1b482950
- Loading branch information
Showing
80 changed files
with
2,594 additions
and
1,408 deletions.
There are no files selected for viewing
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
[default] | ||
extend-ignore-re = [ | ||
"\\w{44,52}", | ||
] | ||
|
||
[default.extend-words] | ||
zink = "zink" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
//! Zink ABI implementation | ||
//! | ||
//! Currently just a wrapper of solidity ABI. | ||
|
||
use core::ops::{Deref, DerefMut}; | ||
|
||
/// Function ABI. | ||
#[derive(Clone, Debug, Default)] | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
pub struct Abi(sol_abi::Abi); | ||
|
||
impl Deref for Abi { | ||
type Target = sol_abi::Abi; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl DerefMut for Abi { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
&mut self.0 | ||
} | ||
} | ||
|
||
#[cfg(feature = "bytes")] | ||
impl Abi { | ||
/// Convert [`Abi`] to bytes. | ||
pub fn to_bytes(&self) -> postcard::Result<Vec<u8>> { | ||
postcard::to_stdvec(self).map_err(Into::into) | ||
} | ||
|
||
/// Convert bytes to [`Abi`]. | ||
pub fn from_bytes(bytes: impl AsRef<[u8]>) -> postcard::Result<Self> { | ||
postcard::from_bytes(bytes.as_ref()).map_err(Into::into) | ||
} | ||
} | ||
|
||
#[cfg(feature = "hex")] | ||
mod hex_impl { | ||
use crate::{result::Result, Abi}; | ||
use core::fmt; | ||
|
||
impl Abi { | ||
/// Convert [`Abi`] to hex string. | ||
pub fn to_hex(&self) -> Result<String> { | ||
Ok("0x".to_string() + &hex::encode(self.to_bytes()?)) | ||
} | ||
|
||
/// Convert hex string to [`Abi`]. | ||
pub fn from_hex(hex: impl AsRef<str>) -> Result<Self> { | ||
Self::from_bytes(hex::decode(hex.as_ref().trim_start_matches("0x"))?) | ||
.map_err(Into::into) | ||
} | ||
} | ||
|
||
impl fmt::Display for Abi { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}", self.to_hex().unwrap_or_default()) | ||
} | ||
} | ||
|
||
impl core::str::FromStr for Abi { | ||
type Err = crate::result::Error; | ||
|
||
fn from_str(hex: &str) -> Result<Self> { | ||
Self::from_hex(hex) | ||
} | ||
} | ||
} | ||
|
||
#[cfg(feature = "syn")] | ||
impl From<&syn::Signature> for Abi { | ||
fn from(sig: &syn::Signature) -> Self { | ||
Self(sol_abi::Abi::from(sig)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.