-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(malachine): set up context boilerplate
- Loading branch information
1 parent
81ad1f2
commit 25ae91d
Showing
11 changed files
with
421 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "malachite" | ||
authors.workspace = true | ||
homepage.workspace = true | ||
edition.workspace = true | ||
repository.workspace = true | ||
version.workspace = true | ||
license.workspace = true | ||
|
||
[dependencies] | ||
|
||
# Madara | ||
mp-block.workspace = true | ||
|
||
# Starknet | ||
malachite-core-types.workspace = true | ||
starknet-types-core.workspace = true | ||
|
||
[lints] | ||
workspace = true |
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,65 @@ | ||
use mp_block::MadaraBlock; | ||
|
||
use crate::{ | ||
proposal::{ProposalPartStub, ProposalStub}, | ||
types::{Address, Height}, | ||
validators::{ValidatorSet, ValidatorStub}, | ||
vote::{SigningProviderStub, SigningSchemeStub, VoteStub}, | ||
}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct MadaraContext; | ||
|
||
impl malachite_core_types::Context for MadaraContext { | ||
type Address = Address; | ||
type Height = Height; | ||
type ProposalPart = ProposalPartStub; | ||
type Proposal = ProposalStub; | ||
type Validator = ValidatorStub; | ||
type ValidatorSet = ValidatorSet; | ||
type Value = MadaraBlock; | ||
type Vote = VoteStub; | ||
type SigningScheme = SigningSchemeStub; | ||
type SigningProvider = SigningProviderStub; | ||
|
||
fn select_proposer<'a>( | ||
&self, | ||
validator_set: &'a Self::ValidatorSet, | ||
height: Self::Height, | ||
round: malachite_core_types::Round, | ||
) -> &'a Self::Validator { | ||
todo!() | ||
} | ||
|
||
fn signing_provider(&self) -> &Self::SigningProvider { | ||
todo!() | ||
} | ||
|
||
fn new_proposal( | ||
height: Self::Height, | ||
round: malachite_core_types::Round, | ||
value: Self::Value, | ||
pol_round: malachite_core_types::Round, | ||
address: Self::Address, | ||
) -> Self::Proposal { | ||
todo!() | ||
} | ||
|
||
fn new_prevote( | ||
height: Self::Height, | ||
round: malachite_core_types::Round, | ||
value_id: malachite_core_types::NilOrVal<malachite_core_types::ValueId<Self>>, | ||
address: Self::Address, | ||
) -> Self::Vote { | ||
todo!() | ||
} | ||
|
||
fn new_precommit( | ||
height: Self::Height, | ||
round: malachite_core_types::Round, | ||
value_id: malachite_core_types::NilOrVal<malachite_core_types::ValueId<Self>>, | ||
address: Self::Address, | ||
) -> Self::Vote { | ||
todo!() | ||
} | ||
} |
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,5 @@ | ||
mod context; | ||
mod proposal; | ||
mod types; | ||
mod validators; | ||
mod vote; |
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,48 @@ | ||
use mp_block::MadaraBlock; | ||
|
||
use crate::{ | ||
context::MadaraContext, | ||
types::{Address, Height}, | ||
}; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] | ||
pub struct ProposalPartStub; | ||
|
||
impl malachite_core_types::ProposalPart<MadaraContext> for ProposalPartStub { | ||
fn is_first(&self) -> bool { | ||
unimplemented!() | ||
} | ||
|
||
fn is_last(&self) -> bool { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] | ||
pub struct ProposalStub; | ||
|
||
impl malachite_core_types::Proposal<MadaraContext> for ProposalStub { | ||
fn height(&self) -> Height { | ||
todo!() | ||
} | ||
|
||
fn round(&self) -> malachite_core_types::Round { | ||
todo!() | ||
} | ||
|
||
fn value(&self) -> &MadaraBlock { | ||
todo!() | ||
} | ||
|
||
fn take_value(self) -> MadaraBlock { | ||
todo!() | ||
} | ||
|
||
fn pol_round(&self) -> malachite_core_types::Round { | ||
todo!() | ||
} | ||
|
||
fn validator_address(&self) -> &Address { | ||
todo!() | ||
} | ||
} |
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,37 @@ | ||
use starknet_types_core::felt::Felt; | ||
|
||
#[repr(transparent)] | ||
#[derive(Clone, Copy, Default, Debug, Eq, PartialEq, Ord, PartialOrd)] | ||
pub struct Height(u64); | ||
|
||
impl std::fmt::Display for Height { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("Height").field("at", &self.0).finish() | ||
} | ||
} | ||
|
||
impl malachite_core_types::Height for Height { | ||
fn increment_by(&self, n: u64) -> Self { | ||
Self(self.0.saturating_add(n)) | ||
} | ||
|
||
fn decrement_by(&self, n: u64) -> Option<Self> { | ||
self.0.checked_sub(n).map(Self) | ||
} | ||
|
||
fn as_u64(&self) -> u64 { | ||
self.0 | ||
} | ||
} | ||
|
||
#[repr(transparent)] | ||
#[derive(Clone, Copy, Default, Debug, Eq, PartialEq, Ord, PartialOrd)] | ||
pub struct Address(Felt); | ||
|
||
impl std::fmt::Display for Address { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("Address").field("at", &self.0).finish() | ||
} | ||
} | ||
|
||
impl malachite_core_types::Address for Address {} |
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,44 @@ | ||
use malachite_core_types::Validator as _; | ||
use std::collections::BTreeMap; | ||
|
||
use crate::{context::MadaraContext, types::Address}; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] | ||
pub struct ValidatorStub; | ||
|
||
impl malachite_core_types::Validator<MadaraContext> for ValidatorStub { | ||
fn address(&self) -> &Address { | ||
todo!() | ||
} | ||
|
||
fn public_key(&self) -> &malachite_core_types::PublicKey<MadaraContext> { | ||
todo!() | ||
} | ||
|
||
fn voting_power(&self) -> malachite_core_types::VotingPower { | ||
todo!() | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] | ||
pub struct ValidatorSet { | ||
validators: BTreeMap<Address, ValidatorStub>, | ||
} | ||
|
||
impl malachite_core_types::ValidatorSet<MadaraContext> for ValidatorSet { | ||
fn count(&self) -> usize { | ||
self.validators.len() | ||
} | ||
|
||
fn total_voting_power(&self) -> malachite_core_types::VotingPower { | ||
self.validators.values().fold(0, |acc, v| acc + v.voting_power()) | ||
} | ||
|
||
fn get_by_address(&self, address: &Address) -> Option<&ValidatorStub> { | ||
self.validators.get(address) | ||
} | ||
|
||
fn get_by_index(&self, index: usize) -> Option<&ValidatorStub> { | ||
self.validators.values().take(index).last() | ||
} | ||
} |
Oops, something went wrong.