Skip to content

Commit 183f1d7

Browse files
committed
Call the IBC transactions in the state module
1 parent c23b7fc commit 183f1d7

File tree

7 files changed

+69
-15
lines changed

7 files changed

+69
-15
lines changed

core/src/block.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::transaction::{SignedTransaction, UnverifiedTransaction};
2222
use crate::BlockId;
2323
use ccrypto::BLAKE_NULL_RLP;
2424
use ckey::Address;
25-
use cstate::{FindActionHandler, StateDB, StateError, StateWithCache, TopLevelState};
25+
use cstate::{FindActionHandler, IBCTransactionExecutor, StateDB, StateError, StateWithCache, TopLevelState};
2626
use ctypes::errors::HistoryError;
2727
use ctypes::header::{Header, Seal};
2828
use ctypes::util::unexpected::Mismatch;
@@ -149,7 +149,7 @@ impl<'x> OpenBlock<'x> {
149149
}
150150

151151
/// Push a transaction into the block.
152-
pub fn push_transaction<C: ChainTimeInfo + FindActionHandler>(
152+
pub fn push_transaction<C: ChainTimeInfo + FindActionHandler + IBCTransactionExecutor>(
153153
&mut self,
154154
tx: SignedTransaction,
155155
h: Option<TxHash>,
@@ -192,7 +192,7 @@ impl<'x> OpenBlock<'x> {
192192
}
193193

194194
/// Push transactions onto the block.
195-
pub fn push_transactions<C: ChainTimeInfo + FindActionHandler>(
195+
pub fn push_transactions<C: ChainTimeInfo + FindActionHandler + IBCTransactionExecutor>(
196196
&mut self,
197197
transactions: &[SignedTransaction],
198198
client: &C,
@@ -455,7 +455,7 @@ impl IsBlock for SealedBlock {
455455
}
456456

457457
/// Enact the block given by block header, transactions and uncles
458-
pub fn enact<C: ChainTimeInfo + EngineInfo + FindActionHandler + TermInfo>(
458+
pub fn enact<C: ChainTimeInfo + EngineInfo + FindActionHandler + TermInfo + IBCTransactionExecutor>(
459459
header: &Header,
460460
transactions: &[SignedTransaction],
461461
engine: &dyn CodeChainEngine,

core/src/client/client.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ use cdb::{new_journaldb, Algorithm, AsHashDB, DatabaseError};
3636
use cio::IoChannel;
3737
use ckey::{Address, NetworkId, PlatformAddress, Public};
3838
use cnetwork::NodeId;
39-
use cstate::{ActionHandler, FindActionHandler, StateDB, StateResult, TopLevelState, TopStateView};
39+
use cstate::{
40+
ActionHandler, FindActionHandler, IBCTransactionExecutor, StateDB, StateResult, TopLevelState, TopStateView,
41+
};
4042
use ctimer::{TimeoutHandler, TimerApi, TimerScheduleError, TimerToken};
4143
use ctypes::header::Header;
4244
use ctypes::transaction::{AssetTransferInput, PartialHashing, ShardTransaction};
@@ -856,3 +858,15 @@ impl SnapshotClient for Client {
856858
}
857859
}
858860
}
861+
862+
impl IBCTransactionExecutor for Client {
863+
fn execute(
864+
&self,
865+
bytes: &[u8],
866+
state: &mut TopLevelState,
867+
fee_payer: &Address,
868+
sender_pubkey: &Public,
869+
) -> StateResult<()> {
870+
unimplemented!()
871+
}
872+
}

core/src/client/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,5 @@ pub trait StateInfo {
324324
pub trait SnapshotClient {
325325
fn notify_snapshot(&self, id: BlockId);
326326
}
327+
328+
pub trait IBCClient {}

core/src/miner/miner.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::scheme::Scheme;
3030
use crate::transaction::{PendingSignedTransactions, SignedTransaction, UnverifiedTransaction};
3131
use crate::types::{BlockId, TransactionId};
3232
use ckey::{public_to_address, Address, Password, PlatformAddress, Public};
33-
use cstate::{FindActionHandler, TopLevelState};
33+
use cstate::{FindActionHandler, IBCTransactionExecutor, TopLevelState};
3434
use ctypes::errors::HistoryError;
3535
use ctypes::transaction::{Action, IncompleteTransaction};
3636
use ctypes::{BlockHash, TxHash};
@@ -287,7 +287,14 @@ impl Miner {
287287

288288
/// Prepares new block for sealing including top transactions from queue and seal it.
289289
fn prepare_and_seal_block<
290-
C: AccountData + BlockChainTrait + BlockProducer + ChainTimeInfo + EngineInfo + FindActionHandler + TermInfo,
290+
C: AccountData
291+
+ BlockChainTrait
292+
+ BlockProducer
293+
+ ChainTimeInfo
294+
+ EngineInfo
295+
+ FindActionHandler
296+
+ TermInfo
297+
+ IBCTransactionExecutor,
291298
>(
292299
&self,
293300
parent_block_id: BlockId,
@@ -519,7 +526,8 @@ impl MinerService for Miner {
519526
+ ImportBlock
520527
+ ChainTimeInfo
521528
+ FindActionHandler
522-
+ TermInfo, {
529+
+ TermInfo
530+
+ IBCTransactionExecutor, {
523531
ctrace!(MINER, "update_sealing: preparing a block");
524532

525533
let block = match self.prepare_and_seal_block(parent_block, chain) {

state/src/ibc.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2020 Kodebox, Inc.
2+
// This file is part of CodeChain.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as
6+
// published by the Free Software Foundation, either version 3 of the
7+
// License, or (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
use crate::{StateResult, TopLevelState};
18+
use ckey::{Address, Public};
19+
20+
pub trait IBCTransactionExecutor {
21+
fn execute(
22+
&self,
23+
bytes: &[u8],
24+
state: &mut TopLevelState,
25+
fee_payer: &Address,
26+
sender_pubkey: &Public,
27+
) -> StateResult<()>;
28+
}

state/src/impls/top_level.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ use crate::checkpoint::{CheckpointId, StateWithCheckpoint};
4040
use crate::error::Error;
4141
use crate::traits::{ShardState, ShardStateView, StateWithCache, TopState, TopStateView};
4242
use crate::{
43-
Account, ActionData, FindActionHandler, IBCData, Metadata, MetadataAddress, RegularAccount, RegularAccountAddress,
44-
Shard, ShardAddress, ShardLevelState, StateDB, StateResult,
43+
Account, ActionData, FindActionHandler, IBCData, IBCTransactionExecutor, Metadata, MetadataAddress, RegularAccount,
44+
RegularAccountAddress, Shard, ShardAddress, ShardLevelState, StateDB, StateResult,
4545
};
4646
use ccrypto::BLAKE_NULL_RLP;
4747
use cdb::{AsHashDB, DatabaseError};
@@ -245,7 +245,7 @@ impl TopLevelState {
245245

246246
/// Execute a given tranasction, charging tranasction fee.
247247
/// This will change the state accordingly.
248-
pub fn apply<C: ChainTimeInfo + FindActionHandler>(
248+
pub fn apply<C: ChainTimeInfo + FindActionHandler + IBCTransactionExecutor>(
249249
&mut self,
250250
tx: &Transaction,
251251
signed_hash: &TxHash,
@@ -276,7 +276,7 @@ impl TopLevelState {
276276
result
277277
}
278278

279-
fn apply_internal<C: ChainTimeInfo + FindActionHandler>(
279+
fn apply_internal<C: ChainTimeInfo + FindActionHandler + IBCTransactionExecutor>(
280280
&mut self,
281281
tx: &Transaction,
282282
signed_hash: &TxHash,
@@ -341,7 +341,7 @@ impl TopLevelState {
341341
}
342342

343343
#[allow(clippy::too_many_arguments)]
344-
fn apply_action<C: ChainTimeInfo + FindActionHandler>(
344+
fn apply_action<C: ChainTimeInfo + FindActionHandler + IBCTransactionExecutor>(
345345
&mut self,
346346
action: &Action,
347347
network_id: NetworkId,
@@ -406,9 +406,9 @@ impl TopLevelState {
406406
return Ok(())
407407
}
408408
Action::IBC {
409-
..
409+
bytes,
410410
} => {
411-
// FIXME: call ibc transactions
411+
IBCTransactionExecutor::execute(client, bytes, self, fee_payer, signer_public)?;
412412
return Ok(())
413413
}
414414
};

state/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ mod cache;
3333
mod checkpoint;
3434
mod db;
3535
mod error;
36+
mod ibc;
3637
mod impls;
3738
mod item;
3839
mod traits;
@@ -43,6 +44,7 @@ pub use crate::action_handler::{ActionDataKeyBuilder, ActionHandler, FindActionH
4344
pub use crate::checkpoint::{CheckpointId, StateWithCheckpoint};
4445
pub use crate::db::StateDB;
4546
pub use crate::error::Error as StateError;
47+
pub use crate::ibc::IBCTransactionExecutor;
4648
pub use crate::impls::{ShardLevelState, TopLevelState};
4749
pub use crate::item::account::Account;
4850
pub use crate::item::action_data::ActionData;

0 commit comments

Comments
 (0)