From dcf8152fd6ab4698f0cfedf03d268d81f4024273 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 15 Aug 2024 14:38:51 -0400 Subject: [PATCH] clean --- .../src/helpers/substrate.rs | 6 +++--- .../src/helpers/tests.rs | 3 +-- .../src/helpers/user.rs | 5 ++--- crates/threshold-signature-server/src/user/api.rs | 15 +++++++-------- .../threshold-signature-server/src/user/tests.rs | 2 +- pallets/oracle/src/lib.rs | 1 - 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/crates/threshold-signature-server/src/helpers/substrate.rs b/crates/threshold-signature-server/src/helpers/substrate.rs index a821409ae..55fcb6772 100644 --- a/crates/threshold-signature-server/src/helpers/substrate.rs +++ b/crates/threshold-signature-server/src/helpers/substrate.rs @@ -19,7 +19,7 @@ use crate::{ entropy::{ self, runtime_types::{ - bounded_collections::bounded_vec::BoundedVec, + bounded_collections::bounded_vec::BoundedVec, pallet_programs::pallet::ProgramInfo, pallet_registry::pallet::RegisteredInfo, }, }, @@ -52,12 +52,12 @@ pub async fn get_program( api: &OnlineClient, rpc: &LegacyRpcMethods, program_pointer: &::Hash, -) -> Result<(Vec, Vec), UserErr> { +) -> Result, UserErr> { let bytecode_address = entropy::storage().programs().programs(program_pointer); let program_info = query_chain(api, rpc, bytecode_address, None) .await? .ok_or(UserErr::NoProgramDefined(program_pointer.to_string()))?; - Ok((program_info.bytecode, program_info.oracle_data_pointer)) + Ok(program_info) } /// Queries the oracle data needed for the program diff --git a/crates/threshold-signature-server/src/helpers/tests.rs b/crates/threshold-signature-server/src/helpers/tests.rs index 5185f9ffe..bb5906f41 100644 --- a/crates/threshold-signature-server/src/helpers/tests.rs +++ b/crates/threshold-signature-server/src/helpers/tests.rs @@ -31,8 +31,7 @@ use crate::{ ValidatorName, DEFAULT_ENDPOINT, }, logger::{Instrumentation, Logger}, - substrate::{get_oracle_data, query_chain, submit_transaction}, - + substrate::{query_chain, submit_transaction}, }, signing_client::ListenerState, AppState, diff --git a/crates/threshold-signature-server/src/helpers/user.rs b/crates/threshold-signature-server/src/helpers/user.rs index e27f1257c..263aac1e9 100644 --- a/crates/threshold-signature-server/src/helpers/user.rs +++ b/crates/threshold-signature-server/src/helpers/user.rs @@ -154,9 +154,8 @@ pub async fn compute_hash( }, HashingAlgorithm::Blake2_256 => Ok(blake2_256(message)), HashingAlgorithm::Custom(i) => { - let (program_bytecode, _) = - get_program(api, rpc, &programs_data[*i].program_pointer).await?; - runtime.custom_hash(program_bytecode.as_slice(), message).map_err(|e| e.into()) + let program_info = get_program(api, rpc, &programs_data[*i].program_pointer).await?; + runtime.custom_hash(program_info.bytecode.as_slice(), message).map_err(|e| e.into()) }, _ => Err(UserErr::UnknownHashingAlgorithm), } diff --git a/crates/threshold-signature-server/src/user/api.rs b/crates/threshold-signature-server/src/user/api.rs index 8526bab9c..ef75bea2d 100644 --- a/crates/threshold-signature-server/src/user/api.rs +++ b/crates/threshold-signature-server/src/user/api.rs @@ -68,8 +68,8 @@ use crate::{ launch::LATEST_BLOCK_NUMBER_NEW_USER, signing::{do_signing, Hasher}, substrate::{ - get_oracle_data, get_program, get_registered_details, get_stash_address, - query_chain, submit_transaction, + get_oracle_data, get_program, get_registered_details, get_stash_address, query_chain, + submit_transaction, }, user::{check_in_registration_group, compute_hash, do_dkg}, validator::{get_signer, get_signer_and_x25519_secret}, @@ -184,16 +184,15 @@ pub async fn sign_tx( let mut runtime = Runtime::new(ProgramConfig { fuel }); - for (i, program_info) in user_details.programs_data.0.iter().enumerate() { - let (program_bytecode, program_oracle_data) = - get_program(&api, &rpc, &program_info.program_pointer).await?; - let oracle_data = get_oracle_data(&api, &rpc, program_oracle_data).await?; + for (i, program_data) in user_details.programs_data.0.iter().enumerate() { + let program_info = get_program(&api, &rpc, &program_data.program_pointer).await?; + let oracle_data = get_oracle_data(&api, &rpc, program_info.oracle_data_pointer).await?; let auxilary_data = auxilary_data_vec[i].as_ref().map(hex::decode).transpose()?; let signature_request = SignatureRequest { message: message.clone(), auxilary_data }; runtime.evaluate( - &program_bytecode, + &program_info.bytecode, &signature_request, - Some(&program_info.program_config), + Some(&program_data.program_config), Some(&oracle_data), )?; } diff --git a/crates/threshold-signature-server/src/user/tests.rs b/crates/threshold-signature-server/src/user/tests.rs index 1a86d07a0..98c6e31c6 100644 --- a/crates/threshold-signature-server/src/user/tests.rs +++ b/crates/threshold-signature-server/src/user/tests.rs @@ -117,7 +117,7 @@ use crate::{ DEFAULT_ENDPOINT, DEFAULT_MNEMONIC, }, signing::Hasher, - substrate::{query_chain, submit_transaction, get_oracle_data}, + substrate::{get_oracle_data, query_chain, submit_transaction}, tests::{ check_has_confirmation, check_if_confirmation, create_clients, initialize_test_logger, remove_program, run_to_block, setup_client, spawn_testing_validators, unsafe_get, diff --git a/pallets/oracle/src/lib.rs b/pallets/oracle/src/lib.rs index 02e27e094..a58e88fd5 100644 --- a/pallets/oracle/src/lib.rs +++ b/pallets/oracle/src/lib.rs @@ -52,7 +52,6 @@ pub mod module { #[pallet::storage] #[pallet::getter(fn oracle_data)] - // TODO: parameterize bounded vec constants pub type OracleData = StorageMap< _, Blake2_128Concat,