From 7b55e69e919c66100b5e3c35fb88ea1042575e0d Mon Sep 17 00:00:00 2001 From: shaorongqiang Date: Wed, 12 Jul 2023 10:10:21 +0800 Subject: [PATCH 1/5] add importCoinBase --- .../abciapp/src/abci/server/callback/mod.rs | 44 ++++++++++-- src/components/contracts/baseapp/src/app.rs | 15 ++++- .../contracts/baseapp/src/modules.rs | 11 +-- .../contracts/baseapp/src/staking.rs | 11 +++ .../contracts/modules/ethereum/src/lib.rs | 1 + .../ethereum/tests/ethereum_integration.rs | 2 +- .../modules/evm/precompile/src/lib.rs | 3 +- .../contracts/modules/evm/src/lib.rs | 67 ++++++++++++++++--- .../contracts/modules/evm/src/utils.rs | 2 + .../template/tests/template_integration.rs | 2 +- .../contracts/primitives/core/src/module.rs | 1 + src/ledger/src/staking/evm.rs | 1 + src/ledger/src/staking/mod.rs | 8 +-- 13 files changed, 136 insertions(+), 32 deletions(-) diff --git a/src/components/abciapp/src/abci/server/callback/mod.rs b/src/components/abciapp/src/abci/server/callback/mod.rs index 46df4ce3b..d0ae04da8 100644 --- a/src/components/abciapp/src/abci/server/callback/mod.rs +++ b/src/components/abciapp/src/abci/server/callback/mod.rs @@ -2,6 +2,13 @@ //! # Impl function of tendermint ABCI //! +use globutils::wallet; +use ledger::{ + data_model::ASSET_TYPE_FRA, + staking::{FF_ADDR_EXTRA_120_0000, FF_ADDR_LIST}, +}; +use zei::xfr::asset_record::AssetRecordType; + mod utils; use { @@ -472,23 +479,27 @@ pub fn end_block( if header.height == CFG.checkpoint.evm_staking_inital_height { let ledger_state = la.get_committed_state().read(); - let validators = ledger_state - .get_staking() + let staking = ledger_state.get_staking(); + let validators = staking .validator_get_current() .map(|v| v.get_validators().values().cloned().collect::>()) .unwrap_or_default(); - let delegations = ledger_state - .get_staking() + let delegations = staking .get_global_delegation_records() .values() .map(|v| (v.id, v.clone())) .collect(); + let coinbase_balance = staking.coinbase_balance(); if let Err(e) = EVM_STAKING.get().c(d!()).and_then(|staking| { - staking.write().import_validators(&validators, &delegations) + staking.write().import_validators( + &validators, + &delegations, + coinbase_balance, + ) }) { - println!("import_validators error {:?}", e); + tracing::error!(target: "evm staking", "import_validators error:{:?}", e); panic!() }; } @@ -527,7 +538,26 @@ pub fn end_block( let evm_resp = if td_height <= CFG.checkpoint.disable_evm_block_height || td_height >= CFG.checkpoint.enable_frc20_height { - s.account_base_app.write().end_block(req) + let mut sum = 0; + let ledger = la.get_committed_state().read(); + let mut addrs = FF_ADDR_LIST.to_vec(); + addrs.push(FF_ADDR_EXTRA_120_0000); + for fra_addr in addrs.iter() { + for (_, (utxo, _)) in pnk!(wallet::public_key_from_bech32(fra_addr) + .and_then(|pub_key| ledger.get_owned_utxos(&pub_key))) + { + if AssetRecordType::NonConfidentialAmount_NonConfidentialAssetType + == utxo.0.record.get_record_type() + && Some(ASSET_TYPE_FRA) == utxo.0.record.asset_type.get_asset_type() + { + if let Some(v) = utxo.0.record.amount.get_amount() { + sum += v; + }; + } + } + } + + s.account_base_app.write().end_block(req, sum) } else { Default::default() }; diff --git a/src/components/contracts/baseapp/src/app.rs b/src/components/contracts/baseapp/src/app.rs index 667c6bc4d..73a2f7661 100644 --- a/src/components/contracts/baseapp/src/app.rs +++ b/src/components/contracts/baseapp/src/app.rs @@ -468,13 +468,22 @@ impl crate::BaseApp { } #[cfg(any(feature = "abci_mock", test))] - pub fn end_block(&mut self, _req: &RequestEndBlock) -> ResponseEndBlock { + pub fn end_block( + &mut self, + _req: &RequestEndBlock, + _ff_addr_balance: u64, + ) -> ResponseEndBlock { Default::default() } #[cfg(all(not(feature = "abci_mock"), not(test)))] - pub fn end_block(&mut self, req: &RequestEndBlock) -> ResponseEndBlock { - self.modules.end_block(&mut self.deliver_state, req) + pub fn end_block( + &mut self, + req: &RequestEndBlock, + ff_addr_balance: u64, + ) -> ResponseEndBlock { + self.modules + .end_block(&mut self.deliver_state, req, ff_addr_balance) } pub fn commit(&mut self, _req: &RequestCommit) -> ResponseCommit { diff --git a/src/components/contracts/baseapp/src/modules.rs b/src/components/contracts/baseapp/src/modules.rs index a7bf4381b..42d91dfdc 100644 --- a/src/components/contracts/baseapp/src/modules.rs +++ b/src/components/contracts/baseapp/src/modules.rs @@ -78,11 +78,12 @@ impl ModuleManager { &mut self, ctx: &mut Context, req: &RequestEndBlock, + ff_addr_balance: u64, ) -> ResponseEndBlock { let mut resp: ResponseEndBlock = Default::default(); // Note: adding new modules need to be updated. - self.account_module.end_block(ctx, req); - let (mresp, burn_amount) = self.evm_module.end_block(ctx, req); + self.account_module.end_block(ctx, req, ff_addr_balance); + let (mresp, burn_amount) = self.evm_module.end_block(ctx, req, 0); if !mresp.validator_updates.is_empty() { resp.validator_updates = mresp.validator_updates; } @@ -93,9 +94,9 @@ impl ModuleManager { ) { tracing::warn!("module_account::App::::burn error: {:?}", e) } - self.ethereum_module.end_block(ctx, req); - self.xhub_module.end_block(ctx, req); - self.template_module.end_block(ctx, req); + self.ethereum_module.end_block(ctx, req, 0); + self.xhub_module.end_block(ctx, req, 0); + self.template_module.end_block(ctx, req, 0); resp } diff --git a/src/components/contracts/baseapp/src/staking.rs b/src/components/contracts/baseapp/src/staking.rs index 1fa43b97e..a99f360f2 100644 --- a/src/components/contracts/baseapp/src/staking.rs +++ b/src/components/contracts/baseapp/src/staking.rs @@ -22,6 +22,7 @@ impl EVMStaking for BaseApp { &self, validators: &[Validator], delegations: &BTreeMap, + coinbase_balance: u64, ) -> Result<()> { let from = H160::from_str(SYSTEM_ADDR).c(d!())?; @@ -158,6 +159,16 @@ impl EVMStaking for BaseApp { tracing::error!(target: "evm staking", "import_reward error:{:?}", e); return Err(e); } + if let Err(e) = self.modules.evm_module.import_coinbase_balance( + &self.deliver_state, + from, + coinbase_balance, + ) { + self.deliver_state.state.write().discard_session(); + self.deliver_state.db.write().discard_session(); + tracing::error!(target: "evm staking", "import_coinbase_balance error:{:?}", e); + return Err(e); + } self.deliver_state.state.write().commit_session(); self.deliver_state.db.write().commit_session(); Ok(()) diff --git a/src/components/contracts/modules/ethereum/src/lib.rs b/src/components/contracts/modules/ethereum/src/lib.rs index acaff1770..02ff0eafc 100644 --- a/src/components/contracts/modules/ethereum/src/lib.rs +++ b/src/components/contracts/modules/ethereum/src/lib.rs @@ -134,6 +134,7 @@ impl AppModule for App { &mut self, ctx: &mut Context, req: &RequestEndBlock, + _ff_addr_balance: u64, ) -> (ResponseEndBlock, U256) { let _ = ruc::info!(self.store_block(ctx, U256::from(req.height))); Default::default() diff --git a/src/components/contracts/modules/ethereum/tests/ethereum_integration.rs b/src/components/contracts/modules/ethereum/tests/ethereum_integration.rs index 958886887..e9764f8f2 100644 --- a/src/components/contracts/modules/ethereum/tests/ethereum_integration.rs +++ b/src/components/contracts/modules/ethereum/tests/ethereum_integration.rs @@ -135,7 +135,7 @@ fn test_abci_deliver_tx() { fn test_abci_end_block() { let mut req = RequestEndBlock::default(); req.height = 3; - let _ = BASE_APP.lock().unwrap().end_block(&req); + let _ = BASE_APP.lock().unwrap().end_block(&req, 0); } fn test_abci_commit() { diff --git a/src/components/contracts/modules/evm/precompile/src/lib.rs b/src/components/contracts/modules/evm/precompile/src/lib.rs index 34a6ca2d3..994ec14ae 100644 --- a/src/components/contracts/modules/evm/precompile/src/lib.rs +++ b/src/components/contracts/modules/evm/precompile/src/lib.rs @@ -4,12 +4,11 @@ use module_evm::precompile::{Precompile, PrecompileResult}; use std::marker::PhantomData; use evm_precompile_anemoi::Anemoi; -use evm_precompile_basic::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256}; +use evm_precompile_basic::{ECRecover, Identity, Ripemd160, Sha256}; use evm_precompile_blake2::Blake2F; use evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing}; use evm_precompile_frc20::FRC20; use evm_precompile_modexp::Modexp; -use evm_precompile_sha3fips::{Sha3FIPS256, Sha3FIPS512}; use fp_core::context::Context as Context2; use module_evm::precompile::PrecompileId; use module_evm::Config; diff --git a/src/components/contracts/modules/evm/src/lib.rs b/src/components/contracts/modules/evm/src/lib.rs index 9893b8a84..f7d59bd7a 100644 --- a/src/components/contracts/modules/evm/src/lib.rs +++ b/src/components/contracts/modules/evm/src/lib.rs @@ -39,6 +39,7 @@ use fp_types::{ crypto::{Address, HA160}, }; use ledger::staking::evm::EVM_STAKING_MINTS; +use ledger::staking::FRA_PRE_ISSUE_AMOUNT; use module_ethereum::storage::{TransactionIndex, DELIVER_PENDING_TRANSACTIONS}; use precompile::PrecompileSet; use protobuf::RepeatedField; @@ -304,8 +305,11 @@ impl App { &self, ctx: &Context, req: &abci::RequestBeginBlock, + ff_addr_balance: u64, ) -> Result { - let input = utils::build_evm_staking_input(&self.contracts, req)?; + let pre_issue_amount = FRA_PRE_ISSUE_AMOUNT - ff_addr_balance; + let input = + utils::build_evm_staking_input(&self.contracts, req, pre_issue_amount)?; let gas_limit = u64::MAX; let value = U256::zero(); @@ -663,7 +667,48 @@ impl App { } Ok(()) } + pub fn import_coinbase_balance( + &self, + ctx: &Context, + from: H160, + coinbase_balance: u64, + ) -> Result<()> { + let function = self.contracts.staking.function("importCoinBase").c(d!())?; + let input = function + .encode_input(&[Token::Uint(U256::from(coinbase_balance))]) + .c(d!())?; + let gas_limit = u64::MAX; + let value = U256::zero(); + tracing::info!( + target: "evm staking", + "importCoinBase from:{:?} gas_limit:{} value:{} contracts_address:{:?} input:{}", + from, + gas_limit, + value, + self.contracts.staking_address, + hex::encode(&input) + ); + let (_, logs, used_gas) = ActionRunner::::execute_systemc_contract( + ctx, + input.clone(), + from, + gas_limit, + self.contracts.staking_address, + value, + )?; + Self::store_transaction( + ctx, + U256::from(gas_limit), + from, + self.contracts.staking_address, + value, + input, + &logs, + used_gas, + )?; + Ok(()) + } #[allow(clippy::too_many_arguments)] pub fn stake( &self, @@ -1153,18 +1198,22 @@ impl AppModule for App { &mut self, ctx: &mut Context, _req: &abci::RequestEndBlock, + ff_addr_balance: u64, ) -> (abci::ResponseEndBlock, U256) { let mut resp = abci::ResponseEndBlock::default(); let mut burn_amount = Default::default(); if ctx.header.height > CFG.checkpoint.evm_staking_inital_height { - burn_amount = - match self.execute_staking_contract(ctx, &self.abci_begin_block) { - Ok(v) => v, - Err(e) => { - tracing::error!("Error on evm staking trigger: {}", e); - Default::default() - } - }; + burn_amount = match self.execute_staking_contract( + ctx, + &self.abci_begin_block, + ff_addr_balance, + ) { + Ok(v) => v, + Err(e) => { + tracing::error!("Error on evm staking trigger: {}", e); + Default::default() + } + }; match self.get_validator_list(ctx) { Ok(r) => { if !r.is_empty() { diff --git a/src/components/contracts/modules/evm/src/utils.rs b/src/components/contracts/modules/evm/src/utils.rs index 93f5d4c37..aba00ec66 100644 --- a/src/components/contracts/modules/evm/src/utils.rs +++ b/src/components/contracts/modules/evm/src/utils.rs @@ -105,6 +105,7 @@ fn build_address(address: &[u8]) -> Result { pub fn build_evm_staking_input( sc: &SystemContracts, req: &abci::RequestBeginBlock, + pre_issue_amount: u64, ) -> Result> { let header = req.get_header(); let commit_info = req.get_last_commit_info(); @@ -153,6 +154,7 @@ pub fn build_evm_staking_input( Token::Array(unsigned), Token::Array(byzantines), Token::Array(behaviors), + Token::Uint(U256::from(pre_issue_amount)), ]) .c(d!())?; diff --git a/src/components/contracts/modules/template/tests/template_integration.rs b/src/components/contracts/modules/template/tests/template_integration.rs index 481f22b98..755d9f412 100644 --- a/src/components/contracts/modules/template/tests/template_integration.rs +++ b/src/components/contracts/modules/template/tests/template_integration.rs @@ -127,7 +127,7 @@ fn test_abci_deliver_tx() { fn test_abci_end_block() { let mut req = RequestEndBlock::default(); req.height = 2; - let _ = BASE_APP.lock().unwrap().end_block(&req); + let _ = BASE_APP.lock().unwrap().end_block(&req, 0); } fn test_abci_commit() { diff --git a/src/components/contracts/primitives/core/src/module.rs b/src/components/contracts/primitives/core/src/module.rs index 5589f8211..7a7e843a4 100644 --- a/src/components/contracts/primitives/core/src/module.rs +++ b/src/components/contracts/primitives/core/src/module.rs @@ -41,6 +41,7 @@ pub trait AppModule: AppModuleBasic { &mut self, _ctx: &mut Context, _req: &RequestEndBlock, + _ff_addr_balance: u64, ) -> (ResponseEndBlock, U256) { Default::default() } diff --git a/src/ledger/src/staking/evm.rs b/src/ledger/src/staking/evm.rs index 1eeee35b9..dd048d4fa 100644 --- a/src/ledger/src/staking/evm.rs +++ b/src/ledger/src/staking/evm.rs @@ -22,6 +22,7 @@ pub trait EVMStaking: Sync + Send + 'static { &self, validators: &[Validator], delegations: &BTreeMap, + coinbase_balance: u64, ) -> Result<()>; /// stake call fn stake( diff --git a/src/ledger/src/staking/mod.rs b/src/ledger/src/staking/mod.rs index 547c50fac..b24b54774 100644 --- a/src/ledger/src/staking/mod.rs +++ b/src/ledger/src/staking/mod.rs @@ -99,8 +99,8 @@ lazy_static! { pub static ref CHAN_D_RWD_HIST: DRHCP = chan!(); } -// Reserved accounts of Findora Foundation. -const FF_ADDR_LIST: [&str; 8] = [ +/// Reserved accounts of Findora Foundation. +pub const FF_ADDR_LIST: [&str; 8] = [ "fra1s9c6p0656as48w8su2gxntc3zfuud7m66847j6yh7n8wezazws3s68p0m9", "fra1zjfttcnvyv9ypy2d4rcg7t4tw8n88fsdzpggr0y2h827kx5qxmjshwrlx7", "fra18rfyc9vfyacssmr5x7ku7udyd5j5vmfkfejkycr06e4as8x7n3dqwlrjrc", @@ -110,8 +110,8 @@ const FF_ADDR_LIST: [&str; 8] = [ "fra1mjdr0mgn2e0670hxptpzu9tmf0ary8yj8nv90znjspwdupv9aacqwrg3dx", "fra1whn756rtqt3gpsmdlw6pvns75xdh3ttqslvxaf7eefwa83pcnlhsree9gv", ]; - -const FF_ADDR_EXTRA_120_0000: &str = +/// +pub const FF_ADDR_EXTRA_120_0000: &str = "fra1dkn9w5c674grdl6gmvj0s8zs0z2nf39zrmp3dpq5rqnnf9axwjrqexqnd6"; /// SEE: From 300f7872a46fec15f8fc3b2c6410ea3d5af4a1f2 Mon Sep 17 00:00:00 2001 From: shaorongqiang Date: Wed, 12 Jul 2023 10:55:10 +0800 Subject: [PATCH 2/5] update CoinbaseMint --- src/components/contracts/baseapp/src/app.rs | 47 ++++++++++++++++--- .../contracts/modules/evm/src/utils.rs | 16 +++---- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/components/contracts/baseapp/src/app.rs b/src/components/contracts/baseapp/src/app.rs index 73a2f7661..bbbec66dd 100644 --- a/src/components/contracts/baseapp/src/app.rs +++ b/src/components/contracts/baseapp/src/app.rs @@ -303,6 +303,7 @@ impl crate::BaseApp { let mut staking_contract_found = false; let mut coinbase_mint_foud = false; + let mut validator = H256::zero(); let mut delegator = H256::zero(); let claim_on_contract_address = if td_height @@ -361,11 +362,22 @@ impl crate::BaseApp { - 1], ) { - if let Some(start) = topic.find(", 0x") { - coinbase_mint_foud = true; - delegator = match H256::from_str( - &topic[start + 2..topic.len() - 1], - ) { + let hashes = topic + .strip_prefix("[") + .and_then(|v| v.strip_suffix("]")) + .unwrap_or(&topic) + .split(",") + .collect::>(); + + let mut validator_flag = false; + if let Some(v) = hashes.get(1) { + validator_flag = true; + + let s = v + .strip_prefix(" ") + .and_then(|v| v.strip_suffix(" ")) + .unwrap_or(v); + validator = match H256::from_str(s) { Ok(v) => v, Err(e) => { resp.code = 1; @@ -374,6 +386,25 @@ impl crate::BaseApp { } }; }; + let mut delegator_flag = false; + if let Some(v) = hashes.get(2) { + delegator_flag = true; + + let s = v + .strip_prefix(" ") + .and_then(|v| v.strip_suffix(" ")) + .unwrap_or(v); + delegator = match H256::from_str(s) { + Ok(v) => v, + Err(e) => { + resp.code = 1; + resp.log = e.to_string(); + return (resp, vec![]); + } + }; + }; + coinbase_mint_foud = + validator_flag && delegator_flag; } } if key == *"data" { @@ -412,7 +443,11 @@ impl crate::BaseApp { let ret = parse_evm_staking_coinbase_mint_event( &event, - vec![event.signature(), delegator], + vec![ + event.signature(), + validator, + delegator, + ], data_vec, ); diff --git a/src/components/contracts/modules/evm/src/utils.rs b/src/components/contracts/modules/evm/src/utils.rs index aba00ec66..a10e5a9c8 100644 --- a/src/components/contracts/modules/evm/src/utils.rs +++ b/src/components/contracts/modules/evm/src/utils.rs @@ -247,14 +247,14 @@ pub fn coinbase_mint_event() -> Event { name: "CoinbaseMint".to_owned(), inputs: vec![ EventParam { - name: "addr".to_owned(), + name: "validator".to_owned(), kind: ParamType::Address, indexed: true, }, EventParam { - name: "ty".to_owned(), - kind: ParamType::Uint(8), - indexed: false, + name: "delegator".to_owned(), + kind: ParamType::Address, + indexed: true, }, EventParam { name: "public_key".to_owned(), @@ -284,19 +284,17 @@ pub fn parse_evm_staking_coinbase_mint_event( ) -> Result<(H160, Option, u64)> { let log = RawLog { topics, data }; let result = event.parse_log(log).map_err(|e| eg!(e))?; - let addr = result.params[0].value.clone().into_address().c(d!())?; - - //let pubkey_type = result.params[1].value.clone().into_uint().c(d!())?.as_u64(); + let delegator = result.params[1].value.clone().into_address().c(d!())?; let public_key_bytes = result.params[2].value.clone().into_bytes().c(d!())?; let amount = result.params[3].value.clone().into_uint().c(d!())?.as_u64(); if public_key_bytes.is_empty() { - return Ok((addr, None, amount)); + return Ok((delegator, None, amount)); } let public_key = XfrPublicKey::zei_from_bytes(public_key_bytes.as_slice())?; - Ok((addr, Some(public_key), amount)) + Ok((delegator, Some(public_key), amount)) } fn build_claim_info(tk: &Token) -> Result<(H160, U256)> { From 3a8a202bfe23ba946e85aab4e67af698a4e9db89 Mon Sep 17 00:00:00 2001 From: shaorongqiang Date: Wed, 12 Jul 2023 10:57:24 +0800 Subject: [PATCH 3/5] update abi --- .../modules/evm/contracts/EVMStaking.abi.json | 72 +++++++++++++------ 1 file changed, 49 insertions(+), 23 deletions(-) diff --git a/src/components/contracts/modules/evm/contracts/EVMStaking.abi.json b/src/components/contracts/modules/evm/contracts/EVMStaking.abi.json index c0f0863ea..586c15f28 100644 --- a/src/components/contracts/modules/evm/contracts/EVMStaking.abi.json +++ b/src/components/contracts/modules/evm/contracts/EVMStaking.abi.json @@ -5,14 +5,14 @@ { "indexed": true, "internalType": "address", - "name": "delegator", + "name": "validator", "type": "address" }, { - "indexed": false, - "internalType": "enum IBaseEnum.PublicKeyType", - "name": "ty", - "type": "uint8" + "indexed": true, + "internalType": "address", + "name": "delegator", + "type": "address" }, { "indexed": false, @@ -81,30 +81,12 @@ "name": "OwnershipTransferred", "type": "event" }, - { - "inputs": [], - "name": "SYSTEM_ADDR", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [ { "internalType": "address", "name": "validator", "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" } ], "name": "claim", @@ -240,6 +222,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "importCoinBase", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -484,6 +479,19 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "addr", + "type": "address" + } + ], + "name": "setSystemAddr", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -525,6 +533,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "systemAddr", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -717,6 +738,11 @@ "internalType": "enum IBaseEnum.ByztineBehavior[]", "name": "behavior", "type": "uint8[]" + }, + { + "internalType": "uint256", + "name": "preIssueAmount", + "type": "uint256" } ], "name": "trigger", From 3431d83338e5cea8a3221e9a2afad7bc59f90917 Mon Sep 17 00:00:00 2001 From: shaorongqiang Date: Wed, 12 Jul 2023 11:07:54 +0800 Subject: [PATCH 4/5] fix build --- src/components/contracts/baseapp/src/app.rs | 30 ++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/components/contracts/baseapp/src/app.rs b/src/components/contracts/baseapp/src/app.rs index bbbec66dd..f327e66fd 100644 --- a/src/components/contracts/baseapp/src/app.rs +++ b/src/components/contracts/baseapp/src/app.rs @@ -320,7 +320,7 @@ impl crate::BaseApp { ) { Ok(v) => v, Err(e) => { - resp.code = 1; + resp.code = 101; resp.log = e.to_string(); return (resp, vec![]); } @@ -363,10 +363,10 @@ impl crate::BaseApp { ) { let hashes = topic - .strip_prefix("[") - .and_then(|v| v.strip_suffix("]")) + .strip_prefix('[') + .and_then(|v| v.strip_suffix(']')) .unwrap_or(&topic) - .split(",") + .split(", ") .collect::>(); let mut validator_flag = false; @@ -374,13 +374,13 @@ impl crate::BaseApp { validator_flag = true; let s = v - .strip_prefix(" ") - .and_then(|v| v.strip_suffix(" ")) + .strip_prefix(' ') + .and_then(|v| v.strip_suffix(' ')) .unwrap_or(v); validator = match H256::from_str(s) { Ok(v) => v, Err(e) => { - resp.code = 1; + resp.code = 102; resp.log = e.to_string(); return (resp, vec![]); } @@ -391,13 +391,13 @@ impl crate::BaseApp { delegator_flag = true; let s = v - .strip_prefix(" ") - .and_then(|v| v.strip_suffix(" ")) + .strip_prefix(' ') + .and_then(|v| v.strip_suffix(' ')) .unwrap_or(v); delegator = match H256::from_str(s) { Ok(v) => v, Err(e) => { - resp.code = 1; + resp.code = 103; resp.log = e.to_string(); return (resp, vec![]); } @@ -423,7 +423,7 @@ impl crate::BaseApp { Ok(deposit) => non_confidential_outputs .push(deposit), Err(e) => { - resp.code = 1; + resp.code = 104; resp.log = e.to_string(); } } @@ -470,12 +470,12 @@ impl crate::BaseApp { &Address::from(addr), U256::from(amount), ) { - resp.code = 2; + resp.code = 105; resp.log = e.to_string(); } } Err(e) => { - resp.code = 1; + resp.code = 106; resp.log = e.to_string(); } } @@ -490,13 +490,13 @@ impl crate::BaseApp { } Err(e) => { error!(target: "baseapp", "Ethereum transaction deliver error: {e}"); - resp.code = 1; + resp.code = 107; resp.log = format!("Ethereum transaction deliver error: {e}"); (resp, non_confidential_outputs) } } } else { - resp.code = 1; + resp.code = 108; resp.log = String::from("Failed to convert transaction when deliver tx!"); (resp, non_confidential_outputs) } From f347f89f5586d3df7ad79a59eade333eb7df7195 Mon Sep 17 00:00:00 2001 From: shaorongqiang Date: Thu, 13 Jul 2023 11:34:19 +0800 Subject: [PATCH 5/5] fix code --- src/components/contracts/baseapp/src/app.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/contracts/baseapp/src/app.rs b/src/components/contracts/baseapp/src/app.rs index f327e66fd..035a76a2e 100644 --- a/src/components/contracts/baseapp/src/app.rs +++ b/src/components/contracts/baseapp/src/app.rs @@ -320,7 +320,7 @@ impl crate::BaseApp { ) { Ok(v) => v, Err(e) => { - resp.code = 101; + resp.code = 1; resp.log = e.to_string(); return (resp, vec![]); } @@ -380,7 +380,7 @@ impl crate::BaseApp { validator = match H256::from_str(s) { Ok(v) => v, Err(e) => { - resp.code = 102; + resp.code = 1; resp.log = e.to_string(); return (resp, vec![]); } @@ -397,7 +397,7 @@ impl crate::BaseApp { delegator = match H256::from_str(s) { Ok(v) => v, Err(e) => { - resp.code = 103; + resp.code = 1; resp.log = e.to_string(); return (resp, vec![]); } @@ -423,7 +423,7 @@ impl crate::BaseApp { Ok(deposit) => non_confidential_outputs .push(deposit), Err(e) => { - resp.code = 104; + resp.code = 1; resp.log = e.to_string(); } } @@ -470,12 +470,12 @@ impl crate::BaseApp { &Address::from(addr), U256::from(amount), ) { - resp.code = 105; + resp.code = 2; resp.log = e.to_string(); } } Err(e) => { - resp.code = 106; + resp.code = 1; resp.log = e.to_string(); } } @@ -490,13 +490,13 @@ impl crate::BaseApp { } Err(e) => { error!(target: "baseapp", "Ethereum transaction deliver error: {e}"); - resp.code = 107; + resp.code = 1; resp.log = format!("Ethereum transaction deliver error: {e}"); (resp, non_confidential_outputs) } } } else { - resp.code = 108; + resp.code = 1; resp.log = String::from("Failed to convert transaction when deliver tx!"); (resp, non_confidential_outputs) }