Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/network/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,25 @@ impl FidRequest {
}
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct VerificationFidRequest {
#[serde(with = "serdehex")]
pub address: Vec<u8>,
}

impl VerificationFidRequest {
pub fn to_proto(self) -> proto::VerificationFidRequest {
proto::VerificationFidRequest {
address: self.address,
}
}
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct VerificationFidResponse {
pub fid: u64,
}

#[allow(non_snake_case)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct FidTimestampRequest {
Expand Down Expand Up @@ -2168,6 +2187,10 @@ pub trait HubHttpService {
&self,
req: FidRequest,
) -> Result<PagedResponse, ErrorResponse>;
async fn get_fid_by_verification(
&self,
req: VerificationFidRequest,
) -> Result<VerificationFidResponse, ErrorResponse>;
async fn get_on_chain_signers_by_fid(
&self,
req: FidRequest,
Expand Down Expand Up @@ -2816,6 +2839,30 @@ where
map_proto_messages_response_to_json_paged_response(proto_resp)
}

/// GET /v1/fidByVerification
async fn get_fid_by_verification(
&self,
req: VerificationFidRequest,
) -> Result<VerificationFidResponse, ErrorResponse> {
let service = &self.service;

let grpc_req = tonic::Request::new(req.to_proto());

let response = service
.get_fid_by_verification(grpc_req)
.await
.map_err(|e| ErrorResponse {
error: "Failed to get fid by verification".to_string(),
error_detail: Some(e.to_string()),
})?;

let proto_resp = response.into_inner();

Ok(VerificationFidResponse {
fid: proto_resp.fid,
})
}

/// GET /v1/onChainSignersByFid
async fn get_on_chain_signers_by_fid(
&self,
Expand Down Expand Up @@ -3132,6 +3179,15 @@ where
})
.await
}
(&Method::GET, "/v1/fidByVerification") => {
self.handle_request::<VerificationFidRequest, VerificationFidResponse, _>(
req,
|service, req| {
Box::pin(async move { service.get_fid_by_verification(req).await })
},
)
.await
}
(&Method::GET, "/v1/onChainSignersByFid") => {
self.handle_request::<FidRequest, OnChainEventResponse, _>(req, |service, req| {
Box::pin(async move { service.get_on_chain_signers_by_fid(req).await })
Expand Down
31 changes: 30 additions & 1 deletion src/network/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use crate::proto::{
ShardChunksResponse, SignerEventType, SignerRequest, StorageLimitsResponse, SubscribeRequest,
TrieNodeMetadataRequest, TrieNodeMetadataResponse, UserDataRequest, UserNameProof,
UserNameType, UsernameProofRequest, UsernameProofsResponse, ValidationResponse,
VerificationAddAddressBody, VerificationRequest,
VerificationAddAddressBody, VerificationFidRequest, VerificationFidResponse,
VerificationRequest,
};
use crate::storage::constants::OnChainEventPostfix;
use crate::storage::constants::RootPrefix;
Expand Down Expand Up @@ -1373,6 +1374,34 @@ impl HubService for MyHubService {
.as_response()
}

async fn get_fid_by_verification(
&self,
request: Request<VerificationFidRequest>,
) -> Result<Response<VerificationFidResponse>, Status> {
let request = request.into_inner();

for (_, stores) in &self.shard_stores {
let store = &stores.verification_store;

match VerificationStore::get_fid_by_verification(store, &request.address) {
Ok(Some(fid)) => {
return Ok(Response::new(VerificationFidResponse { fid }));
}

Ok(None) => {
// look in the next shard
continue;
}

Err(err) => {
return Err(Status::internal(err.to_string()));
}
}
}

Err(Status::not_found("verification not found"))
}

async fn get_all_verification_messages_by_fid(
&self,
request: Request<FidTimestampRequest>,
Expand Down
8 changes: 8 additions & 0 deletions src/proto/request_response.proto
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ message VerificationRequest {
bytes address = 2;
}

message VerificationFidRequest {
bytes address = 1;
}

message VerificationFidResponse {
uint64 fid = 1;
}

message SignerRequest {
uint64 fid = 1;
bytes signer = 2;
Expand Down
1 change: 1 addition & 0 deletions src/proto/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ service HubService {
// Verifications
rpc GetVerification(VerificationRequest) returns (Message);
rpc GetVerificationsByFid(FidRequest) returns (MessagesResponse);
rpc GetFidByVerification(VerificationFidRequest) returns (VerificationFidResponse);

// OnChain Events
rpc GetOnChainSigner(SignerRequest) returns (OnChainEvent);
Expand Down
22 changes: 21 additions & 1 deletion src/storage/store/account/verification_store.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{
make_fid_key, make_user_key,
make_fid_key, make_user_key, read_fid_key,
store::{Store, StoreDef},
MessagesPage, StoreEventHandler, TS_HASH_LENGTH,
};
Expand Down Expand Up @@ -316,4 +316,24 @@ impl VerificationStore {
) -> Result<MessagesPage, HubError> {
store.get_removes_by_fid::<fn(&Message) -> bool>(fid, page_options, None)
}

pub fn get_fid_by_verification(
store: &Store<VerificationStoreDef>,
address: &[u8],
) -> Result<Option<u64>, HubError> {
if address.is_empty() {
return Err(HubError {
code: "bad_request.invalid_param".to_string(),
message: "address empty".to_string(),
});
}

let key = VerificationStoreDef::make_verification_by_address_key(address);

let Some(value) = store.db().get(&key)? else {
return Ok(None);
};

Ok(Some(read_fid_key(&value, 0)))
}
}
Loading