Skip to content

Remove redundant AccountId::from #3404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,40 @@
// You should have received a copy of the GNU General Public License
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.

use std::str::FromStr;

use crate::server::RpcContext;
use crate::ErrorCode;
use executor_primitives::AccountId;
use executor_storage::{IntentIdStorage, Storage};
use jsonrpsee::{types::ErrorObject, RpcModule};
use log::error;
use parentchain_rpc_client::AccountId32;
use serde::Deserialize;
use std::str::FromStr;

#[derive(Debug, Deserialize)]
pub struct GetNextIntentIdParams {
// can be of ss58 or hex format
pub omni_account: String,
}

pub fn register_get_next_intent_id(module: &mut RpcModule<RpcContext>) {
module
.register_async_method("omni_getNextIntentId", |params, ctx, _| async move {
//ss58 encoded account_id
match params.parse::<String>() {
Ok(omni_account) => {
let account = AccountId32::from_str(&omni_account).map_err(|e| {
error!("Could not parse AccountId: {:?}", e);
<ErrorCode as Into<ErrorObject>>::into(ErrorCode::InvalidParams)
})?;
let params = params.parse::<GetNextIntentIdParams>()?;
let account = AccountId::from_str(&params.omni_account).map_err(|e| {
error!("Could not parse AccountId: {:?}", e);
<ErrorCode as Into<ErrorObject>>::into(ErrorCode::InvalidParams)
})?;

let storage = IntentIdStorage::new(ctx.storage_db.clone());
let intent_id = storage
.get(&AccountId::from(account.0))
.map_err(|e| {
log::error!("Could not get IntentId from store: {:?}", e);
<ErrorCode as Into<ErrorObject>>::into(ErrorCode::InternalError)
})?
.unwrap_or_default();
let storage = IntentIdStorage::new(ctx.storage_db.clone());
let intent_id = storage
.get(&account)
.map_err(|e| {
log::error!("Could not get IntentId from store: {:?}", e);
<ErrorCode as Into<ErrorObject>>::into(ErrorCode::InternalError)
})?
.unwrap_or_default();

Ok::<u32, ErrorObject>(intent_id + 1)
},
Err(_) => Err(ErrorCode::ParseError.into()),
}
Ok::<u32, ErrorObject>(intent_id + 1)
})
.expect("Failed to register getIntentId method");
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use crate::ErrorCode;
use crate::{methods::pumpx::common::PumpxRpcError, server::RpcContext};
use executor_primitives::AccountId;
use executor_storage::{IntentIdStorage, Storage};
use heima_primitives::{Identity, Web2IdentityType};
use jsonrpsee::{types::ErrorObject, RpcModule};
Expand All @@ -41,7 +40,7 @@ pub fn register_get_next_intent_id(module: &mut RpcModule<RpcContext>) {

let storage = IntentIdStorage::new(ctx.storage_db.clone());
let intent_id = storage
.get(&AccountId::from(account))
.get(&account)
.map_err(|e| {
log::error!("Could not get IntentId from store: {:?}", e);
PumpxRpcError::from_error_code(ErrorCode::InternalError)
Expand Down