mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Reorganize serai-client
Instead of functions taking a block hash, has a scope to a block hash before functions can be called. Separates functions by pallets.
This commit is contained in:
@@ -15,13 +15,13 @@ use serai_client::{
|
||||
primitives::{ValidatorSet, KeyPair, musig_context, musig_key, set_keys_message},
|
||||
ValidatorSetsEvent,
|
||||
},
|
||||
Serai,
|
||||
SeraiValidatorSets,
|
||||
};
|
||||
|
||||
use crate::common::{serai, tx::publish_tx};
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn set_validator_set_keys(set: ValidatorSet, key_pair: KeyPair) -> [u8; 32] {
|
||||
pub async fn set_keys(set: ValidatorSet, key_pair: KeyPair) -> [u8; 32] {
|
||||
let pair = insecure_pair_from_name("Alice");
|
||||
let public = pair.public();
|
||||
|
||||
@@ -29,7 +29,11 @@ pub async fn set_validator_set_keys(set: ValidatorSet, key_pair: KeyPair) -> [u8
|
||||
let public_key = <Ristretto as Ciphersuite>::read_G::<&[u8]>(&mut public.0.as_ref()).unwrap();
|
||||
assert_eq!(
|
||||
serai
|
||||
.get_validator_set_musig_key(set, serai.get_latest_block_hash().await.unwrap())
|
||||
.with_current_latest_block()
|
||||
.await
|
||||
.unwrap()
|
||||
.validator_sets()
|
||||
.musig_key(set)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap(),
|
||||
@@ -45,7 +49,11 @@ pub async fn set_validator_set_keys(set: ValidatorSet, key_pair: KeyPair) -> [u8
|
||||
musig::<Ristretto>(&musig_context(set), &Zeroizing::new(secret_key), &[public_key]).unwrap();
|
||||
assert_eq!(
|
||||
serai
|
||||
.get_validator_set_musig_key(set, serai.get_latest_block_hash().await.unwrap())
|
||||
.with_current_latest_block()
|
||||
.await
|
||||
.unwrap()
|
||||
.validator_sets()
|
||||
.musig_key(set)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap(),
|
||||
@@ -63,7 +71,7 @@ pub async fn set_validator_set_keys(set: ValidatorSet, key_pair: KeyPair) -> [u8
|
||||
);
|
||||
|
||||
// Vote in a key pair
|
||||
let block = publish_tx(&Serai::set_validator_set_keys(
|
||||
let block = publish_tx(&SeraiValidatorSets::set_keys(
|
||||
set.network,
|
||||
key_pair.clone(),
|
||||
Signature(sig.to_bytes()),
|
||||
@@ -71,10 +79,10 @@ pub async fn set_validator_set_keys(set: ValidatorSet, key_pair: KeyPair) -> [u8
|
||||
.await;
|
||||
|
||||
assert_eq!(
|
||||
serai.get_key_gen_events(block).await.unwrap(),
|
||||
serai.as_of(block).validator_sets().key_gen_events().await.unwrap(),
|
||||
vec![ValidatorSetsEvent::KeyGen { set, key_pair: key_pair.clone() }]
|
||||
);
|
||||
assert_eq!(serai.get_keys(set, block).await.unwrap(), Some(key_pair));
|
||||
assert_eq!(serai.as_of(block).validator_sets().keys(set).await.unwrap(), Some(key_pair));
|
||||
|
||||
block
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user