Skip to content

Commit

Permalink
marketplace solver rollup registration types (#1802)
Browse files Browse the repository at this point in the history
- adds rollup registration and rollup update types 
- implements commitable trait for these types
  • Loading branch information
imabdulbasit authored Jul 31, 2024
2 parents 09dc76a + dc2f5f9 commit 6d52a7e
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
1 change: 1 addition & 0 deletions types/src/v0/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod fee_info;
mod header;
mod instance_state;
mod l1;
mod solver;
mod state;
mod transaction;

Expand Down
67 changes: 67 additions & 0 deletions types/src/v0/impls/solver.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use committable::{Commitment, Committable};
use hotshot::types::SignatureKey;

use super::v0_3::{RollupRegistrationBody, RollupUpdatebody};

impl Committable for RollupRegistrationBody {
fn tag() -> String {
"ROLLUP_REGISTRATION".to_string()
}

fn commit(&self) -> Commitment<Self> {
let mut comm = committable::RawCommitmentBuilder::new(&Self::tag())
.u64_field("namespace_id", u64::from(self.namespace_id))
.var_size_field("reserve_url", self.reserve_url.as_str().as_ref())
.fixed_size_field("reserve_price", &self.reserve_price.to_fixed_bytes())
.fixed_size_field("active", &[u8::from(self.active)])
.constant_str("signature_keys");

for key in self.signature_keys.iter() {
comm = comm.var_size_bytes(&key.to_bytes());
}

comm = comm
.var_size_field("signature_key", &self.signature_key.to_bytes())
.var_size_field("text", self.text.as_bytes());

comm.finalize()
}
}

impl Committable for RollupUpdatebody {
fn tag() -> String {
"ROLLUP_UPDATE".to_string()
}

fn commit(&self) -> Commitment<Self> {
let mut comm = committable::RawCommitmentBuilder::new(&Self::tag())
.u64_field("namespace_id", u64::from(self.namespace_id));

if let Some(reserve_url) = &self.reserve_url {
comm = comm.var_size_field("reserve_url", reserve_url.as_str().as_ref())
}

if let Some(rp) = self.reserve_price {
comm = comm.fixed_size_field("reserve_price", &rp.to_fixed_bytes())
};

if let Some(active) = self.active {
comm = comm.fixed_size_field("active", &[u8::from(active)]);
}

if let Some(keys) = &self.signature_keys {
comm = comm.constant_str("signature_keys");
for key in keys.iter() {
comm = comm.var_size_bytes(&key.to_bytes());
}
}

comm = comm.var_size_field("signature_key", &self.signature_key.to_bytes());

if let Some(text) = &self.text {
comm = comm.var_size_field("text", text.as_bytes());
}

comm.finalize()
}
}
2 changes: 2 additions & 0 deletions types/src/v0/v0_3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ mod auction;
mod chain_config;
mod fee_info;
mod header;
mod solver;

pub use auction::{BidTx, BidTxBody, FullNetworkTx, SolverAuctionResults};
pub use chain_config::*;
pub use fee_info::IterableFeeInfo;
pub use header::Header;
pub use solver::*;
53 changes: 53 additions & 0 deletions types/src/v0/v0_3/solver.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use crate::{FeeAmount, NamespaceId, SeqTypes};
use hotshot::types::SignatureKey;
use hotshot_types::traits::node_implementation::NodeType;
use serde::{Deserialize, Serialize};
use tide_disco::Url;

#[derive(PartialEq, Serialize, Deserialize, Debug, Clone)]
pub struct RollupRegistration {
pub body: RollupRegistrationBody,
// signature over the above data (must be from a key in the 'signature_keys` list)
pub signature:
<<SeqTypes as NodeType>::SignatureKey as SignatureKey>::PureAssembledSignatureType,
}

#[derive(PartialEq, Serialize, Deserialize, Debug, Clone)]
pub struct RollupRegistrationBody {
pub namespace_id: NamespaceId,
pub reserve_url: Url,
// Denominated in Wei
pub reserve_price: FeeAmount,
// whether this registration is active in the marketplace
pub active: bool,
// a list of keys authorized to update the registration information
pub signature_keys: Vec<<SeqTypes as NodeType>::SignatureKey>,
// The signature key used to sign this registration body
pub signature_key: <SeqTypes as NodeType>::SignatureKey,
// Optional field for human readable information
pub text: String,
}

#[derive(PartialEq, Serialize, Deserialize, Debug, Clone)]
pub struct RollupUpdate {
pub body: RollupUpdatebody,
// signature over the above data (must be from a key in the 'signature_keys` list)
pub signature:
<<SeqTypes as NodeType>::SignatureKey as SignatureKey>::PureAssembledSignatureType,
}

#[derive(PartialEq, Serialize, Deserialize, Debug, Clone)]
pub struct RollupUpdatebody {
pub namespace_id: NamespaceId,
// Denominated in Wei
pub reserve_url: Option<Url>,
pub reserve_price: Option<FeeAmount>,
// whether this registration is active in the marketplace
pub active: Option<bool>,
// a list of keys authorized to update the registration information
pub signature_keys: Option<Vec<<SeqTypes as NodeType>::SignatureKey>>,
// The signature key used to sign this update body
pub signature_key: <SeqTypes as NodeType>::SignatureKey,
// Optional field for human readable information
pub text: Option<String>,
}

0 comments on commit 6d52a7e

Please sign in to comment.