Skip to content

Commit

Permalink
Fix export web3rpc (#1060)
Browse files Browse the repository at this point in the history
* fix export web3 rpc

* fix lint

* Update Main.yml

---------

Co-authored-by: shaorongqiang <[email protected]>
Co-authored-by: Hcreak <[email protected]>
  • Loading branch information
3 people authored Dec 9, 2024
1 parent d5b30c3 commit 0a23e5d
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 48 deletions.
1 change: 1 addition & 0 deletions .github/workflows/Main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- main
env:
CARGO_TERM_COLOR: always
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
jobs:
build:
strategy:
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ members = [
"src/components/contracts/primitives/enterprise-web3",
"src/components/contracts/rpc",
]
resolver = "2"

[profile.dev]
incremental = false
Expand Down
2 changes: 2 additions & 0 deletions src/components/abciapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ fc-rpc = { path = "../contracts/rpc" }
fp-storage = { path = "../contracts/primitives/storage" }
fp-utils = { path = "../contracts/primitives/utils" }
fp-types = {path = "../contracts/primitives/types"}
fp-traits = {path = "../contracts/primitives/traits"}

enterprise-web3 = { path = "../contracts/primitives/enterprise-web3" }
module-evm = { path = "../contracts/modules/evm"}
module-account = { path = "../contracts/modules/account" }

[target.'cfg(target_os= "linux")'.dependencies]
btm = "0.1.6"
Expand Down
78 changes: 68 additions & 10 deletions src/components/abciapp/src/abci/server/callback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ use {
chrono::Local,
config::abci::global_cfg::CFG,
enterprise_web3::{
ALLOWANCES, BALANCE_MAP, BLOCK, CODE_MAP, NONCE_MAP, RECEIPTS,
PG_CLIENT, STATE_UPDATE_LIST, TOTAL_ISSUANCE, TXS, WEB3_SERVICE_START_HEIGHT,
ALLOWANCES, BALANCE_MAP, BLOCK, CODE_MAP, NONCE_MAP, PG_CLIENT, RECEIPTS,
STATE_UPDATE_LIST, TOTAL_ISSUANCE, TXS, WEB3_SERVICE_START_HEIGHT,
},
fp_storage::hash::{Sha256, StorageHasher},
fp_storage::BorrowMut,
fp_storage::{
hash::{Sha256, StorageHasher},
BorrowMut,
},
fp_traits::base::BaseProvider,
fp_types::crypto::Address,
globutils::wallet,
lazy_static::lazy_static,
ledger::{
Expand All @@ -44,6 +48,7 @@ use {
},
LEDGER_TENDERMINT_BLOCK_HEIGHT,
},
module_account::storage::{Allowances, TotalIssuance},
parking_lot::{Mutex, RwLock},
protobuf::RepeatedField,
ruc::*,
Expand Down Expand Up @@ -662,29 +667,55 @@ pub fn commit(s: &mut ABCISubmissionServer, req: &RequestCommit) -> ResponseComm
let height = td_height as u32;
let setter = PG_CLIENT.lock().expect("PG_CLIENT error");

let nonce_map = if let Ok(mut nonce_map) = NONCE_MAP.lock() {
let mut nonce_map = if let Ok(mut nonce_map) = NONCE_MAP.lock() {
take(&mut *nonce_map)
} else {
Default::default()
};
nonce_map.iter_mut().for_each(|(k, v)| {
let account_id = Address::from(*k);
if let Ok(sa) = s.account_base_app.read().account_of(&account_id, None) {
*v = sa.nonce;
}
});

let code_map = if let Ok(mut code_map) = CODE_MAP.lock() {
let mut code_map = if let Ok(mut code_map) = CODE_MAP.lock() {
take(&mut *code_map)
} else {
Default::default()
};
code_map.iter_mut().for_each(|(k, v)| {
if let Some(code) = s.account_base_app.read().account_code_at(*k, None) {
*v = code;
}
});

let balance_map = if let Ok(mut balance_map) = BALANCE_MAP.lock() {
let mut balance_map = if let Ok(mut balance_map) = BALANCE_MAP.lock() {
take(&mut *balance_map)
} else {
Default::default()
};
balance_map.iter_mut().for_each(|(k, v)| {
let account_id = Address::from(*k);
if let Ok(sa) = s.account_base_app.read().account_of(&account_id, None) {
*v = sa.balance;
}
});

let state_list = if let Ok(mut state_list) = STATE_UPDATE_LIST.lock() {
let mut state_list = if let Ok(mut state_list) = STATE_UPDATE_LIST.lock() {
take(&mut *state_list)
} else {
Default::default()
};
state_list.iter_mut().for_each(|v| {
if let Some(value) = s.account_base_app.read().account_storage_at(
v.address,
v.index,
Some(v.height as u64),
) {
v.value = value;
}
});

let block = if let Ok(mut block) = BLOCK.lock() {
block.take()
Expand All @@ -704,16 +735,43 @@ pub fn commit(s: &mut ABCISubmissionServer, req: &RequestCommit) -> ResponseComm
Default::default()
};

let total_issuance = if let Ok(mut total_issuance) = TOTAL_ISSUANCE.lock() {
let mut total_issuance = if let Ok(mut total_issuance) = TOTAL_ISSUANCE.lock() {
take(&mut *total_issuance)
} else {
Default::default()
};
let allowances = if let Ok(mut allowances) = ALLOWANCES.lock() {

{
let base_app = s.account_base_app.write();
let state = base_app.deliver_state.state.read();

if total_issuance.is_some() {
if let Some(issuance) = TotalIssuance::get(&state) {
total_issuance = Some(issuance);
}
}
}

let mut allowances = if let Ok(mut allowances) = ALLOWANCES.lock() {
take(&mut *allowances)
} else {
Default::default()
};
{
let base_app = s.account_base_app.write();
let state = base_app.deliver_state.state.read();

allowances.iter_mut().for_each(|(k, v)| {
let owner = Address::from(k.owner_address);

let spender = Address::from(k.spender_address);

if let Some(issuance) = Allowances::get(&state, &owner, &spender) {
*v = issuance
}
});
}

if let Some(v) = total_issuance {
pnk!(setter
.set_total_issuance(height, v)
Expand Down
3 changes: 1 addition & 2 deletions src/components/abciapp/src/api/query_server/query_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ pub async fn get_related_xfrs(

#[allow(missing_docs)]
#[allow(clippy::unnecessary_wraps)]

pub async fn get_circulating_supply(
data: web::Data<Arc<RwLock<QueryServer>>>,
) -> actix_web::Result<web::Json<BTreeMap<&'static str, f64>>, actix_web::error::Error> {
Expand Down Expand Up @@ -651,7 +650,7 @@ impl QueryApi {
});

for (host, port) in addrs.iter() {
hdr = hdr.bind(&format!("{host}:{port}")).c(d!())?
hdr = hdr.bind(format!("{host}:{port}")).c(d!())?
}

hdr.run();
Expand Down
2 changes: 1 addition & 1 deletion src/components/contracts/modules/account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Config for () {
type FeeCalculator = ();
}

mod storage {
pub mod storage {
use fp_core::account::SmartAccount;
use fp_types::crypto::Address;
use primitive_types::U256;
Expand Down
5 changes: 2 additions & 3 deletions src/components/contracts/modules/ethereum/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ impl<C: Config> App<C> {
let mut txn_signers = ctx.eth_cache.current.write();
match txn_signers.get(&transaction_hash) {
Some(signer) => *signer,
None => Self::recover_signer(transaction).map(|signer| {
txn_signers.insert(transaction_hash, Some(signer));
signer
None => Self::recover_signer(transaction).inspect(|signer| {
txn_signers.insert(transaction_hash, Some(*signer));
}),
}
}
Expand Down
10 changes: 3 additions & 7 deletions src/components/contracts/modules/evm/src/runtime/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct FindoraStackSubstate<'context, 'config> {
pub substate: Option<State<FinDB>>,
}

impl<'context, 'config> FindoraStackSubstate<'context, 'config> {
impl<'config> FindoraStackSubstate<'_, 'config> {
pub fn metadata(&self) -> &StackSubstateMetadata<'config> {
&self.metadata
}
Expand Down Expand Up @@ -207,9 +207,7 @@ impl<'context, 'vicinity, 'config, C: Config>
}
}

impl<'context, 'vicinity, 'config, C: Config> Backend
for FindoraStackState<'context, 'vicinity, 'config, C>
{
impl<C: Config> Backend for FindoraStackState<'_, '_, '_, C> {
fn gas_price(&self) -> U256 {
self.vicinity.gas_price
}
Expand Down Expand Up @@ -278,9 +276,7 @@ impl<'context, 'vicinity, 'config, C: Config> Backend
}
}

impl<'context, 'vicinity, 'config, C: Config> StackState<'config>
for FindoraStackState<'context, 'vicinity, 'config, C>
{
impl<'config, C: Config> StackState<'config> for FindoraStackState<'_, '_, 'config, C> {
fn metadata(&self) -> &StackSubstateMetadata<'config> {
self.substate.metadata()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<'a> Deserialize<'a> for Bytes {

struct BytesVisitor;

impl<'a> Visitor<'a> for BytesVisitor {
impl Visitor<'_> for BytesVisitor {
type Value = Bytes;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<'a> Deserialize<'a> for Index {

struct IndexVisitor;

impl<'a> Visitor<'a> for IndexVisitor {
impl Visitor<'_> for IndexVisitor {
type Value = Index;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
Expand Down
12 changes: 6 additions & 6 deletions src/components/contracts/primitives/rpc-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ mod inner {
addr: &str,
io: RpcHandler<M>,
) -> io::Result<ipc::Server> {
let builder = ipc::ServerBuilder::new(io);
#[cfg(target_os = "unix")]
builder.set_security_attributes({
let mut builder = ipc::ServerBuilder::new(io);
#[cfg(target_family = "unix")]
{
let security_attributes = ipc::SecurityAttributes::empty();
security_attributes.set_mode(0o600)?;
security_attributes
});
builder =
builder.set_security_attributes(security_attributes.set_mode(0o600)?);
}
builder.start(addr)
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/contracts/rpc/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ impl EthApi for EthApiImpl {
cumulative_receipts
.truncate((status.transaction_index + 1) as usize);

return Ok(Some(Receipt {
Ok(Some(Receipt {
transaction_hash: Some(status.transaction_hash),
transaction_index: Some(status.transaction_index.into()),
block_hash: Some(block_hash),
Expand Down Expand Up @@ -1197,7 +1197,7 @@ impl EthApi for EthApiImpl {
status_code: Some(U64::from(receipt.state_root.to_low_u64_be())),
logs_bloom: receipt.logs_bloom,
state_root: None,
}));
}))
}
_ => Ok(None),
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/wallet_mobile/src/rust/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub enum EVMTransactionKind {
}

impl EVMTransactionBuilder {
/// transfer to uxto assets from account(ed25519 or ecdsa address) balance.
// transfer to uxto assets from account(ed25519 or ecdsa address) balance.

pub fn new_transfer_to_utxo_from_account(
recipient: XfrPublicKey,
Expand Down
16 changes: 8 additions & 8 deletions src/components/wallet_mobile/src/rust/data_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,20 +749,20 @@ impl TracingPolicy {
/// When an asset is defined, several options governing the assets must be
/// specified:
/// 1. **Traceable**: Records and identities of traceable assets can be decrypted by a provided tracing key. By defaults, assets do not have
/// any tracing policies.
/// any tracing policies.
/// 2. **Transferable**: Non-transferable assets can only be transferred once from the issuer to another user. By default, assets are transferable.
/// 3. **Updatable**: Whether the asset memo can be updated. By default, assets are not updatable.
/// 4. **Transfer signature rules**: Signature weights and threshold for a valid transfer. By
/// default, there are no special signature requirements.
/// 5. **Max units**: Optional limit on the total number of units of this asset that can be issued.
/// By default, assets do not have issuance caps.
/// @see {@link module:Findora-Wasm~TracingPolicies|TracingPolicies} for more information about tracing policies.
/// @see {@link module:Findora-Wasm~TransactionBuilder#add_operation_update_memo|add_operation_update_memo} for more information about how to add
/// a memo update operation to a transaction.
/// @see {@link module:Findora-Wasm~SignatureRules|SignatureRules} for more information about co-signatures.
/// @see {@link
/// module:Findora-Wasm~TransactionBuilder#add_operation_create_asset|add_operation_create_asset}
/// for information about how to add asset rules to an asset definition.
/// @see {@link module:Findora-Wasm~TracingPolicies|TracingPolicies} for more information about tracing policies.
/// @see {@link module:Findora-Wasm~TransactionBuilder#add_operation_update_memo|add_operation_update_memo} for more information about how to add
/// a memo update operation to a transaction.
/// @see {@link module:Findora-Wasm~SignatureRules|SignatureRules} for more information about co-signatures.
/// @see {@link
/// module:Findora-Wasm~TransactionBuilder#add_operation_create_asset|add_operation_create_asset}
/// for information about how to add asset rules to an asset definition.
pub struct AssetRules {
pub(crate) rules: PlatformAssetRules,
}
Expand Down
2 changes: 1 addition & 1 deletion src/ledger/src/data_model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl<'de> Deserialize<'de> for Code {
{
struct CodeVisitor;

impl<'de> Visitor<'de> for CodeVisitor {
impl Visitor<'_> for CodeVisitor {
type Value = Code;

#[inline(always)]
Expand Down
6 changes: 3 additions & 3 deletions src/ledger/src/staking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ lazy_static! {
};
}

/// The lock time after the delegation expires, about 21 days.
//pub const UNBOND_BLOCK_CNT: u64 = 3600 * 24 * 21 / BLOCK_INTERVAL;
// The lock time after the delegation expires, about 21 days.
// pub const UNBOND_BLOCK_CNT: u64 = 3600 * 24 * 21 / BLOCK_INTERVAL;

// minimal number of validators
/// Minimal number of validators
pub const VALIDATORS_MIN: usize = 5;

/// The minimum weight threshold required
Expand Down
3 changes: 1 addition & 2 deletions src/ledger/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ impl LedgerState {
.check_txn_effects(&txe)
.c(d!())
.and_then(|_| block.add_txn_effect(txe).c(d!()))
.map(|tmpid| {
.inspect(|_| {
// NOTE: set at the last position
block.staking_simulator.coinbase_check_and_pay(&tx);
tmpid
})
}

Expand Down

0 comments on commit 0a23e5d

Please sign in to comment.