Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump starknet-rs to 0.11.0 #66

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
280 changes: 252 additions & 28 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ slot = { path = "slot" }

anyhow = "1.0.75"
axum = "0.6"
katana-primitives = { git = "https://github.com/dojoengine/dojo", tag = "v0.7.0-alpha.3" }
graphql_client = "0.13.0"
hyper = "0.14.27"
tokio = { version = "1.18.2", features = ["full", "sync"] }
serde = "1"
serde_json = "1"
starknet = "0.10.0"
thiserror = "1.0.32"
url = "2.2.2"
rand = "0.8.4"

starknet = "0.11.0"
starknet-types-core = "~0.1.4"

[patch.crates-io]
# Remove this patch once the following PR is merged: <https://github.com/xJonathanLEI/starknet-rs/pull/615>
#
# To enable std feature on `starknet-types-core`.
# To re-export the entire `felt` module from `starknet-types-core`.
starknet-core = { git = "https://github.com/kariy/starknet-rs", branch = "dojo-patch" }
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dialoguer = "0.11.0"
env_logger = "0.10"
log = "0.4"
graphql_client.workspace = true
katana-primitives.workspace = true
katana-primitives = { git = "https://github.com/dojoengine/dojo", tag = "v0.7.0-alpha.3" }
hyper.workspace = true
tokio.workspace = true
thiserror.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions cli/src/command/auth/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::str::FromStr;
use anyhow::{anyhow, ensure, Result};
use clap::Parser;
use slot::session::{self, Policy};
use starknet::core::types::FieldElement;
use starknet::core::types::Felt;
use starknet::providers::{jsonrpc::HttpTransport, JsonRpcClient, Provider};
use url::Url;

Expand Down Expand Up @@ -35,15 +35,15 @@ fn parse_policy(value: &str) -> Result<Policy> {
let mut parts = value.split(',');

let target = parts.next().ok_or(anyhow!("missing target"))?.to_owned();
let target = FieldElement::from_str(&target)?;
let target = Felt::from_str(&target)?;
let method = parts.next().ok_or(anyhow!("missing method"))?.to_owned();

ensure!(parts.next().is_none(), " bruh");

Ok(Policy { target, method })
}

async fn get_network_chain_id(url: Url) -> Result<FieldElement> {
async fn get_network_chain_id(url: Url) -> Result<Felt> {
let provider = JsonRpcClient::new(HttpTransport::new(url));
Ok(provider.chain_id().await?)
}
23 changes: 17 additions & 6 deletions cli/src/command/deployments/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ use katana_primitives::genesis::allocation::{
DevAllocationsGenerator, DevGenesisAccount, GenesisAccount,
};
use katana_primitives::genesis::Genesis;
use katana_primitives::FieldElement;
use slot::graphql::deployments::katana_accounts::KatanaAccountsDeploymentConfig::KatanaConfig;
use slot::graphql::deployments::{katana_accounts::*, KatanaAccounts};
use slot::graphql::{GraphQLQuery, Response};
use starknet::core::types::FieldElement;
use starknet::core::types::Felt;

use slot::api::Client;
use slot::credential::Credentials;
Expand Down Expand Up @@ -51,13 +52,23 @@ impl AccountsArgs {
Some(accounts) => {
let mut accounts_vec = Vec::new();
for account in accounts {
// TODO(kariy): update these after updating katana-primitives
let address = ContractAddress::from(
FieldElement::from_hex_be(&account.address).unwrap(),
FieldElement::from_bytes_be(
&Felt::from_hex(&account.address).unwrap().to_bytes_be(),
)
.unwrap(),
);
let public_key =
FieldElement::from_hex_be(&account.public_key).unwrap();
let private_key =
FieldElement::from_hex_be(&account.private_key).unwrap();

let public_key = FieldElement::from_bytes_be(
&Felt::from_hex(&account.public_key).unwrap().to_bytes_be(),
)
.unwrap();
let private_key = FieldElement::from_bytes_be(
&Felt::from_hex(&account.private_key).unwrap().to_bytes_be(),
)
.unwrap();

let genesis_account = GenesisAccount {
public_key,
..GenesisAccount::default()
Expand Down
4 changes: 2 additions & 2 deletions cli/src/command/deployments/services/torii.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Args;
use starknet::core::types::FieldElement;
use starknet::core::types::Felt;

#[derive(Clone, Debug, Args, serde::Serialize)]
#[command(next_help_heading = "Torii create options")]
Expand All @@ -16,7 +16,7 @@ pub struct ToriiCreateArgs {
#[arg(long)]
#[arg(value_name = "world")]
#[arg(help = "World address.")]
pub world: FieldElement,
pub world: Felt,

#[arg(short, long)]
#[arg(help = "Specify a block to start indexing from.")]
Expand Down
4 changes: 2 additions & 2 deletions slot/src/account.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use starknet::core::serde::unsigned_field_element::UfeHex;
use starknet::core::types::FieldElement;
use starknet::core::types::Felt;

#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
Expand All @@ -10,7 +10,7 @@ pub struct Account {
pub name: Option<String>,
#[serde_as(as = "UfeHex")]
#[serde(rename = "contractAddress")]
pub contract_address: FieldElement,
pub contract_address: Felt,
pub credentials: AccountCredentials,
}

Expand Down
6 changes: 3 additions & 3 deletions slot/src/graphql/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::str::FromStr;

use graphql_client::GraphQLQuery;
use me::MeMe;
use starknet::core::types::{FieldElement, FromStrError};
use starknet::core::types::{Felt, FromStrError};

use crate::account::{Account, AccountCredentials, WebAuthnCredential};

Expand Down Expand Up @@ -38,7 +38,7 @@ impl TryFrom<MeMe> for Account {
id: value.id,
name: value.name,
credentials: value.credentials.try_into()?,
contract_address: FieldElement::from_str(&address)?,
contract_address: Felt::from_str(&address)?,
})
}
}
Expand Down Expand Up @@ -89,7 +89,7 @@ mod tests {

assert_eq!(account.id, "id");
assert_eq!(account.name, Some("name".to_string()));
assert_eq!(account.contract_address, FieldElement::ONE);
assert_eq!(account.contract_address, Felt::ONE);
assert_eq!(account.credentials.webauthn.len(), 1);
assert_eq!(account.credentials.webauthn[0].id, "id".to_string());
assert_eq!(
Expand Down
26 changes: 11 additions & 15 deletions slot/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use axum::response::{IntoResponse, Response};
use axum::{extract::State, routing::post, Json, Router};
use hyper::StatusCode;
use serde::{Deserialize, Serialize};
use starknet::core::types::FieldElement;
use starknet::core::types::Felt;
use tokio::sync::mpsc::{channel, Receiver, Sender};
use tower_http::cors::CorsLayer;
use tracing::info;
Expand All @@ -24,7 +24,7 @@ const SESSION_FILE_BASE_NAME: &str = "session.json";
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Policy {
/// The target contract address.
pub target: FieldElement,
pub target: Felt,
/// The method name.
pub method: String,
}
Expand All @@ -44,8 +44,8 @@ pub struct SessionDetails {
#[serde(rename_all = "camelCase")]
pub struct SessionCredentials {
/// The signing key of the session.
pub private_key: FieldElement,
pub authorization: Vec<FieldElement>,
pub private_key: Felt,
pub authorization: Vec<Felt>,
}

/// Retrieves the session for the given chain id of the currently authenticated user.
Expand All @@ -55,7 +55,7 @@ pub struct SessionCredentials {
///
/// This function will return an error if there is no authenticated user.
///
pub fn get(chain: FieldElement) -> Result<Option<SessionDetails>, Error> {
pub fn get(chain: Felt) -> Result<Option<SessionDetails>, Error> {
get_at(utils::config_dir(), chain)
}

Expand All @@ -65,7 +65,7 @@ pub fn get(chain: FieldElement) -> Result<Option<SessionDetails>, Error> {
///
/// This function will return an error if there is no authenticated user.
///
pub fn store(chain: FieldElement, session: &SessionDetails) -> Result<PathBuf, Error> {
pub fn store(chain: Felt, session: &SessionDetails) -> Result<PathBuf, Error> {
store_at(utils::config_dir(), chain, session)
}

Expand All @@ -92,7 +92,7 @@ where

/// Get the session token of the chain id `chain` for the currently authenticated user. It will
/// use `config_dir` as the root path to look for the session file.
fn get_at<P>(config_dir: P, chain: FieldElement) -> Result<Option<SessionDetails>, Error>
fn get_at<P>(config_dir: P, chain: Felt) -> Result<Option<SessionDetails>, Error>
where
P: AsRef<Path>,
{
Expand All @@ -113,11 +113,7 @@ where

/// Stores the session token of the chain id `chain` for the currently authenticated user. It will
/// use `config_dir` as the root path to store the session file.
fn store_at<P>(
config_dir: P,
chain: FieldElement,
session: &SessionDetails,
) -> Result<PathBuf, Error>
fn store_at<P>(config_dir: P, chain: Felt, session: &SessionDetails) -> Result<PathBuf, Error>
where
P: AsRef<Path>,
{
Expand Down Expand Up @@ -260,7 +256,7 @@ fn callback_server(result_sender: Sender<SessionDetails>) -> anyhow::Result<Loca
.with_shutdown_signal(shutdown_rx))
}

fn get_user_relative_file_path(username: &str, chain_id: FieldElement) -> PathBuf {
fn get_user_relative_file_path(username: &str, chain_id: Felt) -> PathBuf {
let file_name = format!("{chain_id:#x}-{}", SESSION_FILE_BASE_NAME);
PathBuf::from(username).join(file_name)
}
Expand All @@ -273,7 +269,7 @@ mod tests {
use crate::error::Error::Unauthorized;
use crate::session::{get_at, get_user_relative_file_path, store_at, SessionDetails};
use crate::utils;
use starknet::{core::types::FieldElement, macros::felt};
use starknet::{core::types::Felt, macros::felt};
use std::ffi::OsStr;
use std::path::{Component, Path};
use tokio::sync::mpsc::channel;
Expand Down Expand Up @@ -317,7 +313,7 @@ mod tests {

#[test]
fn get_session_unauthenticated() {
let chain = FieldElement::ONE;
let chain = Felt::ONE;
let err = get(chain).unwrap_err();
let Unauthorized = err else {
panic!("expected Unauthorized error, got {err:?}");
Expand Down
Loading