Skip to content

Commit

Permalink
feature: Added Get Block
Browse files Browse the repository at this point in the history
  • Loading branch information
a-saksena committed Jun 20, 2024
1 parent e1eeea3 commit 28e363e
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ gradle-app.setting
.project

# JDT-specific (Eclipse Java Development Tools)
.classpath
.classpath

.idea
.DS_Store
21 changes: 21 additions & 0 deletions protos/src/main/protobuf/blockstream.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
syntax = "proto3";

option java_package = "com.hedera.block.protos";
option java_outer_classname = "BlockStreamServiceGrpcProto";

service BlockStreamGrpc {
rpc GetBlock(BlockRequest) returns (Block) {}
}

message Block {
int64 id = 1;
string value = 2;
}

message BlockResponse {
int64 id = 1;
}

message BlockRequest {
int64 id = 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.hedera.block.server;

import com.google.protobuf.Descriptors;
import com.hedera.block.protos.BlockStreamServiceGrpcProto;
import io.grpc.stub.StreamObserver;
import io.helidon.webserver.grpc.GrpcService;

import java.util.logging.Logger;


public class BlockStreamService implements GrpcService {

private final Logger logger = Logger.getLogger(getClass().getName());

@Override
public Descriptors.FileDescriptor proto() {
return BlockStreamServiceGrpcProto.getDescriptor();
}

@Override
public String serviceName() {
return "BlockStreamGrpc";
}

@Override
public void update(Routing routing) {
routing.unary("GetBlock", this::getBlock);
}

// @Override void invoke(ReqT request, StreamObserver<RespT> responseObserver);

private void getBlock(BlockStreamServiceGrpcProto.BlockRequest request, StreamObserver<BlockStreamServiceGrpcProto.Block> responseObserver) {
logger.info("GetBlock request received");
}


}
19 changes: 14 additions & 5 deletions server/src/main/java/com/hedera/block/server/Server.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hedera.block.server;

import com.hedera.block.protos.BlockStreamServiceGrpcProto;
import com.hedera.block.protos.EchoServiceGrpcProto;
import io.grpc.stub.StreamObserver;
import io.helidon.webserver.WebServer;
Expand All @@ -24,15 +25,23 @@ public static void main(String[] args) {
.port(8080)
.addRouting(HttpRouting.builder()
.get("/greet", (req, res) -> res.send("Hello World!")))
// .addRouting(GrpcRouting.builder()
// .service(new EchoService())
// .unary(EchoServiceGrpcProto.getDescriptor(),
// "EchoService",
// "Echo",
// Server::grpcEcho))
.addRouting(GrpcRouting.builder()
.service(new EchoService())
.unary(EchoServiceGrpcProto.getDescriptor(),
"EchoService",
"Echo",
Server::grpcEcho))
.service(new BlockStreamService())
.unary(BlockStreamServiceGrpcProto.getDescriptor(),
"BlockStreamGrpc",
"GetBlock",
Server::grpcGetBlock))
.build()
.start();
}

static void grpcEcho(EchoServiceGrpcProto.EchoRequest request, StreamObserver<EchoServiceGrpcProto.EchoResponse> responseObserver) {}

static void grpcGetBlock(BlockStreamServiceGrpcProto.BlockRequest request, StreamObserver<BlockStreamServiceGrpcProto.Block> responseObserver) {}
}

0 comments on commit 28e363e

Please sign in to comment.