-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #628 from blockscout/lymarenkolev/bens-init
Bens: initial proto def
- Loading branch information
Showing
9 changed files
with
2,526 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[workspace] | ||
|
||
members = [ | ||
"bens-proto", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "bens-proto" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
actix-web = "4" | ||
actix-prost = { git = "https://github.com/blockscout/actix-prost" } | ||
actix-prost-macros = { git = "https://github.com/blockscout/actix-prost" } | ||
prost = "0.11" | ||
serde = { version = "1" } | ||
serde_with = { version = "2.0" } | ||
tonic = "0.8" | ||
|
||
[build-dependencies] | ||
actix-prost-build = { git = "https://github.com/blockscout/actix-prost" } | ||
prost-build = "0.11" | ||
tonic-build = "0.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use actix_prost_build::{ActixGenerator, GeneratorList}; | ||
use prost_build::{Config, ServiceGenerator}; | ||
use std::path::Path; | ||
|
||
// custom function to include custom generator | ||
fn compile( | ||
protos: &[impl AsRef<Path>], | ||
includes: &[impl AsRef<Path>], | ||
generator: Box<dyn ServiceGenerator>, | ||
) -> Result<(), Box<dyn std::error::Error>> { | ||
let mut config = Config::new(); | ||
config | ||
.service_generator(generator) | ||
.compile_well_known_types() | ||
.protoc_arg("--openapiv2_out=swagger/") | ||
.protoc_arg("--openapiv2_opt") | ||
.protoc_arg("grpc_api_configuration=proto/api_config_http.yaml,output_format=yaml,allow_merge=true,merge_file_name=bens") | ||
.bytes(["."]) | ||
.btree_map(["."]) | ||
.type_attribute(".", "#[actix_prost_macros::serde]") | ||
// .field_attribute( | ||
// ".blockscout.ethBytecodeDb.v2.VerifyVyperMultiPartRequest.interfaces", | ||
// "#[serde(default)]" | ||
// ) | ||
; | ||
config.compile_protos(protos, includes)?; | ||
Ok(()) | ||
} | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
// We need to rebuild proto lib only if any of proto definitions | ||
// (or corresponding http mapping) has been changed. | ||
println!("cargo:rerun-if-changed=proto/"); | ||
|
||
std::fs::create_dir_all("./swagger/").unwrap(); | ||
let gens = Box::new(GeneratorList::new(vec![ | ||
tonic_build::configure().service_generator(), | ||
Box::new(ActixGenerator::new("proto/api_config_http.yaml").unwrap()), | ||
])); | ||
compile( | ||
&["proto/bens.proto", "proto/health.proto"], | ||
&["proto"], | ||
gens, | ||
)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
type: google.api.Service | ||
config_version: 3 | ||
|
||
http: | ||
rules: | ||
#################### DomainsExtractor #################### | ||
- selector: blockscout.bens.v1.DomainsExtractor.SearchReverseDomain | ||
post: /api/v1/{chain_id}/domains:search-reverse | ||
body: "*" | ||
|
||
- selector: blockscout.bens.v1.DomainsExtractor.SearchDomain | ||
post: /api/v1/{chain_id}/domains:search | ||
body: "*" | ||
|
||
#################### Health #################### | ||
|
||
- selector: blockscout.ethBytecodeDb.v2.Health.Check | ||
get: /health |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
syntax = "proto3"; | ||
|
||
package blockscout.bens.v1; | ||
|
||
option go_package = "github.com/blockscout/blockscout-rs/bens"; | ||
|
||
service DomainsExtractor { | ||
rpc SearchReverseDomain(SearchReverseDomainRequest) returns (SearchReverseDomainResponse) {} | ||
rpc SearchDomain(SearchDomainRequest) returns (DetailedDomain) {} | ||
} | ||
|
||
message Domain { | ||
/// Unique id for the domain, also known as nodehash | ||
string id = 1; | ||
/// The human readable name, if known. Unknown portions replaced with hash in square brackets (eg, foo.[1234].eth) | ||
string name = 2; | ||
/// Integer representation of labelhash | ||
uint64 token_id = 3; | ||
/// The account that owns the domain | ||
string owner = 4; | ||
/// Optinal. Resolved address of this domain | ||
optional string resolved_address = 5; | ||
/// Optinal. The account that owns the ERC721 NFT for the domain | ||
optional string registrant = 6; | ||
/// Optinal. Unix timestamp of expiry date. None means never expires | ||
optional uint64 expiry_date = 7; | ||
/// Unix timestamp of regisration date | ||
uint64 registration_date = 8; | ||
/// Map chain -> resolved_address that contains other blockchain addresses. | ||
/// This map will contain `current_chain_id` -> `resovled_address` if `resovled_address` is not None | ||
map<string, string> other_address = 9; | ||
} | ||
|
||
message DomainEvent { | ||
/// Transaction hash where action occured | ||
string transaction_hash = 1; | ||
/// Timestamp of this transaction | ||
uint64 timestamp = 2; | ||
/// Sender of transaction | ||
string from_address = 3; | ||
/// Optinal. Action name | ||
optional string action = 4; | ||
} | ||
|
||
|
||
message DetailedDomain { | ||
/// Optinal. Basic domain info | ||
optional Domain domain = 1; | ||
/// List of domain events | ||
repeated DomainEvent history = 2; | ||
} | ||
|
||
|
||
message SearchReverseDomainRequest { | ||
/// Address of EOA or contract | ||
string address = 1; | ||
/// The chain (network) where domain search should be done | ||
uint64 chain_id = 2; | ||
/// Include domains resolved to the address | ||
bool resolved_to = 3; | ||
/// Include domains owned by the address | ||
bool owned_by = 4; | ||
} | ||
|
||
message SearchReverseDomainResponse { | ||
// List of domains that resolved to requested address | ||
// Sorted by relevance, so first address could be displayed as main resolved address | ||
repeated Domain resolved_to = 1; | ||
// List of domains owned by requested address | ||
repeated Domain owned_by = 2; | ||
} | ||
|
||
message SearchDomainRequest { | ||
/// Name of domain, for example vitalik.eth | ||
string name = 1; | ||
/// The chain (network) where domain search should be done | ||
uint64 chain_id = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
syntax = "proto3"; | ||
|
||
package blockscout.bens.v1; | ||
|
||
// Copyright 2015 The gRPC Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// The canonical version of this proto can be found at | ||
// https://github.com/grpc/grpc-proto/blob/master/grpc/health/v1/health.proto | ||
|
||
option csharp_namespace = "Grpc.Health.V2"; | ||
option go_package = "github.com/blockscout/blockscout-rs/bens"; | ||
option java_multiple_files = true; | ||
option java_outer_classname = "HealthProto"; | ||
option java_package = "io.grpc.health.v2"; | ||
|
||
message HealthCheckRequest { | ||
optional string service = 1; | ||
} | ||
|
||
message HealthCheckResponse { | ||
enum ServingStatus { | ||
UNKNOWN = 0; | ||
SERVING = 1; | ||
NOT_SERVING = 2; | ||
SERVICE_UNKNOWN = 3; // Used only by the Watch method. | ||
} | ||
ServingStatus status = 1; | ||
} | ||
|
||
service Health { | ||
// If the requested service is unknown, the call will fail with status | ||
// NOT_FOUND. | ||
rpc Check(HealthCheckRequest) returns (HealthCheckResponse); | ||
|
||
// // Performs a watch for the serving status of the requested service. | ||
// // The server will immediately send back a message indicating the current | ||
// // serving status. It will then subsequently send a new message whenever | ||
// // the service's serving status changes. | ||
// // | ||
// // If the requested service is unknown when the call is received, the | ||
// // server will send a message setting the serving status to | ||
// // SERVICE_UNKNOWN but will *not* terminate the call. If at some | ||
// // future point, the serving status of the service becomes known, the | ||
// // server will send a new message with the service's serving status. | ||
// // | ||
// // If the call terminates with status UNIMPLEMENTED, then clients | ||
// // should assume this method is not supported and should not retry the | ||
// // call. If the call terminates with any other status (including OK), | ||
// // clients should retry the call with appropriate exponential backoff. | ||
// rpc Watch(HealthCheckRequest) returns (stream HealthCheckResponse); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![allow(clippy::derive_partial_eq_without_eq)] | ||
pub mod blockscout { | ||
pub mod eth_bytecode_db { | ||
pub mod v2 { | ||
include!(concat!(env!("OUT_DIR"), "/blockscout.bens.v1.rs")); | ||
} | ||
} | ||
} |
Oops, something went wrong.