Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Add more skeleton code
Browse files Browse the repository at this point in the history
  • Loading branch information
HCastano committed Sep 26, 2019
1 parent 53c5429 commit da12b22
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 10 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ members = [
"srml/assets",
"srml/aura",
"srml/balances",
"srml/bridge",
"srml/contracts",
"srml/collective",
"srml/democracy",
Expand Down
14 changes: 14 additions & 0 deletions srml/bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,18 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false }
session = { package = "srml-session", path = "../session", default-features = false, features = ["historical"] }
sr-primitives = { path = "../../core/sr-primitives", default-features = false }
support = { package = "srml-support", path = "../support", default-features = false }
system = { package = "srml-system", path = "../system", default-features = false }

[features]
default = ["std"]
std = [
"codec/std",
"session/std",
"sr-primitives/std",
"support/std",
"system/std",
]
144 changes: 134 additions & 10 deletions srml/bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,157 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.


//! # Bridge Module
//!
//! This will eventually have some useful documentation.
//! For now though, enjoy this cow's wisdom.
//!
//! ________________________________________
//! / You are only young once, but you can \
//! \ stay immature indefinitely. /
//! \ stay immature indefinitely. /
//! ----------------------------------------
//! \ ^__^
//! \ (oo)\_______
//! (__)\ )\/\
//! ||----w |
//! || ||


// Ensure we're `no_std` when compiling for Wasm.
#![cfg_attr(not(feature = "std"), no_std)]

use support::{
decl_module, decl_event, decl_storage, decl_error,
use codec::{Decode, Encode};
use sr_primitives::{
generic::BlockId,
traits::{Block as BlockT, Header as HeaderT},
};
use support::{decl_error, decl_event, decl_module, decl_storage, dispatch::Result};
use system::{ensure_root, ensure_signed};

// struct Bridge {}
//
// impl Bridge {
// pub fn new() -> Self {}
// pub fn submit_claim() -> Result<(), Err> {}
// pub fn get_id(&self) -> u64 {}
// pub fn get_recently_finalized_block(&self) -> Block {}
// }

pub trait Trait: system::Trait + session::Trait {
// The identifier type for an authority.
// type AuthorityId: Member + Parameter + RuntimeAppPublic + Default;
}

decl_storage! {
trait Store for Module<T: Trait> as Bridge {
/// Get the ID of the current bridge
pub BridgeId get(bridge_id): T::Hash;

/// Get the ID of the current bridge
// TODO: Figure out how to ge a Block here
pub LastFinalizedBlock get(last_finalized_block): u64; // Block;

/// Get latest block number included in the chain
pub BlockNumber get(lastest_block_num): T::BlockNumber;

// What I want to have wrt to the Block are:
// 1. Block Number
// 2. Block Hash
// 3. State Root
// Can I get these from a `Block`, or do they need to
// be stored individually?

/// Latest set of validators
pub Validators get(validators): Vec<T::ValidatorId>;
}
}

decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
// TODO: Figure out the proper type for these proofs
fn new(origin, block_header: T::Header, validator_set: Vec<T::ValidatorId>, validator_set_proof: Vec<u8>, storage_proof: Vec<u8>) {
//
// The macro can't handle arguments like this :(
// fn new(
// origin,
// block_header: T::Header,
// validator_set: Vec<T::ValidatorId>,
// validator_set_proof: Vec<u8>,
// storage_proof: Vec<u8>,
// ) {

// NOTE: Should this be a root call?
let _sender = ensure_signed(origin)?;

Self::check_storage_proof()?;
Self::check_validator_set_proof()?;

// TODO: Do something better than this
let bridge_id = <system::Module<T>>::random(b"this_is_not_a_good_source_of_randomness");
<BridgeId<T>>::put(bridge_id);
}

fn submit_finalized_headers(origin) {
let _sender = ensure_signed(origin)?;
}
}

}

decl_error! {
// Error for the Bridge module
pub enum Error {
InvalidStorageProof,
InvalidValidatorSetProof,
}
}

impl<T: Trait> Module<T> {
// fn check_storage_proof() -> Result<(), Error> {
fn check_storage_proof() -> Result {
// ... Do some math ...
Ok(()) // Otherwise, Error::InvalidStorageProof
}

// fn check_validator_set_proof() -> Result<(), Error> {
fn check_validator_set_proof() -> Result {
// ... Do some math ...
Ok(()) // Otherwise, Error::InvalidValidatorSetProof
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn should_initialize_default_bridge_module() {
let bridge = Bridge::default();
}

#[test]
fn should_initialize_bridge_module() {
let bridge = Bridge::new(header, validator_set, v_set_proof, code_hash);
}

#[test]
fn should_accept_finalized_headers() {
let bridge = Bridge::default();
bridge.submit_finalized_header(last_block_hash, header, ancestry_proof, grandpa_proof);
}

#[test]
fn should_get_recently_finalized_block() {}

#[test]
fn should_do_all_the_things() {
let bridge = Bridge::new(); // or Bridge::default();
bridge.track_chain(); // Maybe part of init process?

pub trait Trait {}
while curr_chain.has_blocks() {
// Using Fred's spec this would be something like `submit_claim()`
bridge.submit_finalized_headers();
}

decl_storage! {}
decl_event!()
decl_module! {}
decl_error! {}
bridge.close();
}
}

0 comments on commit da12b22

Please sign in to comment.