diff --git a/core/src/codechain_machine.rs b/core/src/codechain_machine.rs index 751ec92d9c..d75ccf3361 100644 --- a/core/src/codechain_machine.rs +++ b/core/src/codechain_machine.rs @@ -203,12 +203,6 @@ impl CodeChainMachine { Action::IncreaseAssetSupply { .. } => params.min_asset_supply_increase_cost(), - Action::ComposeAsset { - .. - } => params.min_asset_compose_cost(), - Action::DecomposeAsset { - .. - } => params.min_asset_decompose_cost(), Action::UnwrapCCC { .. } => params.min_asset_unwrap_ccc_cost(), diff --git a/rpc/src/v1/impls/chain.rs b/rpc/src/v1/impls/chain.rs index 4d0001fbb8..addac3d980 100644 --- a/rpc/src/v1/impls/chain.rs +++ b/rpc/src/v1/impls/chain.rs @@ -288,8 +288,6 @@ where "store" => Some(common_parameters.min_store_transaction_cost()), "remove" => Some(common_parameters.min_remove_transaction_cost()), "custom" => Some(common_parameters.min_custom_transaction_cost()), - "composeAsset" => Some(common_parameters.min_asset_compose_cost()), - "decomposeAsset" => Some(common_parameters.min_asset_decompose_cost()), _ => None, }) diff --git a/rpc/src/v1/types/action.rs b/rpc/src/v1/types/action.rs index cc1dc075f4..4552c2a448 100644 --- a/rpc/src/v1/types/action.rs +++ b/rpc/src/v1/types/action.rs @@ -78,27 +78,6 @@ pub enum Action { approvals: Vec, }, #[serde(rename_all = "camelCase")] - ComposeAsset { - network_id: NetworkId, - shard_id: ShardId, - metadata: String, - approver: Option, - registrar: Option, - allowed_script_hashes: Vec, - inputs: Vec, - output: Box, - - approvals: Vec, - }, - #[serde(rename_all = "camelCase")] - DecomposeAsset { - network_id: NetworkId, - input: Box, - outputs: Vec, - - approvals: Vec, - }, - #[serde(rename_all = "camelCase")] UnwrapCCC { network_id: NetworkId, burn: AssetTransferInput, @@ -207,31 +186,7 @@ pub enum ActionWithTracker { tracker: H256, }, - #[serde(rename_all = "camelCase")] - ComposeAsset { - network_id: NetworkId, - shard_id: ShardId, - metadata: String, - approver: Option, - registrar: Option, - allowed_script_hashes: Vec, - inputs: Vec, - output: Box, - approvals: Vec, - - tracker: H256, - }, - #[serde(rename_all = "camelCase")] - DecomposeAsset { - network_id: NetworkId, - input: Box, - outputs: Vec, - - approvals: Vec, - - tracker: H256, - }, #[serde(rename_all = "camelCase")] UnwrapCCC { network_id: NetworkId, @@ -367,40 +322,6 @@ impl ActionWithTracker { approvals, tracker: tracker.unwrap(), }, - ActionType::ComposeAsset { - network_id, - shard_id, - metadata, - approver, - registrar, - allowed_script_hashes, - inputs, - output, - approvals, - } => ActionWithTracker::ComposeAsset { - network_id, - shard_id, - metadata, - approver: approver.map(|approver| PlatformAddress::new_v1(network_id, approver)), - registrar: registrar.map(|registrar| PlatformAddress::new_v1(network_id, registrar)), - allowed_script_hashes, - inputs: inputs.into_iter().map(From::from).collect(), - output: Box::new((*output).into()), - approvals, - tracker: tracker.unwrap(), - }, - ActionType::DecomposeAsset { - network_id, - input, - outputs, - approvals, - } => ActionWithTracker::DecomposeAsset { - network_id, - input: Box::new(input.into()), - outputs: outputs.into_iter().map(From::from).collect(), - approvals, - tracker: tracker.unwrap(), - }, ActionType::UnwrapCCC { network_id, burn, @@ -597,54 +518,6 @@ impl TryFrom for ActionType { approvals, } } - Action::ComposeAsset { - network_id, - shard_id, - metadata, - approver, - registrar, - allowed_script_hashes, - inputs, - output, - - approvals, - } => { - let approver = match approver { - Some(approver) => Some(approver.try_into_address()?), - None => None, - }; - let registrar = match registrar { - Some(registrar) => Some(registrar.try_into_address()?), - None => None, - }; - let output_content = AssetMintOutputType::try_from(*output)?; - ActionType::ComposeAsset { - network_id, - shard_id, - metadata, - approver, - registrar, - allowed_script_hashes, - inputs: inputs.into_iter().map(From::from).collect(), - output: Box::new(output_content), - approvals, - } - } - Action::DecomposeAsset { - network_id, - input, - outputs, - - approvals, - } => { - let outputs = outputs.into_iter().map(TryFrom::try_from).collect::>()?; - ActionType::DecomposeAsset { - network_id, - input: (*input).into(), - outputs, - approvals, - } - } Action::UnwrapCCC { network_id, burn, diff --git a/state/src/impls/shard_level.rs b/state/src/impls/shard_level.rs index 6d2cab86de..48da78ff47 100644 --- a/state/src/impls/shard_level.rs +++ b/state/src/impls/shard_level.rs @@ -15,7 +15,7 @@ // along with this program. If not, see . use std::cell::{RefCell, RefMut}; -use std::collections::{HashMap, HashSet}; +use std::collections::HashSet; use std::iter::{once, FromIterator}; use ccrypto::{Blake, BLAKE_NULL_RLP}; @@ -186,45 +186,6 @@ impl<'db> ShardLevelState<'db> { assert_eq!(*shard_id, self.shard_id); self.increase_asset_supply(transaction.tracker(), *seq, sender, approvers, asset_type, output) } - ShardTransaction::ComposeAsset { - metadata, - approver, - registrar, - allowed_script_hashes, - inputs, - output, - shard_id, - .. - } => self.compose_asset( - &transaction, - metadata, - approver, - registrar, - allowed_script_hashes, - inputs, - output, - sender, - approvers, - shard_users, - *shard_id, - client, - parent_block_number, - parent_block_timestamp, - ), - ShardTransaction::DecomposeAsset { - input, - outputs, - .. - } => self.decompose_asset( - &transaction, - input, - outputs, - sender, - approvers, - client, - parent_block_number, - parent_block_timestamp, - ), ShardTransaction::UnwrapCCC { burn, .. @@ -699,201 +660,6 @@ impl<'db> ShardLevelState<'db> { }) } - // FIXME: Remove this clippy config - #[cfg_attr(feature = "cargo-clippy", allow(clippy::too_many_arguments))] - fn compose_asset( - &mut self, - transaction: &ShardTransaction, - metadata: &str, - approver: &Option
, - registrar: &Option
, - allowed_script_hashes: &[H160], - inputs: &[AssetTransferInput], - output: &AssetMintOutput, - sender: &Address, - approvers: &[Address], - shard_users: &[Address], - output_shard_id: ShardId, - client: &C, - parent_block_number: BlockNumber, - parent_block_timestamp: u64, - ) -> StateResult<()> { - let mut sum: HashMap<(H160, ShardId), u64> = HashMap::new(); - - let mut deleted_assets = Vec::with_capacity(inputs.len()); - for input in inputs.iter() { - if input.prev_out.shard_id != self.shard_id { - continue - } - self.check_and_run_input_script( - input, - transaction, - None, - false, - sender, - approvers, - client, - parent_block_number, - parent_block_timestamp, - )?; - - assert_eq!(self.shard_id, input.prev_out.shard_id); - let shard_asset_type = (input.prev_out.asset_type, input.prev_out.shard_id); - let asset_scheme = - self.asset_scheme(shard_asset_type.0)?.ok_or_else(|| RuntimeError::AssetSchemeNotFound { - shard_id: input.prev_out.shard_id, - asset_type: input.prev_out.asset_type, - })?; - if asset_scheme.is_regulated() { - return Err(RuntimeError::CannotComposeRegulatedAsset.into()) - } - - self.kill_asset(input.prev_out.tracker, input.prev_out.index); - deleted_assets.push((input.prev_out.tracker, input.prev_out.index, input.prev_out.quantity)); - - *sum.entry(shard_asset_type).or_insert_with(Default::default) += input.prev_out.quantity; - } - ctrace!(TX, "Deleted assets {:?}", deleted_assets); - - let pool = sum.into_iter().map(|((asset_type, _), quantity)| Asset::new(asset_type, quantity)).collect(); - - if output_shard_id == self.shard_id { - self.mint_asset( - transaction.tracker(), - metadata, - output, - approver, - approvers, - registrar, - allowed_script_hashes, - sender, - shard_users, - pool, - )?; - } - Ok(()) - } - - fn decompose_asset( - &mut self, - transaction: &ShardTransaction, - input: &AssetTransferInput, - outputs: &[AssetTransferOutput], - sender: &Address, - approvers: &[Address], - client: &C, - parent_block_number: BlockNumber, - parent_block_timestamp: u64, - ) -> StateResult<()> { - let AssetOutPoint { - asset_type, - shard_id, - quantity, - .. - } = input.prev_out; - if self.shard_id == input.prev_out.shard_id { - let asset_scheme = self.asset_scheme(asset_type)?.ok_or_else(|| RuntimeError::AssetSchemeNotFound { - shard_id, - asset_type, - })?; - // The input asset should be composed asset - if asset_scheme.pool().is_empty() { - return Err(RuntimeError::InvalidDecomposedInput { - asset_type, - shard_id, - got: 0, - } - .into()) - } - - // Check that the outputs are match with pool - let mut sum: HashMap = HashMap::new(); - for output in outputs { - let output_type = output.asset_type; - - *sum.entry(output_type).or_insert_with(Default::default) += output.quantity; - } - for asset in asset_scheme.pool() { - let asset_type = asset.asset_type(); - match sum.remove(asset_type) { - None => { - return Err(RuntimeError::InvalidDecomposedOutput { - asset_type: *asset_type, - shard_id: self.shard_id, - expected: asset.quantity(), - got: 0, - } - .into()) - } - Some(value) => { - if value != asset.quantity() { - return Err(RuntimeError::InvalidDecomposedOutput { - asset_type: *asset_type, - shard_id: self.shard_id, - expected: asset.quantity(), - got: value, - } - .into()) - } - } - } - } - if !sum.is_empty() { - let mut invalid_assets: Vec = - sum.into_iter().map(|(asset_type, quantity)| Asset::new(asset_type, quantity)).collect(); - let invalid_asset = invalid_assets.pop().unwrap(); - return Err(RuntimeError::InvalidDecomposedOutput { - asset_type: *invalid_asset.asset_type(), - shard_id: self.shard_id, - expected: 0, - got: invalid_asset.quantity(), - } - .into()) - } - - self.check_and_run_input_script( - input, - transaction, - None, - false, - sender, - approvers, - client, - parent_block_number, - parent_block_timestamp, - )?; - - self.kill_asset(input.prev_out.tracker, input.prev_out.index); - - let mut asset_scheme = self.get_asset_scheme_mut(self.shard_id, asset_type)?; - let previous_supply = asset_scheme.reduce_supply(quantity); - - ctrace!(TX, "Deleted assets {:?} {:?}", asset_type, quantity); - ctrace!(TX, "Reduced asset supply {:?} {:?} {:?}", asset_type, previous_supply, quantity); - } - - // Put asset into DB - let transaction_tracker = transaction.tracker(); - for (index, output) in outputs.iter().enumerate() { - if output.shard_id != self.shard_id { - continue - } - self.check_output_script_hash(output, sender, approvers)?; - self.create_asset( - transaction_tracker, - index, - output.asset_type, - output.lock_script_hash, - output.parameters.clone(), - output.quantity, - None, - )?; - } - ctrace!(TX, "Created assets {}:{}:(0..{})", self.shard_id, transaction_tracker, outputs.len()); - - Ok(()) - } - fn wrap_ccc( &mut self, tx_hash: &H256, @@ -1772,348 +1538,6 @@ mod tests { ]); } - #[test] - fn mint_and_compose() { - let mut state_db = RefCell::new(get_temp_state_db()); - let mut shard_cache = ShardCache::default(); - let mut state = get_temp_shard_state(&mut state_db, SHARD_ID, &mut shard_cache); - let sender = address(); - - let metadata = "metadata".to_string(); - let lock_script_hash = H160::from("0xb042ad154a3359d276835c903587ebafefea22af"); - let amount = 30; - let mint = asset_mint!(asset_mint_output!(lock_script_hash, supply: amount), metadata.clone()); - let mint_tracker = mint.tracker(); - let asset_type = Blake::blake(mint_tracker); - assert_eq!(Ok(()), state.apply(&mint, &sender, &[], &[], &get_test_client(), 0, 0)); - - check_shard_level_state!(state, [ - (scheme: (asset_type) => { metadata: metadata.clone(), supply: amount }), - (asset: (mint_tracker, 0) => { asset_type: asset_type, quantity: amount }) - ]); - - let random_lock_script_hash = H160::random(); - let compose = asset_compose!( - "composed".to_string(), - asset_transfer_inputs![(asset_out_point!(mint_tracker, 0, asset_type, 30), vec![0x30, 0x01])], - asset_mint_output!(random_lock_script_hash, supply: 1) - ); - let compose_tracker = compose.tracker(); - let composed_asset_type = Blake::blake(compose_tracker); - - assert_eq!(Ok(()), state.apply(&compose, &sender, &[], &[], &get_test_client(), 0, 0)); - - check_shard_level_state!(state, [ - (scheme: (asset_type) => { metadata: metadata.clone(), supply: amount }), - (asset: (mint_tracker, 0)), - (scheme: (composed_asset_type) => { metadata: "composed".to_string(), supply: 1, pool: [Asset::new(asset_type, amount)] }), - (asset: (compose_tracker, 0) => { asset_type: composed_asset_type, quantity: 1 }) - ]); - } - - #[test] - fn mint_and_compose_and_decompose() { - let mut state_db = RefCell::new(get_temp_state_db()); - let mut shard_cache = ShardCache::default(); - let mut state = get_temp_shard_state(&mut state_db, SHARD_ID, &mut shard_cache); - let sender = address(); - - let metadata = "metadata".to_string(); - let lock_script_hash = H160::from("0xb042ad154a3359d276835c903587ebafefea22af"); - let amount = 30; - let mint = asset_mint!(asset_mint_output!(lock_script_hash, supply: amount), metadata.clone()); - let mint_tracker = mint.tracker(); - let asset_type = Blake::blake(mint_tracker); - assert_eq!(Ok(()), state.apply(&mint, &sender, &[], &[], &get_test_client(), 0, 0)); - - check_shard_level_state!(state, [ - (scheme: (asset_type) => { metadata: metadata.clone(), supply: amount }), - (asset: (mint_tracker, 0) => { asset_type: asset_type, quantity: amount }) - ]); - - let compose = asset_compose!( - "composed".to_string(), - asset_transfer_inputs![(asset_out_point!(mint_tracker, 0, asset_type, amount), vec![0x30, 0x01])], - asset_mint_output!(lock_script_hash, supply: 1) - ); - let compose_tracker = compose.tracker(); - let composed_asset_type = Blake::blake(compose_tracker); - - assert_eq!(Ok(()), state.apply(&compose, &sender, &[], &[], &get_test_client(), 0, 0)); - - check_shard_level_state!(state, [ - (scheme: (asset_type) => { metadata: metadata.clone(), supply: amount }), - (asset: (mint_tracker, 0)), - (scheme: (composed_asset_type) => { metadata: "composed".to_string(), supply: 1, pool: [Asset::new(asset_type, amount)] }), - (asset: (compose_tracker, 0) => { asset_type: composed_asset_type, quantity: 1 }) - ]); - - let random_lock_script_hash = H160::random(); - let decompose = asset_decompose!( - asset_transfer_input!(asset_out_point!(compose_tracker, 0, composed_asset_type, 1), vec![0x30, 0x01]), - asset_transfer_outputs![(random_lock_script_hash, asset_type, amount)] - ); - let decompose_tracker = decompose.tracker(); - - assert_eq!(Ok(()), state.apply(&decompose, &sender, &[], &[], &get_test_client(), 0, 0)); - - check_shard_level_state!(state, [ - (scheme: (asset_type) => { metadata: metadata.clone(), supply: amount }), - (asset: (mint_tracker, 0)), - (scheme: (composed_asset_type) => { metadata: "composed".to_string(), supply: 0, pool: [Asset::new(asset_type, amount)] }), - (asset: (compose_tracker, 0)), - (asset: (decompose_tracker, 0) => { asset_type: asset_type, quantity: amount }) - ]); - } - - #[test] - #[allow(clippy::cognitive_complexity)] - fn decompose_fail_invalid_input_different_asset_type() { - let mut state_db = RefCell::new(get_temp_state_db()); - let mut shard_cache = ShardCache::default(); - let mut state = get_temp_shard_state(&mut state_db, SHARD_ID, &mut shard_cache); - let sender = address(); - - let metadata = "metadata".to_string(); - let lock_script_hash = H160::from("0xb042ad154a3359d276835c903587ebafefea22af"); - let amount = 30; - let mint = asset_mint!(asset_mint_output!(lock_script_hash, supply: amount), metadata.clone()); - let mint_tracker = mint.tracker(); - let asset_type = Blake::blake(mint_tracker); - - assert_eq!(Ok(()), state.apply(&mint, &sender, &[], &[], &get_test_client(), 0, 0)); - - check_shard_level_state!(state, [ - (scheme: (asset_type) => { metadata: metadata.clone(), supply: amount }), - (asset: (mint_tracker, 0) => { asset_type: asset_type, quantity: amount }) - ]); - - let mint2 = asset_mint!(asset_mint_output!(lock_script_hash, supply: amount), "invalid_asset".to_string()); - let mint2_tracker = mint2.tracker(); - let asset_type2 = Blake::blake(mint2_tracker); - - assert_eq!(Ok(()), state.apply(&mint2, &sender, &[], &[], &get_test_client(), 0, 0)); - - check_shard_level_state!(state, [ - (scheme: (asset_type) => { metadata: metadata.clone(), supply: amount }), - (asset: (mint_tracker, 0) => { asset_type: asset_type, quantity: amount }), - (scheme: (asset_type2) => { metadata: "invalid_asset".to_string(), supply: amount }), - (asset: (mint2_tracker, 0) => { asset_type: asset_type2, quantity: amount }) - ]); - - let compose = asset_compose!( - "composed".to_string(), - asset_transfer_inputs![(asset_out_point!(mint_tracker, 0, asset_type, amount), vec![0x30, 0x01])], - asset_mint_output!(lock_script_hash, supply: 1) - ); - let compose_tracker = compose.tracker(); - let composed_asset_type = Blake::blake(compose_tracker); - - assert_eq!(Ok(()), state.apply(&compose, &sender, &[], &[], &get_test_client(), 0, 0)); - - check_shard_level_state!(state, [ - (scheme: (asset_type) => { metadata: metadata.clone(), supply: amount }), - (asset: (mint_tracker, 0)), - (scheme: (asset_type2) => { metadata: "invalid_asset".to_string(), supply: amount }), - (asset: (mint2_tracker, 0) => { asset_type: asset_type2, quantity: amount }), - (scheme: (composed_asset_type) => { metadata: "composed".to_string(), supply: 1, pool: [Asset::new(asset_type, amount)] }), - (asset: (compose_tracker, 0) => { asset_type: composed_asset_type, quantity: 1 }) - ]); - - let random_lock_script_hash = H160::random(); - let decompose = asset_decompose!( - asset_transfer_input!(asset_out_point!(mint2_tracker, 0, asset_type2, 1), vec![0x30, 0x01]), - asset_transfer_outputs![(random_lock_script_hash, asset_type, amount)] - ); - - assert_eq!( - Err(StateError::Runtime(RuntimeError::InvalidDecomposedInput { - asset_type: asset_type2, - shard_id: SHARD_ID, - got: 0, - })), - state.apply(&decompose, &sender, &[], &[], &get_test_client(), 0, 0) - ); - - check_shard_level_state!(state, [ - (scheme: (asset_type) => { metadata: metadata.clone(), supply: amount }), - (asset: (mint_tracker, 0) ), - (scheme: (asset_type2) => { metadata: "invalid_asset".to_string(), supply: amount }), - (asset: (mint2_tracker, 0) => { asset_type: asset_type2, quantity: amount }), - (scheme: (composed_asset_type) => { metadata: "composed".to_string(), supply: 1, pool: [Asset::new(asset_type, amount)] }), - (asset: (compose_tracker, 0) => { asset_type: composed_asset_type, quantity: 1 }) - ]); - } - - #[test] - #[allow(clippy::cognitive_complexity)] - fn decompose_fail_invalid_output_insufficient_output() { - let mut state_db = RefCell::new(get_temp_state_db()); - let mut shard_cache = ShardCache::default(); - let mut state = get_temp_shard_state(&mut state_db, SHARD_ID, &mut shard_cache); - let sender = address(); - - let metadata = "metadata".to_string(); - let lock_script_hash = H160::from("0xb042ad154a3359d276835c903587ebafefea22af"); - let amount = 30; - let mint = asset_mint!(asset_mint_output!(lock_script_hash, supply: amount), metadata.clone()); - let mint_tracker = mint.tracker(); - let asset_type = Blake::blake(mint_tracker); - - assert_eq!(Ok(()), state.apply(&mint, &sender, &[], &[], &get_test_client(), 0, 0)); - - check_shard_level_state!(state, [ - (scheme: (asset_type) => { metadata: metadata.clone(), supply: amount }), - (asset: (mint_tracker, 0) => { asset_type: asset_type, quantity: amount }) - ]); - - let mint2 = asset_mint!(asset_mint_output!(lock_script_hash, supply: 1), "invalid_asset".to_string()); - let mint2_tracker = mint2.tracker(); - let asset_type2 = Blake::blake(mint2_tracker); - - assert_eq!(Ok(()), state.apply(&mint2, &sender, &[], &[], &get_test_client(), 0, 0)); - - check_shard_level_state!(state, [ - (scheme: (asset_type) => { metadata: metadata.clone(), supply: amount }), - (asset: (mint_tracker, 0) => { asset_type: asset_type, quantity: amount }), - (scheme: (asset_type2) => { metadata: "invalid_asset".to_string(), supply: 1 }), - (asset: (mint2_tracker, 0) => { asset_type: asset_type2, quantity: 1 }) - ]); - - let compose = asset_compose!( - "composed".to_string(), - asset_transfer_inputs![ - (asset_out_point!(mint_tracker, 0, asset_type, amount), vec![0x30, 0x01]), - (asset_out_point!(mint2_tracker, 0, asset_type2, 1), vec![0x30, 0x01]), - ], - asset_mint_output!(lock_script_hash, supply: 1) - ); - let compose_tracker = compose.tracker(); - let composed_asset_type = Blake::blake(compose_tracker); - - assert_eq!(Ok(()), state.apply(&compose, &sender, &[], &[], &get_test_client(), 0, 0)); - - check_shard_level_state!(state, [ - (scheme: (asset_type) => { metadata: metadata.clone(), supply: amount }), - (asset: (mint_tracker, 0)), - (scheme: (asset_type2) => { metadata: "invalid_asset".to_string(), supply: 1 }), - (asset: (mint2_tracker, 0)), - (scheme: (composed_asset_type) => { metadata: "composed".to_string(), supply: 1 }), - (asset: (compose_tracker, 0) => { asset_type: composed_asset_type, quantity: 1 }) - ]); - - let random_lock_script_hash = H160::random(); - let decompose = asset_decompose!( - asset_transfer_input!(asset_out_point!(compose_tracker, 0, composed_asset_type, 1), vec![0x30, 0x01]), - asset_transfer_outputs![(random_lock_script_hash, asset_type, amount)] - ); - - assert_eq!( - Err(StateError::Runtime(RuntimeError::InvalidDecomposedOutput { - asset_type: asset_type2, - shard_id: SHARD_ID, - expected: 1, - got: 0, - })), - state.apply(&decompose, &sender, &[], &[], &get_test_client(), 0, 0) - ); - - check_shard_level_state!(state, [ - (scheme: (asset_type) => { metadata: metadata.clone(), supply: amount }), - (asset: (mint_tracker, 0)), - (scheme: (asset_type2) => { metadata: "invalid_asset".to_string(), supply: 1 }), - (asset: (mint2_tracker, 0)), - (scheme: (composed_asset_type) => { metadata: "composed".to_string(), supply: 1 }), - (asset: (compose_tracker, 0) => { asset_type: composed_asset_type, quantity: 1 }) - ]); - } - - - #[test] - #[allow(clippy::cognitive_complexity)] - fn decompose_fail_invalid_output_insufficient_amount() { - let mut state_db = RefCell::new(get_temp_state_db()); - let mut shard_cache = ShardCache::default(); - let mut state = get_temp_shard_state(&mut state_db, SHARD_ID, &mut shard_cache); - let sender = address(); - - let metadata = "metadata".to_string(); - let lock_script_hash = H160::from("0xb042ad154a3359d276835c903587ebafefea22af"); - let amount = 30; - let mint = asset_mint!(asset_mint_output!(lock_script_hash, supply: amount), metadata.clone()); - let mint_tracker = mint.tracker(); - let asset_type = Blake::blake(mint_tracker); - - assert_eq!(Ok(()), state.apply(&mint, &sender, &[], &[], &get_test_client(), 0, 0)); - - check_shard_level_state!(state, [ - (scheme: (asset_type) => { metadata: metadata.clone(), supply: amount }), - (asset: (mint_tracker, 0) => { asset_type: asset_type, quantity: amount }) - ]); - - let mint2 = asset_mint!(asset_mint_output!(lock_script_hash, supply: 1), "invalid_asset".to_string()); - let mint2_tracker = mint2.tracker(); - let asset_type2 = Blake::blake(mint2_tracker); - assert_eq!(Ok(()), state.apply(&mint2, &sender, &[], &[], &get_test_client(), 0, 0)); - - check_shard_level_state!(state, [ - (scheme: (asset_type) => { metadata: metadata.clone(), supply: amount }), - (asset: (mint_tracker, 0) => { asset_type: asset_type, quantity: amount }), - (scheme: (asset_type2) => { metadata: "invalid_asset".to_string(), supply: 1 }), - (asset: (mint2_tracker, 0) => { asset_type: asset_type2, quantity: 1 }) - ]); - - let compose = asset_compose!( - "composed".to_string(), - asset_transfer_inputs![ - (asset_out_point!(mint_tracker, 0, asset_type, amount), vec![0x30, 0x01]), - (asset_out_point!(mint2_tracker, 0, asset_type2, 1), vec![0x30, 0x01]), - ], - asset_mint_output!(lock_script_hash, supply: 1) - ); - let compose_tracker = compose.tracker(); - let composed_asset_type = Blake::blake(compose_tracker); - - assert_eq!(Ok(()), state.apply(&compose, &sender, &[], &[], &get_test_client(), 0, 0)); - - check_shard_level_state!(state, [ - (scheme: (asset_type) => { metadata: metadata.clone(), supply: amount }), - (asset: (mint_tracker, 0)), - (scheme: (asset_type2) => { metadata: "invalid_asset".to_string(), supply: 1 }), - (asset: (mint2_tracker, 0)), - (scheme: (composed_asset_type) => { metadata: "composed".to_string(), supply: 1 }), - (asset: (compose_tracker, 0) => { asset_type: composed_asset_type, quantity: 1 }) - ]); - - let random_lock_script_hash = H160::random(); - let decompose = asset_decompose!( - asset_transfer_input!(asset_out_point!(compose_tracker, 0, composed_asset_type, 1), vec![0x30, 0x01]), - asset_transfer_outputs![ - (random_lock_script_hash, asset_type, 10), - (random_lock_script_hash, asset_type2, 1), - ] - ); - - assert_eq!( - Err(StateError::Runtime(RuntimeError::InvalidDecomposedOutput { - asset_type, - shard_id: SHARD_ID, - expected: 30, - got: 10, - })), - state.apply(&decompose, &sender, &[], &[], &get_test_client(), 0, 0) - ); - - check_shard_level_state!(state, [ - (scheme: (asset_type) => { metadata: metadata.clone(), supply: amount }), - (asset: (mint_tracker, 0)), - (scheme: (asset_type2) => { metadata: "invalid_asset".to_string(), supply: 1 }), - (asset: (mint2_tracker, 0)), - (scheme: (composed_asset_type) => { metadata: "composed".to_string(), supply: 1 }), - (asset: (compose_tracker, 0) => { asset_type: composed_asset_type, quantity: 1 }) - ]); - } - #[test] fn wrap_and_unwrap_ccc() { let sender = address(); diff --git a/state/src/impls/test_helper.rs b/state/src/impls/test_helper.rs index a1e2990183..cfe4999226 100644 --- a/state/src/impls/test_helper.rs +++ b/state/src/impls/test_helper.rs @@ -324,31 +324,6 @@ macro_rules! order_on_transfer { } } -macro_rules! asset_compose { - ($metadata:expr, $inputs:expr, $outputs:expr) => { - $crate::ctypes::transaction::ShardTransaction::ComposeAsset { - network_id: $crate::impls::test_helper::NETWORK_ID.into(), - shard_id: $crate::impls::test_helper::SHARD_ID, - metadata: $metadata, - approver: None, - registrar: None, - allowed_script_hashes: vec![], - inputs: $inputs, - output: $outputs, - } - }; -} - -macro_rules! asset_decompose { - ($input:expr, $outputs:expr) => { - $crate::ctypes::transaction::ShardTransaction::DecomposeAsset { - network_id: $crate::impls::test_helper::NETWORK_ID.into(), - input: $input, - outputs: $outputs, - } - }; -} - macro_rules! asset_wrap_ccc_output { ($lock_script_hash:expr, $quantity:expr) => { $crate::ctypes::transaction::AssetWrapCCCOutput { diff --git a/state/src/impls/top_level.rs b/state/src/impls/top_level.rs index 725c290645..53c46cd04a 100644 --- a/state/src/impls/top_level.rs +++ b/state/src/impls/top_level.rs @@ -430,14 +430,6 @@ impl TopLevelState { Action::TransferAsset { approvals, .. - } - | Action::ComposeAsset { - approvals, - .. - } - | Action::DecomposeAsset { - approvals, - .. } => { let transaction = Option::::from(action.clone()).expect("It's a shard transaction"); debug_assert_eq!(network_id, transaction.network_id()); diff --git a/test/src/e2e/verification.test.ts b/test/src/e2e/verification.test.ts index 349d90f59b..8e78b9a00a 100644 --- a/test/src/e2e/verification.test.ts +++ b/test/src/e2e/verification.test.ts @@ -150,10 +150,6 @@ describe("solo - 1 node", function() { { actionType: 0x14, actionLength: 10 }, { actionType: 0x15, actionLength: 9 }, // ChangeAssetScheme { actionType: 0x15, actionLength: 11 }, - { actionType: 0x16, actionLength: 11 }, // ComposeAsset - { actionType: 0x16, actionLength: 13 }, - { actionType: 0x17, actionLength: 4 }, // DecomposeAsset - { actionType: 0x17, actionLength: 6 }, { actionType: 0x18, actionLength: 8 }, // IncreaseAssetSupply { actionType: 0x18, actionLength: 10 } ].forEach(function(params: { diff --git a/test/src/helper/spawn.ts b/test/src/helper/spawn.ts index a3e2ff2d03..a2919bb290 100644 --- a/test/src/helper/spawn.ts +++ b/test/src/helper/spawn.ts @@ -21,8 +21,6 @@ import { Asset, AssetAddress, AssetTransferInput, - ComposeAsset, - DecomposeAsset, H256, PlatformAddress, SignedTransaction, @@ -612,10 +610,7 @@ export default class CodeChain { return tx.getMintedAsset(); } - public async signTransactionInput( - tx: TransferAsset | ComposeAsset | DecomposeAsset, - index: number - ) { + public async signTransactionInput(tx: TransferAsset, index: number) { const keyStore = await this.sdk.key.createLocalKeyStore( this.localKeyStorePath ); diff --git a/types/src/common_params.rs b/types/src/common_params.rs index a1cba07c97..06e787483e 100644 --- a/types/src/common_params.rs +++ b/types/src/common_params.rs @@ -45,7 +45,9 @@ pub struct CommonParams { min_asset_transfer_cost: u64, min_asset_scheme_change_cost: u64, min_asset_supply_increase_cost: u64, + /// Deprecated min_asset_compose_cost: u64, + /// Deprecated min_asset_decompose_cost: u64, min_asset_unwrap_ccc_cost: u64, /// Maximum size of block body. @@ -122,9 +124,11 @@ impl CommonParams { pub fn min_asset_supply_increase_cost(&self) -> u64 { self.min_asset_supply_increase_cost } + #[deprecated] pub fn min_asset_compose_cost(&self) -> u64 { self.min_asset_compose_cost } + #[deprecated] pub fn min_asset_decompose_cost(&self) -> u64 { self.min_asset_decompose_cost } @@ -261,7 +265,8 @@ impl From for CommonParams { impl From for Params { fn from(p: CommonParams) -> Params { - let mut result = Params { + #[allow(deprecated)] + let mut result: Params = Params { max_extra_data_size: p.max_extra_data_size().into(), max_asset_scheme_metadata_size: p.max_asset_scheme_metadata_size().into(), max_transfer_metadata_size: p.max_transfer_metadata_size().into(), diff --git a/types/src/errors/runtime_error.rs b/types/src/errors/runtime_error.rs index 5ba8a1dd17..056fc464d9 100644 --- a/types/src/errors/runtime_error.rs +++ b/types/src/errors/runtime_error.rs @@ -50,7 +50,6 @@ pub enum Error { }, AssetSupplyOverflow, CannotBurnRegulatedAsset, - CannotComposeRegulatedAsset, FailedToHandleCustomAction(String), /// Script execution result is `Fail` FailedToUnlock { @@ -80,17 +79,6 @@ pub enum Error { index: usize, mismatch: Mismatch, }, - InvalidDecomposedInput { - asset_type: H160, - shard_id: ShardId, - got: u64, - }, - InvalidDecomposedOutput { - asset_type: H160, - shard_id: ShardId, - expected: u64, - got: u64, - }, /// Errors on orders: origin_outputs of order is not satisfied. InvalidOriginOutputs(H256), /// Failed to decode script. @@ -127,15 +115,18 @@ const ERROR_ID_ASSET_NOT_FOUND: u8 = 1; const ERROR_ID_ASSET_SCHEME_DUPLICATED: u8 = 2; const ERROR_ID_ASSET_SCHEME_NOT_FOUND: u8 = 3; const ERROR_ID_CANNOT_BURN_REGULATED_ASSET: u8 = 4; -const ERROR_ID_CANNOT_COMPOSE_REGULATED_ASSET: u8 = 5; +/// Deprecated +//const ERROR_ID_CANNOT_COMPOSE_REGULATED_ASSET: u8 = 5; const ERROR_ID_FAILED_TO_UNLOCK: u8 = 6; const ERROR_ID_INVALID_SEQ_OF_ASSET_SCHEME: u8 = 7; const ERROR_ID_INSUFFICIENT_BALANCE: u8 = 8; const ERROR_ID_INSUFFICIENT_PERMISSION: u8 = 9; const ERROR_ID_INVALID_ASSET_QUANTITY: u8 = 10; const ERROR_ID_UNEXPECTED_ASSET_TYPE: u8 = 11; -const ERROR_ID_INVALID_DECOMPOSED_INPUT: u8 = 13; -const ERROR_ID_INVALID_DECOMPOSED_OUTPUT: u8 = 14; +/// Deprecated +//const ERROR_ID_INVALID_DECOMPOSED_INPUT: u8 = 13; +/// Deprecated +//const ERROR_ID_INVALID_DECOMPOSED_OUTPUT: u8 = 14; const ERROR_ID_INVALID_SHARD_ID: u8 = 15; const ERROR_ID_INVALID_TRANSFER_DESTINATION: u8 = 16; const ERROR_ID_NEW_OWNERS_MUST_CONTAIN_SENDER: u8 = 17; @@ -169,15 +160,12 @@ impl TaggedRlp for RlpHelper { ERROR_ID_INVALID_SEQ_OF_ASSET_SCHEME => 5, ERROR_ID_ASSET_SUPPLY_OVERFLOW => 1, ERROR_ID_CANNOT_BURN_REGULATED_ASSET => 1, - ERROR_ID_CANNOT_COMPOSE_REGULATED_ASSET => 1, ERROR_ID_FAILED_TO_HANDLE_CUSTOM_ACTION => 2, ERROR_ID_FAILED_TO_UNLOCK => 5, ERROR_ID_INSUFFICIENT_BALANCE => 4, ERROR_ID_INSUFFICIENT_PERMISSION => 1, ERROR_ID_INVALID_ASSET_QUANTITY => 6, ERROR_ID_UNEXPECTED_ASSET_TYPE => 3, - ERROR_ID_INVALID_DECOMPOSED_INPUT => 4, - ERROR_ID_INVALID_DECOMPOSED_OUTPUT => 5, ERROR_ID_INVALID_ORIGIN_OUTPUTS => 2, ERROR_ID_INVALID_SCRIPT => 1, ERROR_ID_INVALID_SEQ => 2, @@ -229,9 +217,6 @@ impl Encodable for Error { .append(actual), Error::AssetSupplyOverflow => RlpHelper::new_tagged_list(s, ERROR_ID_ASSET_SUPPLY_OVERFLOW), Error::CannotBurnRegulatedAsset => RlpHelper::new_tagged_list(s, ERROR_ID_CANNOT_BURN_REGULATED_ASSET), - Error::CannotComposeRegulatedAsset => { - RlpHelper::new_tagged_list(s, ERROR_ID_CANNOT_COMPOSE_REGULATED_ASSET) - } Error::FailedToHandleCustomAction(detail) => { RlpHelper::new_tagged_list(s, ERROR_ID_FAILED_TO_HANDLE_CUSTOM_ACTION).append(detail) } @@ -270,24 +255,6 @@ impl Encodable for Error { index, mismatch, } => RlpHelper::new_tagged_list(s, ERROR_ID_UNEXPECTED_ASSET_TYPE).append(index).append(mismatch), - Error::InvalidDecomposedInput { - asset_type, - shard_id, - got, - } => RlpHelper::new_tagged_list(s, ERROR_ID_INVALID_DECOMPOSED_INPUT) - .append(asset_type) - .append(shard_id) - .append(got), - Error::InvalidDecomposedOutput { - asset_type, - shard_id, - expected, - got, - } => RlpHelper::new_tagged_list(s, ERROR_ID_INVALID_DECOMPOSED_OUTPUT) - .append(asset_type) - .append(shard_id) - .append(expected) - .append(got), Error::InvalidOriginOutputs(addr) => { RlpHelper::new_tagged_list(s, ERROR_ID_INVALID_ORIGIN_OUTPUTS).append(addr) } @@ -356,7 +323,6 @@ impl Decodable for Error { }, ERROR_ID_ASSET_SUPPLY_OVERFLOW => Error::AssetSupplyOverflow, ERROR_ID_CANNOT_BURN_REGULATED_ASSET => Error::CannotBurnRegulatedAsset, - ERROR_ID_CANNOT_COMPOSE_REGULATED_ASSET => Error::CannotComposeRegulatedAsset, ERROR_ID_FAILED_TO_HANDLE_CUSTOM_ACTION => Error::FailedToHandleCustomAction(rlp.val_at(1)?), ERROR_ID_FAILED_TO_UNLOCK => Error::FailedToUnlock { shard_id: rlp.val_at(1)?, @@ -381,17 +347,6 @@ impl Decodable for Error { index: rlp.val_at(1)?, mismatch: rlp.val_at(2)?, }, - ERROR_ID_INVALID_DECOMPOSED_INPUT => Error::InvalidDecomposedInput { - asset_type: rlp.val_at(1)?, - shard_id: rlp.val_at(2)?, - got: rlp.val_at(3)?, - }, - ERROR_ID_INVALID_DECOMPOSED_OUTPUT => Error::InvalidDecomposedOutput { - asset_type: rlp.val_at(1)?, - shard_id: rlp.val_at(2)?, - expected: rlp.val_at(3)?, - got: rlp.val_at(4)?, - }, ERROR_ID_INVALID_ORIGIN_OUTPUTS => Error::InvalidOriginOutputs(rlp.val_at(1)?), ERROR_ID_INVALID_SCRIPT => Error::InvalidScript, ERROR_ID_INVALID_SEQ => Error::InvalidSeq(rlp.val_at(1)?), @@ -443,7 +398,6 @@ impl Display for Error { } => write!(f, "Already used seq of asset scheme {}:{}. expected: {}, actual: {}", asset_type, shard_id, expected, actual), Error::AssetSupplyOverflow => write!(f, "Asset supply should not be overflowed"), Error::CannotBurnRegulatedAsset => write!(f, "Cannot burn the regulated asset"), - Error::CannotComposeRegulatedAsset => write!(f, "Cannot compose the regulated asset"), Error::FailedToHandleCustomAction(detail) => write!(f, "Cannot handle custom action: {}", detail), Error::FailedToUnlock { shard_id, @@ -469,25 +423,6 @@ impl Display for Error { shard_id, tracker, index, expected, got ), Error::UnexpectedAssetType{index, mismatch} => write!(f, "{}th input has an unexpected asset type: {}", index, mismatch), - Error::InvalidDecomposedInput { - asset_type, - shard_id, - got, - } => write!( - f, - "The inputs are not valid. The quantity of asset({}, shard #{}) input must be 1, but {}.", - asset_type, shard_id, got - ), - Error::InvalidDecomposedOutput { - asset_type, - shard_id, - expected, - got, - } => write!( - f, - "The decomposed output is not balid. The quantity of asset({}, shard #{}) must be {}, but {}.", - asset_type, shard_id, expected, got - ), Error::InvalidOriginOutputs(addr) => write!(f, "origin_outputs of order({}) is not satisfied", addr), Error::InvalidScript => write!(f, "Failed to decode script"), Error::InvalidSeq(mismatch) => write!(f, "Invalid transaction seq {}", mismatch), diff --git a/types/src/errors/syntax_error.rs b/types/src/errors/syntax_error.rs index 0a3163db4e..9d9ba40a70 100644 --- a/types/src/errors/syntax_error.rs +++ b/types/src/errors/syntax_error.rs @@ -32,9 +32,6 @@ pub enum Error { tracker: H256, index: usize, }, - /// AssetCompose requires at least 1 input. - EmptyInput, - EmptyOutput, EmptyShardOwners(ShardId), /// Returned when the sum of the transaction's inputs is different from the sum of outputs. InconsistentTransactionInOut, @@ -49,15 +46,7 @@ pub enum Error { }, /// AssetType format error InvalidAssetType(H160), - InvalidComposedOutputAmount { - got: u64, - }, InvalidCustomAction(String), - InvalidDecomposedInputAmount { - asset_type: H160, - shard_id: ShardId, - got: u64, - }, /// Invalid network ID given. InvalidNetworkId(NetworkId), /// invalid asset_quantity_from, asset_quantity_to because of ratio @@ -106,15 +95,17 @@ pub enum Error { } const ERORR_ID_DUPLICATED_PREVIOUS_OUTPUT: u8 = 1; -const ERROR_ID_EMPTY_INPUT: u8 = 2; -const ERROR_ID_EMPTY_OUTPUT: u8 = 3; +/// Deprecated +//const ERROR_ID_EMPTY_INPUT: u8 = 2; +//const ERROR_ID_EMPTY_OUTPUT: u8 = 3; const ERROR_ID_EMPTY_SHARD_OWNERS: u8 = 4; const ERROR_ID_INCONSISTENT_TRANSACTION_IN_OUT: u8 = 5; const ERROR_ID_INCONSISTENT_TRANSACTION_IN_OUT_WITH_ORDERS: u8 = 6; const ERROR_ID_INSUFFICIENT_FEE: u8 = 7; const ERROR_ID_INVALID_ASSET_TYPE: u8 = 8; -const ERROR_ID_INVALID_COMPOSED_OUTPUT_AMOUNT: u8 = 9; -const ERROR_ID_INVALID_DECOMPOSED_INPUT_AMOUNT: u8 = 10; +/// Deprecated +//const ERROR_ID_INVALID_COMPOSED_OUTPUT_AMOUNT: u8 = 9; +//const ERROR_ID_INVALID_DECOMPOSED_INPUT_AMOUNT: u8 = 10; const ERROR_ID_INVALID_NETWORK_ID: u8 = 11; const ERROR_ID_INVALID_ORDER_ASSET_QUANTITIES: u8 = 12; const ERROR_ID_INVALID_ORDER_ASSET_TYPES: u8 = 13; @@ -144,16 +135,12 @@ impl TaggedRlp for RlpHelper { fn length_of(tag: u8) -> Result { Ok(match tag { ERORR_ID_DUPLICATED_PREVIOUS_OUTPUT => 3, - ERROR_ID_EMPTY_INPUT => 1, - ERROR_ID_EMPTY_OUTPUT => 1, ERROR_ID_EMPTY_SHARD_OWNERS => 2, ERROR_ID_INCONSISTENT_TRANSACTION_IN_OUT => 1, ERROR_ID_INCONSISTENT_TRANSACTION_IN_OUT_WITH_ORDERS => 1, ERROR_ID_INSUFFICIENT_FEE => 3, ERROR_ID_INVALID_ASSET_TYPE => 2, - ERROR_ID_INVALID_COMPOSED_OUTPUT_AMOUNT => 2, ERROR_ID_INVALID_CUSTOM_ACTION => 2, - ERROR_ID_INVALID_DECOMPOSED_INPUT_AMOUNT => 4, ERROR_ID_INVALID_NETWORK_ID => 2, ERROR_ID_INVALID_ORDER_ASSET_QUANTITIES => 4, ERROR_ID_INVALID_ORDER_ASSET_TYPES => 1, @@ -186,8 +173,6 @@ impl Encodable for Error { tracker, index, } => RlpHelper::new_tagged_list(s, ERORR_ID_DUPLICATED_PREVIOUS_OUTPUT).append(tracker).append(index), - Error::EmptyInput => RlpHelper::new_tagged_list(s, ERROR_ID_EMPTY_INPUT), - Error::EmptyOutput => RlpHelper::new_tagged_list(s, ERROR_ID_EMPTY_OUTPUT), Error::EmptyShardOwners(shard_id) => { RlpHelper::new_tagged_list(s, ERROR_ID_EMPTY_SHARD_OWNERS).append(shard_id) } @@ -202,20 +187,9 @@ impl Encodable for Error { got, } => RlpHelper::new_tagged_list(s, ERROR_ID_INSUFFICIENT_FEE).append(minimal).append(got), Error::InvalidAssetType(addr) => RlpHelper::new_tagged_list(s, ERROR_ID_INVALID_ASSET_TYPE).append(addr), - Error::InvalidComposedOutputAmount { - got, - } => RlpHelper::new_tagged_list(s, ERROR_ID_INVALID_COMPOSED_OUTPUT_AMOUNT).append(got), Error::InvalidCustomAction(err) => { RlpHelper::new_tagged_list(s, ERROR_ID_INVALID_CUSTOM_ACTION).append(err) } - Error::InvalidDecomposedInputAmount { - asset_type, - shard_id, - got, - } => RlpHelper::new_tagged_list(s, ERROR_ID_INVALID_DECOMPOSED_INPUT_AMOUNT) - .append(asset_type) - .append(shard_id) - .append(got), Error::InvalidNetworkId(network_id) => { RlpHelper::new_tagged_list(s, ERROR_ID_INVALID_NETWORK_ID).append(network_id) } @@ -276,8 +250,6 @@ impl Decodable for Error { tracker: rlp.val_at(1)?, index: rlp.val_at(2)?, }, - ERROR_ID_EMPTY_INPUT => Error::EmptyInput, - ERROR_ID_EMPTY_OUTPUT => Error::EmptyOutput, ERROR_ID_EMPTY_SHARD_OWNERS => Error::EmptyShardOwners(rlp.val_at(1)?), ERROR_ID_INCONSISTENT_TRANSACTION_IN_OUT => Error::InconsistentTransactionInOut, ERROR_ID_INCONSISTENT_TRANSACTION_IN_OUT_WITH_ORDERS => Error::InconsistentTransactionInOutWithOrders, @@ -286,15 +258,7 @@ impl Decodable for Error { got: rlp.val_at(2)?, }, ERROR_ID_INVALID_ASSET_TYPE => Error::InvalidAssetType(rlp.val_at(1)?), - ERROR_ID_INVALID_COMPOSED_OUTPUT_AMOUNT => Error::InvalidComposedOutputAmount { - got: rlp.val_at(1)?, - }, ERROR_ID_INVALID_CUSTOM_ACTION => Error::InvalidCustomAction(rlp.val_at(1)?), - ERROR_ID_INVALID_DECOMPOSED_INPUT_AMOUNT => Error::InvalidDecomposedInputAmount { - asset_type: rlp.val_at(1)?, - shard_id: rlp.val_at(2)?, - got: rlp.val_at(3)?, - }, ERROR_ID_INVALID_NETWORK_ID => Error::InvalidNetworkId(rlp.val_at(1)?), ERROR_ID_INVALID_ORDER_ASSET_QUANTITIES => Error::InvalidOrderAssetQuantities { from: rlp.val_at(1)?, @@ -343,8 +307,6 @@ impl Display for Error { tracker, index, } => write!(f, "The previous output of inputs/burns are duplicated: ({}, {})", tracker, index), - Error::EmptyInput => write!(f, "The input is empty"), - Error::EmptyOutput => writeln!(f, "The output is empty"), Error::EmptyShardOwners (shard_id) => write!(f, "Shard({}) must have at least one owner", shard_id), Error::InconsistentTransactionInOut => write!(f, "The sum of the transaction's inputs is different from the sum of the transaction's outputs"), Error::InconsistentTransactionInOutWithOrders => write!(f, "The transaction's input and output do not follow its orders"), @@ -353,15 +315,7 @@ impl Display for Error { got, } => write!(f, "Insufficient fee. Min={}, Given={}", minimal, got), Error::InvalidAssetType (addr) => write!(f, "Asset type is invalid: {}", addr), - Error::InvalidComposedOutputAmount { - got, - } => write!(f, "The composed output is note valid. The supply must be 1, but {}.", got), Error::InvalidCustomAction(err) => write!(f, "Invalid custom action: {}", err), - Error::InvalidDecomposedInputAmount { - asset_type, - shard_id, - got, - } => write!(f, "The inputs are not valid. The quantity of asset({}, shard #{}) input must be 1, but {}.", asset_type, shard_id, got), Error::InvalidNetworkId (network_id) => write!(f, "{} is an invalid network id", network_id), Error::InvalidOrderAssetQuantities { from, diff --git a/types/src/transaction/action.rs b/types/src/transaction/action.rs index 46de0e6e4a..7199859ea5 100644 --- a/types/src/transaction/action.rs +++ b/types/src/transaction/action.rs @@ -37,8 +37,10 @@ const UNWRAP_CCC: u8 = 0x11; const MINT_ASSET: u8 = 0x13; const TRANSFER_ASSET: u8 = 0x14; const CHANGE_ASSET_SCHEME: u8 = 0x15; -const COMPOSE_ASSET: u8 = 0x16; -const DECOMPOSE_ASSET: u8 = 0x17; +// Derepcated +//const COMPOSE_ASSET: u8 = 0x16; +// Derepcated +//const DECOMPOSE_ASSET: u8 = 0x17; const INCREASE_ASSET_SUPPLY: u8 = 0x18; const CUSTOM: u8 = 0xFF; @@ -84,23 +86,6 @@ pub enum Action { output: Box, approvals: Vec, }, - ComposeAsset { - network_id: NetworkId, - shard_id: ShardId, - metadata: String, - approver: Option
, - registrar: Option
, - allowed_script_hashes: Vec, - inputs: Vec, - output: Box, - approvals: Vec, - }, - DecomposeAsset { - network_id: NetworkId, - input: AssetTransferInput, - outputs: Vec, - approvals: Vec, - }, UnwrapCCC { network_id: NetworkId, burn: AssetTransferInput, @@ -167,12 +152,6 @@ impl Action { | Action::IncreaseAssetSupply { .. } - | Action::ComposeAsset { - .. - } - | Action::DecomposeAsset { - .. - } | Action::UnwrapCCC { .. } => self.clone().into(), @@ -244,51 +223,6 @@ impl Action { return Err(SyntaxError::CannotChangeWcccAssetScheme) } } - Action::ComposeAsset { - inputs, - output, - .. - } => { - let disable_compose_asset = true; - if disable_compose_asset { - return Err(SyntaxError::DisabledTransaction) - } - if inputs.is_empty() { - return Err(SyntaxError::EmptyInput) - } - if inputs.iter().any(|input| input.prev_out.quantity == 0) { - return Err(SyntaxError::ZeroQuantity) - } - check_duplication_in_prev_out(&[], inputs)?; - if output.supply != 1 { - return Err(SyntaxError::InvalidComposedOutputAmount { - got: output.supply, - }) - } - } - Action::DecomposeAsset { - input, - outputs, - .. - } => { - let disable_decompose_asset = true; - if disable_decompose_asset { - return Err(SyntaxError::DisabledTransaction) - } - if input.prev_out.quantity != 1 { - return Err(SyntaxError::InvalidDecomposedInputAmount { - asset_type: input.prev_out.asset_type, - shard_id: input.prev_out.shard_id, - got: input.prev_out.quantity, - }) - } - if outputs.is_empty() { - return Err(SyntaxError::EmptyOutput) - } - if outputs.iter().any(|output| output.quantity == 0) { - return Err(SyntaxError::ZeroQuantity) - } - } Action::UnwrapCCC { burn, .. @@ -360,18 +294,6 @@ impl Action { Action::IncreaseAssetSupply { .. } => {} - Action::ComposeAsset { - metadata, - .. - } => { - let max_asset_scheme_metadata_size = common_params.max_asset_scheme_metadata_size(); - if metadata.len() > max_asset_scheme_metadata_size { - return Err(SyntaxError::MetadataTooBig) - } - } - Action::DecomposeAsset { - .. - } => {} Action::UnwrapCCC { .. } => {} @@ -429,14 +351,6 @@ impl Action { | Action::IncreaseAssetSupply { approvals, .. - } - | Action::ComposeAsset { - approvals, - .. - } - | Action::DecomposeAsset { - approvals, - .. } => Some(approvals), _ => None, } @@ -460,14 +374,6 @@ impl Action { network_id, .. } - | Action::ComposeAsset { - network_id, - .. - } - | Action::DecomposeAsset { - network_id, - .. - } | Action::UnwrapCCC { network_id, .. @@ -546,36 +452,6 @@ impl From for Option { seq, output: *output, }), - Action::ComposeAsset { - network_id, - shard_id, - metadata, - approver, - registrar, - allowed_script_hashes, - inputs, - output, - .. - } => Some(ShardTransaction::ComposeAsset { - network_id, - shard_id, - metadata, - approver, - registrar, - allowed_script_hashes, - inputs, - output: *output, - }), - Action::DecomposeAsset { - network_id, - input, - outputs, - .. - } => Some(ShardTransaction::DecomposeAsset { - network_id, - input, - outputs, - }), Action::UnwrapCCC { network_id, burn, @@ -679,44 +555,6 @@ impl Encodable for Action { .append(&output.supply) .append_list(approvals); } - Action::ComposeAsset { - network_id, - shard_id, - metadata, - approver, - registrar, - allowed_script_hashes, - inputs, - output, - approvals, - } => { - s.begin_list(12) - .append(&COMPOSE_ASSET) - .append(network_id) - .append(shard_id) - .append(metadata) - .append(approver) - .append(registrar) - .append_list(allowed_script_hashes) - .append_list(inputs) - .append(&output.lock_script_hash) - .append(&output.parameters) - .append(&output.supply) - .append_list(approvals); - } - Action::DecomposeAsset { - network_id, - input, - outputs, - approvals, - } => { - s.begin_list(5) - .append(&DECOMPOSE_ASSET) - .append(network_id) - .append(input) - .append_list(outputs) - .append_list(approvals); - } Action::UnwrapCCC { network_id, burn, @@ -899,45 +737,6 @@ impl Decodable for Action { approvals: rlp.list_at(8)?, }) } - COMPOSE_ASSET => { - let item_count = rlp.item_count()?; - if item_count != 12 { - return Err(DecoderError::RlpIncorrectListLen { - got: item_count, - expected: 12, - }) - } - Ok(Action::ComposeAsset { - network_id: rlp.val_at(1)?, - shard_id: rlp.val_at(2)?, - metadata: rlp.val_at(3)?, - approver: rlp.val_at(4)?, - registrar: rlp.val_at(5)?, - allowed_script_hashes: rlp.list_at(6)?, - inputs: rlp.list_at(7)?, - output: Box::new(AssetMintOutput { - lock_script_hash: rlp.val_at(8)?, - parameters: rlp.list_at(9)?, - supply: rlp.val_at(10)?, - }), - approvals: rlp.list_at(11)?, - }) - } - DECOMPOSE_ASSET => { - let item_count = rlp.item_count()?; - if item_count != 5 { - return Err(DecoderError::RlpIncorrectListLen { - got: item_count, - expected: 5, - }) - } - Ok(Action::DecomposeAsset { - network_id: rlp.val_at(1)?, - input: rlp.val_at(2)?, - outputs: rlp.list_at(3)?, - approvals: rlp.list_at(4)?, - }) - } UNWRAP_CCC => { let item_count = rlp.item_count()?; if item_count != 4 { diff --git a/types/src/transaction/shard.rs b/types/src/transaction/shard.rs index 1e9f919d58..32c705b348 100644 --- a/types/src/transaction/shard.rs +++ b/types/src/transaction/shard.rs @@ -62,21 +62,6 @@ pub enum ShardTransaction { seq: usize, output: AssetMintOutput, }, - ComposeAsset { - network_id: NetworkId, - shard_id: ShardId, - metadata: String, - approver: Option
, - registrar: Option
, - allowed_script_hashes: Vec, - inputs: Vec, - output: AssetMintOutput, - }, - DecomposeAsset { - network_id: NetworkId, - input: AssetTransferInput, - outputs: Vec, - }, UnwrapCCC { network_id: NetworkId, burn: AssetTransferInput, @@ -123,18 +108,10 @@ impl ShardTransaction { network_id, .. } - | ShardTransaction::ComposeAsset { - network_id, - .. - } | ShardTransaction::ChangeAssetScheme { network_id, .. } - | ShardTransaction::DecomposeAsset { - network_id, - .. - } | ShardTransaction::UnwrapCCC { network_id, .. @@ -174,26 +151,6 @@ impl ShardTransaction { shard_id, .. } => vec![*shard_id], - ShardTransaction::ComposeAsset { - inputs, - shard_id, - .. - } => { - let mut shards: Vec = inputs.iter().map(|v| v.prev_out.shard_id).collect(); - shards.push(*shard_id); - shards.sort_unstable(); - shards.dedup(); - shards - } - ShardTransaction::DecomposeAsset { - outputs, - .. - } => { - let mut shards: Vec = outputs.iter().map(|v| v.shard_id).collect(); - shards.sort_unstable(); - shards.dedup(); - shards - } ShardTransaction::UnwrapCCC { burn, .. @@ -220,13 +177,6 @@ impl ShardTransaction { ShardTransaction::ChangeAssetScheme { .. } => false, - ShardTransaction::ComposeAsset { - .. - } => index == 0, - ShardTransaction::DecomposeAsset { - outputs, - .. - } => index < outputs.len(), ShardTransaction::UnwrapCCC { .. } => false, @@ -256,14 +206,6 @@ impl ShardTransaction { ShardTransaction::ChangeAssetScheme { .. } => unreachable!("AssetSchemeChange doesn't have a valid index"), - ShardTransaction::ComposeAsset { - shard_id, - .. - } => &id == shard_id, - ShardTransaction::DecomposeAsset { - outputs, - .. - } => id == outputs[index].shard_id, ShardTransaction::UnwrapCCC { .. } => unreachable!("UnwrapCCC doesn't have a valid index"), @@ -366,69 +308,6 @@ impl PartialHashing for ShardTransaction { &blake128(tag.get_tag()), )) } - ShardTransaction::ComposeAsset { - network_id, - shard_id, - metadata, - approver, - registrar, - allowed_script_hashes, - inputs, - output, - } => { - if tag.filter_len != 0 { - return Err(HashingError::InvalidFilter) - } - - let new_inputs = apply_input_scheme(inputs, tag.sign_all_inputs, !is_burn, cur); - - let new_output = if tag.sign_all_outputs { - output.clone() - } else { - AssetMintOutput::default() - }; - - Ok(blake256_with_key( - &ShardTransaction::ComposeAsset { - network_id: *network_id, - shard_id: *shard_id, - metadata: metadata.to_string(), - approver: *approver, - registrar: *registrar, - allowed_script_hashes: allowed_script_hashes.to_vec(), - inputs: new_inputs, - output: new_output, - } - .rlp_bytes(), - &blake128(tag.get_tag()), - )) - } - ShardTransaction::DecomposeAsset { - network_id, - input, - outputs, - } => { - let new_outputs = if tag.sign_all_outputs { - outputs.clone() - } else { - apply_bitmask_to_output(tag.filter.clone(), &outputs, Vec::new())? - }; - - Ok(blake256_with_key( - &ShardTransaction::DecomposeAsset { - network_id: *network_id, - input: AssetTransferInput { - prev_out: input.prev_out.clone(), - timelock: input.timelock, - lock_script: Vec::new(), - unlock_script: Vec::new(), - }, - outputs: new_outputs, - } - .rlp_bytes(), - &blake128(tag.get_tag()), - )) - } ShardTransaction::UnwrapCCC { network_id, burn, @@ -478,8 +357,10 @@ const ASSET_UNWRAP_CCC_ID: TransactionId = 0x11; const ASSET_MINT_ID: TransactionId = 0x13; const ASSET_TRANSFER_ID: TransactionId = 0x14; const ASSET_SCHEME_CHANGE_ID: TransactionId = 0x15; -const ASSET_COMPOSE_ID: TransactionId = 0x16; -const ASSET_DECOMPOSE_ID: TransactionId = 0x17; +/// Deprecated +//const ASSET_COMPOSE_ID: TransactionId = 0x16; +/// Deprecated +//const ASSET_DECOMPOSE_ID: TransactionId = 0x17; const ASSET_INCREASE_SUPPLY_ID: TransactionId = 0x18; impl Decodable for ShardTransaction { @@ -562,43 +443,6 @@ impl Decodable for ShardTransaction { }, }) } - ASSET_COMPOSE_ID => { - let item_count = d.item_count()?; - if item_count != 11 { - return Err(DecoderError::RlpIncorrectListLen { - got: item_count, - expected: 11, - }) - } - Ok(ShardTransaction::ComposeAsset { - network_id: d.val_at(1)?, - shard_id: d.val_at(2)?, - metadata: d.val_at(3)?, - approver: d.val_at(4)?, - registrar: d.val_at(5)?, - allowed_script_hashes: d.list_at(6)?, - inputs: d.list_at(7)?, - output: AssetMintOutput { - lock_script_hash: d.val_at(8)?, - parameters: d.val_at(9)?, - supply: d.val_at(10)?, - }, - }) - } - ASSET_DECOMPOSE_ID => { - let item_count = d.item_count()?; - if item_count != 4 { - return Err(DecoderError::RlpIncorrectListLen { - got: item_count, - expected: 4, - }) - } - Ok(ShardTransaction::DecomposeAsset { - network_id: d.val_at(1)?, - input: d.val_at(2)?, - outputs: d.list_at(3)?, - }) - } ASSET_UNWRAP_CCC_ID => { let item_count = d.item_count()?; if item_count != 4 { @@ -705,41 +549,6 @@ impl Encodable for ShardTransaction { .append(parameters) .append(supply); } - ShardTransaction::ComposeAsset { - network_id, - shard_id, - metadata, - approver, - registrar, - allowed_script_hashes, - inputs, - output: - AssetMintOutput { - lock_script_hash, - parameters, - supply, - }, - } => { - s.begin_list(11) - .append(&ASSET_COMPOSE_ID) - .append(network_id) - .append(shard_id) - .append(metadata) - .append(approver) - .append(registrar) - .append_list(allowed_script_hashes) - .append_list(inputs) - .append(lock_script_hash) - .append(parameters) - .append(supply); - } - ShardTransaction::DecomposeAsset { - network_id, - input, - outputs, - } => { - s.begin_list(4).append(&ASSET_DECOMPOSE_ID).append(network_id).append(input).append_list(outputs); - } ShardTransaction::UnwrapCCC { network_id, burn, @@ -1009,28 +818,6 @@ mod tests { )); } - - #[test] - fn encode_and_decode_decompose_transaction() { - let tx = ShardTransaction::DecomposeAsset { - network_id: NetworkId::default(), - input: AssetTransferInput { - prev_out: AssetOutPoint { - tracker: Default::default(), - index: 0, - asset_type: H160::default(), - shard_id: 0, - quantity: 30, - }, - timelock: None, - lock_script: vec![0x30, 0x01], - unlock_script: vec![], - }, - outputs: Vec::new(), - }; - rlp_encode_and_decode_test!(tx); - } - #[test] fn encode_and_decode_unwrapccc_transaction() { let tx = ShardTransaction::UnwrapCCC {