Skip to content

Commit bf0eb20

Browse files
bingyanglinmuXxer
andcommitted
feat(gRPC): gRPC proto files for internal usage (#9044)
# Description of change - Initialize the gRPC proto files, which addressed APIs documented in #8688. - Note that the design of gRPC request/response in is that we focus on returning low-level BCS iota-type data, instead of extracting fields from the iota-type data and put them in response in most cases (to discuss). ## Links to any relevant issues Part of #8688 ## How the change has been tested - [x] Basic tests (linting, compilation, formatting, unit/integration tests) - [ ] Patch-specific tests (correctness, functionality coverage) - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have checked that new and existing unit tests pass locally with my changes --------- Co-authored-by: muXxer <git@muxxer.de>
1 parent 4aa1bfc commit bf0eb20

File tree

67 files changed

+7975
-2422
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+7975
-2422
lines changed

.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[alias]
22
ci-fmt = "fmt --check"
33
ci-clippy = "clippy --all-targets --all-features -- -D warnings"
4-
ci-license = "license-template --template .license_template"
4+
ci-license = "license-template --template .license_template --ignore .licenseignore"
55
ci-udeps = "udeps --all-targets --backend=depinfo"
66
ci-udeps-external = "udeps --all-targets --manifest-path external-crates/move/Cargo.toml --backend=depinfo"
77

.licenseignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Generated protobuf files from Google
2+
crates/iota-grpc-types/src/proto_generated/google.*

crates/iota-grpc-client/src/checkpoint.rs

Lines changed: 0 additions & 104 deletions
This file was deleted.

crates/iota-grpc-client/src/event.rs

Lines changed: 0 additions & 117 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2025 IOTA Stiftung
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use iota_grpc_types::v0::ledger_service as grpc_ledger_service;
5+
use tonic::transport::Channel;
6+
7+
/// Dedicated client for ledger-related gRPC operations.
8+
///
9+
/// This client handles all ledger service interactions like getting objects,
10+
/// transactions, checkpoints, epochs and a service info.
11+
#[derive(Clone)]
12+
pub struct LedgerClient {
13+
_client: grpc_ledger_service::ledger_service_client::LedgerServiceClient<Channel>,
14+
}
15+
16+
impl LedgerClient {
17+
/// Create a new LedgerClient from a shared gRPC channel.
18+
pub(super) fn new(channel: Channel) -> Self {
19+
Self {
20+
_client: grpc_ledger_service::ledger_service_client::LedgerServiceClient::new(channel),
21+
}
22+
}
23+
}

crates/iota-grpc-client/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33

44
//! gRPC client for IOTA node operations.
55
6-
mod checkpoint;
7-
mod event;
6+
mod ledger;
87
mod node_client;
98

10-
pub use checkpoint::{CheckpointClient, CheckpointContent};
11-
pub use event::EventClient;
9+
pub use ledger::LedgerClient;
1210
pub use node_client::NodeClient;

crates/iota-grpc-client/src/node_client.rs

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ use std::sync::OnceLock;
55

66
use tonic::transport::Channel;
77

8-
use super::{checkpoint::CheckpointClient, event::EventClient};
8+
use crate::LedgerClient;
99

1010
/// gRPC client factory for IOTA node operations.
1111
pub struct NodeClient {
1212
/// Shared gRPC channel for all service clients
1313
channel: Channel,
14-
/// Cached checkpoint client (singleton)
15-
checkpoint_client: OnceLock<CheckpointClient>,
16-
/// Cached event client (singleton)
17-
event_client: OnceLock<EventClient>,
14+
/// Cached ledger client (singleton)
15+
ledger_client: OnceLock<LedgerClient>,
1816
}
1917

2018
impl NodeClient {
@@ -24,8 +22,7 @@ impl NodeClient {
2422

2523
Ok(Self {
2624
channel,
27-
checkpoint_client: OnceLock::new(),
28-
event_client: OnceLock::new(),
25+
ledger_client: OnceLock::new(),
2926
})
3027
}
3128

@@ -41,32 +38,17 @@ impl NodeClient {
4138
// Service Client Factories
4239
// ========================================
4340

44-
/// Get a checkpoint service client.
41+
/// Get a ledger service client.
4542
///
46-
/// Returns `Some(CheckpointClient)` if the node supports checkpoint
43+
/// Returns `Some(LedgerClient)` if the node supports ledger-related
4744
/// operations, `None` otherwise. The client is created only once and
4845
/// cached for subsequent calls.
49-
pub fn checkpoint_client(&self) -> Option<CheckpointClient> {
50-
// For now, always return Some since checkpoint service is always available
46+
pub fn ledger_service_client(&self) -> Option<super::ledger::LedgerClient> {
47+
// For now, always return Some since ledger service is always available
5148
// In the future, this could check node capabilities first
5249
Some(
53-
self.checkpoint_client
54-
.get_or_init(|| CheckpointClient::new(self.channel.clone()))
55-
.clone(),
56-
)
57-
}
58-
59-
/// Get an event service client.
60-
///
61-
/// Returns `Some(EventClient)` if the node supports event streaming
62-
/// operations, `None` otherwise. The client is created only once and
63-
/// cached for subsequent calls.
64-
pub fn event_client(&self) -> Option<EventClient> {
65-
// For now, always return Some since event service is always available
66-
// In the future, this could check node capabilities first
67-
Some(
68-
self.event_client
69-
.get_or_init(|| EventClient::new(self.channel.clone()))
50+
self.ledger_client
51+
.get_or_init(|| LedgerClient::new(self.channel.clone()))
7052
.clone(),
7153
)
7254
}

0 commit comments

Comments
 (0)