Skip to content

Commit

Permalink
fix: signature validation starknet rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Dec 15, 2023
1 parent c32a894 commit eeef9ae
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 136 deletions.
149 changes: 25 additions & 124 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 @@ -14,7 +14,7 @@ torii-grpc = { git = "https://github.com/dojoengine/dojo", features = [
] }

parking_lot = "0.12.1"
starknet = "0.6.0"
starknet = "0.8.0"
starknet-crypto = "0.6.0"
tokio = { version = "1.32.0", features = [ "full" ] }
url = "2.5.0"
Expand Down
2 changes: 1 addition & 1 deletion dojo.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ typedef struct CArray_Model {
} CArray_Model;

typedef struct Entity {
struct FieldElement key;
struct FieldElement id;
struct CArray_Model models;
} Entity;

Expand Down
17 changes: 14 additions & 3 deletions example/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main()

const char *playerKey = "0x028cd7ee02d7f6ec9810e75b930e8e607793b302445abbdee0ac88143f18da20";
const char *playerAddress = "0x0517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973";
const char *world = "0x05010c31f127114c6198df8a5239e2b7a5151e1156fb43791e37e7385faa8138";
const char *world = "0x033ac2f528bb97cc7b79148fd1756dc368be0e95d391d8c6d6473ecb60b4560e";
// Initialize world.data here...

KeysClause entities[1] = {};
Expand Down Expand Up @@ -122,6 +122,11 @@ int main()
Query query = {};
query.limit = 100;
query.clause.tag = None_Clause;
query.clause.some.tag = Keys;
query.clause.some.keys.keys.data = malloc(sizeof(char *));
query.clause.some.keys.keys.data_len = 1;
query.clause.some.keys.keys.data[0] = playerAddress;
query.clause.some.keys.model = "Moves";
Result_CArray_Entity resEntities = client_entities(client, &query);
if (resEntities.tag == Err_CArray_Entity)
{
Expand All @@ -137,9 +142,15 @@ int main()
printf("Key: 0x");
for (size_t j = 0; j < 32; j++)
{
printf("%02x", fetchedEntities.data[i].key.data[j]);
printf("%02x", fetchedEntities.data[i].id.data[j]);
}
printf("\n");

// print models name
for (size_t j = 0; j < fetchedEntities.data[i].models.data_len; j++)
{
printf("Model: %s\n", fetchedEntities.data[i].models.data[j].name);
}
}


Expand Down Expand Up @@ -175,7 +186,7 @@ int main()
}

Call call = {
.to = "0x031571485922572446df9e3198a891e10d3a48e544544317dbcbb667e15848cd",
.to = "0x0152dcff993befafe5001975149d2c50bd9621da7cbaed74f68e7d5e54e65abc",
.selector = "spawn",
};

Expand Down
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ pub unsafe extern "C" fn client_on_sync_model_update(
let model: torii_grpc::types::KeysClause = (&model).into();
let storage = (*client).inner.storage();

println!("model: {:?}", model);

let rcv = storage.add_listener(
cairo_short_string_to_felt(model.model.as_str()).unwrap(),
model.keys.as_slice(),
Expand Down Expand Up @@ -227,7 +225,7 @@ pub unsafe extern "C" fn client_on_entity_state_update(

(*client).runtime.spawn(async move {
while let Some(Ok(entity)) = rcv.next().await {
let key: types::FieldElement = (&entity.key).into();
let key: types::FieldElement = (&entity.id).into();
let models: Vec<Model> = entity.models.into_iter().map(|e| (&e).into()).collect();
callback(key, models.into());
}
Expand Down Expand Up @@ -412,7 +410,6 @@ pub unsafe extern "C" fn account_execute_raw(
.into_iter()
.map(|c| (&c).into())
.collect::<Vec<starknet::accounts::Call>>();

let call = (*account).0.execute(calldata);

let result = tokio::runtime::Runtime::new()
Expand Down
6 changes: 3 additions & 3 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ pub enum ValueType {
#[derive(Clone, Debug)]
#[repr(C)]
pub struct Entity {
pub key: FieldElement,
pub id: FieldElement,
pub models: CArray<Model>,
}

Expand All @@ -282,7 +282,7 @@ impl From<&Entity> for torii_grpc::types::schema::Entity {
let models = models.iter().map(|m| (&m.clone()).into()).collect();

torii_grpc::types::schema::Entity {
key: (&val.key.clone()).into(),
id: (&val.id.clone()).into(),
models,
}
}
Expand All @@ -297,7 +297,7 @@ impl From<&torii_grpc::types::schema::Entity> for Entity {
.collect::<Vec<Model>>();

Entity {
key: (&val.key.clone()).into(),
id: (&val.id.clone()).into(),
models: models.into(),
}
}
Expand Down

0 comments on commit eeef9ae

Please sign in to comment.