Skip to content
Merged
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
34 changes: 2 additions & 32 deletions core/src/codechain_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use ckey::Address;
use cstate::{StateError, TopState, TopStateView};
use ctypes::errors::{HistoryError, SyntaxError};
use ctypes::transaction::{Action, AssetTransferInput, OrderOnTransfer, Timelock};
use ctypes::transaction::{Action, AssetTransferInput, Timelock};
use ctypes::{CommonParams, Header};

use crate::block::{ExecutedBlock, IsBlock};
Expand All @@ -28,14 +28,12 @@ use crate::transaction::{SignedTransaction, UnverifiedTransaction};

pub struct CodeChainMachine {
params: CommonParams,
is_order_disabled: bool,
}

impl CodeChainMachine {
pub fn new(params: CommonParams) -> Self {
CodeChainMachine {
params,
is_order_disabled: is_order_disabled(),
}
}

Expand All @@ -58,7 +56,7 @@ impl CodeChainMachine {
}
.into())
}
tx.verify_with_params(common_params, self.is_order_disabled)?;
tx.verify_with_params(common_params)?;

Ok(())
}
Expand All @@ -79,7 +77,6 @@ impl CodeChainMachine {
) -> Result<(), Error> {
if let Action::TransferAsset {
inputs,
orders,
expiration,
..
} = &tx.action
Expand All @@ -88,7 +85,6 @@ impl CodeChainMachine {
if verify_timelock {
Self::verify_transfer_timelock(inputs, header, client)?;
}
Self::verify_transfer_order_expired(orders, header)?;
}
// FIXME: Filter transactions.
Ok(())
Expand Down Expand Up @@ -176,19 +172,6 @@ impl CodeChainMachine {
Ok(())
}

fn verify_transfer_order_expired(orders: &[OrderOnTransfer], header: &Header) -> Result<(), Error> {
for order_tx in orders {
if order_tx.order.expiration < header.timestamp() {
return Err(HistoryError::OrderExpired {
expiration: order_tx.order.expiration,
timestamp: header.timestamp(),
}
.into())
}
}
Ok(())
}

pub fn min_cost(params: &CommonParams, action: &Action) -> u64 {
match action {
Action::MintAsset {
Expand Down Expand Up @@ -250,16 +233,3 @@ impl CodeChainMachine {
Ok(())
}
}

fn is_order_disabled() -> bool {
#[cfg(test)]
const DEFAULT_ORDER_DISABLED: bool = false;
#[cfg(not(test))]
const DEFAULT_ORDER_DISABLED: bool = true;
let var = std::env::var("ENABLE_ORDER");
match var.as_ref().map(|x| x.trim()) {
Ok(value) => !value.parse::<bool>().unwrap(),
Err(std::env::VarError::NotPresent) => DEFAULT_ORDER_DISABLED,
Err(err) => unreachable!("{:?}", err),
}
}
1 change: 0 additions & 1 deletion core/src/miner/mem_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,6 @@ pub mod test {
burns: vec![],
inputs: vec![],
outputs: vec![],
orders: vec![],
metadata: "".into(),
approvals: vec![],
expiration: None,
Expand Down
4 changes: 2 additions & 2 deletions core/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ impl UnverifiedTransaction {
}

/// Verify transactiosn with the common params. Does not attempt signer recovery.
pub fn verify_with_params(&self, params: &CommonParams, is_order_disabled: bool) -> Result<(), SyntaxError> {
pub fn verify_with_params(&self, params: &CommonParams) -> Result<(), SyntaxError> {
if self.network_id != params.network_id() {
return Err(SyntaxError::InvalidNetworkId(self.network_id))
}
let byte_size = rlp::encode(self).to_vec().len();
if byte_size >= params.max_body_size() {
return Err(SyntaxError::TransactionIsTooBig)
}
self.action.verify_with_params(params, is_order_disabled)
self.action.verify_with_params(params)
}
}

Expand Down
1 change: 0 additions & 1 deletion rpc/src/v1/impls/devel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ where
burns: vec![],
inputs: $inputs,
outputs: $outputs,
orders: vec![],
metadata: "".to_string(),
approvals: vec![],
expiration: None,
Expand Down
13 changes: 5 additions & 8 deletions rpc/src/v1/types/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use primitives::{Bytes, H160, H256};
use rustc_serialize::hex::{FromHex, ToHex};

use super::super::errors::ConversionError;
use super::{AssetMintOutput, AssetTransferInput, AssetTransferOutput, OrderOnTransfer};
use super::{AssetMintOutput, AssetTransferInput, AssetTransferOutput};

#[derive(Debug, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase", tag = "type")]
Expand All @@ -48,7 +48,6 @@ pub enum Action {
burns: Vec<AssetTransferInput>,
inputs: Vec<AssetTransferInput>,
outputs: Vec<AssetTransferOutput>,
orders: Vec<OrderOnTransfer>,

metadata: String,
approvals: Vec<Signature>,
Expand Down Expand Up @@ -151,7 +150,9 @@ pub enum ActionWithTracker {
burns: Vec<AssetTransferInput>,
inputs: Vec<AssetTransferInput>,
outputs: Vec<AssetTransferOutput>,
orders: Vec<OrderOnTransfer>,
// NOTE: The orders field is removed in the core but it remains to
// support the old version of the SDK
orders: Vec<()>,

metadata: String,
approvals: Vec<Signature>,
Expand Down Expand Up @@ -269,7 +270,6 @@ impl ActionWithTracker {
burns,
inputs,
outputs,
orders,
metadata,
approvals,
expiration,
Expand All @@ -278,7 +278,7 @@ impl ActionWithTracker {
burns: burns.into_iter().map(From::from).collect(),
inputs: inputs.into_iter().map(From::from).collect(),
outputs: outputs.into_iter().map(From::from).collect(),
orders: orders.into_iter().map(From::from).collect(),
orders: vec![],
metadata,
approvals,
expiration: expiration.map(From::from),
Expand Down Expand Up @@ -449,20 +449,17 @@ impl TryFrom<Action> for ActionType {
burns,
inputs,
outputs,
orders,

metadata,
approvals,
expiration,
} => {
let outputs = outputs.into_iter().map(TryFrom::try_from).collect::<Result<_, _>>()?;
let orders = orders.into_iter().map(TryFrom::try_from).collect::<Result<_, _>>()?;
ActionType::TransferAsset {
network_id,
burns: burns.into_iter().map(From::from).collect(),
inputs: inputs.into_iter().map(From::from).collect(),
outputs,
orders,
metadata,
approvals,
expiration: expiration.map(From::from),
Expand Down
4 changes: 1 addition & 3 deletions rpc/src/v1/types/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::ops::Deref;

use cjson::uint::Uint;
use cstate::{Asset as AssetType, OwnedAsset as OwnedAssetType};
use primitives::{H160, H256};
use primitives::H160;
use rustc_serialize::hex::ToHex;

#[derive(Clone, Debug, PartialEq, Serialize)]
Expand All @@ -35,7 +35,6 @@ pub struct OwnedAsset {
asset: Asset,
lock_script_hash: H160,
parameters: Vec<String>,
order_hash: Option<H256>,
}

impl From<AssetType> for Asset {
Expand All @@ -55,7 +54,6 @@ impl From<OwnedAssetType> for OwnedAsset {
quantity: asset.quantity().into(),
},
lock_script_hash: *asset.lock_script_hash(),
order_hash: *asset.order_hash(),
parameters: asset.parameters().iter().map(Deref::deref).map(<[u8]>::to_hex).collect(),
}
}
Expand Down
4 changes: 1 addition & 3 deletions rpc/src/v1/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ mod asset_input;
mod asset_output;
mod asset_scheme;
mod block;
mod order;
mod text;
mod transaction;
mod unsigned_transaction;
Expand All @@ -29,9 +28,8 @@ mod work;
use primitives::H256;

use self::asset::Asset;
use self::asset_input::{AssetOutPoint, AssetTransferInput};
use self::asset_input::AssetTransferInput;
use self::asset_output::{AssetMintOutput, AssetTransferOutput};
use self::order::OrderOnTransfer;

pub use self::action::{Action, ActionWithTracker};
pub use self::asset::OwnedAsset;
Expand Down
144 changes: 0 additions & 144 deletions rpc/src/v1/types/order.rs

This file was deleted.

Loading