diff --git a/Cargo.lock b/Cargo.lock index 051bd7842..620d7952a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -698,9 +698,9 @@ checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" [[package]] name = "async-trait" -version = "0.1.72" +version = "0.1.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc6dde6e4ed435a4c1ee4e73592f5ba9da2151af10076cc04858746af9352d09" +checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", @@ -2673,7 +2673,7 @@ dependencies = [ "fuel-indexer-database-types", "fuel-indexer-lib", "fuel-tx 0.35.3", - "fuels 0.45.0", + "fuels", "hex", "hyper-rustls 0.23.2", "indicatif", @@ -3340,7 +3340,7 @@ dependencies = [ "async-graphql-parser 5.0.10", "bincode", "clap 3.2.25", - "fuels 0.45.0", + "fuels", "http", "lazy_static", "proc-macro2", @@ -3379,9 +3379,9 @@ dependencies = [ "fuel-indexer-plugin", "fuel-indexer-schema", "fuel-indexer-types", - "fuels 0.45.0", - "fuels-code-gen 0.45.0 (registry+https://github.com/rust-lang/crates.io-index)", - "fuels-macros 0.45.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fuels", + "fuels-code-gen", + "fuels-macros", "lazy_static", "proc-macro-error", "proc-macro2", @@ -3462,7 +3462,7 @@ name = "fuel-indexer-test" version = "0.0.0" dependencies = [ "fuel-indexer-utils", - "fuels 0.45.0", + "fuels", "serde", ] @@ -3485,7 +3485,7 @@ dependencies = [ "fuel-indexer-schema", "fuel-indexer-types", "fuel-tx 0.35.3", - "fuels 0.45.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fuels", "futures", "hex", "hyper", @@ -3516,7 +3516,7 @@ dependencies = [ "fuel-indexer-lib", "fuel-tx 0.35.3", "fuel-types 0.35.3", - "fuels 0.45.0", + "fuels", "serde", "serde_json", "tai64", @@ -3566,7 +3566,7 @@ dependencies = [ "clap 3.2.25", "fuel-indexer-tests", "fuel-types 0.35.3", - "fuels 0.45.0", + "fuels", "tokio", ] @@ -3699,64 +3699,35 @@ dependencies = [ ] [[package]] -name = "fuels" -version = "0.45.0" +name = "fuel_explorer" +version = "0.0.0" dependencies = [ - "fuel-core-client", - "fuel-tx 0.35.3", - "fuels-accounts 0.45.0", - "fuels-core 0.45.0", - "fuels-macros 0.45.0", - "fuels-programs 0.45.0", - "fuels-test-helpers 0.45.0", + "fuel-indexer-utils", + "fuels", + "serde", ] [[package]] name = "fuels" -version = "0.45.0" +version = "0.45.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0a24ee9d2eee78b933bea2ca275e00a558111ffa37e32dc4dce060dc89b70b6" +checksum = "aa0d9fe01b4f234c07ef7d9e619ccb8d17e4a502af63f30a30a2097acab0dfdf" dependencies = [ "fuel-core", "fuel-core-client", "fuel-tx 0.35.3", - "fuels-accounts 0.45.0 (registry+https://github.com/rust-lang/crates.io-index)", - "fuels-core 0.45.0 (registry+https://github.com/rust-lang/crates.io-index)", - "fuels-macros 0.45.0 (registry+https://github.com/rust-lang/crates.io-index)", - "fuels-programs 0.45.0 (registry+https://github.com/rust-lang/crates.io-index)", - "fuels-test-helpers 0.45.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fuels-accounts", + "fuels-core", + "fuels-macros", + "fuels-programs", + "fuels-test-helpers", ] [[package]] name = "fuels-accounts" -version = "0.45.0" -dependencies = [ - "async-trait", - "bytes", - "chrono", - "elliptic-curve 0.13.5", - "eth-keystore", - "fuel-core-client", - "fuel-crypto 0.35.3", - "fuel-tx 0.35.3", - "fuel-types 0.35.3", - "fuel-vm 0.35.3", - "fuels-core 0.45.0", - "hex", - "itertools", - "rand", - "serde", - "sha2 0.10.7", - "tai64", - "thiserror", - "tokio", -] - -[[package]] -name = "fuels-accounts" -version = "0.45.0" +version = "0.45.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9556ba92649eda5e1a37d0b3f846e4ab03cc3f0b11106b371f48cf01799d1b95" +checksum = "5b8d03d520ea383743f78af6909ac5a04c805ad4eb1f03d99c80b0d4679a44f6" dependencies = [ "async-trait", "bytes", @@ -3768,7 +3739,7 @@ dependencies = [ "fuel-tx 0.35.3", "fuel-types 0.35.3", "fuel-vm 0.35.3", - "fuels-core 0.45.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fuels-core", "hex", "itertools", "rand", @@ -3781,23 +3752,9 @@ dependencies = [ [[package]] name = "fuels-code-gen" -version = "0.45.0" -dependencies = [ - "Inflector", - "fuel-abi-types 0.3.0", - "itertools", - "proc-macro2", - "quote", - "regex", - "serde_json", - "syn 2.0.28", -] - -[[package]] -name = "fuels-code-gen" -version = "0.45.0" +version = "0.45.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ac588c4ab7e8ff614c82e065f7fa42c972ee7114bd51619af28e827ee8d113a" +checksum = "a18b307990519c78c5c7661666a912c05915d1deed7bf4b577b50987fe97ae31" dependencies = [ "Inflector", "fuel-abi-types 0.3.0", @@ -3811,36 +3768,9 @@ dependencies = [ [[package]] name = "fuels-core" -version = "0.45.0" -dependencies = [ - "bech32 0.9.1", - "chrono", - "fuel-abi-types 0.3.0", - "fuel-asm 0.35.3", - "fuel-core-chain-config", - "fuel-core-client", - "fuel-tx 0.35.3", - "fuel-types 0.35.3", - "fuel-vm 0.35.3", - "fuels-macros 0.45.0", - "hex", - "itertools", - "proc-macro2", - "regex", - "serde", - "serde_json", - "sha2 0.10.7", - "strum", - "strum_macros 0.24.3", - "thiserror", - "uint", -] - -[[package]] -name = "fuels-core" -version = "0.45.0" +version = "0.45.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba9ed2470f4554a4ef46637589cfec5994826174e0541982d098d9e8339fd337" +checksum = "79566b388d8822c4c06aac60d9647dbb9393807cd5e6653cfa0c1630644da196" dependencies = [ "bech32 0.9.1", "chrono", @@ -3851,7 +3781,7 @@ dependencies = [ "fuel-tx 0.35.3", "fuel-types 0.35.3", "fuel-vm 0.35.3", - "fuels-macros 0.45.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fuels-macros", "hex", "itertools", "proc-macro2", @@ -3867,29 +3797,13 @@ dependencies = [ [[package]] name = "fuels-macros" -version = "0.45.0" -dependencies = [ - "Inflector", - "fuel-abi-types 0.3.0", - "fuels-code-gen 0.45.0", - "itertools", - "proc-macro2", - "quote", - "rand", - "regex", - "serde_json", - "syn 2.0.28", -] - -[[package]] -name = "fuels-macros" -version = "0.45.0" +version = "0.45.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a45842e7d90d899aaa282ea4b154c6fd385759e30b7df6a533a30772a55d33a" +checksum = "8c92232ef42b254a1649c6a6bfddd35b2c50f358b15e98e953eb82d69b397c57" dependencies = [ "Inflector", "fuel-abi-types 0.3.0", - "fuels-code-gen 0.45.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fuels-code-gen", "itertools", "proc-macro2", "quote", @@ -3901,35 +3815,9 @@ dependencies = [ [[package]] name = "fuels-programs" -version = "0.45.0" -dependencies = [ - "async-trait", - "bytes", - "fuel-abi-types 0.3.0", - "fuel-asm 0.35.3", - "fuel-tx 0.35.3", - "fuel-types 0.35.3", - "fuels-accounts 0.45.0", - "fuels-core 0.45.0", - "hex", - "itertools", - "proc-macro2", - "rand", - "regex", - "serde", - "serde_json", - "sha2 0.10.7", - "strum", - "strum_macros 0.24.3", - "thiserror", - "tokio", -] - -[[package]] -name = "fuels-programs" -version = "0.45.0" +version = "0.45.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6815775e3a9cd9fbfd80f3b53a6a3338510eef4f31e3f6885d45b5603496b00b" +checksum = "e1e4250bb73ff44cfdcd39f86c0e3163c11753e16583013fae698e9132400280" dependencies = [ "async-trait", "bytes", @@ -3937,8 +3825,8 @@ dependencies = [ "fuel-asm 0.35.3", "fuel-tx 0.35.3", "fuel-types 0.35.3", - "fuels-accounts 0.45.0 (registry+https://github.com/rust-lang/crates.io-index)", - "fuels-core 0.45.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fuels-accounts", + "fuels-core", "hex", "itertools", "proc-macro2", @@ -3955,32 +3843,9 @@ dependencies = [ [[package]] name = "fuels-test-helpers" -version = "0.45.0" -dependencies = [ - "fuel-core-chain-config", - "fuel-core-client", - "fuel-core-types", - "fuel-tx 0.35.3", - "fuel-types 0.35.3", - "fuels-accounts 0.45.0", - "fuels-core 0.45.0", - "futures", - "hex", - "portpicker", - "rand", - "serde", - "serde_json", - "serde_with 2.3.3", - "tempfile", - "tokio", - "which", -] - -[[package]] -name = "fuels-test-helpers" -version = "0.45.0" +version = "0.45.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32910f7aeed5fd5f8293aef233100e8224c992096f0310fe7ba8df0a1069a56e" +checksum = "4df1a046adf1862f5b1844800abed842c6748abb2dc94c8e0df43473e96c3f4d" dependencies = [ "fuel-core", "fuel-core-chain-config", @@ -3988,8 +3853,8 @@ dependencies = [ "fuel-core-types", "fuel-tx 0.35.3", "fuel-types 0.35.3", - "fuels-accounts 0.45.0 (registry+https://github.com/rust-lang/crates.io-index)", - "fuels-core 0.45.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fuels-accounts", + "fuels-core", "futures", "hex", "portpicker", @@ -4392,7 +4257,7 @@ dependencies = [ "fuel-indexer-tests", "fuel-tx 0.35.3", "fuel-types 0.35.3", - "fuels 0.45.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fuels", "rand", "thiserror", "tokio", @@ -4407,6 +4272,26 @@ dependencies = [ "tokio", ] +[[package]] +name = "hello_indexer" +version = "0.0.0" +dependencies = [ + "fuel-indexer-utils", + "fuels", + "serde", +] + +[[package]] +name = "hello_indexer_native" +version = "0.0.0" +dependencies = [ + "async-trait", + "fuel-indexer", + "fuel-indexer-utils", + "fuels", + "serde", +] + [[package]] name = "hermit-abi" version = "0.1.19" @@ -7437,18 +7322,18 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.44" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90" +checksum = "d9207952ae1a003f42d3d5e892dac3c6ba42aa6ac0c79a6a91a2b5cb4253e75c" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.44" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96" +checksum = "f1728216d3244de4f14f14f8c15c79be1a7c67867d28d69b719690e2a19fb445" dependencies = [ "proc-macro2", "quote", @@ -7540,9 +7425,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.30.0" +version = "1.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d3ce25f50619af8b0aec2eb23deebe84249e19e2ddd393a6e16e3300a6dadfd" +checksum = "40de3a2ba249dcb097e01be5e67a5ff53cf250397715a071a81543e8a832a920" dependencies = [ "backtrace", "bytes", diff --git a/Cargo.toml b/Cargo.toml index ae372828a..b3a6924e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,9 +2,9 @@ # Use the new resolver to prevent dev-deps and build-deps from enabling debugging or test features in production. resolver = "2" members = [ - # "examples/fuel-explorer/fuel-explorer", - # "examples/hello-world-native/hello-indexer-native", - # "examples/hello-world/hello-indexer", + "examples/fuel-explorer/fuel-explorer", + "examples/hello-world-native/hello-indexer-native", + "examples/hello-world/hello-indexer", "examples/hello-world/hello-world-data", "examples/hello-world/hello-world-node", "packages/fuel-indexer", @@ -86,7 +86,7 @@ fuel-indexer-utils = { version = "0.19.4", path = "./packages/fuel-indexer-utils fuel-tx = { version = "0.35", default-features = false } fuel-types = { version = "0.35", default-features = false, features = ["serde"] } fuel-vm = { version = "0.35", default-features = false } -fuels = { version = "0.45", path = "/Users/rashad/dev/repos/fuels-rs/packages/fuels", default-features = false } +fuels = { version = "0.45.1", default-features = false } serde = { version = "1.0", default-features = false, features = ["derive"] } serde_json = { version = "1.0", default-features = false } thiserror = "1.0" diff --git a/examples/fuel-explorer/fuel-explorer/src/lib.rs b/examples/fuel-explorer/fuel-explorer/src/lib.rs index e8a4da705..8f5220652 100644 --- a/examples/fuel-explorer/fuel-explorer/src/lib.rs +++ b/examples/fuel-explorer/fuel-explorer/src/lib.rs @@ -146,11 +146,7 @@ impl From for ContractIdFragment { fn from(hash: Bytes32) -> Self { // Since the ID will just be derived from the hash, rather than using `::new()`, // just manaully derived the ID, then use `::get_or_create()`. - Self { - id: id(hash), - hash, - } - .get_or_create() + Self { id: id(hash), hash }.get_or_create() } } @@ -170,11 +166,7 @@ impl From for BlockIdFragment { fn from(hash: Bytes32) -> Self { // Since the ID will just be derived from the hash, rather than using `::new()`, // just manaully derived the ID, then use `::get_or_create()`. - Self { - id: id(hash), - hash, - } - .get_or_create() + Self { id: id(hash), hash }.get_or_create() } } @@ -182,11 +174,7 @@ impl From for TransactionIdFragment { fn from(hash: Bytes32) -> Self { // Since the ID will just be derived from the hash, rather than using `::new()`, // just manaully derived the ID, then use `::get_or_create()`. - Self { - id: id(hash), - hash, - } - .get_or_create() + Self { id: id(hash), hash }.get_or_create() } } diff --git a/examples/hello-world-native/hello-indexer-native/src/main.rs b/examples/hello-world-native/hello-indexer-native/src/main.rs index 3ab771852..fa91d20db 100644 --- a/examples/hello-world-native/hello-indexer-native/src/main.rs +++ b/examples/hello-world-native/hello-indexer-native/src/main.rs @@ -30,9 +30,6 @@ mod hello_world_native { async fn index_logged_greeting(event: Greeting, block: BlockData) { info!("Handling {:?}.", event); - // We're using the `::new()` method to create a Greeter, which automatically - // generates an ID for the entity. Then, we use `::get_or_create()` to - // load the corresponding record from the database, if present. let greeter = Greeter::new( event.person.name.to_right_trimmed_str().into(), block.height.into(), @@ -42,27 +39,23 @@ mod hello_world_native { .get_or_create() .await; - // Here we show how you can use the Charfield type to store strings with - // length <= 255. The fuel-indexer-utils package contains a number of helpful - // functions for byte conversion, string manipulation, etc. let message = format!( "{} 👋, my name is {}", event.greeting.to_right_trimmed_str(), event.person.name.to_right_trimmed_str(), ); - let message_hash = first32_bytes_to_bytes32(&message); + let message_hash = bytes32(&message); let salutation = Salutation::new( message_hash, message, - greeter.id, + greeter.id.clone(), block.height.into(), block.height.into(), ) .get_or_create() .await; - // Finally, we save the entities to the database. greeter.save().await; salutation.save().await; } diff --git a/examples/hello-world/hello-indexer/src/lib.rs b/examples/hello-world/hello-indexer/src/lib.rs index 3db41d00a..6b1f19071 100644 --- a/examples/hello-world/hello-indexer/src/lib.rs +++ b/examples/hello-world/hello-indexer/src/lib.rs @@ -33,9 +33,6 @@ use fuel_indexer_utils::prelude::*; mod hello_world_indexer { fn index_logged_greeting(event: Greeting, block: BlockData) { - // We're using the `::new()` method to create a Greeter, which automatically - // generates an ID for the entity. Then, we use `::get_or_create()` to - // load the corresponding record from the database, if present. let greeter = Greeter::new( event.person.name.to_right_trimmed_str().into(), block.height, @@ -44,26 +41,22 @@ mod hello_world_indexer { ) .get_or_create(); - // Here we show how you can use the Charfield type to store strings with - // length <= 255. The fuel-indexer-utils package contains a number of helpful - // functions for byte conversion, string manipulation, etc. let message = format!( "{} 👋, my name is {}", event.greeting.to_right_trimmed_str(), event.person.name.to_right_trimmed_str(), ); - let message_hash = first32_bytes_to_bytes32(&message); + let message_hash = bytes32(&message); let salutation = Salutation::new( message_hash, message, - greeter.id, + greeter.id.clone(), block.height, block.height, ) .get_or_create(); - // Finally, we save the entities to the database. greeter.save(); salutation.save(); } diff --git a/packages/fuel-indexer-macros/src/decoder.rs b/packages/fuel-indexer-macros/src/decoder.rs index 7216a6df7..80215d9e8 100644 --- a/packages/fuel-indexer-macros/src/decoder.rs +++ b/packages/fuel-indexer-macros/src/decoder.rs @@ -845,7 +845,7 @@ impl From for TokenStream { unsafe { match &db { Some(d) => { - match d.lock().await.get_object(Self::TYPE_ID, id).await { + match d.lock().await.get_object(Self::TYPE_ID, id.to_string()).await { Some(bytes) => { let columns: Vec = bincode::deserialize(&bytes).expect("Failed to deserialize Vec for Entity::load."); let obj = Self::from_row(columns); diff --git a/packages/fuel-indexer-tests/tests/database.rs b/packages/fuel-indexer-tests/tests/database.rs index 227b47167..409d7f338 100644 --- a/packages/fuel-indexer-tests/tests/database.rs +++ b/packages/fuel-indexer-tests/tests/database.rs @@ -142,7 +142,7 @@ async fn generate_schema_then_load_schema_from_wasm_module(database_url: &str) { assert!(db.schema().contains_key(&key)); } - let object_id = 4; + let object_id = SizedAsciiString::new("0000000000000000000000000000000000000000000000000000000000000000".to_string()).unwrap(); let columns = vec![ FtColumn::ID(Some(object_id)), FtColumn::Address(Some(fuel_indexer_types::fuel::Address::from([0x04; 32]))), @@ -173,5 +173,5 @@ async fn generate_schema_then_load_schema_from_wasm_module(database_url: &str) { assert_eq!(obj, bytes); - assert_eq!(db.get_object(thing1_ty_id, 90).await, None); + assert_eq!(db.get_object(thing1_ty_id, SizedAsciiString::new("0000000000000000000000000000000000000000000000000000000000000001".to_string()).unwrap()).await, None); } diff --git a/packages/fuel-indexer-utils/src/utilities.rs b/packages/fuel-indexer-utils/src/utilities.rs index f1acb20ea..7b327fb3a 100644 --- a/packages/fuel-indexer-utils/src/utilities.rs +++ b/packages/fuel-indexer-utils/src/utilities.rs @@ -1,8 +1,17 @@ /// Utility functions for Fuel indexers. use fuel_indexer_plugin::prelude::sha256_digest; -use fuel_indexer_plugin::types::SizedAsciiString; +use fuel_indexer_plugin::types::{Bytes32, SizedAsciiString}; /// Returns the SHA256 hex digest of the input as a `SizedAsciiString`. pub fn id(data: impl AsRef<[u8]>) -> SizedAsciiString<64> { SizedAsciiString::<64>::new(sha256_digest(&data)).unwrap() } + +/// Converts a given input into a `Bytes32` object by taking the first 32 bytes +/// of the input's SHA256 hex digest. +pub fn bytes32(data: impl AsRef<[u8]>) -> Bytes32 { + let digest = sha256_digest(&data); + let mut result = [0u8; 32]; + result.copy_from_slice(&digest.as_bytes()[0..32]); + Bytes32::from(result) +}