Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
DOBEN committed Oct 21, 2024
1 parent 7604c7e commit b758d16
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 50 deletions.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions backend-rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ To run the services, the following dependencies are required to be available on
For instructions on how to use the indexer run:

```
cargo run --bin ccdscan-indexer -- --help
ccdscan-indexer --help
```

Example:
## Run the Indexer Service during development

Examples:

```
cargo run --bin ccdscan-indexer -- --node http://localhost:20001 --max-parallel-block-preprocessors 20 --max-processing-batch 20
cargo run --bin ccdscan-indexer -- --node http://node.testnet.concordium.com:20000
cargo run --bin ccdscan-indexer -- --node https://grpc.testnet.concordium.com:20000
cargo run --bin ccdscan-indexer -- --node https://grpc.testnet.concordium.com:20000 --max-parallel-block-preprocessors 20 --max-processing-batch 20
```

Note: Queries like `getSourceModule` might timeout (are disabled) on our public-facing nodes. The recommendation is to run
your own local node during development.
Note: Since the indexer puts a lot of load on the node, use your own local node whenever possible.
If using the public nodes, run the indexer as short as possible.

<!-- TODO When service become stable: add documentation of arguments and environment variables. -->

Expand All @@ -44,6 +45,8 @@ For instructions on how to use the API service run:
cargo run --bin ccdscan-api -- --help
```

## Run the GraphQL API Service during development

Example:

```
Expand Down Expand Up @@ -173,7 +176,7 @@ This will generate type metadata for the queries in the `.sqlx` folder.

- Feature 2:

If you want to update your database to a new schema, execute the command:
If you want to drop the entire database and start with an empty database that uses the current schema, execute the command:

```
sqlx database reset --force
Expand Down
14 changes: 6 additions & 8 deletions backend-rust/migrations/0001_initialize.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,13 @@ CREATE TABLE bakers(
BIGINT
);

-- Every WASM module on chain.
-- Every module on chain.
CREATE TABLE smart_contract_modules(
index
BIGINT
PRIMARY KEY,
-- Module reference of the wasm module.
-- Module reference of the module.
module_reference
CHAR(64)
UNIQUE
PRIMARY KEY
NOT NULL,
-- The absolute block height when the module was deployed.
deployment_block_height
Expand All @@ -265,7 +263,7 @@ CREATE TABLE smart_contract_modules(
deployment_transaction_index
BIGINT
NOT NULL,
-- Embedded schema in the wasm module if present.
-- Embedded schema in the module if present.
schema TEXT
);

Expand All @@ -280,13 +278,13 @@ CREATE TABLE contracts(
BIGINT
NOT NULL,
-- Note: It might be better to use `module_reference_index` which would save storage space but would require more work in inserting/querying by the indexer.
-- Module reference of the wasm module.
-- Module reference of the module.
module_reference
CHAR(64)
NOT NULL,
-- The contract name.
name
TEXT
VARCHAR(100)
NOT NULL,
-- The total balance of the contract in micro CCD.
amount
Expand Down
18 changes: 5 additions & 13 deletions backend-rust/src/graphql_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ enum ApiError {
#[error("Invalid integer: {0}")]
InvalidIntString(#[from] std::num::ParseIntError),
#[error("Parse error: {0}")]
UnsignedLongParse(#[from] UnsignedLongParseError),
UnsignedLongNotNegative(#[from] UnsignedLongNotNegativeError),
}

impl From<sqlx::Error> for ApiError {
Expand Down Expand Up @@ -1046,21 +1046,13 @@ impl ScalarType for UnsignedLong {
}

#[derive(Debug, thiserror::Error, Clone)]
enum UnsignedLongParseError {
#[error("Negative number cannot be converted to UnsignedLong.")]
NotNegative,
}
#[error("Negative number cannot be converted to UnsignedLong.")]
struct UnsignedLongNotNegativeError;

impl TryFrom<i64> for UnsignedLong {
type Error = UnsignedLongParseError;
type Error = <u64 as TryFrom<i64>>::Error;

fn try_from(number: i64) -> Result<Self, Self::Error> {
if number < 0 {
Err(UnsignedLongParseError::NotNegative)?
} else {
Ok(UnsignedLong(number as u64))
}
}
fn try_from(number: i64) -> Result<Self, Self::Error> { Ok(UnsignedLong(number.try_into()?)) }
}

/// The `Long` scalar type represents non-fractional signed whole 64-bit numeric
Expand Down
2 changes: 0 additions & 2 deletions backend-rust/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1425,13 +1425,11 @@ impl PreparedModuleDeployed {
sqlx::query!(
r#"
INSERT INTO smart_contract_modules (
index,
module_reference,
deployment_block_height,
deployment_transaction_index,
schema
) VALUES (
(SELECT COALESCE(MAX(index) + 1, 0) FROM smart_contract_modules),
$1, $2, $3, $4
)"#,
self.module_reference,
Expand Down

0 comments on commit b758d16

Please sign in to comment.