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:
Luke Parker
2023-10-14 02:47:58 -04:00
parent 96cc5d0157
commit cb61c9052a
13 changed files with 384 additions and 365 deletions

View File

@@ -13,7 +13,7 @@ use serai_client::{
primitives::{InInstruction, InInstructionWithBalance, Batch},
InInstructionsEvent,
},
tokens::TokensEvent,
coins::TokensEvent,
Serai,
};
@@ -48,23 +48,25 @@ serai_test!(
let block = provide_batch(batch.clone()).await;
let serai = serai().await;
assert_eq!(serai.get_latest_block_for_network(block, network).await.unwrap(), Some(block_hash));
let batches = serai.get_batch_events(block).await.unwrap();
assert_eq!(
batches,
vec![InInstructionsEvent::Batch {
network,
id,
block: block_hash,
instructions_hash: Blake2b::<U32>::digest(batch.instructions.encode()).into(),
}]
);
let serai = serai.as_of(block);
{
let serai = serai.in_instructions();
assert_eq!(serai.latest_block_for_network(network).await.unwrap(), Some(block_hash));
let batches = serai.batch_events().await.unwrap();
assert_eq!(
batches,
vec![InInstructionsEvent::Batch {
network,
id,
block: block_hash,
instructions_hash: Blake2b::<U32>::digest(batch.instructions.encode()).into(),
}]
);
}
assert_eq!(
serai.get_mint_events(block).await.unwrap(),
vec![TokensEvent::Mint { address, balance }],
);
assert_eq!(serai.get_token_supply(block, coin).await.unwrap(), amount);
assert_eq!(serai.get_token_balance(block, coin, address).await.unwrap(), amount);
let serai = serai.coins();
assert_eq!(serai.mint_events().await.unwrap(), vec![TokensEvent::Mint { address, balance }],);
assert_eq!(serai.token_supply(coin).await.unwrap(), amount);
assert_eq!(serai.token_balance(coin, address).await.unwrap(), amount);
}
);