Skip to content

Commit f5cda59

Browse files
authored
feat: implement get_id_registry_on_chain_event_by_address in http (#474)
closes #416 Tested local with `http://localhost:3381/v1/idRegistryOnChainEventByAddress?address=0x3a6dd569de84c91828fc42dce20f5b827e0ef5c5`
1 parent 2a7fb10 commit f5cda59

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/network/http_server.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,19 @@ impl EventRequest {
11231123
}
11241124
}
11251125
}
1126+
#[derive(Debug, Clone, Deserialize, Serialize)]
1127+
pub struct IdRegistryEventByAddressRequest {
1128+
#[serde(with = "serdehex")]
1129+
pub address: Vec<u8>,
1130+
}
1131+
1132+
impl IdRegistryEventByAddressRequest {
1133+
pub fn to_proto(self) -> proto::IdRegistryEventByAddressRequest {
1134+
proto::IdRegistryEventByAddressRequest {
1135+
address: self.address,
1136+
}
1137+
}
1138+
}
11261139

11271140
#[derive(Debug, Clone, Deserialize, Serialize)]
11281141
pub struct ValidationResult {
@@ -1994,6 +2007,10 @@ pub trait HubHttpService {
19942007
) -> Result<OnChainEventResponse, ErrorResponse>;
19952008
async fn get_events(&self, req: EventsRequest) -> Result<EventsResponse, ErrorResponse>;
19962009
async fn get_event_by_id(&self, req: EventRequest) -> Result<HubEvent, ErrorResponse>;
2010+
async fn get_id_registry_on_chain_event_by_address(
2011+
&self,
2012+
req: IdRegistryEventByAddressRequest,
2013+
) -> Result<OnChainEvent, ErrorResponse>;
19972014
}
19982015

19992016
#[async_trait]
@@ -2633,6 +2650,22 @@ impl HubHttpService for HubHttpServiceImpl {
26332650
response.into_inner(),
26342651
)?)
26352652
}
2653+
async fn get_id_registry_on_chain_event_by_address(
2654+
&self,
2655+
req: IdRegistryEventByAddressRequest,
2656+
) -> Result<OnChainEvent, ErrorResponse> {
2657+
let grpc_req = tonic::Request::new(req.to_proto());
2658+
let response = self
2659+
.service
2660+
.get_id_registry_on_chain_event_by_address(grpc_req)
2661+
.await
2662+
.map_err(|e| ErrorResponse {
2663+
error: "Failed to get id registry event".to_string(),
2664+
error_detail: Some(e.to_string()),
2665+
})?;
2666+
let onchain = response.into_inner();
2667+
map_proto_on_chain_event_to_json_on_chain_event(onchain)
2668+
}
26362669
}
26372670

26382671
// Router implementation
@@ -2813,6 +2846,17 @@ impl Router {
28132846
)
28142847
.await
28152848
}
2849+
(&Method::GET, "/v1/onChainIdRegistryEventByAddress") => {
2850+
self.handle_request::<IdRegistryEventByAddressRequest, OnChainEvent, _>(
2851+
req,
2852+
|service, req| {
2853+
Box::pin(async move {
2854+
service.get_id_registry_on_chain_event_by_address(req).await
2855+
})
2856+
},
2857+
)
2858+
.await
2859+
}
28162860
(&Method::GET, "/v1/events") => {
28172861
self.handle_request::<EventsRequest, EventsResponse, _>(req, |service, req| {
28182862
Box::pin(async move { service.get_events(req).await })

0 commit comments

Comments
 (0)