Skip to content

Commit

Permalink
fix: remove chain_id from import entities
Browse files Browse the repository at this point in the history
  • Loading branch information
lok52 committed Jan 7, 2025
1 parent 9e92990 commit a77599e
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,22 @@ impl From<Address> for proto::Address {
}

pub fn proto_token_type_to_db_token_type(
token_type: proto::address::TokenType,
token_type: proto::TokenType,
) -> Option<db_enum::TokenType> {
match token_type {
proto::address::TokenType::Erc20 => Some(db_enum::TokenType::Erc20),
proto::address::TokenType::Erc1155 => Some(db_enum::TokenType::Erc1155),
proto::address::TokenType::Erc721 => Some(db_enum::TokenType::Erc721),
proto::address::TokenType::Erc404 => Some(db_enum::TokenType::Erc404),
proto::address::TokenType::Unspecified => None,
proto::TokenType::Erc20 => Some(db_enum::TokenType::Erc20),
proto::TokenType::Erc1155 => Some(db_enum::TokenType::Erc1155),
proto::TokenType::Erc721 => Some(db_enum::TokenType::Erc721),
proto::TokenType::Erc404 => Some(db_enum::TokenType::Erc404),
proto::TokenType::Unspecified => None,
}
}

pub fn db_token_type_to_proto_token_type(
token_type: db_enum::TokenType,
) -> proto::address::TokenType {
pub fn db_token_type_to_proto_token_type(token_type: db_enum::TokenType) -> proto::TokenType {
match token_type {
db_enum::TokenType::Erc20 => proto::address::TokenType::Erc20,
db_enum::TokenType::Erc1155 => proto::address::TokenType::Erc1155,
db_enum::TokenType::Erc721 => proto::address::TokenType::Erc721,
db_enum::TokenType::Erc404 => proto::address::TokenType::Erc404,
db_enum::TokenType::Erc20 => proto::TokenType::Erc20,
db_enum::TokenType::Erc1155 => proto::TokenType::Erc1155,
db_enum::TokenType::Erc721 => proto::TokenType::Erc721,
db_enum::TokenType::Erc404 => proto::TokenType::Erc404,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ impl From<Hash> for proto::Hash {
}
}

pub fn proto_hash_type_to_db_hash_type(hash_type: proto::hash::HashType) -> db_enum::HashType {
pub fn proto_hash_type_to_db_hash_type(hash_type: proto::HashType) -> db_enum::HashType {
match hash_type {
proto::hash::HashType::Block => db_enum::HashType::Block,
proto::hash::HashType::Transaction => db_enum::HashType::Transaction,
proto::HashType::Block => db_enum::HashType::Block,
proto::HashType::Transaction => db_enum::HashType::Transaction,
}
}

pub fn db_hash_type_to_proto_hash_type(hash_type: db_enum::HashType) -> proto::hash::HashType {
pub fn db_hash_type_to_proto_hash_type(hash_type: db_enum::HashType) -> proto::HashType {
match hash_type {
db_enum::HashType::Block => proto::hash::HashType::Block,
db_enum::HashType::Transaction => proto::hash::HashType::Transaction,
db_enum::HashType::Block => proto::HashType::Block,
db_enum::HashType::Transaction => proto::HashType::Transaction,
}
}
10 changes: 5 additions & 5 deletions multichain-aggregator/multichain-aggregator-proto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ fn compile(
.bytes(["."])
.btree_map(["."])
.type_attribute(".", "#[actix_prost_macros::serde(rename_all=\"snake_case\")]")
.field_attribute(".blockscout.multichainAggregator.v1.Address.token_type", "#[serde(default)]")
.field_attribute(".blockscout.multichainAggregator.v1.Address.TokenType.TOKEN_TYPE_ERC_20", "#[serde(rename = \"ERC-20\")]")
.field_attribute(".blockscout.multichainAggregator.v1.Address.TokenType.TOKEN_TYPE_ERC_721", "#[serde(rename = \"ERC-721\")]")
.field_attribute(".blockscout.multichainAggregator.v1.Address.TokenType.TOKEN_TYPE_ERC_1155", "#[serde(rename = \"ERC-1155\")]")
.field_attribute(".blockscout.multichainAggregator.v1.Address.TokenType.TOKEN_TYPE_ERC_404", "#[serde(rename = \"ERC-404\")]");
.field_attribute(".blockscout.multichainAggregator.v1.BatchImportRequest.AddressImport.token_type", "#[serde(default)]")
.field_attribute(".blockscout.multichainAggregator.v1.TokenType.TOKEN_TYPE_ERC_20", "#[serde(rename = \"ERC-20\")]")
.field_attribute(".blockscout.multichainAggregator.v1.TokenType.TOKEN_TYPE_ERC_721", "#[serde(rename = \"ERC-721\")]")
.field_attribute(".blockscout.multichainAggregator.v1.TokenType.TOKEN_TYPE_ERC_1155", "#[serde(rename = \"ERC-1155\")]")
.field_attribute(".blockscout.multichainAggregator.v1.TokenType.TOKEN_TYPE_ERC_404", "#[serde(rename = \"ERC-404\")]");
config.compile_protos(protos, includes)?;
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ service MultichainAggregatorService {
rpc ListTokens(ListTokensRequest) returns (ListTokensResponse) {}
}

enum TokenType {
TOKEN_TYPE_UNSPECIFIED = 0;
TOKEN_TYPE_ERC_20 = 1;
TOKEN_TYPE_ERC_721 = 2;
TOKEN_TYPE_ERC_1155 = 3;
TOKEN_TYPE_ERC_404 = 4;
}

enum HashType {
HASH_TYPE_BLOCK = 0;
HASH_TYPE_TRANSACTION = 1;
}

message Pagination {
string page_token = 1;
uint32 page_size = 2;
Expand All @@ -21,15 +34,6 @@ message Address {
optional string ens_name = 2;
optional string contract_name = 3;
optional string token_name = 4;

enum TokenType {
TOKEN_TYPE_UNSPECIFIED = 0;
TOKEN_TYPE_ERC_20 = 1;
TOKEN_TYPE_ERC_721 = 2;
TOKEN_TYPE_ERC_1155 = 3;
TOKEN_TYPE_ERC_404 = 4;
}

TokenType token_type = 5;
optional bool is_contract = 6;
optional bool is_verified_contract = 7;
Expand All @@ -45,12 +49,6 @@ message BlockRange {

message Hash {
string hash = 1;

enum HashType {
HASH_TYPE_BLOCK = 0;
HASH_TYPE_TRANSACTION = 1;
}

HashType hash_type = 2;
string chain_id = 3;
}
Expand All @@ -72,10 +70,31 @@ message Token {
}

message BatchImportRequest {
message AddressImport {
string hash = 1;
optional string ens_name = 2;
optional string contract_name = 3;
optional string token_name = 4;
TokenType token_type = 5;
optional bool is_contract = 6;
optional bool is_verified_contract = 7;
optional bool is_token = 8;
}

message HashImport {
string hash = 1;
HashType hash_type = 2;
}

message BlockRangeImport {
uint64 min_block_number = 1;
uint64 max_block_number = 2;
}

string chain_id = 1;
repeated Address addresses = 2;
repeated BlockRange block_ranges = 3;
repeated Hash hashes = 4;
repeated AddressImport addresses = 2;
repeated BlockRangeImport block_ranges = 3;
repeated HashImport hashes = 4;
string api_key = 5;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,41 @@ paths:
tags:
- Health
definitions:
AddressTokenType:
type: string
enum:
- TOKEN_TYPE_UNSPECIFIED
- TOKEN_TYPE_ERC_20
- TOKEN_TYPE_ERC_721
- TOKEN_TYPE_ERC_1155
- TOKEN_TYPE_ERC_404
default: TOKEN_TYPE_UNSPECIFIED
HashHashType:
type: string
enum:
- HASH_TYPE_BLOCK
- HASH_TYPE_TRANSACTION
default: HASH_TYPE_BLOCK
BatchImportRequestAddressImport:
type: object
properties:
hash:
type: string
ens_name:
type: string
contract_name:
type: string
token_name:
type: string
token_type:
$ref: '#/definitions/v1TokenType'
is_contract:
type: boolean
is_verified_contract:
type: boolean
is_token:
type: boolean
BatchImportRequestBlockRangeImport:
type: object
properties:
min_block_number:
type: string
format: uint64
max_block_number:
type: string
format: uint64
BatchImportRequestHashImport:
type: object
properties:
hash:
type: string
hash_type:
$ref: '#/definitions/v1HashType'
HealthCheckResponseServingStatus:
type: string
enum:
Expand Down Expand Up @@ -235,7 +255,7 @@ definitions:
token_name:
type: string
token_type:
$ref: '#/definitions/AddressTokenType'
$ref: '#/definitions/v1TokenType'
is_contract:
type: boolean
is_verified_contract:
Expand All @@ -253,44 +273,39 @@ definitions:
type: array
items:
type: object
$ref: '#/definitions/v1Address'
$ref: '#/definitions/BatchImportRequestAddressImport'
block_ranges:
type: array
items:
type: object
$ref: '#/definitions/v1BlockRange'
$ref: '#/definitions/BatchImportRequestBlockRangeImport'
hashes:
type: array
items:
type: object
$ref: '#/definitions/v1Hash'
$ref: '#/definitions/BatchImportRequestHashImport'
api_key:
type: string
v1BatchImportResponse:
type: object
properties:
status:
type: string
v1BlockRange:
type: object
properties:
min_block_number:
type: string
format: uint64
max_block_number:
type: string
format: uint64
chain_id:
type: string
v1Hash:
type: object
properties:
hash:
type: string
hash_type:
$ref: '#/definitions/HashHashType'
$ref: '#/definitions/v1HashType'
chain_id:
type: string
v1HashType:
type: string
enum:
- HASH_TYPE_BLOCK
- HASH_TYPE_TRANSACTION
default: HASH_TYPE_BLOCK
v1HealthCheckResponse:
type: object
properties:
Expand Down Expand Up @@ -357,3 +372,12 @@ definitions:
type: string
chain_id:
type: string
v1TokenType:
type: string
enum:
- TOKEN_TYPE_UNSPECIFIED
- TOKEN_TYPE_ERC_20
- TOKEN_TYPE_ERC_721
- TOKEN_TYPE_ERC_1155
- TOKEN_TYPE_ERC_404
default: TOKEN_TYPE_UNSPECIFIED

0 comments on commit a77599e

Please sign in to comment.