Skip to content

Commit

Permalink
fix: support all the int solidity types - #45
Browse files Browse the repository at this point in the history
  • Loading branch information
joshstevens19 committed Jul 16, 2024
1 parent 56ad08e commit 74e2944
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ start_indexer_lens_mirrors:
RUSTFLAGS='-C target-cpu=native' cargo run --release --features jemalloc -- start --path /Users/joshstevens/code/rindexer/examples/lens_mirrors all
start_graphql:
cargo run -- start --path /Users/joshstevens/code/rindexer/examples/rindexer_demo_cli graphql
start_indexer_uniswap_v3_factory:
RUSTFLAGS='-C target-cpu=native' cargo run --release --features jemalloc -- start --path /Users/joshstevens/code/rindexer/examples/uniswap_v3_factory all
codegen:
RUSTFLAGS='-C target-cpu=native' cargo run --release --features jemalloc -- codegen --path /Users/joshstevens/code/rust typings
codegen_typings:
Expand Down
20 changes: 16 additions & 4 deletions core/src/database/postgres/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,24 @@ pub fn solidity_type_to_db_type(abi_type: &str) -> String {
let sql_type = match base_type {
"address" => "CHAR(42)",
"bool" => "BOOLEAN",
"int256" | "uint256" => "VARCHAR(78)",
"int64" | "uint64" | "int128" | "uint128" => "NUMERIC",
"int32" | "uint32" => "INTEGER",
"string" => "TEXT",
t if t.starts_with("bytes") => "BYTEA",
"uint8" | "uint16" | "int8" | "int16" => "SMALLINT",
t if t.starts_with("int") || t.starts_with("uint") => {
// Handling fixed-size integers (intN and uintN where N can be 8 to 256 in steps of 8)
let (prefix, size): (&str, usize) = if t.starts_with("int") {
("int", t[3..].parse().expect("Invalid intN type"))
} else {
("uint", t[4..].parse().expect("Invalid uintN type"))
};

match size {
8 | 16 => "SMALLINT",
24 | 32 => "INTEGER",
40 | 48 | 56 | 64 | 72 | 80 | 88 | 96 | 104 | 112 | 120 | 128 => "NUMERIC",
136 | 144 | 152 | 160 | 168 | 176 | 184 | 192 | 200 | 208 | 216 | 224 | 232 | 240 | 248 | 256 => "VARCHAR(78)",
_ => panic!("Unsupported {}N size: {}", prefix, size),
}
},
_ => panic!("Unsupported type: {}", base_type),
};

Expand Down
2 changes: 2 additions & 0 deletions documentation/docs/pages/docs/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
### Bug fixes
-------------------------------------------------

fix: support all the int solidity types - https://github.com/joshstevens19/rindexer/issues/45

### Breaking changes
-------------------------------------------------

Expand Down

0 comments on commit 74e2944

Please sign in to comment.