mirror of
https://github.com/serai-dex/serai.git
synced 2024-11-16 17:07:35 +00:00
Add SRI balanace/transfer functions to serai_client
This commit is contained in:
parent
22f3c9e58f
commit
37b6de9c0c
3 changed files with 27 additions and 2 deletions
|
@ -24,7 +24,7 @@ use subxt::{
|
|||
};
|
||||
|
||||
pub use serai_runtime::primitives;
|
||||
pub use primitives::{Signature, SeraiAddress};
|
||||
pub use primitives::{SeraiAddress, Signature, Amount};
|
||||
|
||||
pub use serai_runtime as runtime;
|
||||
use serai_runtime::{
|
||||
|
@ -306,6 +306,30 @@ impl Serai {
|
|||
// If we are to return something, it should be block included in and position within block
|
||||
self.0.rpc().submit_extrinsic(tx).await.map(|_| ()).map_err(SeraiError::RpcError)
|
||||
}
|
||||
|
||||
pub async fn get_sri_balance(
|
||||
&self,
|
||||
block: [u8; 32],
|
||||
address: SeraiAddress,
|
||||
) -> Result<u64, SeraiError> {
|
||||
let data: Option<
|
||||
serai_runtime::system::AccountInfo<u32, serai_runtime::balances::AccountData<u64>>,
|
||||
> = self.storage("System", "Account", Some(vec![scale_value(address)]), block).await?;
|
||||
Ok(data.map(|data| data.data.free).unwrap_or(0))
|
||||
}
|
||||
|
||||
pub fn transfer_sri(to: SeraiAddress, amount: Amount) -> Payload<Composite<()>> {
|
||||
Payload::new(
|
||||
"Balances",
|
||||
// TODO: Use transfer_allow_death?
|
||||
// TODO: Replace the Balances pallet with something much simpler
|
||||
"transfer",
|
||||
scale_composite(serai_runtime::balances::Call::<Runtime>::transfer {
|
||||
dest: to,
|
||||
value: amount.0,
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
|
@ -34,7 +34,7 @@ fn testnet_genesis(
|
|||
system: SystemConfig { code: wasm_binary.to_vec(), _config: PhantomData },
|
||||
|
||||
balances: BalancesConfig {
|
||||
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
|
||||
balances: endowed_accounts.into_iter().map(|k| (k, 1 << 60)).collect(),
|
||||
},
|
||||
transaction_payment: Default::default(),
|
||||
|
||||
|
|
|
@ -232,6 +232,7 @@ impl balances::Config for Runtime {
|
|||
|
||||
type DustRemoval = ();
|
||||
type ExistentialDeposit = ConstU64<1>;
|
||||
// TODO: What's the benefit to this?
|
||||
type AccountStore = System;
|
||||
type WeightInfo = balances::weights::SubstrateWeight<Runtime>;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue