Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Aug 15, 2024
1 parent 8828ef2 commit dcf8152
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 18 deletions.
6 changes: 3 additions & 3 deletions crates/threshold-signature-server/src/helpers/substrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand Down Expand Up @@ -52,12 +52,12 @@ pub async fn get_program(
api: &OnlineClient<EntropyConfig>,
rpc: &LegacyRpcMethods<EntropyConfig>,
program_pointer: &<EntropyConfig as Config>::Hash,
) -> Result<(Vec<u8>, Vec<u8>), UserErr> {
) -> Result<ProgramInfo<AccountId32>, 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
Expand Down
3 changes: 1 addition & 2 deletions crates/threshold-signature-server/src/helpers/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions crates/threshold-signature-server/src/helpers/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
15 changes: 7 additions & 8 deletions crates/threshold-signature-server/src/user/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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),
)?;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/threshold-signature-server/src/user/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion pallets/oracle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ pub mod module {

#[pallet::storage]
#[pallet::getter(fn oracle_data)]
// TODO: parameterize bounded vec constants
pub type OracleData<T: Config> = StorageMap<
_,
Blake2_128Concat,
Expand Down

0 comments on commit dcf8152

Please sign in to comment.