Skip to content

Commit

Permalink
feat: use pending block for account deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Oct 3, 2023
1 parent 2b25eda commit f03f7d2
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 42 deletions.
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ serde = { version = "1.0.164", features = ["derive"] }
serde_json = { version = "1.0.99", features = ["preserve_order"] }
serde_with = "2.3.3"
shellexpand = "3.1.0"
starknet = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "f16271877c9dbf08bc7bf61e4fc72decc13ff73d" }
starknet = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "4ab2f36872435ce57b1d8f55856702a6a30f270a" }
tempfile = "3.8.0"
thiserror = "1.0.40"
tokio = { version = "1.28.2", default-features = false, features = ["macros", "rt-multi-thread"] }
Expand Down
16 changes: 15 additions & 1 deletion src/account_factory/braavos.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use async_trait::async_trait;
use starknet::{
accounts::{AccountFactory, PreparedAccountDeployment, RawAccountDeployment},
core::{crypto::compute_hash_on_elements, types::FieldElement},
core::{
crypto::compute_hash_on_elements,
types::{BlockId, BlockTag, FieldElement},
},
macros::selector,
providers::Provider,
signers::Signer,
Expand All @@ -15,6 +18,7 @@ pub struct BraavosAccountFactory<S, P> {
signer_public_key: FieldElement,
signer: S,
provider: P,
block_id: BlockId,
}

impl<S, P> BraavosAccountFactory<S, P>
Expand All @@ -38,8 +42,14 @@ where
signer_public_key: signer_public_key.scalar(),
signer,
provider,
block_id: BlockId::Tag(BlockTag::Latest),
})
}

pub fn set_block_id(&mut self, block_id: BlockId) -> &Self {
self.block_id = block_id;
self
}
}

#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
Expand Down Expand Up @@ -73,6 +83,10 @@ where
&self.provider
}

fn block_id(&self) -> BlockId {
self.block_id
}

async fn sign_deployment(
&self,
deployment: &RawAccountDeployment,
Expand Down
10 changes: 9 additions & 1 deletion src/account_factory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use starknet::{
accounts::{
AccountFactory, ArgentAccountFactory, OpenZeppelinAccountFactory, RawAccountDeployment,
},
core::types::FieldElement,
core::types::{BlockId, FieldElement},
providers::Provider,
signers::Signer,
};
Expand Down Expand Up @@ -59,6 +59,14 @@ where
}
}

fn block_id(&self) -> BlockId {
match self {
AnyAccountFactory::OpenZeppelin(inner) => inner.block_id(),
AnyAccountFactory::Argent(inner) => inner.block_id(),
AnyAccountFactory::Braavos(inner) => inner.block_id(),
}
}

async fn sign_deployment(
&self,
deployment: &RawAccountDeployment,
Expand Down
59 changes: 31 additions & 28 deletions src/subcommands/account/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use clap::Parser;
use colored::Colorize;
use starknet::{
accounts::{AccountFactory, ArgentAccountFactory, OpenZeppelinAccountFactory},
core::types::FieldElement,
core::types::{BlockId, BlockTag, FieldElement},
providers::Provider,
signers::Signer,
};
Expand Down Expand Up @@ -89,15 +89,16 @@ impl Deploy {
);
}

AnyAccountFactory::OpenZeppelin(
OpenZeppelinAccountFactory::new(
undeployed_status.class_hash,
chain_id,
signer.clone(),
provider.clone(),
)
.await?,
let mut factory = OpenZeppelinAccountFactory::new(
undeployed_status.class_hash,
chain_id,
signer.clone(),
provider.clone(),
)
.await?;
factory.set_block_id(BlockId::Tag(BlockTag::Pending));

AnyAccountFactory::OpenZeppelin(factory)
}
AccountVariant::Argent(argent_config) => {
// It's probably not worth it to continue to support legacy account deployment.
Expand All @@ -117,16 +118,17 @@ impl Deploy {
);
}

AnyAccountFactory::Argent(
ArgentAccountFactory::new(
undeployed_status.class_hash,
chain_id,
FieldElement::ZERO,
signer.clone(),
provider.clone(),
)
.await?,
let mut factory = ArgentAccountFactory::new(
undeployed_status.class_hash,
chain_id,
FieldElement::ZERO,
signer.clone(),
provider.clone(),
)
.await?;
factory.set_block_id(BlockId::Tag(BlockTag::Pending));

AnyAccountFactory::Argent(factory)
}
AccountVariant::Braavos(braavos_config) => {
if !matches!(braavos_config.multisig, BraavosMultisigConfig::Off) {
Expand All @@ -151,17 +153,18 @@ impl Deploy {
);
}

AnyAccountFactory::Braavos(
BraavosAccountFactory::new(
undeployed_status.class_hash,
context.mock_implementation,
braavos_config.implementation,
chain_id,
signer.clone(),
provider.clone(),
)
.await?,
let mut factory = BraavosAccountFactory::new(
undeployed_status.class_hash,
context.mock_implementation,
braavos_config.implementation,
chain_id,
signer.clone(),
provider.clone(),
)
.await?;
factory.set_block_id(BlockId::Tag(BlockTag::Pending));

AnyAccountFactory::Braavos(factory)
} // Reject other variants as we add more types
}
}
Expand Down

0 comments on commit f03f7d2

Please sign in to comment.