Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete abcf entry #29

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ members = [
"abcf",
"macros",
"sdk",
# "node",
"node",
]

1 change: 1 addition & 0 deletions abcf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
log = "0.4.14"
abcf-macros = { path = "../macros" }
bs3 = { git = "ssh://git@github.com/FindoraNetwork/bs3.git", default-features = false, features = ["nightly", "cbor"] }
digest = "0.9.0"

[dev-dependencies]
tokio = { version = "1", features = ["full"] }
90 changes: 79 additions & 11 deletions abcf/examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,95 @@
use abcf::{Application, Event};
#![feature(generic_associated_types)]

#[abcf::module(
name = "mock",
version = "0.1",
impl_version = "0.1.1",
target_height = 0
)]
pub struct MockModule {}
use abcf::{Application, Event};
use bs3::model::{Map, Value};

/// Module's Event
#[derive(Debug, Event)]
pub struct Event1 {}

#[abcf::module(name = "mock", version = 1, impl_version = "0.1.1", target_height = 0)]
pub struct MockModule {
/// In memory.
pub inner: u32,
#[stateful]
pub sf_value: Value<u32>,
#[stateless]
pub sl_value: Value<u32>,
#[stateless]
pub sl_map: Map<i32, u32>,
}

mod __abcf_storage_mockmodule {
use super::*;
use abcf::Result;
pub struct ABCFModuleMockModuleSl<S>
where
S: abcf::bs3::Store,
{
pub sl_value: abcf::bs3::SnapshotableStorage<S, Value<u32>>,
pub sl_map: abcf::bs3::SnapshotableStorage<S, Map<i32, u32>>,
}
pub struct ABCFModuleMockModuleSlTx<'a, S>
where
S: abcf::bs3::Store,
{
pub sl_value: abcf::bs3::Transaction<'a, S, Value<u32>>,
pub sl_map: abcf::bs3::Transaction<'a, S, Map<i32, u32>>,
}
impl<S> abcf::Storage for ABCFModuleMockModuleSl<S>
where
S: abcf::bs3::Store,
{
fn rollback(&mut self, height: i64) -> Result<()> {
self.sl_value.rollback(height)?;
self.sl_map.rollback(height)?;
Ok(())
}
fn height(&self) -> Result<i64> {
Ok(0)
}
fn commit(&mut self) -> Result<()> {
self.sl_value.commit()?;
self.sl_map.commit()?;
Ok(())
}
}
pub struct ABCFModuleMockModuleSf<S>
where
S: abcf::bs3::Store,
{
pub sf_value: abcf::bs3::SnapshotableStorage<S, Value<u32>>,
}
}
/// Module's rpc.
#[abcf::rpcs]
impl MockModule {}

/// Module's block logic.
#[abcf::application]
impl Application for MockModule {

}
impl Application for MockModule {}

/// Module's methods.
impl MockModule {}

// pub struct SimpleNodeSl {}
//
// pub struct SimpleNodeSf {}
//
// pub struct SimpleNode {
// mock: MockModule,
// }
//
// impl Module for SimpleNode {
// fn metadata(&self) -> ModuleMetadata<'_> {
// ModuleMetadata {
// name: "simple_node",
// module_type: abcf::ModuleType::Manager,
// version: 1,
// impl_version: "0.1",
// genesis: Genesis { target_height: 0 },
// }
// }
// }

fn main() {}
37 changes: 37 additions & 0 deletions abcf/src/entry/context/events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::{module::Event, Result};
use alloc::vec::Vec;
use tm_protos::abci;

pub struct EventContext<'a> {
pub events: &'a mut Vec<abci::Event>,
}

impl<'a> EventContext<'a> {
pub fn new(events: &'a mut Vec<abci::Event>) -> Self {
EventContext { events }
}

pub fn emmit(&mut self, event: impl Event) -> Result<()> {
let event = event.to_abci_event()?;
self.events.push(event);
Ok(())
}
}

pub struct EventContextImpl {
pub begin_block_events: Vec<abci::Event>,
pub check_tx_events: Vec<abci::Event>,
pub deliver_tx_events: Vec<abci::Event>,
pub end_block_events: Vec<abci::Event>,
}

impl Default for EventContextImpl {
fn default() -> Self {
Self {
begin_block_events: Vec::new(),
check_tx_events: Vec::new(),
deliver_tx_events: Vec::new(),
end_block_events: Vec::new(),
}
}
}
27 changes: 27 additions & 0 deletions abcf/src/entry/context/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
mod events;

use bs3::Store;
pub use events::{EventContext, EventContextImpl};

use crate::{Storage, module::StorageTransaction};

pub struct AContext<'a, Sl, Sf> {
pub events: EventContext<'a>,
pub stateless: &'a mut Sl,
pub stateful: &'a mut Sf,
}

pub struct RContext<'a, Sl, Sf> {
pub stateless: &'a mut Sl,
pub stateful: &'a Sf,
}

pub struct TContext<'a, Sl, Sf>
where
Sl: StorageTransaction,
Sf: StorageTransaction,
{
pub events: EventContext<'a>,
pub stateless: Sl::Transaction,
pub stateful: Sf::Transaction,
}
7 changes: 7 additions & 0 deletions abcf/src/entry/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mod node;
pub use node::Node;

mod context;
pub use context::{AContext, EventContext, EventContextImpl, RContext, TContext};

mod prelude;
Loading