-
Notifications
You must be signed in to change notification settings - Fork 97
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 market_orders_deprecation_date-remove
- Loading branch information
Showing
109 changed files
with
1,358 additions
and
886 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "app-data" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
app-data-hash = { path = "../app-data-hash" } | ||
anyhow = { workspace = true } | ||
model = { path = "../model" } | ||
serde = { workspace = true } | ||
serde_json = { workspace = true } | ||
serde_with = { workspace = true } | ||
primitive-types = { workspace = true } | ||
hex = "0.4.3" | ||
|
||
[dev-dependencies] | ||
ethcontract = { workspace = true } | ||
|
||
[features] | ||
test_helpers = [] |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use {super::ProtocolAppData, crate::Hooks, serde::Deserialize}; | ||
|
||
/// The legacy `backend` app data object. | ||
#[derive(Debug, Default, Deserialize)] | ||
pub struct BackendAppData { | ||
#[serde(default)] | ||
pub hooks: Hooks, | ||
} | ||
|
||
impl From<BackendAppData> for ProtocolAppData { | ||
fn from(value: BackendAppData) -> Self { | ||
Self { | ||
hooks: value.hooks, | ||
signer: None, | ||
replaced_order: None, | ||
partner_fee: None, | ||
} | ||
} | ||
} |
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,58 @@ | ||
use { | ||
model::bytes_hex::BytesHex, | ||
primitive_types::H160, | ||
serde::{Deserialize, Serialize}, | ||
serde_with::{serde_as, DisplayFromStr}, | ||
std::{ | ||
fmt, | ||
fmt::{Debug, Formatter}, | ||
}, | ||
}; | ||
|
||
/// Order hooks are user-specified Ethereum calls that get executed as part of | ||
/// a pre- or post- interaction. | ||
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] | ||
pub struct Hooks { | ||
#[serde(default)] | ||
pub pre: Vec<Hook>, | ||
#[serde(default)] | ||
pub post: Vec<Hook>, | ||
} | ||
|
||
impl Hooks { | ||
pub fn is_empty(&self) -> bool { | ||
self.pre.is_empty() && self.post.is_empty() | ||
} | ||
|
||
pub fn gas_limit(&self) -> u64 { | ||
std::iter::empty() | ||
.chain(&self.pre) | ||
.chain(&self.post) | ||
.fold(0_u64, |total, hook| total.saturating_add(hook.gas_limit)) | ||
} | ||
} | ||
|
||
/// A user-specified hook. | ||
#[serde_as] | ||
#[derive(Clone, Eq, PartialEq, Deserialize, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Hook { | ||
pub target: H160, | ||
#[serde_as(as = "BytesHex")] | ||
pub call_data: Vec<u8>, | ||
#[serde_as(as = "DisplayFromStr")] | ||
pub gas_limit: u64, | ||
} | ||
|
||
impl Debug for Hook { | ||
fn fmt(&self, f: &mut Formatter) -> fmt::Result { | ||
f.debug_struct("Hook") | ||
.field("target", &self.target) | ||
.field( | ||
"call_data", | ||
&format_args!("0x{}", hex::encode(&self.call_data)), | ||
) | ||
.field("gas_limit", &self.gas_limit) | ||
.finish() | ||
} | ||
} |
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,4 @@ | ||
mod app_data; | ||
mod hooks; | ||
|
||
pub use {app_data::*, hooks::*}; |
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.