From f02438a4422a73499b8a5cf5a6ee95cc76146a27 Mon Sep 17 00:00:00 2001 From: rashad Date: Fri, 29 Sep 2023 10:52:22 -0400 Subject: [PATCH] chore/breaking: simplify scalar types (#1388) * chore: simplify scalar types * rename xstring to string * update tests * updates * updates * fix snapshot tests --------- Co-authored-by: Rashad Alston --- Cargo.lock | 2 - docs/src/designing-a-schema/directives.md | 2 +- docs/src/designing-a-schema/relationships.md | 4 +- docs/src/designing-a-schema/scalars.md | 32 +-- docs/src/designing-a-schema/types.md | 10 +- docs/src/indexing-custom-types/index.md | 8 +- docs/src/project-components/schema.md | 8 +- docs/src/querying/basic-queries.md | 8 +- docs/src/storing-records/index.md | 35 +-- .../schema/fuel_explorer.schema.graphql | 250 ++++++++-------- .../fuel-explorer/fuel-explorer/src/lib.rs | 12 +- .../hello_indexer_native.schema.graphql | 8 +- .../schema/hello_indexer.schema.graphql | 8 +- .../benches/graphql.rs | 4 +- .../fuel-indexer-benchmarks/src/bin/qa.rs | 23 +- .../database-types/src/lib.rs | 272 +++++++----------- .../postgres/sqlx-data.json | 22 +- packages/fuel-indexer-graphql/src/dynamic.rs | 77 ++--- packages/fuel-indexer-graphql/src/graphql.rs | 6 +- packages/fuel-indexer-lib/src/constants.rs | 68 ++--- .../fuel-indexer-lib/src/graphql/base.graphql | 32 +-- .../fuel-indexer-lib/src/graphql/constants.rs | 39 +-- .../fuel-indexer-lib/src/graphql/parser.rs | 66 ++--- packages/fuel-indexer-macros/src/decoder.rs | 12 +- packages/fuel-indexer-schema/src/lib.rs | 242 +++++----------- ...chema__tests__fragments_some_types-10.snap | 4 +- ...chema__tests__fragments_some_types-11.snap | 4 +- ...chema__tests__fragments_some_types-12.snap | 4 +- ...chema__tests__fragments_some_types-13.snap | 4 +- ...chema__tests__fragments_some_types-14.snap | 4 +- ...chema__tests__fragments_some_types-15.snap | 4 +- ...chema__tests__fragments_some_types-16.snap | 4 +- ...chema__tests__fragments_some_types-17.snap | 4 +- ...chema__tests__fragments_some_types-18.snap | 4 +- ...chema__tests__fragments_some_types-19.snap | 4 +- ...schema__tests__fragments_some_types-2.snap | 4 +- ...chema__tests__fragments_some_types-21.snap | 4 +- ...chema__tests__fragments_some_types-22.snap | 4 +- ...chema__tests__fragments_some_types-23.snap | 4 +- ...schema__tests__fragments_some_types-4.snap | 4 +- ...schema__tests__fragments_some_types-5.snap | 4 +- ...schema__tests__fragments_some_types-6.snap | 4 +- ...schema__tests__fragments_some_types-7.snap | 4 +- ...schema__tests__fragments_some_types-8.snap | 4 +- ...schema__tests__fragments_some_types-9.snap | 4 +- ...r_schema__tests__fragments_some_types.snap | 4 +- .../schema/fuel_indexer_test.graphql | 144 +++++----- .../indexers/fuel-indexer-test/src/lib.rs | 18 +- packages/fuel-indexer-tests/tests/indexing.rs | 2 +- ...fail_if_abi_contains_reserved_fuel_type.rs | 4 +- .../fail_if_ident_not_defined_in_abi.rs | 2 +- packages/fuel-indexer-types/Cargo.toml | 2 - packages/fuel-indexer-types/src/fuel.rs | 14 +- packages/fuel-indexer-types/src/graphql.rs | 4 +- packages/fuel-indexer-types/src/scalar.rs | 91 +----- packages/fuel-indexer-utils/src/utilities.rs | 8 +- packages/fuel-indexer/src/executor.rs | 14 +- plugins/forc-index/src/defaults.rs | 2 +- 58 files changed, 650 insertions(+), 989 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cdcf0e849..b1f0c74b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3520,7 +3520,6 @@ dependencies = [ name = "fuel-indexer-types" version = "0.20.11" dependencies = [ - "bincode", "bytes", "fuel-tx 0.35.3", "fuel-types 0.35.3", @@ -3528,7 +3527,6 @@ dependencies = [ "serde", "serde_json", "sha2 0.9.9", - "tai64", ] [[package]] diff --git a/docs/src/designing-a-schema/directives.md b/docs/src/designing-a-schema/directives.md index b429006aa..8426d0ca6 100644 --- a/docs/src/designing-a-schema/directives.md +++ b/docs/src/designing-a-schema/directives.md @@ -55,7 +55,7 @@ The `@join` directive is used to relate a field in one type to others by referen ```graphql type Book @entity { id: ID! - name: Charfield! @unique + name: String! @unique } type Library @entity { diff --git a/docs/src/designing-a-schema/relationships.md b/docs/src/designing-a-schema/relationships.md index 590defc69..5b2444c35 100644 --- a/docs/src/designing-a-schema/relationships.md +++ b/docs/src/designing-a-schema/relationships.md @@ -19,7 +19,7 @@ Let's learn how to use each foreign key type by looking at some GraphQL schema e ```graphql type Library @entity { id: ID! - name: Charfield! + name: String! } type Book @entity { @@ -35,7 +35,7 @@ Given the above schema, two entities will be created: a `Book` entity, and a `Li ```graphql type Library @entity { id: ID! - name: Charfield! @unique + name: String! @unique } type Book @entity { diff --git a/docs/src/designing-a-schema/scalars.md b/docs/src/designing-a-schema/scalars.md index d026af518..f66526526 100644 --- a/docs/src/designing-a-schema/scalars.md +++ b/docs/src/designing-a-schema/scalars.md @@ -6,31 +6,23 @@ The Fuel indexer has a collection of GraphQL scalars that cover virtually any va --- | --- | --- | Address | `u8[32]` | | AssetId | `u8[32]` | -| Blob | `Vec` | Byte blob of arbitary size | -| BlockId | `u8[32]` | 32-byte block ID | | Boolean | `bool` | -| Bytes4 | `u8[4]` | -| Bytes8 | `u8[8]` | +| Bytes | `Vec` | Byte blob of arbitary size | | Bytes32 | `u8[32]` | +| Bytes4 | `u8[4]` | | Bytes64 | `u8[64]` | -| Charfield | `String` | String of arbitrary size | +| Bytes8 | `u8[8]` | | ContractId | `u8[32]` | | HexString | `Vec` | Byte blob of arbitrary size | +| I128 | `i128` | +| I32 | `i32` | +| I64 | `i64` | +| I8 | `i8` | | ID | `SizedAsciiString<64>` | Alias of `UID` -| Int1 | `i8` | -| Int4 | `i32` | -| Int8 | `i64` | -| Int16 | `i128` | | Json | `String` | JSON string of arbitary size | -| MessageId | `u8[32]` | -| Nonce | `u8[32]` | -| Salt | `u8[32]` | -| Signature | `u8[64]` | 64-byte signature | -| Tai64Timestamp | `Tai64` | `Tai64` timestamp | -| Timestamp | `u64` | +| U128 | `u128` | +| U32 | `u32` | +| U64 | `u64` | +| U8 | `u8` | | UID | `SizedAsciiString<64>` | 32-byte unique ID | -| UInt1 | `u8` | -| UInt4 | `u32` | -| UInt8 | `u64` | -| UInt16 | `u128` | -| Virtual | `String` | Used to store types tagged with `@virtual` directive | +| String | `String` | String of arbitrary size | diff --git a/docs/src/designing-a-schema/types.md b/docs/src/designing-a-schema/types.md index 11ed5561c..534904f79 100644 --- a/docs/src/designing-a-schema/types.md +++ b/docs/src/designing-a-schema/types.md @@ -8,7 +8,7 @@ Object types are the most commonly used type in indexer GraphQL schema. Each obj type Account @entity { id: ID! address: Address! - balance: UInt8! + balance: U64! } ``` @@ -69,14 +69,14 @@ enum TransactionLabel { type CreateTransaction @entity { id: ID! - bytecode_length: UInt8! + bytecode_length: U64! contract_id: ContractId! label: TransactionLabel! } type ScriptTransaction @entity { id: ID! - maturity: UInt8! + maturity: U64! label: TransactionLabel! } @@ -94,10 +94,10 @@ The `Transaction` union type above, will internally produce the following object ```graphql type Transaction @entity { id: ID! - bytecode_length: UInt8! + bytecode_length: U64! contract_id: ContractId! label: TransactionLabel! - maturity: UInt8! + maturity: U64! metadata: Json } ``` diff --git a/docs/src/indexing-custom-types/index.md b/docs/src/indexing-custom-types/index.md index a93456d85..c80c72981 100644 --- a/docs/src/indexing-custom-types/index.md +++ b/docs/src/indexing-custom-types/index.md @@ -150,14 +150,14 @@ To index the contracts and store information about our Sway types in the databas ```graphql type AddEntity @entity { id: ID! - value: UInt8! - updated_total: UInt8! + value: U64! + updated_total: U64! } type SubtractEntity @entity { id: ID! - value: UInt8! - updated_total: UInt8! + value: U64! + updated_total: U64! } ``` diff --git a/docs/src/project-components/schema.md b/docs/src/project-components/schema.md index f4c93bf20..f139dca7d 100644 --- a/docs/src/project-components/schema.md +++ b/docs/src/project-components/schema.md @@ -6,20 +6,20 @@ Below is a sample GraphQL schema for a Fuel indexer. ```graphql type Metadata @entity(virtual: true) { - imageUrl: Charfield! - data: Blob + imageUrl: String! + data: Bytes } type Account @entity { id: ID! address: Address! - index: UInt8! + index: U64! metadata: Metadata } type Wallet @entity { id: ID! - name: Charfield! + name: String! accounts: [Account!]! } ``` diff --git a/docs/src/querying/basic-queries.md b/docs/src/querying/basic-queries.md index 324d05b2b..09532475f 100644 --- a/docs/src/querying/basic-queries.md +++ b/docs/src/querying/basic-queries.md @@ -90,24 +90,24 @@ We'll start with the following example schema: ```graphql type City @entity { id: ID! - name: Charfield! + name: String! } type Library @entity { id: ID! - name: Charfield! + name: String! city: City! } type Book @entity { id: ID! - title: Charfield! + title: String! library: Library! } type Character @entity { id: ID! - name: Charfield! + name: String! book: Book! } ``` diff --git a/docs/src/storing-records/index.md b/docs/src/storing-records/index.md index 2ac4384fe..2f06a2fb0 100644 --- a/docs/src/storing-records/index.md +++ b/docs/src/storing-records/index.md @@ -12,34 +12,25 @@ Below is a mapping of GraphQL schema types to their Sway and database equivalent --- | --- | --- | Address | `b256` | varchar(64) | | AssetId | `u8[32]` | varchar(64) | -| Blob | `str[]` | varchar(10485760) | -| BlockId | | varchar(64) | | Boolean | `bool` | boolean | -| Bytes4 | `str[4]` | varchar(8) | -| Bytes8 | `str[8]` | varchar(16) | +| Bytes | `str[]` | varchar(10485760) | | Bytes32 | `str[32]` | varchar(64) | +| Bytes4 | `str[4]` | varchar(8) | | Bytes64 | `str[64]` | varchar(128) | -| Charfield | `str[]` | varchar(255) | +| Bytes8 | `str[8]` | varchar(16) | | ContractId | `b256` | varchar(64) | -| HexString | `str[]` | varchar(10485760) | +| I128 | | numeric(39,0) | +| I32 | `u32` | integer | +| I64 | `u64` | bigint | +| I8 | `u8` | integer | | ID | | varchar(64) primary key | -| Int1 | `u8` | integer | -| Int4 | `u32` | integer | -| Int8 | `u64` | bigint | -| Int16 | | numeric(39,0) | | Json | `str[]` | json | -| MessageId | `str[32]` | varchar(64) | -| Nonce | `str[32]` | varchar(64) | -| Salt | `str[32]` | varchar(64) | -| Signature | `str[64]` | varchar(128) | -| Tai64Timestamp | | varchar(128) | -| Timestamp | `u64` | timestamp | +| U128 | | numeric(39, 0) | +| U32 | `u32` | integer | +| U64 | `u64` | numeric(20, 0) | +| U8 | `u8` | integer | | UID | | varchar(64) | -| UInt1 | `u8` | integer | -| UInt4 | `u32` | integer | -| UInt8 | `u64` | numeric(20, 0) | -| UInt16 | | numeric(39, 0) | -| Virtual | | json | +| String | `str[]` | varchar(255) | ## Example @@ -59,7 +50,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/examples/fuel-explorer/fuel-explorer/schema/fuel_explorer.schema.graphql b/examples/fuel-explorer/fuel-explorer/schema/fuel_explorer.schema.graphql index 91ab44bf4..63635ad2a 100644 --- a/examples/fuel-explorer/fuel-explorer/schema/fuel_explorer.schema.graphql +++ b/examples/fuel-explorer/fuel-explorer/schema/fuel_explorer.schema.graphql @@ -101,21 +101,21 @@ enum OutputLabel { } type Witness @entity(virtual: true) { - data: Blob! + data: Bytes! } type InstructionResult @entity(virtual: true) { reason: PanicReason! - instruction: UInt4! + instruction: U32! } type ProgramState @entity(virtual: true) { return_type: ReturnType! - data: HexString! + data: Bytes! } type DryRun @entity(virtual: true) { - tx: HexString! + tx: Bytes! utxo_validation: Boolean } @@ -126,14 +126,14 @@ type TransactionIdFragment @entity { type UtxoId @entity { id: ID! - tx_id: TxId! @indexed - output_index: UInt4! + tx_id: Bytes32! @indexed + output_index: U32! } type TxPointer @entity { id: ID! - block_height: UInt4! - tx_index: UInt8! + block_height: U32! + tx_index: U64! } type ContractIdFragment @entity { @@ -160,7 +160,7 @@ type PoA @entity { id: ID! # TODO: Is this important? The fact that signature is different # on almost every `PoA` implies that this type might be virtual? - signature: Signature! @indexed + signature: Bytes64! @indexed is_poa: Boolean! label: ConsensusLabel! } @@ -177,13 +177,13 @@ 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! - predicate: HexString! - predicate_data: HexString! + witness_index: I64! + maturity: U32! + predicate: Bytes! + predicate_data: Bytes! label: InputLabel! is_coin: Boolean! } @@ -203,12 +203,12 @@ type InputMessage @entity { id: ID! sender: Address! @indexed recipient: Address! @indexed - amount: UInt8! - nonce: Nonce! - witness_index: Int8! - data: HexString! - predicate: HexString! - predicate_data: HexString! + amount: U64! + nonce: Bytes32! + witness_index: I64! + data: Bytes! + predicate: Bytes! + predicate_data: Bytes! label: InputLabel! is_message: Boolean! } @@ -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! + data: Bytes + 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! + data: Bytes + 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,11 +349,11 @@ 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! - nonce: Nonce! - len: UInt8! + amount: U64! + nonce: Bytes32! + len: U64! digest: Bytes32! - data: Blob + data: Bytes label: ReceiptLabel! is_message_out: Boolean! } @@ -361,18 +361,18 @@ type MessageOutReceipt @entity(virtual: true) { type MintReceipt @entity(virtual: true) { sub_id: Bytes32! contract_id: ContractId! - val: UInt8! - pc: UInt8! - isr: UInt8! + val: U64! + pc: U64! + isr: U64! } type BurnReceipt @entity(virtual: true) { sub_id: Bytes32! contract_id: ContractId! - val: UInt8! - pc: UInt8! - isr: UInt8! + val: U64! + pc: U64! + isr: U64! } union Receipt = @@ -394,7 +394,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! @@ -404,7 +404,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! @@ -412,7 +412,7 @@ type ChangeOutput @entity { type ContractOutput @entity { id: ID! - input_index: Int8! + input_index: I64! balance_root: Bytes32! state_root: Bytes32! is_contract: Boolean! @@ -423,7 +423,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! @@ -445,7 +445,7 @@ type ContractCreated @entity { type MessageOutput @entity { id: ID! - amount: UInt8! + amount: U64! recipient: Address! @indexed } @@ -462,16 +462,16 @@ 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!] witnesses: [Witness!] - salt: Salt! + salt: Bytes32! metadata: Json is_create: Boolean! receipts: [Receipt!] @@ -481,11 +481,11 @@ type CreateTransaction @entity { type ScriptTransaction @entity { id: ID! - gas_price: UInt8! - gas_limit: UInt8! - maturity: UInt4! - script: Blob! - script_data: Blob! + gas_price: U64! + gas_limit: U64! + maturity: U32! + script: Bytes! + script_data: Bytes! inputs: [Input!] outputs: [Output!] witnesses: [Witness!] @@ -512,14 +512,14 @@ union Transaction = CreateTransaction | ScriptTransaction | MintTransaction type SubmittedStatus @entity { id: ID! - time: UInt8! + time: U64! label: TransactionStatusLabel! is_submitted: Boolean! } type SqueezedOutStatus @entity { id: ID! - reason: Charfield! + reason: String! label: TransactionStatusLabel! is_squeezed_out: Boolean! } @@ -527,8 +527,8 @@ type SqueezedOutStatus @entity { type FailureStatus @entity { id: ID! block: BlockIdFragment! - time: UInt8! - reason: Charfield! + time: U64! + reason: String! program_state: ProgramState label: TransactionStatusLabel! is_failure: Boolean! @@ -536,7 +536,7 @@ type FailureStatus @entity { type SuccessStatus @entity { id: ID! - time: UInt8! + time: U64! block: BlockIdFragment! program_state: ProgramState label: TransactionStatusLabel! @@ -558,21 +558,21 @@ union TransactionStatus = type Header @entity { id: ID! - block_id: BlockId! - da_height: UInt8! - transactions_count: UInt8! - message_receipt_count: UInt8! + block_id: Bytes32! + 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! + time: I64! application_hash: Bytes32! } type Block @entity { id: ID! - block_id: BlockId! @indexed + block_id: Bytes32! @indexed header: Header! @indexed consensus: Consensus! transactions: [TransactionIdFragment!] @@ -582,60 +582,60 @@ type NodeInfo @entity { id: ID! utxo_validation: Boolean! vm_backtrace: Boolean! - min_gas_price: UInt8! - max_tx: UInt8! - max_depth: UInt8! - node_version: Charfield! + min_gas_price: U64! + max_tx: U64! + max_depth: U64! + node_version: String! } 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! - name: Charfield! - peer_count: Int4! + base_chain_height: U32! + name: String! + peer_count: I32! latest_block: Block! consensus_parameters: ConsensusParameters! } 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! + nonce: Bytes32! + da_height: U64! } type Contract @entity { id: ID! contract_id: ContractId! @indexed - bytecode: HexString! - salt: Salt! + bytecode: Bytes! + salt: Bytes32! } diff --git a/examples/fuel-explorer/fuel-explorer/src/lib.rs b/examples/fuel-explorer/fuel-explorer/src/lib.rs index c23b18ddb..fbd94ec2e 100644 --- a/examples/fuel-explorer/fuel-explorer/src/lib.rs +++ b/examples/fuel-explorer/fuel-explorer/src/lib.rs @@ -144,35 +144,31 @@ impl From for UtxoId { impl From for ContractIdFragment { fn from(hash: Bytes32) -> Self { - let hash = Bytes32::from(<[u8; 32]>::from(hash)); Self::new(hash).get_or_create() } } impl From for ContractIdFragment { fn from(hash: ContractId) -> Self { - let hash = Bytes32::from(<[u8; 32]>::from(hash)); - Self::new(hash).get_or_create() + Self::new(bytes32(hash)).get_or_create() } } impl From for BlockIdFragment { fn from(hash: Bytes32) -> Self { - let hash = Bytes32::from(<[u8; 32]>::from(hash)); Self::new(hash).get_or_create() } } impl From for TransactionIdFragment { fn from(hash: Bytes32) -> Self { - let hash = Bytes32::from(<[u8; 32]>::from(hash)); Self::new(hash).get_or_create() } } impl From for TransactionIdFragment { fn from(tx: fuel::TransactionData) -> Self { - Self::from(Bytes32::from(<[u8; 32]>::from(tx.id))).get_or_create() + Self::from(bytes32(tx.id)).get_or_create() } } @@ -259,7 +255,7 @@ impl From for Input { sender, recipient, amount, - Nonce::from(<[u8; 32]>::from(nonce)), + Bytes32::from(<[u8; 32]>::from(nonce)), witness_index.into(), data, predicate, @@ -834,7 +830,7 @@ impl From for Transaction { Some(inputs), Some(outputs), Some(witnesses), - salt, + bytes32(salt), metadata.to_owned().map(|m| m.into()), true, Some(receipts), diff --git a/examples/hello-world-native/hello-indexer-native/schema/hello_indexer_native.schema.graphql b/examples/hello-world-native/hello-indexer-native/schema/hello_indexer_native.schema.graphql index 98a900b13..7c2f35d16 100644 --- a/examples/hello-world-native/hello-indexer-native/schema/hello_indexer_native.schema.graphql +++ b/examples/hello-world-native/hello-indexer-native/schema/hello_indexer_native.schema.graphql @@ -1,14 +1,14 @@ # Calling this `Greeter` so as to not clash with `Person` in the contract type Greeter @entity { id: ID! - name: Charfield! - last_seen: UInt4! + name: String! + last_seen: U32! } # Calling this `Salutation` so as to not clash with `Greeting` in the contract type Salutation @entity { id: ID! - message: Charfield! + message: String! greeter: Greeter! - last_seen: UInt4! + last_seen: U32! } 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 98a900b13..7c2f35d16 100644 --- a/examples/hello-world/hello-indexer/schema/hello_indexer.schema.graphql +++ b/examples/hello-world/hello-indexer/schema/hello_indexer.schema.graphql @@ -1,14 +1,14 @@ # Calling this `Greeter` so as to not clash with `Person` in the contract type Greeter @entity { id: ID! - name: Charfield! - last_seen: UInt4! + name: String! + last_seen: U32! } # Calling this `Salutation` so as to not clash with `Greeting` in the contract type Salutation @entity { id: ID! - message: Charfield! + message: String! greeter: Greeter! - last_seen: UInt4! + 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-benchmarks/src/bin/qa.rs b/packages/fuel-indexer-benchmarks/src/bin/qa.rs index a8f5333b3..a843838d1 100644 --- a/packages/fuel-indexer-benchmarks/src/bin/qa.rs +++ b/packages/fuel-indexer-benchmarks/src/bin/qa.rs @@ -169,7 +169,19 @@ impl RunStat { } pub fn tick(&mut self) { - self.mem.push(record_mem_usage()); + // `sort` will occassionally panic, so just use the last iteration's value + let bytes = 1500; + let mem = match record_mem_usage() { + Ok(v) => { + if v.is_empty() { + self.mem.last().unwrap_or(&bytes).to_owned() + } else { + v.parse::().unwrap_or(bytes) + } + } + Err(_) => self.mem.last().unwrap_or(&bytes).clone(), + }; + self.mem.push(mem); self.cpu.push(record_cpu_usage()); } @@ -452,22 +464,19 @@ fn record_cpu_usage() -> f64 { .pipe(cmd!("awk", "{{print $4}}")) .stdout_capture() .read() - .unwrap(); + .unwrap_or_default(); output.trim().parse::().unwrap() } -fn record_mem_usage() -> u64 { - let output = cmd!("ps", "x", "-o", "rss,vsz,command") +fn record_mem_usage() -> Result { + cmd!("ps", "x", "-o", "rss,vsz,command") .pipe(cmd!("grep", "fuel-indexer")) .pipe(cmd!("sort", "-nr")) .pipe(cmd!("head", "-n", "1")) .pipe(cmd!("awk", "{print $1}")) .stdout_capture() .read() - .unwrap(); - - output.trim().parse::().unwrap() } #[tokio::main] diff --git a/packages/fuel-indexer-database/database-types/src/lib.rs b/packages/fuel-indexer-database/database-types/src/lib.rs index 512d18639..a872eb587 100644 --- a/packages/fuel-indexer-database/database-types/src/lib.rs +++ b/packages/fuel-indexer-database/database-types/src/lib.rs @@ -55,39 +55,28 @@ pub enum ColumnType { Bytes8 = 4, Bytes32 = 5, ContractId = 6, - Salt = 7, - Int4 = 8, - Int8 = 9, - UInt4 = 10, - UInt8 = 11, - Timestamp = 12, - Blob = 13, - ForeignKey = 14, - Json = 15, - MessageId = 16, - Charfield = 17, - Identity = 18, - Boolean = 19, - Object = 20, - UInt16 = 21, - Int16 = 22, - Bytes64 = 23, - Signature = 24, - Nonce = 25, - HexString = 26, - Tai64Timestamp = 27, - TxId = 28, - BlockHeight = 29, - Enum = 30, - Int1 = 31, - UInt1 = 32, - Virtual = 33, - BlockId = 34, - Array = 35, + I32 = 7, + I64 = 8, + U32 = 9, + U64 = 10, + Bytes = 11, + ForeignKey = 12, + Json = 13, + String = 14, + Identity = 15, + Boolean = 16, + Object = 17, + U128 = 18, + I128 = 19, + Bytes64 = 20, + Enum = 21, + I8 = 22, + U8 = 23, + Array = 24, // `ID` is a primary key, but when using foreign keys, we can't have two // primary key columns, so we need a version of `ID` that does not include // a primary key constraint. - UID = 36, + UID = 25, } impl From for i32 { @@ -100,36 +89,25 @@ impl From for i32 { ColumnType::Bytes8 => 4, ColumnType::Bytes32 => 5, ColumnType::ContractId => 6, - ColumnType::Salt => 7, - ColumnType::Int4 => 8, - ColumnType::Int8 => 9, - ColumnType::UInt4 => 10, - ColumnType::UInt8 => 11, - ColumnType::Timestamp => 12, - ColumnType::Blob => 13, - ColumnType::ForeignKey => 14, - ColumnType::Json => 15, - ColumnType::MessageId => 16, - ColumnType::Charfield => 17, - ColumnType::Identity => 18, - ColumnType::Boolean => 19, - ColumnType::Object => 20, - ColumnType::UInt16 => 21, - ColumnType::Int16 => 22, - ColumnType::Bytes64 => 23, - ColumnType::Signature => 24, - ColumnType::Nonce => 25, - ColumnType::HexString => 26, - ColumnType::Tai64Timestamp => 27, - ColumnType::TxId => 28, - ColumnType::BlockHeight => 29, - ColumnType::Enum => 30, - ColumnType::Int1 => 31, - ColumnType::UInt1 => 32, - ColumnType::Virtual => 33, - ColumnType::BlockId => 34, - ColumnType::Array => 35, - ColumnType::UID => 36, + ColumnType::I32 => 7, + ColumnType::I64 => 8, + ColumnType::U32 => 9, + ColumnType::U64 => 10, + ColumnType::Bytes => 11, + ColumnType::ForeignKey => 12, + ColumnType::Json => 13, + ColumnType::String => 14, + ColumnType::Identity => 15, + ColumnType::Boolean => 16, + ColumnType::Object => 17, + ColumnType::U128 => 18, + ColumnType::I128 => 19, + ColumnType::Bytes64 => 20, + ColumnType::Enum => 21, + ColumnType::I8 => 22, + ColumnType::U8 => 23, + ColumnType::Array => 24, + ColumnType::UID => 25, } } } @@ -157,36 +135,25 @@ impl From for ColumnType { 4 => ColumnType::Bytes8, 5 => ColumnType::Bytes32, 6 => ColumnType::ContractId, - 7 => ColumnType::Salt, - 8 => ColumnType::Int4, - 9 => ColumnType::Int8, - 10 => ColumnType::UInt4, - 11 => ColumnType::UInt8, - 12 => ColumnType::Timestamp, - 13 => ColumnType::Blob, - 14 => ColumnType::ForeignKey, - 15 => ColumnType::Json, - 16 => ColumnType::MessageId, - 17 => ColumnType::Charfield, - 18 => ColumnType::Identity, - 19 => ColumnType::Boolean, - 20 => ColumnType::Object, - 21 => ColumnType::Int16, - 22 => ColumnType::UInt16, - 23 => ColumnType::Bytes64, - 24 => ColumnType::Signature, - 25 => ColumnType::Nonce, - 26 => ColumnType::HexString, - 27 => ColumnType::Tai64Timestamp, - 28 => ColumnType::TxId, - 29 => ColumnType::BlockHeight, - 30 => ColumnType::Enum, - 31 => ColumnType::Int1, - 32 => ColumnType::UInt1, - 33 => ColumnType::Virtual, - 34 => ColumnType::BlockId, - 35 => ColumnType::Array, - 36 => ColumnType::UID, + 7 => ColumnType::I32, + 8 => ColumnType::I64, + 9 => ColumnType::U32, + 10 => ColumnType::U64, + 11 => ColumnType::Bytes, + 12 => ColumnType::ForeignKey, + 13 => ColumnType::Json, + 14 => ColumnType::String, + 15 => ColumnType::Identity, + 16 => ColumnType::Boolean, + 17 => ColumnType::Object, + 18 => ColumnType::I128, + 19 => ColumnType::U128, + 20 => ColumnType::Bytes64, + 21 => ColumnType::Enum, + 22 => ColumnType::I8, + 23 => ColumnType::U8, + 24 => ColumnType::Array, + 25 => ColumnType::UID, _ => unimplemented!("Invalid ColumnType: {num}."), } } @@ -195,42 +162,31 @@ 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, + "Boolean" => ColumnType::Boolean, + "Bytes" => ColumnType::Bytes, + "Bytes32" => ColumnType::Bytes32, "Bytes4" => ColumnType::Bytes4, + "Bytes64" => ColumnType::Bytes64, "Bytes8" => ColumnType::Bytes8, - "Bytes32" => ColumnType::Bytes32, "ContractId" => ColumnType::ContractId, - "Salt" => ColumnType::Salt, - "Int4" => ColumnType::Int4, - "Int8" => ColumnType::Int8, - "UInt4" => ColumnType::UInt4, - "UInt8" => ColumnType::UInt8, - "Timestamp" => ColumnType::Timestamp, - "Blob" => ColumnType::Blob, + "Enum" => ColumnType::Enum, "ForeignKey" => ColumnType::ForeignKey, - "Json" => ColumnType::Json, - "MessageId" => ColumnType::MessageId, - "Charfield" => ColumnType::Charfield, + "I128" => ColumnType::I128, + "I32" => ColumnType::I32, + "I64" => ColumnType::I64, + "I8" => ColumnType::I8, + "ID" => ColumnType::ID, "Identity" => ColumnType::Identity, - "Boolean" => ColumnType::Boolean, + "Json" => ColumnType::Json, "Object" => ColumnType::Object, - "UInt16" => ColumnType::UInt16, - "Int16" => ColumnType::Int16, - "Bytes64" => ColumnType::Bytes64, - "Signature" => ColumnType::Signature, - "Nonce" => ColumnType::Nonce, - "HexString" => ColumnType::HexString, - "Tai64Timestamp" => ColumnType::Tai64Timestamp, - "TxId" => ColumnType::TxId, - "BlockHeight" => ColumnType::BlockHeight, - "Enum" => ColumnType::Enum, - "Int1" => ColumnType::Int1, - "UInt1" => ColumnType::UInt1, - "Virtual" => ColumnType::Virtual, - "BlockId" => ColumnType::BlockId, - "Array" => ColumnType::Array, + "String" => ColumnType::String, + "U128" => ColumnType::U128, + "U32" => ColumnType::U32, + "U64" => ColumnType::U64, + "U8" => ColumnType::U8, "UID" => ColumnType::UID, _ => unimplemented!("Invalid ColumnType: '{name}'."), } @@ -380,73 +336,53 @@ impl Column { match self.coltype { ColumnType::Address => "varchar(64)".to_string(), ColumnType::AssetId => "varchar(64)".to_string(), - ColumnType::Blob => "varchar(10485760)".to_string(), - ColumnType::BlockHeight => "integer".to_string(), - ColumnType::BlockId => "varchar(64)".to_string(), + ColumnType::Bytes => "varchar(10485760)".to_string(), ColumnType::Boolean => "boolean".to_string(), ColumnType::Bytes32 => "varchar(64)".to_string(), ColumnType::Bytes4 => "varchar(8)".to_string(), ColumnType::Bytes64 => "varchar(128)".to_string(), ColumnType::Bytes8 => "varchar(16)".to_string(), - ColumnType::Charfield => "varchar(255)".to_string(), + ColumnType::String => "varchar(255)".to_string(), ColumnType::ContractId => "varchar(64)".to_string(), ColumnType::Enum => "varchar(255)".to_string(), ColumnType::ForeignKey => "numeric(20, 0)".to_string(), - 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::Int4 => "integer".to_string(), - ColumnType::Int8 => "bigint".to_string(), + ColumnType::I8 => "integer".to_string(), + ColumnType::I128 => "numeric(39, 0)".to_string(), + ColumnType::I32 => "integer".to_string(), + ColumnType::I64 => "bigint".to_string(), ColumnType::Json => "json".to_string(), - ColumnType::MessageId => "varchar(64)".to_string(), - ColumnType::Nonce => "varchar(64)".to_string(), ColumnType::Object => "bytea".to_string(), - ColumnType::Salt => "varchar(64)".to_string(), - ColumnType::Signature => "varchar(128)".to_string(), - 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::Virtual => "json".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::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::Int4 - | ColumnType::UInt4 - | ColumnType::BlockHeight => "integer", - ColumnType::Timestamp => "timestamp", - ColumnType::Int8 => "bigint", - ColumnType::UInt8 => "numeric(20, 0)", - ColumnType::UInt16 | ColumnType::Int16 => "numeric(39, 0)", + ColumnType::I8 + | ColumnType::U8 + | ColumnType::I32 + | ColumnType::U32 + | ColumnType::I64 => "bigint", + ColumnType::U64 => "numeric(20, 0)", + ColumnType::U128 | ColumnType::I128 => "numeric(39, 0)", ColumnType::Address | ColumnType::Bytes4 | ColumnType::Bytes8 | ColumnType::Bytes32 | ColumnType::AssetId | ColumnType::ContractId - | ColumnType::Salt - | ColumnType::MessageId - | ColumnType::Charfield + | ColumnType::String | ColumnType::Identity | ColumnType::Bytes64 - | ColumnType::Signature - | ColumnType::Nonce - | ColumnType::HexString - | ColumnType::TxId - | ColumnType::BlockId | ColumnType::ID | ColumnType::UID => "varchar(64)", - ColumnType::Blob => "bytea", - ColumnType::Json | ColumnType::Virtual => "json", + ColumnType::Bytes => "bytea", + ColumnType::Json => "json", _ => unimplemented!(), }; @@ -1276,15 +1212,15 @@ mod tests { let schema = r#" type Person @entity { id: ID! - name: Charfield! @unique - age: UInt1! + name: String! @unique + age: U8! }"#; let fields = [ ("id", "ID", None), ( "name", - "Charfield", + "String", Some(vec![Positioned { pos: Pos::default(), node: ConstDirective { @@ -1296,7 +1232,7 @@ type Person @entity { }, }]), ), - ("age", "UInt1", None), + ("age", "U8", None), ] .iter() .map(|(name, typ, directives)| { @@ -1354,8 +1290,8 @@ type Person @entity { let schema = r#" type Person @entity { id: ID! - name: Charfield! @unique - age: UInt1! + name: String! @unique + age: U8! }"#; let schema = ParsedGraphQLSchema::new( @@ -1376,7 +1312,7 @@ type Person @entity { ty: Positioned { pos: Pos::default(), node: Type { - base: BaseType::Named(Name::new("Charfield")), + base: BaseType::Named(Name::new("String")), nullable: false, }, }, @@ -1395,8 +1331,8 @@ type Person @entity { let type_id = type_id(&schema.fully_qualified_namespace(), "Person"); let column = Column::from_field_def(&field_def, &schema, type_id, 0, Persistence::Scalar); - assert_eq!(column.graphql_type, "Charfield".to_string()); - assert_eq!(column.coltype, ColumnType::Charfield); + assert_eq!(column.graphql_type, "String".to_string()); + assert_eq!(column.coltype, ColumnType::String); assert!(column.unique); assert!(!column.nullable); } @@ -1406,7 +1342,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-database/postgres/sqlx-data.json b/packages/fuel-indexer-database/postgres/sqlx-data.json index 5c9405e71..38e66a332 100644 --- a/packages/fuel-indexer-database/postgres/sqlx-data.json +++ b/packages/fuel-indexer-database/postgres/sqlx-data.json @@ -6,12 +6,12 @@ { "name": "id: i64", "ordinal": 0, - "type_info": "Int8" + "type_info": "I64" }, { "name": "root_id: i64", "ordinal": 1, - "type_info": "Int8" + "type_info": "I64" }, { "name": "column_name", @@ -32,7 +32,7 @@ ], "parameters": { "Left": [ - "Int8" + "I64" ] } }, @@ -44,7 +44,7 @@ { "name": "id", "ordinal": 0, - "type_info": "Int8" + "type_info": "I64" }, { "name": "namespace", @@ -77,7 +77,7 @@ { "name": "id", "ordinal": 0, - "type_info": "Int8" + "type_info": "I64" }, { "name": "namespace", @@ -107,17 +107,17 @@ { "name": "id: i64", "ordinal": 0, - "type_info": "Int8" + "type_info": "I64" }, { "name": "type_id", "ordinal": 1, - "type_info": "Int8" + "type_info": "I64" }, { "name": "column_position", "ordinal": 2, - "type_info": "Int4" + "type_info": "I32" }, { "name": "column_name", @@ -151,7 +151,7 @@ ], "parameters": { "Left": [ - "Int8" + "I64" ] } }, @@ -184,7 +184,7 @@ { "name": "type_id", "ordinal": 0, - "type_info": "Int8" + "type_info": "I64" }, { "name": "table_name", @@ -194,7 +194,7 @@ { "name": "column_position", "ordinal": 2, - "type_info": "Int4" + "type_info": "I32" }, { "name": "column_name", diff --git a/packages/fuel-indexer-graphql/src/dynamic.rs b/packages/fuel-indexer-graphql/src/dynamic.rs index 89cbd867a..4aad74ade 100644 --- a/packages/fuel-indexer-graphql/src/dynamic.rs +++ b/packages/fuel-indexer-graphql/src/dynamic.rs @@ -23,51 +23,36 @@ lazy_static! { static ref SCALAR_TYPES: HashSet<&'static str> = HashSet::from([ "Address", "AssetId", - "Blob", - "BlockHeight", - "BlockId", "Boolean", + "Bytes", "Bytes32", "Bytes4", "Bytes64", "Bytes8", - "Charfield", - "Color", "ContractId", - "HexString", + "I128", + "I32", + "I64", + "I8", "ID", "Identity", - "Int1", - "Int16", - "Int4", - "Int8", "Json", - "MessageId", - "Nonce", - "Salt", - "Signature", - "Tai64Timestamp", - "Timestamp", - "TxId", + "U128", + "U32", + "U64", + "U8", "UID", - "UInt1", - "UInt16", - "UInt4", - "UInt8", - "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", - "Int4", - "Int8", - "Timestamp", - "Tai64Timestamp", - "UInt16", - "UInt4", - "UInt8", + "I128", + "I32", + "I64", + "U128", + "U32", + "U64", ]); /// Scalar types that are represented by a string type. This ensures that the @@ -75,25 +60,16 @@ lazy_static! { static ref STRING_SCALAR_TYPES: HashSet<&'static str> = HashSet::from([ "Address", "AssetId", - "Blob", - "BlockHeight", - "BlockId", + "Bytes", "Bytes32", "Bytes4", "Bytes64", "Bytes64", "Bytes8", - "Charfield", - "Color", "ContractId", - "HexString", "ID", "Identity", "Json", - "MessageId", - "Nonce", - "Salt", - "Signature", "UID", ]); @@ -101,25 +77,16 @@ lazy_static! { static ref SORTABLE_SCALAR_TYPES: HashSet<&'static str> = HashSet::from([ "Address", "AssetId", - "Charfield", - "Color", "ContractId", - "HexString", + "I128", + "I32", + "I64", "ID", "Identity", - "Int16", - "Int4", - "Int8", - "MessageId", - "Nonce", - "Salt", - "Signature", - "Tai64Timestamp", - "Timestamp", + "U128", + "U32", + "U64", "UID", - "UInt16", - "UInt4", - "UInt8", ]); /// 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..ab7465d7c 100644 --- a/packages/fuel-indexer-graphql/src/graphql.rs +++ b/packages/fuel-indexer-graphql/src/graphql.rs @@ -756,13 +756,13 @@ mod tests { let schema = r#" type Block @entity { id: ID! - height: UInt8! - timestamp: Int8! + height: U64! + timestamp: I64! } type Tx @entity { id: ID! - timestamp: Int8! + timestamp: I64! block: Block input_data: Json! } diff --git a/packages/fuel-indexer-lib/src/constants.rs b/packages/fuel-indexer-lib/src/constants.rs index c874f9501..1cff8f521 100644 --- a/packages/fuel-indexer-lib/src/constants.rs +++ b/packages/fuel-indexer-lib/src/constants.rs @@ -12,48 +12,32 @@ lazy_static! { pub static ref ASREF_BYTE_TYPES: HashSet<&'static str> = HashSet::from([ "Address", "AssetId", - "Blob", - "BlockId", + "Bytes", "Boolean", "Bytes", - "Bytes20", "Bytes32", "Bytes4", "Bytes64", "Bytes8", - "Charfield", + "String", "ContractId", - "HexString", "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", - "Option", - "Option", - "Salt", - "Signature", "UID", - "TxId", - "Virtual", ]); /// Set of external types that do not implement `AsRef<[u8]>`. @@ -92,23 +76,19 @@ lazy_static! { /// Set of types that should be copied instead of referenced. pub static ref COPY_TYPES: HashSet<&'static str> = HashSet::from([ - "Blob", - "Charfield", - "HexString", + "Bytes", "ID", "Identity", "Json", - "Option", - "Option", - "Option", + "Option", "Option", "Option", "Option", "Option", - "Option", + "Option", "UID", "Vec", - "Virtual", + "String", ]); /// Fuel-specific receipt-related type names. @@ -133,39 +113,27 @@ lazy_static! { // Scalars. "Address", "AssetId", - "Blob", - "BlockHeight", - "BlockId", "Boolean", "Bytes", + "Bytes", "Bytes32", "Bytes4", "Bytes64", "Bytes8", - "Charfield", - "Color", "ContractId", - "HexString", + "I128", + "I32", + "I64", + "I8", "ID", "Identity", - "Int1", - "Int16", - "Int4", - "Int8", "Json", - "MessageId", - "Nonce", - "Salt", - "Signature", - "Tai64Timestamp", - "Timestamp", - "TxId", + "U128", + "U32", + "U64", + "U8", "UID", - "UInt1", - "UInt16", - "UInt4", - "UInt8", - "Virtual", + "String", // Imports for transaction fields. // https://github.com/FuelLabs/fuel-indexer/issues/286 diff --git a/packages/fuel-indexer-lib/src/graphql/base.graphql b/packages/fuel-indexer-lib/src/graphql/base.graphql index 60a95d400..a497706be 100644 --- a/packages/fuel-indexer-lib/src/graphql/base.graphql +++ b/packages/fuel-indexer-lib/src/graphql/base.graphql @@ -1,38 +1,26 @@ scalar Address scalar AssetId -scalar Blob -scalar BlockHeight -scalar BlockId scalar Boolean scalar Bytes +scalar Bytes scalar Bytes32 scalar Bytes4 scalar Bytes64 scalar Bytes8 -scalar Charfield -scalar Color scalar ContractId -scalar HexString +scalar I128 +scalar I32 +scalar I64 +scalar I8 scalar ID scalar Identity -scalar Int1 -scalar Int16 -scalar Int4 -scalar Int8 scalar Json -scalar MessageId -scalar Nonce -scalar Salt -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 +scalar String enum IndexType { BTree, diff --git a/packages/fuel-indexer-lib/src/graphql/constants.rs b/packages/fuel-indexer-lib/src/graphql/constants.rs index 08d77ac4c..5905bbf31 100644 --- a/packages/fuel-indexer-lib/src/graphql/constants.rs +++ b/packages/fuel-indexer-lib/src/graphql/constants.rs @@ -12,26 +12,19 @@ lazy_static! { pub static ref ASREF_BYTE_TYPES: HashSet<&'static str> = HashSet::from([ "Address", "AssetId", - "Blob", - "BlockId", + "Bytes", "Boolean", "Bytes", - "Bytes20", "Bytes32", "Bytes4", "Bytes64", "Bytes8", - "Charfield", + "String", "ContractId", - "HexString", "Json", - "MessageId", - "Virtual", - "Nonce", "Option
", "Option", - "Option", - "Option", + "Option", "Option", "Option", "Option", @@ -39,27 +32,15 @@ lazy_static! { "Option", "Option", "Option", - "Option", + "Option", "Option", - "Option", "Option", - "Option", - "Option", - "Option", - "Option", - "Option", - "Option", - "Salt", - "Signature", - "TxId", ]); /// 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. @@ -71,17 +52,13 @@ lazy_static! { /// Set of types that should be copied instead of referenced. pub static ref COPY_TYPES: HashSet<&'static str> = HashSet::from([ - "Blob", - "Charfield", - "HexString", + "Bytes", + "String", "Identity", "Json", - "Virtual", - "Option", - "Option", - "Option", + "Option", + "Option", "Option", "Option", - "Option", ]); } diff --git a/packages/fuel-indexer-lib/src/graphql/parser.rs b/packages/fuel-indexer-lib/src/graphql/parser.rs index 7956a26e7..0e609a7e7 100644 --- a/packages/fuel-indexer-lib/src/graphql/parser.rs +++ b/packages/fuel-indexer-lib/src/graphql/parser.rs @@ -401,9 +401,9 @@ impl ParsedGraphQLSchema { return ref_coltype; } else if self.is_virtual_typedef(&typ_name) { - return "Virtual".to_string(); + return "Json".to_string(); } else if self.is_enum_typedef(&typ_name) { - return "Charfield".to_string(); + return "String".to_string(); } else { return typ_name; } @@ -416,11 +416,11 @@ impl ParsedGraphQLSchema { } if self.is_virtual_typedef(&typ_name) { - return "Virtual".to_string(); + return "Json".to_string(); } if self.is_enum_typedef(&typ_name) { - return "Charfield".to_string(); + return "String".to_string(); } typ_name @@ -967,17 +967,17 @@ type Account @entity { type User @entity { id: ID! account: Account! - username: Charfield! + username: String! } type Loser @entity { id: ID! account: Account! - age: UInt8! + age: U64! } type Metadata @entity(virtual: true) { - count: UInt8! + count: U64! } union Person = User | Loser @@ -995,7 +995,7 @@ type Safe @entity { type Vault @entity { id: ID! - label: Charfield! + label: String! user: [User!]! } @@ -1079,16 +1079,16 @@ type TransactionData @entity { let schema = r#" type Foo @entity { id: ID! - name: Charfield! + name: String! } type Bar @entity { id: ID! - age: UInt8! + age: U64! } type Zoo @entity(virtual: true) { - height: UInt8! + height: U64! } union Baz = Foo | Bar | Zoo @@ -1111,17 +1111,17 @@ union Baz = Foo | Bar | Zoo let schema = r#" type Foo @entity { id: ID! - name: Charfield! + name: String! } type Bar @entity { id: ID! - age: UInt8! + age: U64! } type Zoo @entity { id: ID! - name: UInt8! + name: U64! } union Baz = Foo | Bar | Zoo @@ -1144,7 +1144,7 @@ union Baz = Foo | Bar | Zoo let schema = r#" type Foo @entity { id: ID! - name: Charfield! + name: String! } type Zoo @entity { @@ -1164,13 +1164,13 @@ type Zoo @entity { #[test] #[should_panic( - expected = "FieldDefinition(id) on TypeDefinition(Foo) must be of type `ID!`. Found type `Charfield!`." + expected = "FieldDefinition(id) on TypeDefinition(Foo) must be of type `ID!`. Found type `String!`." )] fn test_schema_validator_id_field_is_type_id() { let schema = r#" type Foo @entity { - id: Charfield! - name: Charfield! + id: String! + name: String! }"#; let _ = ParsedGraphQLSchema::new( @@ -1190,7 +1190,7 @@ type Foo @entity { let schema = r#" type Foo @entity(virtual: true) { id: ID! - name: Charfield! + name: String! }"#; let _ = ParsedGraphQLSchema::new( @@ -1210,7 +1210,7 @@ type Foo @entity(virtual: true) { let schema = r#" type Foo @entity { id: ID! - name: Charfield! + name: String! } type Bar @entity { @@ -1236,57 +1236,57 @@ type Bar @entity { let schema = r#" type Type1 @entity { id: ID! - name: Charfield! + name: String! } type Type2 @entity { id: ID! - name: Charfield! + name: String! } type Type3 @entity { id: ID! - name: Charfield! + name: String! } type Type4 @entity { id: ID! - name: Charfield! + name: String! } type Type5 @entity { id: ID! - name: Charfield! + name: String! } type Type6 @entity { id: ID! - name: Charfield! + name: String! } type Type7 @entity { id: ID! - name: Charfield! + name: String! } type Type8 @entity { id: ID! - name: Charfield! + name: String! } type Type9 @entity { id: ID! - name: Charfield! + name: String! } type Type10 @entity { id: ID! - name: Charfield! + name: String! } type Type11 @entity { id: ID! - name: Charfield! + name: String! } type Bar @entity { @@ -1316,13 +1316,13 @@ type Bar @entity { #[test] #[should_panic( - expected = "FieldDefinition(foo) on TypeDefinition(Bar) is a many-to-many relationship where the inner scalar is of type `name: Charfield!`. However, only inner scalars of type `id: ID!` are allowed." + expected = "FieldDefinition(foo) on TypeDefinition(Bar) is a many-to-many relationship where the inner scalar is of type `name: String!`. However, only inner scalars of type `id: ID!` are allowed." )] fn test_schema_validator_m2m_fk_field_ref_col_is_id() { let schema = r#" type Foo @entity { id: ID! - name: Charfield! + name: String! } type Bar @entity { diff --git a/packages/fuel-indexer-macros/src/decoder.rs b/packages/fuel-indexer-macros/src/decoder.rs index d875e3f80..cf50be7d9 100644 --- a/packages/fuel-indexer-macros/src/decoder.rs +++ b/packages/fuel-indexer-macros/src/decoder.rs @@ -967,11 +967,11 @@ mod tests { let schema = r#" type Person @entity { id: ID! - name: Charfield! - age: UInt1! + name: String! + age: U8! }"#; - let fields = [("id", "ID"), ("name", "Charfield"), ("age", "UInt1")] + let fields = [("id", "ID"), ("name", "String"), ("age", "U8")] .iter() .map(|(name, typ)| Positioned { pos: Pos::default(), @@ -1032,9 +1032,7 @@ type Person @entity { assert!(tokenstream.contains("pub struct Person")); 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") - ); + assert!(tokenstream.contains("pub fn new (name : String , age : U8 ,) -> Self")); assert!(tokenstream.contains("pub fn get_or_create (self) -> Self")); assert!(tokenstream.contains("fn from_row (mut vec : Vec < FtColumn >) -> Self")); assert!(tokenstream.contains("fn to_row (& self) -> Vec < FtColumn >")); @@ -1046,7 +1044,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/src/lib.rs b/packages/fuel-indexer-schema/src/lib.rs index 29f0e9152..1605e5452 100644 --- a/packages/fuel-indexer-schema/src/lib.rs +++ b/packages/fuel-indexer-schema/src/lib.rs @@ -8,7 +8,7 @@ extern crate alloc; use fuel_indexer_lib::MAX_ARRAY_LENGTH; -use fuel_indexer_types::{fuel::*, scalar::*, Identity}; +use fuel_indexer_types::{scalar::*, Identity}; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -53,38 +53,27 @@ pub enum FtColumn { Address(Option
), Array(Option>), AssetId(Option), - Blob(Option), - BlockHeight(Option), - BlockId(Option), Boolean(Option), + Bytes(Option), Bytes32(Option), Bytes4(Option), Bytes64(Option), Bytes8(Option), - Charfield(Option), ContractId(Option), Enum(Option), - HexString(Option), + I128(Option), + I32(Option), + I64(Option), + I8(Option), ID(Option), Identity(Option), - Int1(Option), - Int16(Option), - Int4(Option), - Int8(Option), Json(Option), - MessageId(Option), - Nonce(Option), - Salt(Option), - Signature(Option), - Tai64Timestamp(Option), - Timestamp(Option), - TxId(Option), + U128(Option), + U32(Option), + U64(Option), + U8(Option), UID(Option), - UInt1(Option), - UInt16(Option), - UInt4(Option), - UInt8(Option), - Virtual(Option), + String(Option), } impl FtColumn { @@ -121,11 +110,7 @@ impl FtColumn { Some(val) => format!("'{val:x}'"), None => String::from(NULL_VALUE), }, - FtColumn::Bytes32(value) | FtColumn::BlockId(value) => match value { - Some(val) => format!("'{val:x}'"), - None => String::from(NULL_VALUE), - }, - FtColumn::Nonce(value) => match value { + FtColumn::Bytes32(value) => match value { Some(val) => format!("'{val:x}'"), None => String::from(NULL_VALUE), }, @@ -133,85 +118,50 @@ impl FtColumn { Some(val) => format!("'{val:x}'"), None => String::from(NULL_VALUE), }, - FtColumn::TxId(value) => match value { - Some(val) => format!("'{val:x}'"), - None => String::from(NULL_VALUE), - }, - FtColumn::HexString(value) => match value { - Some(val) => format!("'{val:x}'"), - None => String::from(NULL_VALUE), - }, - FtColumn::Signature(value) => match value { - Some(val) => format!("'{val:x}'"), - None => String::from(NULL_VALUE), - }, FtColumn::ContractId(value) => match value { Some(val) => format!("'{val:x}'"), None => String::from(NULL_VALUE), }, - FtColumn::Int4(value) => match value { - Some(val) => format!("{val}"), - None => String::from(NULL_VALUE), - }, - FtColumn::Int1(value) => match value { - Some(val) => format!("{val}"), - None => String::from(NULL_VALUE), - }, - FtColumn::UInt1(value) => match value { + FtColumn::I32(value) => match value { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), }, - FtColumn::Int8(value) => match value { + FtColumn::I8(value) => match value { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), }, - FtColumn::Int16(value) => match value { + FtColumn::U8(value) => match value { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), }, - FtColumn::UInt4(value) => match value { + FtColumn::I64(value) => match value { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), }, - FtColumn::BlockHeight(value) => match value { + FtColumn::I128(value) => match value { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), }, - FtColumn::UInt8(value) => match value { + FtColumn::U32(value) => match value { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), }, - FtColumn::UInt16(value) => match value { + FtColumn::U64(value) => match value { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), }, - FtColumn::Timestamp(value) => match value { + FtColumn::U128(value) => match value { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), }, - FtColumn::Tai64Timestamp(value) => match value { - Some(val) => { - let x = hex::encode(val.to_bytes()); - format!("'{x}'") - } - None => String::from(NULL_VALUE), - }, - FtColumn::Salt(value) => match value { - Some(val) => format!("'{val:x}'"), - None => String::from(NULL_VALUE), - }, - FtColumn::Json(value) | FtColumn::Virtual(value) => match value { + FtColumn::Json(value) => match value { Some(val) => { let x = &val.0; format!("'{x}'") } None => String::from(NULL_VALUE), }, - FtColumn::MessageId(value) => match value { - Some(val) => format!("'{val:x}'"), - None => String::from(NULL_VALUE), - }, - FtColumn::Charfield(value) => match value { + FtColumn::String(value) => match value { Some(val) => format!("'{val}'"), None => String::from(NULL_VALUE), }, @@ -226,7 +176,7 @@ impl FtColumn { Some(val) => format!("{val}"), None => String::from(NULL_VALUE), }, - FtColumn::Blob(value) => match value { + FtColumn::Bytes(value) => match value { Some(blob) => { let x = hex::encode(blob.as_ref()); format!("'{x}'") @@ -272,7 +222,7 @@ impl FtColumn { // We have to force sqlx to see this as a JSON type else it will think this type // should be TEXT let suffix = match arr[0] { - FtColumn::Virtual(_) | FtColumn::Json(_) => "::json[]", + FtColumn::Json(_) => "::json[]", _ => "", }; @@ -308,78 +258,50 @@ mod tests { FtColumn::Bytes8(Some(Bytes8::try_from([0x9D; 8]).expect("Bad bytes"))); let bytes32 = FtColumn::Bytes32(Some(Bytes32::try_from([0xEE; 32]).expect("Bad bytes"))); - let nonce = - FtColumn::Nonce(Some(Nonce::try_from([0x12; 32]).expect("Bad bytes"))); let bytes64 = FtColumn::Bytes64(Some(Bytes64::try_from([0x12; 64]).expect("Bad bytes"))); - let txid = FtColumn::TxId(Some(TxId::try_from([0x12; 32]).expect("Bad bytes"))); - let hex = FtColumn::HexString(Some( - HexString::try_from("this is a hexstring").expect("Bad bytes"), - )); - let sig = FtColumn::Signature(Some( - Signature::try_from([0x12; 64]).expect("Bad bytes"), - )); let contractid = FtColumn::ContractId(Some( ContractId::try_from([0x78; 32]).expect("Bad bytes"), )); - 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 uint1 = FtColumn::UInt1(Some(u8::from_le_bytes([0x78; 1]))); - let uint8 = FtColumn::UInt8(Some(u64::from_le_bytes([0x78; 8]))); - let uint16 = FtColumn::UInt16(Some(u128::from_le_bytes([0x78; 16]))); - let int64 = FtColumn::Timestamp(Some(i64::from_le_bytes([0x78; 8]))); - let block_height = - FtColumn::BlockHeight(Some(BlockHeight::try_from(0x78).unwrap())); - let timestamp = FtColumn::Timestamp(Some(i64::from_le_bytes([0x78; 8]))); - let tai64_timestamp = FtColumn::Tai64Timestamp(Some( - Tai64Timestamp::try_from([0u8; 8]).expect("Bad bytes"), - )); - let salt = FtColumn::Salt(Some(Salt::try_from([0x31; 32]).expect("Bad bytes"))); - let message_id = FtColumn::MessageId(Some( - MessageId::try_from([0x0F; 32]).expect("Bad bytes"), - )); - let charfield = FtColumn::Charfield(Some(String::from("hello world"))); - let json = FtColumn::Json(Some(Json(r#"{"hello":"world"}"#.to_string()))); + let array = FtColumn::Array(Some(vec![FtColumn::I32(Some(1))])); + let bytes = FtColumn::Bytes(Some(Bytes::from(vec![0u8, 1, 2, 3, 4, 5]))); let identity = FtColumn::Identity(Some(Identity::Address([0x12; 32].into()))); + let int16 = FtColumn::I128(Some(i128::from_le_bytes([0x78; 16]))); + let int4 = FtColumn::I32(Some(i32::from_le_bytes([0x78; 4]))); + let int64 = FtColumn::I64(Some(i64::from_le_bytes([0x78; 8]))); + let int8 = FtColumn::I64(Some(i64::from_le_bytes([0x78; 8]))); + let json = FtColumn::Json(Some(Json(r#"{"hello":"world"}"#.to_string()))); let r#bool = FtColumn::Boolean(Some(true)); - let blob = FtColumn::Blob(Some(Blob::from(vec![0u8, 1, 2, 3, 4, 5]))); let r#enum = FtColumn::Enum(Some(String::from("hello"))); - let array = FtColumn::Array(Some(vec![FtColumn::Int4(Some(1))])); + let uint1 = FtColumn::U8(Some(u8::from_le_bytes([0x78; 1]))); + let uint16 = FtColumn::U128(Some(u128::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 xstring = FtColumn::String(Some(String::from("hello world"))); - insta::assert_yaml_snapshot!(uid.query_fragment()); insta::assert_yaml_snapshot!(addr.query_fragment()); + insta::assert_yaml_snapshot!(array.query_fragment()); insta::assert_yaml_snapshot!(asset_id.query_fragment()); - insta::assert_yaml_snapshot!(bytes4.query_fragment()); - insta::assert_yaml_snapshot!(bytes8.query_fragment()); + insta::assert_yaml_snapshot!(bytes.query_fragment()); insta::assert_yaml_snapshot!(bytes32.query_fragment()); - insta::assert_yaml_snapshot!(nonce.query_fragment()); + insta::assert_yaml_snapshot!(bytes4.query_fragment()); insta::assert_yaml_snapshot!(bytes64.query_fragment()); - insta::assert_yaml_snapshot!(txid.query_fragment()); - insta::assert_yaml_snapshot!(hex.query_fragment()); - insta::assert_yaml_snapshot!(sig.query_fragment()); + insta::assert_yaml_snapshot!(bytes8.query_fragment()); insta::assert_yaml_snapshot!(contractid.query_fragment()); - insta::assert_yaml_snapshot!(salt.query_fragment()); - insta::assert_yaml_snapshot!(int4.query_fragment()); - insta::assert_yaml_snapshot!(int8.query_fragment()); + insta::assert_yaml_snapshot!(identity.query_fragment()); insta::assert_yaml_snapshot!(int16.query_fragment()); - insta::assert_yaml_snapshot!(uint4.query_fragment()); - insta::assert_yaml_snapshot!(uint1.query_fragment()); - insta::assert_yaml_snapshot!(uint8.query_fragment()); - insta::assert_yaml_snapshot!(uint16.query_fragment()); + insta::assert_yaml_snapshot!(int4.query_fragment()); insta::assert_yaml_snapshot!(int64.query_fragment()); - insta::assert_yaml_snapshot!(block_height.query_fragment()); - insta::assert_yaml_snapshot!(timestamp.query_fragment()); - insta::assert_yaml_snapshot!(tai64_timestamp.query_fragment()); - insta::assert_yaml_snapshot!(message_id.query_fragment()); - insta::assert_yaml_snapshot!(charfield.query_fragment()); + insta::assert_yaml_snapshot!(int8.query_fragment()); insta::assert_yaml_snapshot!(json.query_fragment()); - insta::assert_yaml_snapshot!(identity.query_fragment()); insta::assert_yaml_snapshot!(r#bool.query_fragment()); - insta::assert_yaml_snapshot!(blob.query_fragment()); insta::assert_yaml_snapshot!(r#enum.query_fragment()); - insta::assert_yaml_snapshot!(array.query_fragment()); + insta::assert_yaml_snapshot!(uid.query_fragment()); + insta::assert_yaml_snapshot!(uint1.query_fragment()); + insta::assert_yaml_snapshot!(uint16.query_fragment()); + insta::assert_yaml_snapshot!(uint4.query_fragment()); + insta::assert_yaml_snapshot!(uint8.query_fragment()); + insta::assert_yaml_snapshot!(xstring.query_fragment()); } #[test] @@ -387,66 +309,48 @@ mod tests { use super::*; let addr_none = FtColumn::Address(None); + let array = FtColumn::Array(None); let asset_id_none = FtColumn::AssetId(None); + let bytes = FtColumn::Bytes(None); + let bytes32_none = FtColumn::Bytes32(None); let bytes4_none = FtColumn::Bytes4(None); + let bytes64 = FtColumn::Bytes64(None); let bytes8_none = FtColumn::Bytes8(None); - let bytes32_none = FtColumn::Bytes32(None); let contractid_none = FtColumn::ContractId(None); - 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 int64_none = FtColumn::Timestamp(None); - let salt_none = FtColumn::Salt(None); - let message_id_none = FtColumn::MessageId(None); - let charfield_none = FtColumn::Charfield(None); - let json_none = FtColumn::Json(None); let identity_none = FtColumn::Identity(None); - let nonce = FtColumn::Nonce(None); - let bytes64 = FtColumn::Bytes64(None); - let txid = FtColumn::TxId(None); - let hex = FtColumn::HexString(None); - let sig = FtColumn::Signature(None); - let block_height = FtColumn::BlockHeight(None); - let timestamp = FtColumn::Timestamp(None); - let tai64_timestamp = FtColumn::Tai64Timestamp(None); + let int16_none = FtColumn::I64(None); + let int4_none = FtColumn::I32(None); + let int64_none = FtColumn::I64(None); + let int8_none = FtColumn::I64(None); + let json_none = FtColumn::Json(None); let r#bool = FtColumn::Boolean(None); - let blob = FtColumn::Blob(None); let r#enum = FtColumn::Enum(None); - let array = FtColumn::Array(None); + let uint16_none = FtColumn::U64(None); + let uint4_none = FtColumn::U32(None); + let uint8_none = FtColumn::U64(None); + let xstring_none = FtColumn::String(None); insta::assert_yaml_snapshot!(addr_none.query_fragment()); + insta::assert_yaml_snapshot!(array.query_fragment()); insta::assert_yaml_snapshot!(asset_id_none.query_fragment()); + insta::assert_yaml_snapshot!(bytes.query_fragment()); + insta::assert_yaml_snapshot!(bytes32_none.query_fragment()); insta::assert_yaml_snapshot!(bytes4_none.query_fragment()); + insta::assert_yaml_snapshot!(bytes64.query_fragment()); insta::assert_yaml_snapshot!(bytes8_none.query_fragment()); - insta::assert_yaml_snapshot!(bytes32_none.query_fragment()); insta::assert_yaml_snapshot!(contractid_none.query_fragment()); - insta::assert_yaml_snapshot!(salt_none.query_fragment()); - insta::assert_yaml_snapshot!(int4_none.query_fragment()); - insta::assert_yaml_snapshot!(int8_none.query_fragment()); + insta::assert_yaml_snapshot!(identity_none.query_fragment()); insta::assert_yaml_snapshot!(int16_none.query_fragment()); - insta::assert_yaml_snapshot!(uint4_none.query_fragment()); - insta::assert_yaml_snapshot!(uint8_none.query_fragment()); - insta::assert_yaml_snapshot!(uint16_none.query_fragment()); + insta::assert_yaml_snapshot!(int4_none.query_fragment()); insta::assert_yaml_snapshot!(int64_none.query_fragment()); - insta::assert_yaml_snapshot!(message_id_none.query_fragment()); - insta::assert_yaml_snapshot!(charfield_none.query_fragment()); + insta::assert_yaml_snapshot!(int8_none.query_fragment()); insta::assert_yaml_snapshot!(json_none.query_fragment()); - insta::assert_yaml_snapshot!(identity_none.query_fragment()); - insta::assert_yaml_snapshot!(nonce.query_fragment()); - insta::assert_yaml_snapshot!(bytes64.query_fragment()); - insta::assert_yaml_snapshot!(txid.query_fragment()); - insta::assert_yaml_snapshot!(hex.query_fragment()); - insta::assert_yaml_snapshot!(sig.query_fragment()); - insta::assert_yaml_snapshot!(block_height.query_fragment()); - insta::assert_yaml_snapshot!(timestamp.query_fragment()); - insta::assert_yaml_snapshot!(tai64_timestamp.query_fragment()); insta::assert_yaml_snapshot!(r#bool.query_fragment()); - insta::assert_yaml_snapshot!(blob.query_fragment()); insta::assert_yaml_snapshot!(r#enum.query_fragment()); - insta::assert_yaml_snapshot!(array.query_fragment()); + insta::assert_yaml_snapshot!(uint16_none.query_fragment()); + insta::assert_yaml_snapshot!(uint4_none.query_fragment()); + insta::assert_yaml_snapshot!(uint8_none.query_fragment()); + insta::assert_yaml_snapshot!(xstring_none.query_fragment()); } #[test] diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-10.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-10.snap index b06dca9aa..f0e136800 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-10.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-10.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: hex.query_fragment() +expression: identity.query_fragment() --- -"'74686973206973206120686578737472696e67'" +"'1212121212121212121212121212121212121212121212121212121212121212'" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-11.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-11.snap index 6f08b4a22..f25d928ec 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-11.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-11.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: sig.query_fragment() +expression: int16.query_fragment() --- -"'12121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212'" +"160132878551029865159235109379655628920" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-12.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-12.snap index e372c02fc..eec7383bf 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-12.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-12.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: contractid.query_fragment() +expression: int4.query_fragment() --- -"'7878787878787878787878787878787878787878787878787878787878787878'" +"2021161080" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-13.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-13.snap index 82cc7387f..99ecba546 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-13.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-13.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: salt.query_fragment() +expression: int64.query_fragment() --- -"'3131313131313131313131313131313131313131313131313131313131313131'" +"8680820740569200760" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-14.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-14.snap index eec7383bf..4cb031a9b 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-14.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-14.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: int4.query_fragment() +expression: int8.query_fragment() --- -"2021161080" +"8680820740569200760" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-15.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-15.snap index 99ecba546..a8aa65623 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-15.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-15.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: int64.query_fragment() +expression: json.query_fragment() --- -"8680820740569200760" +"'{\"hello\":\"world\"}'" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-16.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-16.snap index f25d928ec..aa1625461 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-16.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-16.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: int16.query_fragment() +expression: bool.query_fragment() --- -"160132878551029865159235109379655628920" +"true" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-17.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-17.snap index b85fe7cc2..9e48debc2 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-17.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-17.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: uint4.query_fragment() +expression: "r#enum.query_fragment()" --- -"2021161080" +"'hello'" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-18.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-18.snap index a568e0424..82218dfdc 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-18.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-18.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: uint1.query_fragment() +expression: uid.query_fragment() --- -"120" +"'0000000000000000000000000000000000000000000000000000000000000000'" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-19.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-19.snap index 5eef3ec48..a568e0424 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-19.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-19.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: uint8.query_fragment() +expression: uint1.query_fragment() --- -"8680820740569200760" +"120" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-2.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-2.snap index f2261536c..7e0273c75 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-2.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-2.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: addr.query_fragment() +expression: array.query_fragment() --- -"'1212121212121212121212121212121212121212121212121212121212121212'" +"ARRAY [1]" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-21.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-21.snap index 99ecba546..b85fe7cc2 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-21.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-21.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: int64.query_fragment() +expression: uint4.query_fragment() --- -"8680820740569200760" +"2021161080" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-22.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-22.snap index 5720c79ec..5eef3ec48 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-22.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-22.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: block_height.query_fragment() +expression: uint8.query_fragment() --- -"00000078" +"8680820740569200760" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-23.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-23.snap index fd3b3daff..96ab48b80 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-23.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-23.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: timestamp.query_fragment() +expression: xstring.query_fragment() --- -"8680820740569200760" +"'hello world'" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-4.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-4.snap index 63a324d47..547c7c573 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-4.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-4.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: bytes4.query_fragment() +expression: bytes.query_fragment() --- -"'f0f0f0f0'" +"'000102030405'" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-5.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-5.snap index 9c743d80a..663eb4a12 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-5.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-5.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: bytes8.query_fragment() +expression: bytes32.query_fragment() --- -"'9d9d9d9d9d9d9d9d'" +"'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-6.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-6.snap index 663eb4a12..63a324d47 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-6.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-6.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: bytes32.query_fragment() +expression: bytes4.query_fragment() --- -"'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'" +"'f0f0f0f0'" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-7.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-7.snap index 8db0c6511..177fe61b9 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-7.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-7.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: nonce.query_fragment() +expression: bytes64.query_fragment() --- -"'1212121212121212121212121212121212121212121212121212121212121212'" +"'12121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212'" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-8.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-8.snap index 177fe61b9..9c743d80a 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-8.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-8.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: bytes64.query_fragment() +expression: bytes8.query_fragment() --- -"'12121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212'" +"'9d9d9d9d9d9d9d9d'" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-9.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-9.snap index 144ba0424..e372c02fc 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-9.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types-9.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: txid.query_fragment() +expression: contractid.query_fragment() --- -"'1212121212121212121212121212121212121212121212121212121212121212'" +"'7878787878787878787878787878787878787878787878787878787878787878'" diff --git a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types.snap b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types.snap index 03e0d54e4..f2261536c 100644 --- a/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types.snap +++ b/packages/fuel-indexer-schema/src/snapshots/fuel_indexer_schema__tests__fragments_some_types.snap @@ -1,6 +1,6 @@ --- source: packages/fuel-indexer-schema/src/lib.rs -expression: id.query_fragment() +expression: addr.query_fragment() --- -"'0000000000000000000000000000000000000000000000000000000000000000'" +"'1212121212121212121212121212121212121212121212121212121212121212'" 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..eb7c16554 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,38 +1,38 @@ type PingEntity @entity { id: ID! - value: UInt8! - message: Charfield! + value: U64! + message: String! } 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! - timestamp: Int8! + height: U32! + timestamp: I64! } type TxEntity @entity { id: ID! block: BlockEntity! input_data: Json! - timestamp: Int8! + timestamp: I64! } type TransferEntity @entity { @@ -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,52 +48,52 @@ 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! - blob: Blob! + result: U64! + gas_used: U64! + blob: Bytes! } type MessageOutEntity @entity { id: ID! - message_id: MessageId! + message_id: Bytes32! sender: Address! recipient: Address! - amount: UInt8! - nonce: Nonce! - len: UInt8! + amount: U64! + nonce: Bytes32! + 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! - simple_a: Charfield! + complex_a: String! + complex_b: U64! + simple_a: String! } type MessageEntity @entity { id: ID! - message: Charfield! + message: String! } type CallEntity @entity { @@ -101,91 +101,91 @@ type CallEntity @entity { contract_id: ContractId! callee: ContractId! asset_id: AssetId! - gas: UInt8! - fn_name: Charfield! - amount: UInt8! + gas: U64! + fn_name: String! + 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 { id: ID! - name: Charfield! + name: String! } type Person @entity { id: ID! - name: Charfield! + name: String! } type Planet @entity { id: ID! - name: Charfield! + name: String! } type Continent @entity { id: ID! - name: Charfield! + name: String! planet: Planet! } type Country @entity { id: ID! - name: Charfield! + name: String! continent: Continent! } type Region @entity { id: ID! - name: Charfield! + name: String! country: Country! } type City @entity { id: ID! - name: Charfield! + name: String! region: Region! } type Author @entity { id: ID! - name: Charfield! + name: String! genre: Genre! } type Library @entity { id: ID! - name: Charfield! + name: String! city: City! } type Book @entity { id: ID! - name: Charfield! + name: String! author: Author! @indexed library: Library! genre: Genre! @@ -193,8 +193,8 @@ type Book @entity { type Sponsor @entity { id: ID! - name: Charfield! @unique - amount: UInt8! + name: String! @unique + amount: U64! representative: Person! } @@ -208,42 +208,42 @@ type BookClub @entity { type Municipality @entity { id: ID! - name: Charfield! @unique + name: String! @unique } type SportsTeam @entity { id: ID! - name: Charfield! + name: String! municipality: Municipality! @join(on: name) } type InnerFilterEntity @entity { id: ID! - inner_foo: Charfield! - inner_bar: UInt8! - inner_baz: UInt8! + inner_foo: String! + inner_bar: U64! + inner_baz: U64! } type FilterEntity @entity { id: ID! - foola: Charfield! - maybe_null_bar: UInt8 - bazoo: UInt8! + foola: String! + 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 { id: ID! - nonce: Nonce! - time: Tai64Timestamp - hex: HexString - sig: Signature! + nonce: Bytes32! + time: U64 + hex: Bytes + sig: Bytes64! bytes: Bytes64! } @@ -259,13 +259,13 @@ type ComplexEnumEntity @entity { } type VirtualEntity @entity(virtual: true) { - name: Charfield - size: UInt1! + name: String + size: U8! } type UsesVirtualEntity @entity { id: ID! - name: Charfield! + name: String! no_table: VirtualEntity! } @@ -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,16 +320,16 @@ type VirtualUnionContainerEntity @entity { type ListFKType @entity { id: ID! - value: UInt8! + value: U64! } type ListTypeEntity @entity { id: ID! - foo_field: Charfield! + foo_field: String! required_all: [ListFKType!]! - optional_inner: [Charfield]! - optional_outer: [UInt8!] - optional_all: [UInt8] + optional_inner: [String]! + optional_outer: [U64!] + optional_all: [U64] virtual_optional_inner: [VirtualEntity]! enum_required_all: [EnumEntity!]! } diff --git a/packages/fuel-indexer-tests/indexers/fuel-indexer-test/src/lib.rs b/packages/fuel-indexer-tests/indexers/fuel-indexer-test/src/lib.rs index a86761c60..b3658f8bd 100644 --- a/packages/fuel-indexer-tests/indexers/fuel-indexer-test/src/lib.rs +++ b/packages/fuel-indexer-tests/indexers/fuel-indexer-test/src/lib.rs @@ -120,8 +120,16 @@ mod fuel_indexer_test { .. } = messageout; - MessageOutEntity::new(message_id, sender, recipient, amount, nonce, len, digest) - .get_or_create(); + MessageOutEntity::new( + bytes32(message_id), + sender, + recipient, + amount, + bytes32(nonce), + len, + digest, + ) + .get_or_create(); } fn fuel_indexer_test_callreturn(pungentity: Pung) { @@ -423,11 +431,11 @@ mod fuel_indexer_test { info!("fuel_indexer_block_explorer_types handling explorer_types event."); let e = ExplorerEntity { id: uid(8675309_u32.to_le_bytes()), - nonce: Nonce::default(), + nonce: Bytes32::default(), // TOOD: Finish time: None, - hex: Some(HexString::from("hello world!")), - sig: Signature::default(), + hex: Some(Bytes::from("hello world!")), + sig: Bytes64::default(), bytes: Bytes64::default(), }; diff --git a/packages/fuel-indexer-tests/tests/indexing.rs b/packages/fuel-indexer-tests/tests/indexing.rs index d4fc97910..bd27f3a0d 100644 --- a/packages/fuel-indexer-tests/tests/indexing.rs +++ b/packages/fuel-indexer-tests/tests/indexing.rs @@ -432,7 +432,7 @@ async fn test_index_types_for_block_explorer() { let hexstring = row.get::<&str, usize>(3); let hexstring = hex::decode(hexstring).unwrap(); - assert_eq!(hexstring, HexString::from("hello world!")); + assert_eq!(hexstring, Bytes::from("hello world!")); // Non-indexable types let row = diff --git a/packages/fuel-indexer-tests/trybuild/fail_if_abi_contains_reserved_fuel_type.rs b/packages/fuel-indexer-tests/trybuild/fail_if_abi_contains_reserved_fuel_type.rs index 651fe3004..2b426749f 100644 --- a/packages/fuel-indexer-tests/trybuild/fail_if_abi_contains_reserved_fuel_type.rs +++ b/packages/fuel-indexer-tests/trybuild/fail_if_abi_contains_reserved_fuel_type.rs @@ -3,8 +3,8 @@ use fuel_indexer_utils::prelude::*; #[indexer(manifest = "packages/fuel-indexer-tests/trybuild/invalid_abi_type_simple_wasm.yaml")] mod indexer { - fn function_one(event: BlockHeight) { - let BlockHeight { id, account } = event; + fn function_one(event: Bytes32) { + let Bytes32 { id, account } = event; let t1 = Thing1 { id, account }; t1.save(); diff --git a/packages/fuel-indexer-tests/trybuild/fail_if_ident_not_defined_in_abi.rs b/packages/fuel-indexer-tests/trybuild/fail_if_ident_not_defined_in_abi.rs index 2e0ccd8f2..f1a9bfb0a 100644 --- a/packages/fuel-indexer-tests/trybuild/fail_if_ident_not_defined_in_abi.rs +++ b/packages/fuel-indexer-tests/trybuild/fail_if_ident_not_defined_in_abi.rs @@ -4,7 +4,7 @@ use fuel_indexer_utils::prelude::*; #[indexer(manifest = "packages/fuel-indexer-tests/trybuild/simple_wasm.yaml")] mod indexer { fn function_one(event: ThisIsNotDefinedInTheABI) { - let BlockHeight { id, account } = event; + let Bytes32 { id, account } = event; let t1 = Thing1 { id, account }; t1.save(); diff --git a/packages/fuel-indexer-types/Cargo.toml b/packages/fuel-indexer-types/Cargo.toml index 48249d3ed..4a4eabe8e 100644 --- a/packages/fuel-indexer-types/Cargo.toml +++ b/packages/fuel-indexer-types/Cargo.toml @@ -10,7 +10,6 @@ rust-version = { workspace = true } description = "Fuel Indexer Types" [dependencies] -bincode = "1.3" bytes = { version = "1.4", features = ["serde"] } fuel-tx = { workspace = true, features = ["serde"] } fuel-types = { workspace = true } @@ -18,4 +17,3 @@ fuels = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } sha2 = "0.9" -tai64 = { version = "4.0", default-features = false, features = ["serde"] } diff --git a/packages/fuel-indexer-types/src/fuel.rs b/packages/fuel-indexer-types/src/fuel.rs index fdb770f41..04f1b173d 100644 --- a/packages/fuel-indexer-types/src/fuel.rs +++ b/packages/fuel-indexer-types/src/fuel.rs @@ -305,8 +305,8 @@ pub struct InputCoin { pub tx_pointer: TxPointer, pub witness_index: u8, pub maturity: BlockHeight, - pub predicate: HexString, - pub predicate_data: HexString, + pub predicate: Bytes, + pub predicate_data: Bytes, } #[derive(Clone, Debug, Serialize, Deserialize)] @@ -325,9 +325,9 @@ pub struct InputMessage { pub amount: u64, pub nonce: Nonce, pub witness_index: u8, - pub data: HexString, - pub predicate: HexString, - pub predicate_data: HexString, + pub data: Bytes, + pub predicate: Bytes, + pub predicate_data: Bytes, } #[derive(Clone, Debug, Serialize, Deserialize)] @@ -503,7 +503,7 @@ pub struct Genesis { #[derive(Clone, Debug, Serialize, Deserialize)] pub struct PoA { - pub signature: Signature, + pub signature: Bytes64, } #[derive(Clone, Debug, Default, Serialize, Deserialize)] @@ -524,7 +524,7 @@ pub enum ReturnType { #[derive(Clone, Debug, Serialize, Deserialize)] pub struct ProgramState { pub return_type: ReturnType, - pub data: HexString, + pub data: Bytes, } impl From for Json { 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..e540a6939 100644 --- a/packages/fuel-indexer-types/src/scalar.rs +++ b/packages/fuel-indexer-types/src/scalar.rs @@ -1,11 +1,10 @@ -use bytes::Bytes; +use bytes::Bytes as _Bytes; pub use fuel_types::{ Address, AssetId, BlockHeight, Bytes32, Bytes4, Bytes64, Bytes8, ContractId, MessageId, Nonce, Salt, Word, }; use fuels::types::SizedAsciiString; use serde::{Deserialize, Serialize}; -use tai64::Tai64; /// Scalar for 32-byte unique ID payloads. pub type UID = SizedAsciiString<64>; @@ -14,75 +13,34 @@ pub type UID = SizedAsciiString<64>; pub type ID = UID; /// Scalar for 4-byte signed integers. -pub type Int4 = i32; +pub type I32 = i32; /// Scalar for 8-byte signed integers. -pub type Int8 = i64; +pub type I64 = 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; - -/// Scalar for 8-byte integers aliased as `Timestamp`s. -pub type Timestamp = u64; - -/// Scalar for arbitrarily sized `String`s aliased as `Charfield`s. -pub type Charfield = String; +pub type U128 = u128; /// Scalar for boolean. pub type Boolean = bool; -/// Scalar for 64-byte signature payloads. -pub type Signature = Bytes64; - -/// Scalar for arbitrarily sized byte payloads aliased as `HexString`. -pub type HexString = Bytes; - -/// Scalar for `Tai64` timestamps aliased as `Tai64Timestamp`. -pub type Tai64Timestamp = Tai64; - -/// Scalar for 32-byte payloads aliased as `BlockId`. -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; - -/// Blob type used to store arbitrarily sized UTF-8 payloads. -#[derive(Deserialize, Serialize, Clone, Eq, PartialEq, Debug, Hash, Default)] -pub struct Blob(pub Vec); - -impl From> for Blob { - fn from(value: Vec) -> Self { - Blob(value) - } -} - -impl AsRef<[u8]> for Blob { - fn as_ref(&self) -> &[u8] { - &self.0 - } -} - -impl From for Vec { - fn from(value: Blob) -> Self { - value.0 - } -} +pub type U8 = u8; -/// JSON type used to store types tagged with a `@virtual` directive in -/// GraphQL schema. Aliased as `Virtual`. -pub type Virtual = Json; +/// Scalar for arbitrarily-sized byte payloads. +pub type Bytes = _Bytes; /// JSON type used to store arbitrary object payloads. #[derive(Deserialize, Serialize, Clone, Eq, PartialEq, Debug, Hash)] @@ -99,30 +57,3 @@ impl AsRef<[u8]> for Json { self.0.as_bytes() } } - -macro_rules! json_impl { - ($($ty:ty),*) => { - $( - impl From<$ty> for Json { - fn from(value: $ty) -> Self { - Json(value.to_string()) - } - } - )* - } -} - -macro_rules! blob_impl { - ($($ty:ty),*) => { - $( - impl From<$ty> for Blob { - fn from(value: $ty) -> Self { - Blob::from(bincode::serialize(&value).unwrap().to_vec()) - } - } - )* - } -} - -json_impl!(i32, i64, i128, u32, u64, u128); -blob_impl!(i32, i64, i128, u32, u64, u128); diff --git a/packages/fuel-indexer-utils/src/utilities.rs b/packages/fuel-indexer-utils/src/utilities.rs index 0ac393087..7159879c5 100644 --- a/packages/fuel-indexer-utils/src/utilities.rs +++ b/packages/fuel-indexer-utils/src/utilities.rs @@ -9,11 +9,11 @@ pub fn uid(data: impl AsRef<[u8]>) -> UID { UID::new(sha256_digest(&data)).expect("Failed to create UID.") } -/// Converts a given input into a `Bytes32` object by taking the first 32 bytes -/// of the input's SHA256 hex digest. +/// Converts a given input into a `Bytes32` object by taking the first 32 bytes of the input. 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]); + let data = data.as_ref(); + let len = data.len().min(32); // take the minimum of the data length and 32 + result[..len].copy_from_slice(&data[..len]); // copy only up to len bytes Bytes32::from(result) } diff --git a/packages/fuel-indexer/src/executor.rs b/packages/fuel-indexer/src/executor.rs index 031a23ee6..70a64f01d 100644 --- a/packages/fuel-indexer/src/executor.rs +++ b/packages/fuel-indexer/src/executor.rs @@ -17,7 +17,7 @@ use fuel_indexer_lib::{ }; use fuel_indexer_types::{ fuel::{field::*, *}, - scalar::{Bytes32, HexString}, + scalar::{Bytes, Bytes32}, }; use fuel_tx::UniqueIdentifier; use fuel_vm::prelude::Deserializable; @@ -368,15 +368,15 @@ pub async fn retrieve_blocks_from_node( let program_state = program_state.map(|p| match p { ClientProgramState::Return(w) => ProgramState { return_type: ReturnType::Return, - data: HexString::from(w.to_le_bytes().to_vec()), + data: Bytes::from(w.to_le_bytes().to_vec()), }, ClientProgramState::ReturnData(d) => ProgramState { return_type: ReturnType::ReturnData, - data: HexString::from(d.to_vec()), + data: Bytes::from(d.to_vec()), }, ClientProgramState::Revert(w) => ProgramState { return_type: ReturnType::Revert, - data: HexString::from(w.to_le_bytes().to_vec()), + data: Bytes::from(w.to_le_bytes().to_vec()), }, // Either `cargo watch` complains that this is unreachable, or `clippy` complains // that all patterns are not matched. These other program states are only used in @@ -399,15 +399,15 @@ pub async fn retrieve_blocks_from_node( let program_state = program_state.map(|p| match p { ClientProgramState::Return(w) => ProgramState { return_type: ReturnType::Return, - data: HexString::from(w.to_le_bytes().to_vec()), + data: Bytes::from(w.to_le_bytes().to_vec()), }, ClientProgramState::ReturnData(d) => ProgramState { return_type: ReturnType::ReturnData, - data: HexString::from(d.to_vec()), + data: Bytes::from(d.to_vec()), }, ClientProgramState::Revert(w) => ProgramState { return_type: ReturnType::Revert, - data: HexString::from(w.to_le_bytes().to_vec()), + data: Bytes::from(w.to_le_bytes().to_vec()), }, // Either `cargo watch` complains that this is unreachable, or `clippy` complains // that all patterns are not matched. These other program states are only used in diff --git a/plugins/forc-index/src/defaults.rs b/plugins/forc-index/src/defaults.rs index 82929f878..62db4fb63 100644 --- a/plugins/forc-index/src/defaults.rs +++ b/plugins/forc-index/src/defaults.rs @@ -211,7 +211,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 }