pop_contracts/utils/
map_account.rs1use crate::{DefaultEnvironment, errors::Error};
4use contract_extrinsics::{ExtrinsicOpts, MapAccountCommandBuilder, MapAccountExec};
5use pop_common::{DefaultConfig, Keypair};
6use subxt::{ext::scale_encode::EncodeAsType, utils::H160};
7
8pub struct AccountMapper {
10 map_exec: MapAccountExec<DefaultConfig, DefaultEnvironment, Keypair>,
11}
12
13impl AccountMapper {
14 pub async fn new(
19 extrinsic_opts: &ExtrinsicOpts<DefaultConfig, DefaultEnvironment, Keypair>,
20 ) -> Result<Self, Error> {
21 let map_exec = MapAccountCommandBuilder::new(extrinsic_opts.clone()).done().await?;
22 Ok(Self { map_exec })
23 }
24
25 pub async fn needs_mapping(&self) -> Result<bool, Error> {
27 Ok(self.map_exec.map_account_dry_run().await.is_ok())
28 }
29
30 pub async fn map_account(&self) -> Result<H160, Error> {
32 let result = self
33 .map_exec
34 .map_account()
35 .await
36 .map_err(|e| Error::MapAccountError(e.to_string()))?;
37 Ok(result.address)
38 }
39}
40
41#[derive(Debug, EncodeAsType)]
43#[encode_as_type(crate_path = "subxt::ext::scale_encode")]
44pub(crate) struct MapAccount {}
45
46impl MapAccount {
47 pub(crate) fn new() -> Self {
49 Self {}
50 }
51 pub(crate) fn build(self) -> subxt::tx::DefaultPayload<Self> {
53 subxt::tx::DefaultPayload::new("Revive", "map_account", self)
54 }
55}