From 27538fcd20b13178040d49aa63e5fafab000d5e1 Mon Sep 17 00:00:00 2001 From: rashad Date: Tue, 5 Sep 2023 15:56:00 -0400 Subject: [PATCH] chore: update columntypes (#1333) Co-authored-by: Rashad Alston --- Cargo.lock | 85 +------ docs/src/data-types/types.md | 6 +- docs/src/project-components/schema.md | 10 +- .../schema/fuel_explorer.schema.graphql | 174 ++++++------- .../schema/hello_indexer.schema.graphql | 8 +- .../benches/graphql.rs | 4 +- .../database-types/src/lib.rs | 112 ++++----- packages/fuel-indexer-graphql-dyn/Cargo.toml | 4 +- packages/fuel-indexer-graphql/Cargo.toml | 6 +- packages/fuel-indexer-graphql/src/dynamic.rs | 28 +-- packages/fuel-indexer-graphql/src/graphql.rs | 2 +- packages/fuel-indexer-lib/src/constants.rs | 229 ++++++++++++++++++ .../fuel-indexer-lib/src/graphql/base.graphql | 12 +- .../fuel-indexer-lib/src/graphql/constants.rs | 12 +- .../fuel-indexer-lib/src/graphql/parser.rs | 4 +- packages/fuel-indexer-macros/Cargo.toml | 4 +- packages/fuel-indexer-macros/src/constants.rs | 12 +- packages/fuel-indexer-macros/src/decoder.rs | 8 +- packages/fuel-indexer-schema/Cargo.toml | 2 +- packages/fuel-indexer-schema/src/lib.rs | 44 ++-- .../schema/fuel_indexer_test.graphql | 78 +++--- packages/fuel-indexer-types/src/graphql.rs | 4 +- packages/fuel-indexer-types/src/scalar.rs | 12 +- plugins/forc-index/src/defaults.rs | 2 +- 24 files changed, 509 insertions(+), 353 deletions(-) create mode 100644 packages/fuel-indexer-lib/src/constants.rs diff --git a/Cargo.lock b/Cargo.lock index f7e80659d..03e949fa6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -488,39 +488,6 @@ dependencies = [ "tracing-futures", ] -[[package]] -name = "async-graphql" -version = "5.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b35ef8f9be23ee30fe1eb1cf175c689bc33517c6c6d0fd0669dade611e5ced7f" -dependencies = [ - "async-graphql-derive 5.0.10", - "async-graphql-parser 5.0.10", - "async-graphql-value 5.0.10", - "async-stream", - "async-trait", - "base64 0.13.1", - "bytes", - "fast_chemail", - "fnv", - "futures-util", - "handlebars", - "http", - "indexmap 1.9.3", - "mime", - "multer", - "num-traits", - "once_cell", - "pin-project-lite", - "regex", - "serde", - "serde_json", - "serde_urlencoded", - "static_assertions", - "tempfile", - "thiserror", -] - [[package]] name = "async-graphql" version = "6.0.4" @@ -591,22 +558,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "async-graphql-derive" -version = "5.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a0f6ceed3640b4825424da70a5107e79d48d9b2bc6318dfc666b2fc4777f8c4" -dependencies = [ - "Inflector", - "async-graphql-parser 5.0.10", - "darling 0.14.4", - "proc-macro-crate", - "proc-macro2", - "quote", - "syn 1.0.109", - "thiserror", -] - [[package]] name = "async-graphql-derive" version = "6.0.4" @@ -636,18 +587,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "async-graphql-parser" -version = "5.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc308cd3bc611ee86c9cf19182d2b5ee583da40761970e41207f088be3db18f" -dependencies = [ - "async-graphql-value 5.0.10", - "pest", - "serde", - "serde_json", -] - [[package]] name = "async-graphql-parser" version = "6.0.4" @@ -672,18 +611,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "async-graphql-value" -version = "5.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d461325bfb04058070712296601dfe5e5bd6cdff84780a0a8c569ffb15c87eb3" -dependencies = [ - "bytes", - "indexmap 1.9.3", - "serde", - "serde_json", -] - [[package]] name = "async-graphql-value" version = "6.0.4" @@ -3397,9 +3324,9 @@ dependencies = [ name = "fuel-indexer-graphql" version = "0.20.5" dependencies = [ - "async-graphql 5.0.10", - "async-graphql-parser 5.0.10", - "async-graphql-value 5.0.10", + "async-graphql 6.0.4", + "async-graphql-parser 6.0.4", + "async-graphql-value 6.0.4", "fuel-indexer-database", "fuel-indexer-database-types", "fuel-indexer-lib", @@ -3473,8 +3400,8 @@ dependencies = [ name = "fuel-indexer-macros" version = "0.20.5" dependencies = [ - "async-graphql-parser 5.0.10", - "async-graphql-value 5.0.10", + "async-graphql-parser 6.0.4", + "async-graphql-value 6.0.4", "fuel-abi-types 0.3.0", "fuel-indexer-database-types", "fuel-indexer-lib", @@ -3543,7 +3470,7 @@ dependencies = [ name = "fuel-indexer-schema" version = "0.20.5" dependencies = [ - "async-graphql-parser 5.0.10", + "async-graphql-parser 6.0.4", "fuel-indexer-database", "fuel-indexer-lib", "fuel-indexer-types", diff --git a/docs/src/data-types/types.md b/docs/src/data-types/types.md index 2dca9a3d3..069cf5671 100644 --- a/docs/src/data-types/types.md +++ b/docs/src/data-types/types.md @@ -15,9 +15,9 @@ Below is a mapping of GraphQL schema types to their Sway and database equivalent | str[32] | AssetId | varchar(64) | | str[32] | MessageId | varchar(64) | | str[32] | Salt | varchar(64) | -| u32 | UInt4 | integer | +| u32 | U32 | integer | | u64 | ID | bigint primary key | -| u64 | UInt8 | bigint | +| u64 | U64 | bigint | | | Json | json | | | Charfield | varchar(255) | | | Blob | varchar(10485760) | @@ -40,7 +40,7 @@ The corresponding GraphQL schema to mirror this `Event` struct would resemble: type Event @entity { id: ID! account: Address! - block_height: UInt8! + block_height: U64! } ``` diff --git a/docs/src/project-components/schema.md b/docs/src/project-components/schema.md index ba3f1faa9..3a4edddaa 100644 --- a/docs/src/project-components/schema.md +++ b/docs/src/project-components/schema.md @@ -7,25 +7,25 @@ In its most basic form, a Fuel indexer GraphQL schema should have a `schema` def ```graphql type FirstThing @entity { id: ID! - value: UInt8! + value: U64! } type SecondThing @entity { id: ID! - optional_value: UInt8 + optional_value: U64 timestamp: Timestamp! } ``` -The types you see above (e.g., `ID`, `UInt8`, etc) are Fuel abstractions that were created to more seamlessly integrate with the Fuel VM and are not native to GraphQL. A deeper explanation on these +The types you see above (e.g., `ID`, `U64`, etc) are Fuel abstractions that were created to more seamlessly integrate with the Fuel VM and are not native to GraphQL. A deeper explanation on these types can be found in [the Types section](../data-types/types.md). > Important: It is up to developers to manage their own unique IDs for each type, meaning that a data structure's `ID` field needs to be manually generated prior to saving it to the database. This generation can be as simple or complex as you want in order to fit your particular situation; the only requirement is that the developer implement their own custom generation. ## Required and Optional Fields -Required fields are denoted with a `!` following its type; for example, the `value` field of the `FirstThing` type is a `UInt8` and is required to be present for the indexer to successfully persist the entity. If a certain piece of information is essential to your use case, then you should mark that field as required. +Required fields are denoted with a `!` following its type; for example, the `value` field of the `FirstThing` type is a `U64` and is required to be present for the indexer to successfully persist the entity. If a certain piece of information is essential to your use case, then you should mark that field as required. -In contrast, optional fields are not required to be present for the indexer to persist the entity in storage. You can denote an optional field by just using the type name; for example, the `optional_value` field of the `SecondThing` type is optional, and should be a `UInt8` if present. If it's possible that a value might not always exist in the data you wish to index, consider making that the corresponding field optional. In your indexer code, you will need to use the `Option` Rust type when assigning a value to an optional field; values that are present should be assigned after being wrapped in `Some(..)` while absent values should be assigned using `None`. +In contrast, optional fields are not required to be present for the indexer to persist the entity in storage. You can denote an optional field by just using the type name; for example, the `optional_value` field of the `SecondThing` type is optional, and should be a `U64` if present. If it's possible that a value might not always exist in the data you wish to index, consider making that the corresponding field optional. In your indexer code, you will need to use the `Option` Rust type when assigning a value to an optional field; values that are present should be assigned after being wrapped in `Some(..)` while absent values should be assigned using `None`. > Important: The `ID` field is _always_ required. An indexer **will** return an error if an optional value is used for the `ID` field. diff --git a/examples/fuel-explorer/fuel-explorer/schema/fuel_explorer.schema.graphql b/examples/fuel-explorer/fuel-explorer/schema/fuel_explorer.schema.graphql index 1650b44bf..b030a36e7 100644 --- a/examples/fuel-explorer/fuel-explorer/schema/fuel_explorer.schema.graphql +++ b/examples/fuel-explorer/fuel-explorer/schema/fuel_explorer.schema.graphql @@ -106,7 +106,7 @@ type Witness @entity(virtual: true) { type InstructionResult @entity(virtual: true) { reason: PanicReason! - instruction: UInt4! + instruction: U32! } type ProgramState @entity(virtual: true) { @@ -127,13 +127,13 @@ type TransactionIdFragment @entity { type UtxoId @entity { id: ID! tx_id: TxId! @indexed - output_index: UInt4! + output_index: U32! } type TxPointer @entity { id: ID! - block_height: UInt4! - tx_index: UInt8! + block_height: U32! + tx_index: U64! } type ContractIdFragment @entity { @@ -177,11 +177,11 @@ type InputCoin @entity { id: ID! utxo_id: UtxoId! @indexed owner: Address! @indexed - amount: UInt8! + amount: U64! asset_id: AssetId! @indexed tx_pointer: TxPointer! witness_index: Int8! - maturity: UInt4! + maturity: U32! predicate: HexString! predicate_data: HexString! label: InputLabel! @@ -203,7 +203,7 @@ type InputMessage @entity { id: ID! sender: Address! @indexed recipient: Address! @indexed - amount: UInt8! + amount: U64! nonce: Nonce! witness_index: Int8! data: HexString! @@ -226,27 +226,27 @@ type CallReceipt @entity(virtual: true) { # `recipient` has a different type of different `Reciept` members, so # we make it something more generic: `Identity`. recipient: Identity! - amount: UInt8! + amount: U64! asset_id: AssetId! - gas: UInt8! - param1: UInt8! - param2: UInt8! - pc: UInt8! + gas: U64! + param1: U64! + param2: U64! + pc: U64! # `is` is a reserved keyword in PostgreSQL. - isr: UInt8! + isr: U64! label: ReceiptLabel! is_call: Boolean! } type ReturnDataReceipt @entity(virtual: true) { contract_id: ContractId! - ptr: UInt8! - len: UInt8! + ptr: U64! + len: U64! digest: Bytes32! data: Blob - pc: UInt8! + pc: U64! # `is` is a reserved keyword in PostgreSQL. - isr: UInt8! + isr: U64! label: ReceiptLabel! is_return_data: Boolean! } @@ -254,57 +254,57 @@ type ReturnDataReceipt @entity(virtual: true) { type PanicReceipt @entity(virtual: true) { contract_id: ContractId reason: InstructionResult - pc: UInt8! + pc: U64! # `is` is a reserved keyword in PostgreSQL. - isr: UInt8! + isr: U64! label: ReceiptLabel! is_panic: Boolean! } type RevertReceipt @entity(virtual: true) { contract_id: ContractId! - ra: UInt8! - pc: UInt8! + ra: U64! + pc: U64! # `is` is a reserved keyword in PostgreSQL. - isr: UInt8! + isr: U64! label: ReceiptLabel! is_revert: Boolean! } type LogReceipt @entity(virtual: true) { contract_id: ContractId! - ra: UInt8! - rb: UInt8! - rc: UInt8! - rd: UInt8! - pc: UInt8! + ra: U64! + rb: U64! + rc: U64! + rd: U64! + pc: U64! # `is` is a reserved keyword in PostgreSQL. - isr: UInt8! + isr: U64! label: ReceiptLabel! is_log: Boolean! } type LogDataReceipt @entity(virtual: true) { contract_id: ContractId! - ra: UInt8! - rb: UInt8! - ptr: UInt8! - len: UInt8! + ra: U64! + rb: U64! + ptr: U64! + len: U64! digest: Bytes32! data: Blob - pc: UInt8! + pc: U64! # `is` is a reserved keyword in PostgreSQL. - isr: UInt8! + isr: U64! label: ReceiptLabel! is_log_data: Boolean! } type ReturnReceipt @entity(virtual: true) { contract_id: ContractId! - val: UInt8! - pc: UInt8! + val: U64! + pc: U64! # `is` is a reserved keyword in PostgreSQL. - isr: UInt8! + isr: U64! label: ReceiptLabel! is_return: Boolean! } @@ -314,11 +314,11 @@ type TransferReceipt @entity(virtual: true) { # `recipient` has a different type of different `Reciept` members, so # we make it something more generic: `Identity`. recipient: Identity! - amount: UInt8! + amount: U64! asset_id: AssetId! - pc: UInt8! + pc: U64! # `is` is a reserved keyword in PostgreSQL. - isr: UInt8! + isr: U64! label: ReceiptLabel! is_transfer: Boolean! } @@ -328,18 +328,18 @@ type TransferOutReceipt @entity(virtual: true) { # `recipient` has a different type of different `Reciept` members, so # we make it something more generic: `Identity`. recipient: Identity! - amount: UInt8! + amount: U64! asset_id: AssetId! - pc: UInt8! + pc: U64! # `is` is a reserved keyword in PostgreSQL. - isr: UInt8! + isr: U64! label: ReceiptLabel! is_transfer_out: Boolean! } type ScriptResultReceipt @entity(virtual: true) { result: ScriptExecutionResult! - gas_used: UInt8! + gas_used: U64! label: ReceiptLabel! is_script_result: Boolean! } @@ -349,9 +349,9 @@ type MessageOutReceipt @entity(virtual: true) { # `recipient` has a different type of different `Reciept` members, so # we make it something more generic: `Identity`. recipient: Identity! - amount: UInt8! + amount: U64! nonce: Nonce! - len: UInt8! + len: U64! digest: Bytes32! data: Blob label: ReceiptLabel! @@ -375,7 +375,7 @@ type VariableOutput @entity { id: ID! # `to` is a reserved keyword in PostgreSQL. recipient: Address! @indexed - amount: UInt8! + amount: U64! asset_id: AssetId! @indexed is_variable: Boolean! label: OutputLabel! @@ -385,7 +385,7 @@ type ChangeOutput @entity { id: ID! # `to` is a reserved keyword in PostgreSQL. recipient: Address! @indexed - amount: UInt8! + amount: U64! asset_id: AssetId! @indexed is_change: Boolean! label: OutputLabel! @@ -404,7 +404,7 @@ type CoinOutput @entity { id: ID! # `to` is a reserved keyword in PostgreSQL. recipient: Address! @indexed - amount: UInt8! + amount: U64! asset_id: AssetId! @indexed is_coin: Boolean! label: OutputLabel! @@ -426,7 +426,7 @@ type ContractCreated @entity { type MessageOutput @entity { id: ID! - amount: UInt8! + amount: U64! recipient: Address! @indexed } @@ -443,11 +443,11 @@ union Output = # transaction type names. type CreateTransaction @entity { id: ID! - gas_price: UInt8! - gas_limit: UInt8! - maturity: UInt4! - bytecode_length: UInt8! - bytecode_witness_index: UInt1! + gas_price: U64! + gas_limit: U64! + maturity: U32! + bytecode_length: U64! + bytecode_witness_index: U8! storage_slots: [StorageSlot!] inputs: [Input!] outputs: [Output!] @@ -462,9 +462,9 @@ type CreateTransaction @entity { type ScriptTransaction @entity { id: ID! - gas_price: UInt8! - gas_limit: UInt8! - maturity: UInt4! + gas_price: U64! + gas_limit: U64! + maturity: U32! script: Blob! script_data: Blob! inputs: [Input!] @@ -493,7 +493,7 @@ union Transaction = CreateTransaction | ScriptTransaction | MintTransaction type SubmittedStatus @entity { id: ID! - time: UInt8! + time: U64! label: TransactionStatusLabel! is_submitted: Boolean! } @@ -508,7 +508,7 @@ type SqueezedOutStatus @entity { type FailureStatus @entity { id: ID! block: BlockIdFragment! - time: UInt8! + time: U64! reason: Charfield! program_state: ProgramState label: TransactionStatusLabel! @@ -517,7 +517,7 @@ type FailureStatus @entity { type SuccessStatus @entity { id: ID! - time: UInt8! + time: U64! block: BlockIdFragment! program_state: ProgramState label: TransactionStatusLabel! @@ -540,12 +540,12 @@ union TransactionStatus = type Header @entity { id: ID! block_id: BlockId! - da_height: UInt8! - transactions_count: UInt8! - message_receipt_count: UInt8! + da_height: U64! + transactions_count: U64! + message_receipt_count: U64! transactions_root: Bytes32! message_receipt_root: Bytes32! - height: UInt4! + height: U32! prev_root: Bytes32! time: Int8! application_hash: Bytes32! @@ -563,32 +563,32 @@ type NodeInfo @entity { id: ID! utxo_validation: Boolean! vm_backtrace: Boolean! - min_gas_price: UInt8! - max_tx: UInt8! - max_depth: UInt8! + min_gas_price: U64! + max_tx: U64! + max_depth: U64! node_version: Charfield! } type ConsensusParameters @entity { id: ID! - contract_max_size: UInt8! - max_inputs: UInt8! - max_outputs: UInt8! - max_witnesses: UInt8! - max_gas_per_tx: UInt8! - max_script_length: UInt8! - max_script_data_length: UInt8! - max_storage_slots: UInt8! - max_predicate_length: UInt8! - gas_price_factor: UInt8! - gas_per_byte: UInt8! - max_message_data_length: UInt8! - chain_id: UInt8! + contract_max_size: U64! + max_inputs: U64! + max_outputs: U64! + max_witnesses: U64! + max_gas_per_tx: U64! + max_script_length: U64! + max_script_data_length: U64! + max_storage_slots: U64! + max_predicate_length: U64! + gas_price_factor: U64! + gas_per_byte: U64! + max_message_data_length: U64! + chain_id: U64! } type ChainInfo @entity { id: ID! - base_chain_height: UInt4! + base_chain_height: U32! name: Charfield! peer_count: Int4! latest_block: Block! @@ -597,21 +597,21 @@ type ChainInfo @entity { type Coin @entity { id: ID! - amount: UInt8! - block_created: UInt4! + amount: U64! + block_created: U32! asset_id: AssetId! @indexed utxo_id: UtxoId! @indexed - maturity: UInt4! + maturity: U32! owner: Address! @indexed } type MessageCoin @entity { id: ID! - amount: UInt8! + amount: U64! sender: Address! @indexed recipient: Address! @indexed nonce: Nonce! - da_height: UInt8! + da_height: U64! } type Contract @entity { diff --git a/examples/hello-world/hello-indexer/schema/hello_indexer.schema.graphql b/examples/hello-world/hello-indexer/schema/hello_indexer.schema.graphql index 8e6997378..b8d0f4b87 100644 --- a/examples/hello-world/hello-indexer/schema/hello_indexer.schema.graphql +++ b/examples/hello-world/hello-indexer/schema/hello_indexer.schema.graphql @@ -2,8 +2,8 @@ type Greeter @entity { id: ID! name: Charfield! - first_seen: UInt4! - last_seen: UInt4! + first_seen: U32! + last_seen: U32! visits: Blob! } @@ -13,6 +13,6 @@ type Salutation @entity { message_hash: Bytes32! message: Charfield! greeter: Greeter! - first_seen: UInt4! - last_seen: UInt4! + first_seen: U32! + last_seen: U32! } diff --git a/packages/fuel-indexer-benchmarks/benches/graphql.rs b/packages/fuel-indexer-benchmarks/benches/graphql.rs index 0cd46b7b0..9ef9015f2 100644 --- a/packages/fuel-indexer-benchmarks/benches/graphql.rs +++ b/packages/fuel-indexer-benchmarks/benches/graphql.rs @@ -9,7 +9,7 @@ fn build_and_parse_query(c: &mut Criterion) { b.iter(|| { let schema_str = r#"type Block { id: ID! - height: UInt8! + height: U64! hash: Bytes32! @unique } @@ -44,7 +44,7 @@ fn build_and_parse_query_with_args(c: &mut Criterion) { b.iter(|| { let schema_str = r#"type Block { id: ID! - height: UInt8! + height: U64! hash: Bytes32! @unique } diff --git a/packages/fuel-indexer-database/database-types/src/lib.rs b/packages/fuel-indexer-database/database-types/src/lib.rs index c532f5b62..82dd08492 100644 --- a/packages/fuel-indexer-database/database-types/src/lib.rs +++ b/packages/fuel-indexer-database/database-types/src/lib.rs @@ -58,8 +58,8 @@ pub enum ColumnType { Salt = 7, Int4 = 8, Int8 = 9, - UInt4 = 10, - UInt8 = 11, + U32 = 10, + U64 = 11, Timestamp = 12, Blob = 13, ForeignKey = 14, @@ -69,8 +69,8 @@ pub enum ColumnType { Identity = 18, Boolean = 19, Object = 20, - UInt16 = 21, - Int16 = 22, + U128 = 21, + I128 = 22, Bytes64 = 23, Signature = 24, Nonce = 25, @@ -79,8 +79,8 @@ pub enum ColumnType { TxId = 28, BlockHeight = 29, Enum = 30, - Int1 = 31, - UInt1 = 32, + I8 = 31, + U8 = 32, Virtual = 33, BlockId = 34, Array = 35, @@ -103,8 +103,8 @@ impl From for i32 { ColumnType::Salt => 7, ColumnType::Int4 => 8, ColumnType::Int8 => 9, - ColumnType::UInt4 => 10, - ColumnType::UInt8 => 11, + ColumnType::U32 => 10, + ColumnType::U64 => 11, ColumnType::Timestamp => 12, ColumnType::Blob => 13, ColumnType::ForeignKey => 14, @@ -114,8 +114,8 @@ impl From for i32 { ColumnType::Identity => 18, ColumnType::Boolean => 19, ColumnType::Object => 20, - ColumnType::UInt16 => 21, - ColumnType::Int16 => 22, + ColumnType::U128 => 21, + ColumnType::I128 => 22, ColumnType::Bytes64 => 23, ColumnType::Signature => 24, ColumnType::Nonce => 25, @@ -124,8 +124,8 @@ impl From for i32 { ColumnType::TxId => 28, ColumnType::BlockHeight => 29, ColumnType::Enum => 30, - ColumnType::Int1 => 31, - ColumnType::UInt1 => 32, + ColumnType::I8 => 31, + ColumnType::U8 => 32, ColumnType::Virtual => 33, ColumnType::BlockId => 34, ColumnType::Array => 35, @@ -160,8 +160,8 @@ impl From for ColumnType { 7 => ColumnType::Salt, 8 => ColumnType::Int4, 9 => ColumnType::Int8, - 10 => ColumnType::UInt4, - 11 => ColumnType::UInt8, + 10 => ColumnType::U32, + 11 => ColumnType::U64, 12 => ColumnType::Timestamp, 13 => ColumnType::Blob, 14 => ColumnType::ForeignKey, @@ -171,8 +171,8 @@ impl From for ColumnType { 18 => ColumnType::Identity, 19 => ColumnType::Boolean, 20 => ColumnType::Object, - 21 => ColumnType::Int16, - 22 => ColumnType::UInt16, + 21 => ColumnType::I128, + 22 => ColumnType::U128, 23 => ColumnType::Bytes64, 24 => ColumnType::Signature, 25 => ColumnType::Nonce, @@ -181,8 +181,8 @@ impl From for ColumnType { 28 => ColumnType::TxId, 29 => ColumnType::BlockHeight, 30 => ColumnType::Enum, - 31 => ColumnType::Int1, - 32 => ColumnType::UInt1, + 31 => ColumnType::I8, + 32 => ColumnType::U8, 33 => ColumnType::Virtual, 34 => ColumnType::BlockId, 35 => ColumnType::Array, @@ -195,43 +195,43 @@ impl From for ColumnType { impl From<&str> for ColumnType { fn from(name: &str) -> ColumnType { match name { - "ID" => ColumnType::ID, "Address" => ColumnType::Address, + "Array" => ColumnType::Array, "AssetId" => ColumnType::AssetId, + "Blob" => ColumnType::Blob, + "BlockHeight" => ColumnType::BlockHeight, + "BlockId" => ColumnType::BlockId, + "Boolean" => ColumnType::Boolean, + "Bytes32" => ColumnType::Bytes32, "Bytes4" => ColumnType::Bytes4, + "Bytes64" => ColumnType::Bytes64, "Bytes8" => ColumnType::Bytes8, - "Bytes32" => ColumnType::Bytes32, + "Charfield" => ColumnType::Charfield, "ContractId" => ColumnType::ContractId, - "Salt" => ColumnType::Salt, + "Enum" => ColumnType::Enum, + "ForeignKey" => ColumnType::ForeignKey, + "HexString" => ColumnType::HexString, + "I128" => ColumnType::I128, + "I8" => ColumnType::I8, + "ID" => ColumnType::ID, + "Identity" => ColumnType::Identity, "Int4" => ColumnType::Int4, "Int8" => ColumnType::Int8, - "UInt4" => ColumnType::UInt4, - "UInt8" => ColumnType::UInt8, - "Timestamp" => ColumnType::Timestamp, - "Blob" => ColumnType::Blob, - "ForeignKey" => ColumnType::ForeignKey, "Json" => ColumnType::Json, "MessageId" => ColumnType::MessageId, - "Charfield" => ColumnType::Charfield, - "Identity" => ColumnType::Identity, - "Boolean" => ColumnType::Boolean, + "Nonce" => ColumnType::Nonce, "Object" => ColumnType::Object, - "UInt16" => ColumnType::UInt16, - "Int16" => ColumnType::Int16, - "Bytes64" => ColumnType::Bytes64, + "Salt" => ColumnType::Salt, "Signature" => ColumnType::Signature, - "Nonce" => ColumnType::Nonce, - "HexString" => ColumnType::HexString, "Tai64Timestamp" => ColumnType::Tai64Timestamp, + "Timestamp" => ColumnType::Timestamp, "TxId" => ColumnType::TxId, - "BlockHeight" => ColumnType::BlockHeight, - "Enum" => ColumnType::Enum, - "Int1" => ColumnType::Int1, - "UInt1" => ColumnType::UInt1, - "Virtual" => ColumnType::Virtual, - "BlockId" => ColumnType::BlockId, - "Array" => ColumnType::Array, + "U128" => ColumnType::U128, + "U32" => ColumnType::U32, + "U64" => ColumnType::U64, + "U8" => ColumnType::U8, "UID" => ColumnType::UID, + "Virtual" => ColumnType::Virtual, _ => unimplemented!("Invalid ColumnType: '{name}'."), } } @@ -395,8 +395,8 @@ impl Column { ColumnType::HexString => "varchar(10485760)".to_string(), ColumnType::ID => "varchar(64) primary key".to_string(), ColumnType::Identity => "varchar(66)".to_string(), - ColumnType::Int1 => "integer".to_string(), - ColumnType::Int16 => "numeric(39, 0)".to_string(), + ColumnType::I8 => "integer".to_string(), + ColumnType::I128 => "numeric(39, 0)".to_string(), ColumnType::Int4 => "integer".to_string(), ColumnType::Int8 => "bigint".to_string(), ColumnType::Json => "json".to_string(), @@ -408,25 +408,25 @@ impl Column { ColumnType::Tai64Timestamp => "varchar(128)".to_string(), ColumnType::Timestamp => "timestamp".to_string(), ColumnType::TxId => "varchar(64)".to_string(), - ColumnType::UInt1 => "integer".to_string(), - ColumnType::UInt16 => "numeric(39, 0)".to_string(), - ColumnType::UInt4 => "integer".to_string(), - ColumnType::UInt8 => "numeric(20, 0)".to_string(), + ColumnType::U8 => "integer".to_string(), + ColumnType::U128 => "numeric(39, 0)".to_string(), + ColumnType::U32 => "integer".to_string(), + ColumnType::U64 => "numeric(20, 0)".to_string(), ColumnType::Virtual => "json".to_string(), ColumnType::UID => "varchar(64)".to_string(), ColumnType::Array => { let t = match self.array_coltype.expect( "Column.array_coltype cannot be None when using `ColumnType::Array`.", ) { - ColumnType::Int1 - | ColumnType::UInt1 + ColumnType::I8 + | ColumnType::U8 | ColumnType::Int4 - | ColumnType::UInt4 + | ColumnType::U32 | ColumnType::BlockHeight => "integer", ColumnType::Timestamp => "timestamp", ColumnType::Int8 => "bigint", - ColumnType::UInt8 => "numeric(20, 0)", - ColumnType::UInt16 | ColumnType::Int16 => "numeric(39, 0)", + ColumnType::U64 => "numeric(20, 0)", + ColumnType::U128 | ColumnType::I128 => "numeric(39, 0)", ColumnType::Address | ColumnType::Bytes4 | ColumnType::Bytes8 @@ -1280,7 +1280,7 @@ mod tests { type Person @entity { id: ID! name: Charfield! @unique - age: UInt1! + age: U8! }"#; let fields = [ @@ -1299,7 +1299,7 @@ type Person @entity { }, }]), ), - ("age", "UInt1", None), + ("age", "U8", None), ] .iter() .map(|(name, typ, directives)| { @@ -1358,7 +1358,7 @@ type Person @entity { type Person @entity { id: ID! name: Charfield! @unique - age: UInt1! + age: U8! }"#; let schema = ParsedGraphQLSchema::new( @@ -1409,7 +1409,7 @@ type Person @entity { let schema = r#" type Account @entity { id: ID! - index: UInt8! + index: U64! } type Wallet @entity { diff --git a/packages/fuel-indexer-graphql-dyn/Cargo.toml b/packages/fuel-indexer-graphql-dyn/Cargo.toml index fad9f7fde..2f2f08b93 100644 --- a/packages/fuel-indexer-graphql-dyn/Cargo.toml +++ b/packages/fuel-indexer-graphql-dyn/Cargo.toml @@ -27,8 +27,8 @@ thiserror = { workspace = true } anyhow = "1.0" lazy_static = "1.4.0" convert_case = "0.6.0" -async-graphql-parser = "6.0.4" -serde.workspace = true +async-graphql-parser = { workspace = true } +serde = { workspace = true } [dev-dependencies] assert_matches = "1.5.0" diff --git a/packages/fuel-indexer-graphql/Cargo.toml b/packages/fuel-indexer-graphql/Cargo.toml index af0774798..6566ef821 100644 --- a/packages/fuel-indexer-graphql/Cargo.toml +++ b/packages/fuel-indexer-graphql/Cargo.toml @@ -10,9 +10,9 @@ rust-version = { workspace = true } description = "Fuel Indexer GraphQL" [dependencies] -async-graphql = { version = "5.0", features = ["dynamic-schema"] } -async-graphql-parser = "5.0" -async-graphql-value = "5.0" +async-graphql = { workspace = true, features = ["dynamic-schema"] } +async-graphql-parser = { workspace = true } +async-graphql-value = { workspace = true } fuel-indexer-database = { workspace = true } fuel-indexer-database-types = { workspace = true } fuel-indexer-schema = { workspace = true, features = ["db-models"] } diff --git a/packages/fuel-indexer-graphql/src/dynamic.rs b/packages/fuel-indexer-graphql/src/dynamic.rs index 89cbd867a..3dc6e3154 100644 --- a/packages/fuel-indexer-graphql/src/dynamic.rs +++ b/packages/fuel-indexer-graphql/src/dynamic.rs @@ -37,8 +37,8 @@ lazy_static! { "HexString", "ID", "Identity", - "Int1", - "Int16", + "I8", + "I128", "Int4", "Int8", "Json", @@ -50,24 +50,24 @@ lazy_static! { "Timestamp", "TxId", "UID", - "UInt1", - "UInt16", - "UInt4", - "UInt8", + "U8", + "U128", + "U32", + "U64", "Virtual", ]); /// Scalar types that are represented by a numeric type. This ensures that the /// value type provided for a field filter matches the type of the scalar itself. static ref NUMERIC_SCALAR_TYPES: HashSet<&'static str> = HashSet::from([ - "Int16", + "I128", "Int4", "Int8", "Timestamp", "Tai64Timestamp", - "UInt16", - "UInt4", - "UInt8", + "U128", + "U32", + "U64", ]); /// Scalar types that are represented by a string type. This ensures that the @@ -107,7 +107,7 @@ lazy_static! { "HexString", "ID", "Identity", - "Int16", + "I128", "Int4", "Int8", "MessageId", @@ -117,9 +117,9 @@ lazy_static! { "Tai64Timestamp", "Timestamp", "UID", - "UInt16", - "UInt4", - "UInt8", + "U128", + "U32", + "U64", ]); /// Entity types that should be ignored when building the dynamic schema, diff --git a/packages/fuel-indexer-graphql/src/graphql.rs b/packages/fuel-indexer-graphql/src/graphql.rs index cf1942ebf..19b042000 100644 --- a/packages/fuel-indexer-graphql/src/graphql.rs +++ b/packages/fuel-indexer-graphql/src/graphql.rs @@ -756,7 +756,7 @@ mod tests { let schema = r#" type Block @entity { id: ID! - height: UInt8! + height: U64! timestamp: Int8! } diff --git a/packages/fuel-indexer-lib/src/constants.rs b/packages/fuel-indexer-lib/src/constants.rs new file mode 100644 index 000000000..593994311 --- /dev/null +++ b/packages/fuel-indexer-lib/src/constants.rs @@ -0,0 +1,229 @@ +use lazy_static::lazy_static; +use std::collections::HashSet; + +lazy_static! { + + /// Set of internal indexer entities. + pub static ref INTERNAL_INDEXER_ENTITIES: HashSet<&'static str> = HashSet::from([ + "IndexMetadataEntity", + ]); + + /// Set of types that implement `AsRef<[u8]>`. + pub static ref ASREF_BYTE_TYPES: HashSet<&'static str> = HashSet::from([ + "Address", + "AssetId", + "Blob", + "BlockId", + "Boolean", + "Bytes", + "Bytes20", + "Bytes32", + "Bytes4", + "Bytes64", + "Bytes8", + "Charfield", + "ContractId", + "Bytes", + "Json", + "MessageId", + "Nonce", + "Option
", + "Option", + "Option", + "Option", + "Option", + "Option", + "Option", + "Option", + "Option", + "Option", + "Option", + "Option", + "Option", + "Option", + "Option", + "Option", + "Option", + "Option", + "Option", + "Option", + "Option", + "Option", + "Salt", + "Signature", + "UID", + "TxId", + "Virtual", + ]); + + /// Set of external types that do not implement `AsRef<[u8]>`. + pub static ref EXTERNAL_FIELD_TYPES: HashSet<&'static str> = HashSet::from([ + "Identity", + "Option", + "Option", + "Tai64Timestamp", + ]); + + /// Set of field types that are currently unable to be used as a digest for SHA-256 hashing. + pub static ref NON_DIGESTIBLE_FIELD_TYPES: HashSet<&'static str> = HashSet::from([ + "Boolean", + "Identity" + ]); + + /// Sway ABI types we don't support and won't in the near future. + pub static ref IGNORED_ABI_JSON_TYPES: HashSet<&'static str> = + HashSet::from(["()", "struct Vec"]); + + /// Fuel VM receipt-related types. + pub static ref FUEL_RECEIPT_TYPES: HashSet<&'static str> = HashSet::from([ + "Burn", + "Call", + "Log", + "LogData", + "MessageOut", + "Mint", + "Panic", + "Return", + "Revert", + "ScriptResult", + "Transfer", + "TransferOut", + ]); + + /// Set of types that should be copied instead of referenced. + pub static ref COPY_TYPES: HashSet<&'static str> = HashSet::from([ + "Blob", + "Charfield", + "Bytes", + "ID", + "Identity", + "Json", + "Option", + "Option", + "Option", + "Option", + "Option", + "Option", + "Option", + "Option", + "UID", + "Vec", + "Virtual", + ]); + + /// Fuel-specific receipt-related type names. + pub static ref FUEL_PRIMITIVES: HashSet<&'static str> = HashSet::from([ + "BlockData", + "Call", + "Log", + "LogData", + "MessageOut", + "Panic", + "Return", + "Revert", + "ScriptResult", + "Transfer", + "TransferOut", + "Mint", + "Burn", + ]); + + /// Type names that are not allowed in GraphQL schema. + pub static ref RESERVED_TYPEDEF_NAMES: HashSet<&'static str> = HashSet::from([ + // Scalars. + "Address", + "AssetId", + "Blob", + "BlockHeight", + "BlockId", + "Boolean", + "Bytes", + "Bytes32", + "Bytes4", + "Bytes64", + "Bytes8", + "Charfield", + "Color", + "ContractId", + "Bytes", + "ID", + "Identity", + "I8", + "I128", + "I32", + "I64", + "Json", + "MessageId", + "Nonce", + "Salt", + "Signature", + "Tai64Timestamp", + "Timestamp", + "TxId", + "UID", + "U8", + "U128", + "U32", + "U64", + "Virtual", + + // Imports for transaction fields. + // https://github.com/FuelLabs/fuel-indexer/issues/286 + "BlockData", + "Burn", + "BytecodeLength", + "BytecodeWitnessIndex", + "Call", + "FieldTxPointer", + "GasLimit", + "GasPrice", + "Inputs", + "Log", + "Log", + "LogData", + "LogData", + "Maturity", + "MessageId", + "MessageOut", + "Mint", + "Outputs", + "Panic", + "ReceiptsRoot", + "Return", + "Revert", + "Script", + "ScriptData", + "ScriptResult", + "ScriptResult", + "StorageSlots", + "TransactionData", + "Transfer", + "Transfer", + "TransferOut", + "TransferOut", + "TxFieldSalt", + "TxFieldScript", + "TxId", + "Witnesses", + ]); + + + /// ABI types not allowed in the contract ABI. + pub static ref DISALLOWED_ABI_JSON_TYPES: HashSet<&'static str> = HashSet::from([]); + + /// Generic Sway ABI types. + pub static ref GENERIC_TYPES: HashSet<&'static str> = HashSet::from([ + "generic T", + "raw untyped ptr", + "struct RawVec", + ]); + + pub static ref COLLECTION_TYPES: HashSet<&'static str> = HashSet::from([ + "Vec", + ]); + + /// Set of Rust primitive types. + pub static ref RUST_PRIMITIVES: HashSet<&'static str> = + HashSet::from(["u8", "u16", "u32", "u64", "bool", "String"]); + +} diff --git a/packages/fuel-indexer-lib/src/graphql/base.graphql b/packages/fuel-indexer-lib/src/graphql/base.graphql index 60a95d400..6ab176df0 100644 --- a/packages/fuel-indexer-lib/src/graphql/base.graphql +++ b/packages/fuel-indexer-lib/src/graphql/base.graphql @@ -13,10 +13,10 @@ scalar Charfield scalar Color scalar ContractId scalar HexString +scalar I128 +scalar I8 scalar ID scalar Identity -scalar Int1 -scalar Int16 scalar Int4 scalar Int8 scalar Json @@ -27,11 +27,11 @@ scalar Signature scalar Tai64Timestamp scalar Timestamp scalar TxId +scalar U128 +scalar U32 +scalar U64 +scalar U8 scalar UID -scalar UInt1 -scalar UInt16 -scalar UInt4 -scalar UInt8 scalar Virtual enum IndexType { diff --git a/packages/fuel-indexer-lib/src/graphql/constants.rs b/packages/fuel-indexer-lib/src/graphql/constants.rs index 529ffae6c..a48a8b0b4 100644 --- a/packages/fuel-indexer-lib/src/graphql/constants.rs +++ b/packages/fuel-indexer-lib/src/graphql/constants.rs @@ -156,8 +156,8 @@ lazy_static! { "HexString", "ID", "Identity", - "Int1", - "Int16", + "I8", + "I128", "Int4", "Int8", "Json", @@ -169,10 +169,10 @@ lazy_static! { "Tai64Timestamp", "Timestamp", "TxId", - "UInt1", - "UInt16", - "UInt4", - "UInt8", + "U8", + "U128", + "U32", + "U64", // Imports for transaction fields. // https://github.com/FuelLabs/fuel-indexer/issues/286 diff --git a/packages/fuel-indexer-lib/src/graphql/parser.rs b/packages/fuel-indexer-lib/src/graphql/parser.rs index 72a3d728d..b547a57d1 100644 --- a/packages/fuel-indexer-lib/src/graphql/parser.rs +++ b/packages/fuel-indexer-lib/src/graphql/parser.rs @@ -856,11 +856,11 @@ type User @entity { type Loser @entity { id: ID! account: Account! - age: UInt8! + age: U64! } type Metadata @entity(virtual: true) { - count: UInt8! + count: U64! } union Person = User | Loser diff --git a/packages/fuel-indexer-macros/Cargo.toml b/packages/fuel-indexer-macros/Cargo.toml index 6a193bc45..3089845a4 100644 --- a/packages/fuel-indexer-macros/Cargo.toml +++ b/packages/fuel-indexer-macros/Cargo.toml @@ -13,8 +13,8 @@ description = "Fuel Indexer Macros" proc-macro = true [dependencies] -async-graphql-parser = "5.0" -async-graphql-value = "5.0" +async-graphql-parser = { workspace = true } +async-graphql-value = { workspace = true } fuel-abi-types = "0.3" fuel-indexer-database-types = { workspace = true } fuel-indexer-lib = { workspace = true, default-features = true } diff --git a/packages/fuel-indexer-macros/src/constants.rs b/packages/fuel-indexer-macros/src/constants.rs index 09af2328f..640b21c84 100644 --- a/packages/fuel-indexer-macros/src/constants.rs +++ b/packages/fuel-indexer-macros/src/constants.rs @@ -163,8 +163,8 @@ lazy_static! { "HexString", "ID", "Identity", - "Int1", - "Int16", + "I8", + "I128", "Int4", "Int8", "Json", @@ -176,10 +176,10 @@ lazy_static! { "Timestamp", "TxId", "UID", - "UInt1", - "UInt16", - "UInt4", - "UInt8", + "U8", + "U128", + "U32", + "U64", "Virtual", // Imports for transaction fields. diff --git a/packages/fuel-indexer-macros/src/decoder.rs b/packages/fuel-indexer-macros/src/decoder.rs index 7b1b14dc3..b46be536b 100644 --- a/packages/fuel-indexer-macros/src/decoder.rs +++ b/packages/fuel-indexer-macros/src/decoder.rs @@ -970,10 +970,10 @@ mod tests { type Person @entity { id: ID! name: Charfield! - age: UInt1! + age: U8! }"#; - let fields = [("id", "ID"), ("name", "Charfield"), ("age", "UInt1")] + let fields = [("id", "ID"), ("name", "Charfield"), ("age", "U8")] .iter() .map(|(name, typ)| Positioned { pos: Pos::default(), @@ -1035,7 +1035,7 @@ type Person @entity { assert!(tokenstream.contains("impl < 'a > Entity < 'a > for Person")); assert!(tokenstream.contains("impl Person")); assert!( - tokenstream.contains("pub fn new (name : Charfield , age : UInt1 ,) -> Self") + tokenstream.contains("pub fn new (name : Charfield , age : U8 ,) -> Self") ); assert!(tokenstream.contains("pub fn get_or_create (self) -> Self")); assert!(tokenstream.contains("fn from_row (mut vec : Vec < FtColumn >) -> Self")); @@ -1048,7 +1048,7 @@ type Person @entity { let schema = r#" type Account @entity { id: ID! - index: UInt8! + index: U64! } type Wallet @entity { diff --git a/packages/fuel-indexer-schema/Cargo.toml b/packages/fuel-indexer-schema/Cargo.toml index 90fd243c5..5cd33c95f 100644 --- a/packages/fuel-indexer-schema/Cargo.toml +++ b/packages/fuel-indexer-schema/Cargo.toml @@ -10,7 +10,7 @@ rust-version = { workspace = true } description = "Fuel Indexer Schema" [dependencies] -async-graphql-parser = "5.0" +async-graphql-parser = { workspace = true } fuel-indexer-database = { workspace = true, optional = true } fuel-indexer-lib = { workspace = true } fuel-indexer-types = { workspace = true } diff --git a/packages/fuel-indexer-schema/src/lib.rs b/packages/fuel-indexer-schema/src/lib.rs index 9a849778e..bd6f59db2 100644 --- a/packages/fuel-indexer-schema/src/lib.rs +++ b/packages/fuel-indexer-schema/src/lib.rs @@ -51,9 +51,11 @@ pub enum IndexerSchemaError { #[derive(Debug, PartialEq, Eq, Deserialize, Serialize, Clone, Hash)] pub enum FtColumn { Address(Option
), + Array(Option>), AssetId(Option), Blob(Option), BlockHeight(Option), + BlockId(Option), Boolean(Option), Bytes32(Option), Bytes4(Option), @@ -63,10 +65,10 @@ pub enum FtColumn { ContractId(Option), Enum(Option), HexString(Option), + I128(Option), + I8(Option), ID(Option), Identity(Option), - Int1(Option), - Int16(Option), Int4(Option), Int8(Option), Json(Option), @@ -77,14 +79,12 @@ pub enum FtColumn { Tai64Timestamp(Option), Timestamp(Option), TxId(Option), - UInt1(Option), - UInt16(Option), - UInt4(Option), - UInt8(Option), - Virtual(Option), - BlockId(Option), - Array(Option>), + U128(Option), + U32(Option), + U64(Option), + U8(Option), UID(Option), + Virtual(Option), } impl FtColumn { @@ -153,11 +153,11 @@ impl FtColumn { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), }, - FtColumn::Int1(value) => match value { + FtColumn::I8(value) => match value { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), }, - FtColumn::UInt1(value) => match value { + FtColumn::U8(value) => match value { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), }, @@ -165,11 +165,11 @@ impl FtColumn { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), }, - FtColumn::Int16(value) => match value { + FtColumn::I128(value) => match value { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), }, - FtColumn::UInt4(value) => match value { + FtColumn::U32(value) => match value { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), }, @@ -177,11 +177,11 @@ impl FtColumn { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), }, - FtColumn::UInt8(value) => match value { + FtColumn::U64(value) => match value { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), }, - FtColumn::UInt16(value) => match value { + FtColumn::U128(value) => match value { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), }, @@ -313,10 +313,10 @@ mod tests { )); let int4 = FtColumn::Int4(Some(i32::from_le_bytes([0x78; 4]))); let int8 = FtColumn::Int8(Some(i64::from_le_bytes([0x78; 8]))); - let int16 = FtColumn::Int16(Some(i128::from_le_bytes([0x78; 16]))); - let uint4 = FtColumn::UInt4(Some(u32::from_le_bytes([0x78; 4]))); - let uint8 = FtColumn::UInt8(Some(u64::from_le_bytes([0x78; 8]))); - let uint16 = FtColumn::UInt16(Some(u128::from_le_bytes([0x78; 16]))); + let int16 = FtColumn::I128(Some(i128::from_le_bytes([0x78; 16]))); + let uint4 = FtColumn::U32(Some(u32::from_le_bytes([0x78; 4]))); + let uint8 = FtColumn::U64(Some(u64::from_le_bytes([0x78; 8]))); + let uint16 = FtColumn::U128(Some(u128::from_le_bytes([0x78; 16]))); let int64 = FtColumn::Timestamp(Some(i64::from_le_bytes([0x78; 8]))); let salt = FtColumn::Salt(Some(Salt::try_from([0x31; 32]).expect("Bad bytes"))); let message_id = FtColumn::MessageId(Some( @@ -360,9 +360,9 @@ mod tests { let int4_none = FtColumn::Int4(None); let int8_none = FtColumn::Int8(None); let int16_none = FtColumn::Int8(None); - let uint4_none = FtColumn::UInt4(None); - let uint8_none = FtColumn::UInt8(None); - let uint16_none = FtColumn::UInt8(None); + let uint4_none = FtColumn::U32(None); + let uint8_none = FtColumn::U64(None); + let uint16_none = FtColumn::U64(None); let int64_none = FtColumn::Timestamp(None); let salt_none = FtColumn::Salt(None); let message_id_none = FtColumn::MessageId(None); diff --git a/packages/fuel-indexer-tests/indexers/fuel-indexer-test/schema/fuel_indexer_test.graphql b/packages/fuel-indexer-tests/indexers/fuel-indexer-test/schema/fuel_indexer_test.graphql index 5e1c622f0..f2e351386 100644 --- a/packages/fuel-indexer-tests/indexers/fuel-indexer-test/schema/fuel_indexer_test.graphql +++ b/packages/fuel-indexer-tests/indexers/fuel-indexer-test/schema/fuel_indexer_test.graphql @@ -1,30 +1,30 @@ type PingEntity @entity { id: ID! - value: UInt8! + value: U64! message: Charfield! } type PungEntity @entity { id: ID! - value: UInt8! + value: U64! is_pung: Boolean! pung_from: Identity! } type U16Entity @entity { id: ID! - value1: UInt16! - value2: Int16! + value1: U128! + value2: I128! } type PongEntity @entity { id: ID! - value: UInt8! + value: U64! } type BlockEntity @entity { id: ID! - height: UInt4! + height: U32! timestamp: Int8! } @@ -40,7 +40,7 @@ type TransferEntity @entity { contract_id: ContractId! # 'to' is a reserved SQL word, so using 'recipient' recipient: ContractId! - amount: UInt8! + amount: U64! asset_id: AssetId! } @@ -48,21 +48,21 @@ type TransferOutEntity @entity { id: ID! contract_id: ContractId! recipient: Address! - amount: UInt8! + amount: U64! asset_id: AssetId! } type LogEntity @entity { id: ID! contract_id: ContractId! - ra: UInt8! - rb: UInt8! + ra: U64! + rb: U64! } type ScriptResultEntity @entity { id: ID! - result: UInt8! - gas_used: UInt8! + result: U64! + gas_used: U64! blob: Blob! } @@ -71,23 +71,23 @@ type MessageOutEntity @entity { message_id: MessageId! sender: Address! recipient: Address! - amount: UInt8! + amount: U64! nonce: Nonce! - len: UInt8! + len: U64! digest: Bytes32! } type OptionEntity @entity { id: ID! - int_required: UInt8! - int_optional_some: UInt8 + int_required: U64! + int_optional_some: U64 addr_optional_none: Address } type TupleEntity @entity { id: ID! complex_a: Charfield! - complex_b: UInt8! + complex_b: U64! simple_a: Charfield! } @@ -101,35 +101,35 @@ type CallEntity @entity { contract_id: ContractId! callee: ContractId! asset_id: AssetId! - gas: UInt8! + gas: U64! fn_name: Charfield! - amount: UInt8! + amount: U64! } type PanicEntity @entity { id: ID! contract_id: ContractId! - reason: UInt4! + reason: U32! } type RevertEntity @entity { id: ID! contract_id: ContractId! - error_val: UInt8! + error_val: U64! } type MintEntity @entity { id: ID! sub_id: AssetId! contract_id: ContractId! - val: UInt8! + val: U64! } type BurnEntity @entity { id: ID! sub_id: AssetId! contract_id: ContractId! - val: UInt8! + val: U64! } type Genre @entity { @@ -194,7 +194,7 @@ type Book @entity { type Sponsor @entity { id: ID! name: Charfield! @unique - amount: UInt8! + amount: U64! representative: Person! } @@ -220,22 +220,22 @@ type SportsTeam @entity { type InnerFilterEntity @entity { id: ID! inner_foo: Charfield! - inner_bar: UInt8! - inner_baz: UInt8! + inner_bar: U64! + inner_baz: U64! } type FilterEntity @entity { id: ID! foola: Charfield! - maybe_null_bar: UInt8 - bazoo: UInt8! + maybe_null_bar: U64 + bazoo: U64! inner_entity: InnerFilterEntity! } type EnumError @entity { id: ID! contract_id: ContractId! - error_val: UInt8! + error_val: U64! } type ExplorerEntity @entity { @@ -260,7 +260,7 @@ type ComplexEnumEntity @entity { type VirtualEntity @entity(virtual: true) { name: Charfield - size: UInt1! + size: U8! } type UsesVirtualEntity @entity { @@ -277,34 +277,34 @@ enum UnionType { type IndexableUnionA @entity { id: ID! - a: UInt8! + a: U64! union_type: UnionType! } type IndexableUnionB @entity { id: ID! - b: UInt8! + b: U64! union_type: UnionType! } type IndexableUnionC @entity { id: ID! - c: UInt8! + c: U64! union_type: UnionType! } type VirtualUnionA @entity(virtual: true) { - a: UInt8! + a: U64! union_type: UnionType! } type VirtualUnionB @entity(virtual: true) { - b: UInt8! + b: U64! union_type: UnionType! } type VirtualUnionC @entity(virtual: true) { - c: UInt8! + c: U64! union_type: UnionType! } @@ -320,7 +320,7 @@ type VirtualUnionContainerEntity @entity { type ListFKType @entity { id: ID! - value: UInt8! + value: U64! } type ListTypeEntity @entity { @@ -328,8 +328,8 @@ type ListTypeEntity @entity { foo_field: Charfield! required_all: [ListFKType!]! optional_inner: [Charfield]! - optional_outer: [UInt8!] - optional_all: [UInt8] + optional_outer: [U64!] + optional_all: [U64] virtual_optional_inner: [VirtualEntity]! enum_required_all: [EnumEntity!]! } diff --git a/packages/fuel-indexer-types/src/graphql.rs b/packages/fuel-indexer-types/src/graphql.rs index d9d8cc47a..86b852ecd 100644 --- a/packages/fuel-indexer-types/src/graphql.rs +++ b/packages/fuel-indexer-types/src/graphql.rs @@ -26,8 +26,8 @@ impl IndexMetadata { type IndexMetadataEntity @entity { id: ID! - time: UInt8! - block_height: UInt4! + time: U64! + block_height: U32! block_id: Bytes32! } "# diff --git a/packages/fuel-indexer-types/src/scalar.rs b/packages/fuel-indexer-types/src/scalar.rs index 684dc0cb4..5b77e1927 100644 --- a/packages/fuel-indexer-types/src/scalar.rs +++ b/packages/fuel-indexer-types/src/scalar.rs @@ -20,16 +20,16 @@ pub type Int4 = i32; pub type Int8 = i64; /// Scalar for 16-byte signed integers. -pub type Int16 = i128; +pub type I128 = i128; /// Scalar for 4-byte unsigned integers. -pub type UInt4 = u32; +pub type U32 = u32; /// Scalar for 8-byte unsigned integers. -pub type UInt8 = u64; +pub type U64 = u64; /// Scalar for 16-byte unsigned integers. -pub type UInt16 = u128; +pub type U128 = u128; /// Scalar for 8-byte integers aliased as `Timestamp`s. pub type Timestamp = u64; @@ -53,10 +53,10 @@ pub type Tai64Timestamp = Tai64; pub type BlockId = Bytes32; /// Scalar for 1-byte signed integers. -pub type Int1 = i8; +pub type I8 = i8; /// Scalar for 1-byte unsigned integers. -pub type UInt1 = u8; +pub type U8 = u8; /// Blob type used to store arbitrarily sized UTF-8 payloads. #[derive(Deserialize, Serialize, Clone, Eq, PartialEq, Debug, Hash, Default)] diff --git a/plugins/forc-index/src/defaults.rs b/plugins/forc-index/src/defaults.rs index 0a3f058c6..57f8f6691 100644 --- a/plugins/forc-index/src/defaults.rs +++ b/plugins/forc-index/src/defaults.rs @@ -214,7 +214,7 @@ pub mod {indexer_name}_index_mod {{ pub fn default_indexer_schema() -> String { r#"type Block @entity { id: ID! - height: UInt8! + height: U64! hash: Bytes32! @unique }