Skip to content

Commit

Permalink
type update (keep-starknet-strange#26)
Browse files Browse the repository at this point in the history
* type update

* update SingleOwnerAccount to Arc

* update types with Arc

* fix clippy error
  • Loading branch information
byteZorvin authored Sep 18, 2024
1 parent f6c35c3 commit 91057c0
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 39 deletions.
28 changes: 14 additions & 14 deletions crates/l3/appchain-core-contract-client/src/clients/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,36 @@ use starknet_core::types::Felt;

use appchain_utils::LocalWalletSignerMiddleware;

pub struct StarknetCoreContractClient<'a> {
operator: Operator<'a>,
messaging: Messaging<'a>,
core_contract: CoreContract<'a>,
pub struct StarknetCoreContractClient {
operator: Operator,
messaging: Messaging,
core_contract: CoreContract,
}

impl<'a> StarknetCoreContractClient<'a> {
pub fn new(address: Felt, signer: &'a LocalWalletSignerMiddleware) -> Self {
impl StarknetCoreContractClient {
pub fn new(address: Felt, signer: LocalWalletSignerMiddleware) -> Self {
Self {
operator: Operator::new(address, signer),
messaging: Messaging::new(address, signer),
operator: Operator::new(address, signer.clone()),
messaging: Messaging::new(address, signer.clone()),
core_contract: CoreContract::new(address, signer),
}
}
}

impl<'a> AsRef<Operator<'a>> for StarknetCoreContractClient<'a> {
fn as_ref(&self) -> &Operator<'a> {
impl AsRef<Operator> for StarknetCoreContractClient {
fn as_ref(&self) -> &Operator {
&self.operator
}
}

impl<'a> AsRef<Messaging<'a>> for StarknetCoreContractClient<'a> {
fn as_ref(&self) -> &Messaging<'a> {
impl AsRef<Messaging> for StarknetCoreContractClient {
fn as_ref(&self) -> &Messaging {
&self.messaging
}
}

impl<'a> AsRef<CoreContract<'a>> for StarknetCoreContractClient<'a> {
fn as_ref(&self) -> &CoreContract<'a> {
impl AsRef<CoreContract> for StarknetCoreContractClient {
fn as_ref(&self) -> &CoreContract {
&self.core_contract
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use appchain_utils::LocalWalletSignerMiddleware;
use color_eyre::Result;
use starknet_core::types::{Felt, InvokeTransactionResult};

pub struct CoreContract<'a> {
signer: &'a LocalWalletSignerMiddleware,
pub struct CoreContract {
signer: LocalWalletSignerMiddleware,
address: Felt,
}

impl<'a> CoreContract<'a> {
pub fn new(address: Felt, signer: &'a LocalWalletSignerMiddleware) -> Self {
impl CoreContract {
pub fn new(address: Felt, signer: LocalWalletSignerMiddleware) -> Self {
Self { signer, address }
}

Expand All @@ -24,6 +24,6 @@ impl<'a> CoreContract<'a> {
calldata.push(onchain_data_hash);
calldata.push(onchain_data_size);

invoke_contract(self.signer, self.address, "update_state", calldata).await
invoke_contract(&self.signer, self.address, "update_state", calldata).await
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use appchain_utils::LocalWalletSignerMiddleware;
use color_eyre::Result;
use starknet_core::types::{Felt, InvokeTransactionResult};

pub struct Messaging<'a> {
signer: &'a LocalWalletSignerMiddleware,
pub struct Messaging {
signer: LocalWalletSignerMiddleware,
address: Felt,
}

impl<'a> Messaging<'a> {
pub fn new(address: Felt, signer: &'a LocalWalletSignerMiddleware) -> Self {
impl Messaging {
pub fn new(address: Felt, signer: LocalWalletSignerMiddleware) -> Self {
Self { signer, address }
}

Expand All @@ -25,7 +25,7 @@ impl<'a> Messaging<'a> {
calldata.extend(payload);

invoke_contract(
self.signer,
&self.signer,
self.address,
"send_message_to_appchain",
calldata,
Expand All @@ -43,7 +43,7 @@ impl<'a> Messaging<'a> {
calldata.extend(payload);

invoke_contract(
self.signer,
&self.signer,
self.address,
"consume_message_from_appchain",
calldata,
Expand All @@ -65,7 +65,7 @@ impl<'a> Messaging<'a> {
calldata.extend(payload);

invoke_contract(
self.signer,
&self.signer,
self.address,
"start_message_cancellation",
calldata,
Expand All @@ -86,6 +86,6 @@ impl<'a> Messaging<'a> {
calldata.push(nonce);
calldata.extend(payload);

invoke_contract(self.signer, self.address, "cancel_message", calldata).await
invoke_contract(&self.signer, self.address, "cancel_message", calldata).await
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use starknet_accounts::ConnectedAccount;
use starknet_core::types::{Felt, InvokeTransactionResult};
use starknet_providers::jsonrpc::{HttpTransport, JsonRpcClient};

pub struct Operator<'a> {
signer: &'a LocalWalletSignerMiddleware,
pub struct Operator {
signer: LocalWalletSignerMiddleware,
address: Felt,
}

impl<'a> Operator<'a> {
pub fn new(address: Felt, signer: &'a LocalWalletSignerMiddleware) -> Self {
impl Operator {
pub fn new(address: Felt, signer: LocalWalletSignerMiddleware) -> Self {
Self { signer, address }
}

Expand All @@ -21,7 +21,7 @@ impl<'a> Operator<'a> {

pub async fn register_operator(&self, new_operator: Felt) -> Result<InvokeTransactionResult> {
invoke_contract(
self.signer,
&self.signer,
self.address,
"register_operator",
vec![new_operator],
Expand All @@ -34,7 +34,7 @@ impl<'a> Operator<'a> {
removed_operator: Felt,
) -> Result<InvokeTransactionResult> {
invoke_contract(
self.signer,
&self.signer,
self.address,
"unregister_operator",
vec![removed_operator],
Expand All @@ -58,7 +58,7 @@ impl<'a> Operator<'a> {
config_hash: Felt,
) -> Result<InvokeTransactionResult> {
invoke_contract(
self.signer,
&self.signer,
self.address,
"set_program_info",
vec![program_hash, config_hash],
Expand All @@ -81,7 +81,7 @@ impl<'a> Operator<'a> {
facts_registry: Felt,
) -> Result<InvokeTransactionResult> {
invoke_contract(
self.signer,
&self.signer,
self.address,
"set_facts_registry",
vec![facts_registry],
Expand Down
6 changes: 3 additions & 3 deletions crates/l3/appchain-core-contract-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use std::path::Path;
// TODO: check for proxy contract implementation

pub async fn deploy_starknet_core_contract<'a>(
signer: &'a LocalWalletSignerMiddleware,
signer: LocalWalletSignerMiddleware,
path_to_sierra: &Path,
path_to_casm: &Path,
) -> Result<StarknetCoreContractClient<'a>> {
) -> Result<StarknetCoreContractClient> {
let contract_address =
deploy_contract(signer, path_to_sierra, path_to_casm, NO_CONSTRUCTOR_ARG).await?;
deploy_contract(&signer, path_to_sierra, path_to_casm, NO_CONSTRUCTOR_ARG).await?;

Ok(StarknetCoreContractClient::new(contract_address, signer))
}
4 changes: 3 additions & 1 deletion crates/l3/appchain-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod errors;

use std::sync::Arc;

use color_eyre::{eyre::eyre, Result};
use starknet_accounts::{Account, Call, ExecutionV1, SingleOwnerAccount};
use starknet_contract::ContractFactory;
Expand All @@ -13,7 +15,7 @@ use starknet_signers::LocalWallet;
use std::path::Path;

pub type LocalWalletSignerMiddleware =
SingleOwnerAccount<JsonRpcClient<HttpTransport>, LocalWallet>;
Arc<SingleOwnerAccount<Arc<JsonRpcClient<HttpTransport>>, LocalWallet>>;

type RpcAccount<'a> = SingleOwnerAccount<&'a JsonRpcClient<HttpTransport>, LocalWallet>;
pub type TransactionExecution<'a> = ExecutionV1<'a, RpcAccount<'a>>;
Expand Down

0 comments on commit 91057c0

Please sign in to comment.