refactor: 重构trustlog-sdk目录结构到trustlog/go-trustlog

- 将所有trustlog-sdk文件移动到trustlog/go-trustlog/目录
- 更新README中所有import路径从trustlog-sdk改为go-trustlog
- 更新cookiecutter配置文件中的项目名称
- 更新根目录.lefthook.yml以引用新位置的配置
- 添加go.sum文件到版本控制
- 删除过时的示例文件

这次重构与trustlog-server保持一致的目录结构,
为未来支持多语言SDK(Python、Java等)预留空间。
This commit is contained in:
ryan
2025-12-22 13:37:57 +08:00
commit d313449c5c
87 changed files with 20622 additions and 0 deletions

20
api/grpc/common.proto Normal file
View File

@@ -0,0 +1,20 @@
syntax = "proto3";
package common;
option go_package = "go.yandata.net/iod/iod/trustlog-sdk/api/grpc/pb;pb";
message MerkleTreeProofItem {
uint32 floor = 1;
string hash = 2;
bool left = 3;
}
message Proof {
repeated MerkleTreeProofItem colItems = 1;
repeated MerkleTreeProofItem rawItems = 2;
repeated MerkleTreeProofItem colRootItem = 3;
repeated MerkleTreeProofItem rawRootItem = 4;
string sign = 5;
string version = 6; // 版本号
}

5
api/grpc/generator.go Normal file
View File

@@ -0,0 +1,5 @@
package grpc
//go:generate protoc --go_out=./pb --go-grpc_out=./pb --go_opt=module=go.yandata.net/iod/iod/trustlog-sdk/api/grpc/pb --go-grpc_opt=module=go.yandata.net/iod/iod/trustlog-sdk/api/grpc/pb --proto_path=. ./common.proto ./operation.proto ./record.proto
// 注意common.proto 必须首先列出,因为 operation.proto 和 record.proto 都依赖它
// 生成的代码将包含 common.pb.go其中定义了 Proof 类型

72
api/grpc/operation.proto Normal file
View File

@@ -0,0 +1,72 @@
syntax = "proto3";
package operation;
option go_package = "go.yandata.net/iod/iod/trustlog-sdk/api/grpc/pb;pb";
import "google/protobuf/timestamp.proto";
import "common.proto";
// ======================== 公共数据结构 ========================
message OperationData {
// 操作元数据信息
string op_id = 1; // 操作唯一标识符
google.protobuf.Timestamp timestamp = 2;// 操作时间戳
string op_source = 3; // 操作来源系统
string op_type = 4; // 操作类型
string do_prefix = 5; // 数据前缀标识符
string do_repository = 6; // 数据仓库标识符
string doid = 7; // 数据对象唯一标识
string producer_id = 8; // 生产者ID
string op_actor = 9; // 操作执行者信息
string request_body_hash = 10; // 请求体哈希值(可选)
string response_body_hash = 11; // 响应体哈希值(可选)
}
// ======================== 验证请求 & 流式响应 ========================
message ValidationReq {
google.protobuf.Timestamp time = 1; // 操作时间戳(ISO8601格式)
string op_id = 2; // 操作唯一标识符
string op_type = 3; // 操作类型
string do_repository = 4; // 数据仓库标识
}
message ValidationStreamRes {
int32 code = 1; // 状态码100处理中200完成500失败
string msg = 2; // 消息描述
string progress = 3; // 当前进度(比如 "50%"
OperationData data = 4; // 最终完成时返回,过程可为空
common.Proof proof = 5; // 取证证明(仅在完成时返回)
}
// ======================== 列表查询请求 & 返回 ========================
message ListOperationReq {
// 分页条件
uint64 page_size = 1; // 页面大小
google.protobuf.Timestamp pre_time = 2; //上一页最后一个时间
// 可选条件
google.protobuf.Timestamp timestamp = 3;// 操作时间戳
string op_source = 4; // 操作来源
string op_type = 5; // 操作类型
string do_prefix = 6; // 数据前缀
string do_repository = 7; // 数据仓库
}
message ListOperationRes {
int64 count=1; // 数据总量
repeated OperationData data = 2; // 数据列表
}
// ======================== gRPC 服务定义 ========================
service OperationValidationService {
// 单个请求,服务端流式返回进度与最终结果
rpc ValidateOperation (ValidationReq) returns (stream ValidationStreamRes);
// 分页查询操作记录
rpc ListOperations (ListOperationReq) returns (ListOperationRes);
}

236
api/grpc/pb/common.pb.go Normal file
View File

@@ -0,0 +1,236 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.10
// protoc v3.21.12
// source: common.proto
package pb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type MerkleTreeProofItem struct {
state protoimpl.MessageState `protogen:"open.v1"`
Floor uint32 `protobuf:"varint,1,opt,name=floor,proto3" json:"floor,omitempty"`
Hash string `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"`
Left bool `protobuf:"varint,3,opt,name=left,proto3" json:"left,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *MerkleTreeProofItem) Reset() {
*x = MerkleTreeProofItem{}
mi := &file_common_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *MerkleTreeProofItem) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*MerkleTreeProofItem) ProtoMessage() {}
func (x *MerkleTreeProofItem) ProtoReflect() protoreflect.Message {
mi := &file_common_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use MerkleTreeProofItem.ProtoReflect.Descriptor instead.
func (*MerkleTreeProofItem) Descriptor() ([]byte, []int) {
return file_common_proto_rawDescGZIP(), []int{0}
}
func (x *MerkleTreeProofItem) GetFloor() uint32 {
if x != nil {
return x.Floor
}
return 0
}
func (x *MerkleTreeProofItem) GetHash() string {
if x != nil {
return x.Hash
}
return ""
}
func (x *MerkleTreeProofItem) GetLeft() bool {
if x != nil {
return x.Left
}
return false
}
type Proof struct {
state protoimpl.MessageState `protogen:"open.v1"`
ColItems []*MerkleTreeProofItem `protobuf:"bytes,1,rep,name=colItems,proto3" json:"colItems,omitempty"`
RawItems []*MerkleTreeProofItem `protobuf:"bytes,2,rep,name=rawItems,proto3" json:"rawItems,omitempty"`
ColRootItem []*MerkleTreeProofItem `protobuf:"bytes,3,rep,name=colRootItem,proto3" json:"colRootItem,omitempty"`
RawRootItem []*MerkleTreeProofItem `protobuf:"bytes,4,rep,name=rawRootItem,proto3" json:"rawRootItem,omitempty"`
Sign string `protobuf:"bytes,5,opt,name=sign,proto3" json:"sign,omitempty"`
Version string `protobuf:"bytes,6,opt,name=version,proto3" json:"version,omitempty"` // 版本号
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Proof) Reset() {
*x = Proof{}
mi := &file_common_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Proof) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Proof) ProtoMessage() {}
func (x *Proof) ProtoReflect() protoreflect.Message {
mi := &file_common_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Proof.ProtoReflect.Descriptor instead.
func (*Proof) Descriptor() ([]byte, []int) {
return file_common_proto_rawDescGZIP(), []int{1}
}
func (x *Proof) GetColItems() []*MerkleTreeProofItem {
if x != nil {
return x.ColItems
}
return nil
}
func (x *Proof) GetRawItems() []*MerkleTreeProofItem {
if x != nil {
return x.RawItems
}
return nil
}
func (x *Proof) GetColRootItem() []*MerkleTreeProofItem {
if x != nil {
return x.ColRootItem
}
return nil
}
func (x *Proof) GetRawRootItem() []*MerkleTreeProofItem {
if x != nil {
return x.RawRootItem
}
return nil
}
func (x *Proof) GetSign() string {
if x != nil {
return x.Sign
}
return ""
}
func (x *Proof) GetVersion() string {
if x != nil {
return x.Version
}
return ""
}
var File_common_proto protoreflect.FileDescriptor
const file_common_proto_rawDesc = "" +
"\n" +
"\fcommon.proto\x12\x06common\"S\n" +
"\x13MerkleTreeProofItem\x12\x14\n" +
"\x05floor\x18\x01 \x01(\rR\x05floor\x12\x12\n" +
"\x04hash\x18\x02 \x01(\tR\x04hash\x12\x12\n" +
"\x04left\x18\x03 \x01(\bR\x04left\"\xa5\x02\n" +
"\x05Proof\x127\n" +
"\bcolItems\x18\x01 \x03(\v2\x1b.common.MerkleTreeProofItemR\bcolItems\x127\n" +
"\brawItems\x18\x02 \x03(\v2\x1b.common.MerkleTreeProofItemR\brawItems\x12=\n" +
"\vcolRootItem\x18\x03 \x03(\v2\x1b.common.MerkleTreeProofItemR\vcolRootItem\x12=\n" +
"\vrawRootItem\x18\x04 \x03(\v2\x1b.common.MerkleTreeProofItemR\vrawRootItem\x12\x12\n" +
"\x04sign\x18\x05 \x01(\tR\x04sign\x12\x18\n" +
"\aversion\x18\x06 \x01(\tR\aversionB4Z2go.yandata.net/iod/iod/trustlog-sdk/api/grpc/pb;pbb\x06proto3"
var (
file_common_proto_rawDescOnce sync.Once
file_common_proto_rawDescData []byte
)
func file_common_proto_rawDescGZIP() []byte {
file_common_proto_rawDescOnce.Do(func() {
file_common_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_common_proto_rawDesc), len(file_common_proto_rawDesc)))
})
return file_common_proto_rawDescData
}
var file_common_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_common_proto_goTypes = []any{
(*MerkleTreeProofItem)(nil), // 0: common.MerkleTreeProofItem
(*Proof)(nil), // 1: common.Proof
}
var file_common_proto_depIdxs = []int32{
0, // 0: common.Proof.colItems:type_name -> common.MerkleTreeProofItem
0, // 1: common.Proof.rawItems:type_name -> common.MerkleTreeProofItem
0, // 2: common.Proof.colRootItem:type_name -> common.MerkleTreeProofItem
0, // 3: common.Proof.rawRootItem:type_name -> common.MerkleTreeProofItem
4, // [4:4] is the sub-list for method output_type
4, // [4:4] is the sub-list for method input_type
4, // [4:4] is the sub-list for extension type_name
4, // [4:4] is the sub-list for extension extendee
0, // [0:4] is the sub-list for field type_name
}
func init() { file_common_proto_init() }
func file_common_proto_init() {
if File_common_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_common_proto_rawDesc), len(file_common_proto_rawDesc)),
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_common_proto_goTypes,
DependencyIndexes: file_common_proto_depIdxs,
MessageInfos: file_common_proto_msgTypes,
}.Build()
File_common_proto = out.File
file_common_proto_goTypes = nil
file_common_proto_depIdxs = nil
}

552
api/grpc/pb/operation.pb.go Normal file
View File

@@ -0,0 +1,552 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.10
// protoc v3.21.12
// source: operation.proto
package pb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// ======================== 公共数据结构 ========================
type OperationData struct {
state protoimpl.MessageState `protogen:"open.v1"`
// 操作元数据信息
OpId string `protobuf:"bytes,1,opt,name=op_id,json=opId,proto3" json:"op_id,omitempty"` // 操作唯一标识符
Timestamp *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"` // 操作时间戳
OpSource string `protobuf:"bytes,3,opt,name=op_source,json=opSource,proto3" json:"op_source,omitempty"` // 操作来源系统
OpType string `protobuf:"bytes,4,opt,name=op_type,json=opType,proto3" json:"op_type,omitempty"` // 操作类型
DoPrefix string `protobuf:"bytes,5,opt,name=do_prefix,json=doPrefix,proto3" json:"do_prefix,omitempty"` // 数据前缀标识符
DoRepository string `protobuf:"bytes,6,opt,name=do_repository,json=doRepository,proto3" json:"do_repository,omitempty"` // 数据仓库标识符
Doid string `protobuf:"bytes,7,opt,name=doid,proto3" json:"doid,omitempty"` // 数据对象唯一标识
ProducerId string `protobuf:"bytes,8,opt,name=producer_id,json=producerId,proto3" json:"producer_id,omitempty"` // 生产者ID
OpActor string `protobuf:"bytes,9,opt,name=op_actor,json=opActor,proto3" json:"op_actor,omitempty"` // 操作执行者信息
RequestBodyHash string `protobuf:"bytes,10,opt,name=request_body_hash,json=requestBodyHash,proto3" json:"request_body_hash,omitempty"` // 请求体哈希值(可选)
ResponseBodyHash string `protobuf:"bytes,11,opt,name=response_body_hash,json=responseBodyHash,proto3" json:"response_body_hash,omitempty"` // 响应体哈希值(可选)
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *OperationData) Reset() {
*x = OperationData{}
mi := &file_operation_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *OperationData) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*OperationData) ProtoMessage() {}
func (x *OperationData) ProtoReflect() protoreflect.Message {
mi := &file_operation_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use OperationData.ProtoReflect.Descriptor instead.
func (*OperationData) Descriptor() ([]byte, []int) {
return file_operation_proto_rawDescGZIP(), []int{0}
}
func (x *OperationData) GetOpId() string {
if x != nil {
return x.OpId
}
return ""
}
func (x *OperationData) GetTimestamp() *timestamppb.Timestamp {
if x != nil {
return x.Timestamp
}
return nil
}
func (x *OperationData) GetOpSource() string {
if x != nil {
return x.OpSource
}
return ""
}
func (x *OperationData) GetOpType() string {
if x != nil {
return x.OpType
}
return ""
}
func (x *OperationData) GetDoPrefix() string {
if x != nil {
return x.DoPrefix
}
return ""
}
func (x *OperationData) GetDoRepository() string {
if x != nil {
return x.DoRepository
}
return ""
}
func (x *OperationData) GetDoid() string {
if x != nil {
return x.Doid
}
return ""
}
func (x *OperationData) GetProducerId() string {
if x != nil {
return x.ProducerId
}
return ""
}
func (x *OperationData) GetOpActor() string {
if x != nil {
return x.OpActor
}
return ""
}
func (x *OperationData) GetRequestBodyHash() string {
if x != nil {
return x.RequestBodyHash
}
return ""
}
func (x *OperationData) GetResponseBodyHash() string {
if x != nil {
return x.ResponseBodyHash
}
return ""
}
// ======================== 验证请求 & 流式响应 ========================
type ValidationReq struct {
state protoimpl.MessageState `protogen:"open.v1"`
Time *timestamppb.Timestamp `protobuf:"bytes,1,opt,name=time,proto3" json:"time,omitempty"` // 操作时间戳(ISO8601格式)
OpId string `protobuf:"bytes,2,opt,name=op_id,json=opId,proto3" json:"op_id,omitempty"` // 操作唯一标识符
OpType string `protobuf:"bytes,3,opt,name=op_type,json=opType,proto3" json:"op_type,omitempty"` // 操作类型
DoRepository string `protobuf:"bytes,4,opt,name=do_repository,json=doRepository,proto3" json:"do_repository,omitempty"` // 数据仓库标识
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *ValidationReq) Reset() {
*x = ValidationReq{}
mi := &file_operation_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *ValidationReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ValidationReq) ProtoMessage() {}
func (x *ValidationReq) ProtoReflect() protoreflect.Message {
mi := &file_operation_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ValidationReq.ProtoReflect.Descriptor instead.
func (*ValidationReq) Descriptor() ([]byte, []int) {
return file_operation_proto_rawDescGZIP(), []int{1}
}
func (x *ValidationReq) GetTime() *timestamppb.Timestamp {
if x != nil {
return x.Time
}
return nil
}
func (x *ValidationReq) GetOpId() string {
if x != nil {
return x.OpId
}
return ""
}
func (x *ValidationReq) GetOpType() string {
if x != nil {
return x.OpType
}
return ""
}
func (x *ValidationReq) GetDoRepository() string {
if x != nil {
return x.DoRepository
}
return ""
}
type ValidationStreamRes struct {
state protoimpl.MessageState `protogen:"open.v1"`
Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码100处理中200完成500失败
Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` // 消息描述
Progress string `protobuf:"bytes,3,opt,name=progress,proto3" json:"progress,omitempty"` // 当前进度(比如 "50%"
Data *OperationData `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // 最终完成时返回,过程可为空
Proof *Proof `protobuf:"bytes,5,opt,name=proof,proto3" json:"proof,omitempty"` // 取证证明(仅在完成时返回)
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *ValidationStreamRes) Reset() {
*x = ValidationStreamRes{}
mi := &file_operation_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *ValidationStreamRes) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ValidationStreamRes) ProtoMessage() {}
func (x *ValidationStreamRes) ProtoReflect() protoreflect.Message {
mi := &file_operation_proto_msgTypes[2]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ValidationStreamRes.ProtoReflect.Descriptor instead.
func (*ValidationStreamRes) Descriptor() ([]byte, []int) {
return file_operation_proto_rawDescGZIP(), []int{2}
}
func (x *ValidationStreamRes) GetCode() int32 {
if x != nil {
return x.Code
}
return 0
}
func (x *ValidationStreamRes) GetMsg() string {
if x != nil {
return x.Msg
}
return ""
}
func (x *ValidationStreamRes) GetProgress() string {
if x != nil {
return x.Progress
}
return ""
}
func (x *ValidationStreamRes) GetData() *OperationData {
if x != nil {
return x.Data
}
return nil
}
func (x *ValidationStreamRes) GetProof() *Proof {
if x != nil {
return x.Proof
}
return nil
}
// ======================== 列表查询请求 & 返回 ========================
type ListOperationReq struct {
state protoimpl.MessageState `protogen:"open.v1"`
// 分页条件
PageSize uint64 `protobuf:"varint,1,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"` // 页面大小
PreTime *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=pre_time,json=preTime,proto3" json:"pre_time,omitempty"` //上一页最后一个时间
// 可选条件
Timestamp *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=timestamp,proto3" json:"timestamp,omitempty"` // 操作时间戳
OpSource string `protobuf:"bytes,4,opt,name=op_source,json=opSource,proto3" json:"op_source,omitempty"` // 操作来源
OpType string `protobuf:"bytes,5,opt,name=op_type,json=opType,proto3" json:"op_type,omitempty"` // 操作类型
DoPrefix string `protobuf:"bytes,6,opt,name=do_prefix,json=doPrefix,proto3" json:"do_prefix,omitempty"` // 数据前缀
DoRepository string `protobuf:"bytes,7,opt,name=do_repository,json=doRepository,proto3" json:"do_repository,omitempty"` // 数据仓库
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *ListOperationReq) Reset() {
*x = ListOperationReq{}
mi := &file_operation_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *ListOperationReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ListOperationReq) ProtoMessage() {}
func (x *ListOperationReq) ProtoReflect() protoreflect.Message {
mi := &file_operation_proto_msgTypes[3]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ListOperationReq.ProtoReflect.Descriptor instead.
func (*ListOperationReq) Descriptor() ([]byte, []int) {
return file_operation_proto_rawDescGZIP(), []int{3}
}
func (x *ListOperationReq) GetPageSize() uint64 {
if x != nil {
return x.PageSize
}
return 0
}
func (x *ListOperationReq) GetPreTime() *timestamppb.Timestamp {
if x != nil {
return x.PreTime
}
return nil
}
func (x *ListOperationReq) GetTimestamp() *timestamppb.Timestamp {
if x != nil {
return x.Timestamp
}
return nil
}
func (x *ListOperationReq) GetOpSource() string {
if x != nil {
return x.OpSource
}
return ""
}
func (x *ListOperationReq) GetOpType() string {
if x != nil {
return x.OpType
}
return ""
}
func (x *ListOperationReq) GetDoPrefix() string {
if x != nil {
return x.DoPrefix
}
return ""
}
func (x *ListOperationReq) GetDoRepository() string {
if x != nil {
return x.DoRepository
}
return ""
}
type ListOperationRes struct {
state protoimpl.MessageState `protogen:"open.v1"`
Count int64 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` // 数据总量
Data []*OperationData `protobuf:"bytes,2,rep,name=data,proto3" json:"data,omitempty"` // 数据列表
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *ListOperationRes) Reset() {
*x = ListOperationRes{}
mi := &file_operation_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *ListOperationRes) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ListOperationRes) ProtoMessage() {}
func (x *ListOperationRes) ProtoReflect() protoreflect.Message {
mi := &file_operation_proto_msgTypes[4]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ListOperationRes.ProtoReflect.Descriptor instead.
func (*ListOperationRes) Descriptor() ([]byte, []int) {
return file_operation_proto_rawDescGZIP(), []int{4}
}
func (x *ListOperationRes) GetCount() int64 {
if x != nil {
return x.Count
}
return 0
}
func (x *ListOperationRes) GetData() []*OperationData {
if x != nil {
return x.Data
}
return nil
}
var File_operation_proto protoreflect.FileDescriptor
const file_operation_proto_rawDesc = "" +
"\n" +
"\x0foperation.proto\x12\toperation\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\fcommon.proto\"\x80\x03\n" +
"\rOperationData\x12\x13\n" +
"\x05op_id\x18\x01 \x01(\tR\x04opId\x128\n" +
"\ttimestamp\x18\x02 \x01(\v2\x1a.google.protobuf.TimestampR\ttimestamp\x12\x1b\n" +
"\top_source\x18\x03 \x01(\tR\bopSource\x12\x17\n" +
"\aop_type\x18\x04 \x01(\tR\x06opType\x12\x1b\n" +
"\tdo_prefix\x18\x05 \x01(\tR\bdoPrefix\x12#\n" +
"\rdo_repository\x18\x06 \x01(\tR\fdoRepository\x12\x12\n" +
"\x04doid\x18\a \x01(\tR\x04doid\x12\x1f\n" +
"\vproducer_id\x18\b \x01(\tR\n" +
"producerId\x12\x19\n" +
"\bop_actor\x18\t \x01(\tR\aopActor\x12*\n" +
"\x11request_body_hash\x18\n" +
" \x01(\tR\x0frequestBodyHash\x12,\n" +
"\x12response_body_hash\x18\v \x01(\tR\x10responseBodyHash\"\x92\x01\n" +
"\rValidationReq\x12.\n" +
"\x04time\x18\x01 \x01(\v2\x1a.google.protobuf.TimestampR\x04time\x12\x13\n" +
"\x05op_id\x18\x02 \x01(\tR\x04opId\x12\x17\n" +
"\aop_type\x18\x03 \x01(\tR\x06opType\x12#\n" +
"\rdo_repository\x18\x04 \x01(\tR\fdoRepository\"\xaa\x01\n" +
"\x13ValidationStreamRes\x12\x12\n" +
"\x04code\x18\x01 \x01(\x05R\x04code\x12\x10\n" +
"\x03msg\x18\x02 \x01(\tR\x03msg\x12\x1a\n" +
"\bprogress\x18\x03 \x01(\tR\bprogress\x12,\n" +
"\x04data\x18\x04 \x01(\v2\x18.operation.OperationDataR\x04data\x12#\n" +
"\x05proof\x18\x05 \x01(\v2\r.common.ProofR\x05proof\"\x98\x02\n" +
"\x10ListOperationReq\x12\x1b\n" +
"\tpage_size\x18\x01 \x01(\x04R\bpageSize\x125\n" +
"\bpre_time\x18\x02 \x01(\v2\x1a.google.protobuf.TimestampR\apreTime\x128\n" +
"\ttimestamp\x18\x03 \x01(\v2\x1a.google.protobuf.TimestampR\ttimestamp\x12\x1b\n" +
"\top_source\x18\x04 \x01(\tR\bopSource\x12\x17\n" +
"\aop_type\x18\x05 \x01(\tR\x06opType\x12\x1b\n" +
"\tdo_prefix\x18\x06 \x01(\tR\bdoPrefix\x12#\n" +
"\rdo_repository\x18\a \x01(\tR\fdoRepository\"V\n" +
"\x10ListOperationRes\x12\x14\n" +
"\x05count\x18\x01 \x01(\x03R\x05count\x12,\n" +
"\x04data\x18\x02 \x03(\v2\x18.operation.OperationDataR\x04data2\xb9\x01\n" +
"\x1aOperationValidationService\x12O\n" +
"\x11ValidateOperation\x12\x18.operation.ValidationReq\x1a\x1e.operation.ValidationStreamRes0\x01\x12J\n" +
"\x0eListOperations\x12\x1b.operation.ListOperationReq\x1a\x1b.operation.ListOperationResB4Z2go.yandata.net/iod/iod/trustlog-sdk/api/grpc/pb;pbb\x06proto3"
var (
file_operation_proto_rawDescOnce sync.Once
file_operation_proto_rawDescData []byte
)
func file_operation_proto_rawDescGZIP() []byte {
file_operation_proto_rawDescOnce.Do(func() {
file_operation_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_operation_proto_rawDesc), len(file_operation_proto_rawDesc)))
})
return file_operation_proto_rawDescData
}
var file_operation_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
var file_operation_proto_goTypes = []any{
(*OperationData)(nil), // 0: operation.OperationData
(*ValidationReq)(nil), // 1: operation.ValidationReq
(*ValidationStreamRes)(nil), // 2: operation.ValidationStreamRes
(*ListOperationReq)(nil), // 3: operation.ListOperationReq
(*ListOperationRes)(nil), // 4: operation.ListOperationRes
(*timestamppb.Timestamp)(nil), // 5: google.protobuf.Timestamp
(*Proof)(nil), // 6: common.Proof
}
var file_operation_proto_depIdxs = []int32{
5, // 0: operation.OperationData.timestamp:type_name -> google.protobuf.Timestamp
5, // 1: operation.ValidationReq.time:type_name -> google.protobuf.Timestamp
0, // 2: operation.ValidationStreamRes.data:type_name -> operation.OperationData
6, // 3: operation.ValidationStreamRes.proof:type_name -> common.Proof
5, // 4: operation.ListOperationReq.pre_time:type_name -> google.protobuf.Timestamp
5, // 5: operation.ListOperationReq.timestamp:type_name -> google.protobuf.Timestamp
0, // 6: operation.ListOperationRes.data:type_name -> operation.OperationData
1, // 7: operation.OperationValidationService.ValidateOperation:input_type -> operation.ValidationReq
3, // 8: operation.OperationValidationService.ListOperations:input_type -> operation.ListOperationReq
2, // 9: operation.OperationValidationService.ValidateOperation:output_type -> operation.ValidationStreamRes
4, // 10: operation.OperationValidationService.ListOperations:output_type -> operation.ListOperationRes
9, // [9:11] is the sub-list for method output_type
7, // [7:9] is the sub-list for method input_type
7, // [7:7] is the sub-list for extension type_name
7, // [7:7] is the sub-list for extension extendee
0, // [0:7] is the sub-list for field type_name
}
func init() { file_operation_proto_init() }
func file_operation_proto_init() {
if File_operation_proto != nil {
return
}
file_common_proto_init()
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_operation_proto_rawDesc), len(file_operation_proto_rawDesc)),
NumEnums: 0,
NumMessages: 5,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_operation_proto_goTypes,
DependencyIndexes: file_operation_proto_depIdxs,
MessageInfos: file_operation_proto_msgTypes,
}.Build()
File_operation_proto = out.File
file_operation_proto_goTypes = nil
file_operation_proto_depIdxs = nil
}

View File

@@ -0,0 +1,172 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc v3.21.12
// source: operation.proto
package pb
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
OperationValidationService_ValidateOperation_FullMethodName = "/operation.OperationValidationService/ValidateOperation"
OperationValidationService_ListOperations_FullMethodName = "/operation.OperationValidationService/ListOperations"
)
// OperationValidationServiceClient is the client API for OperationValidationService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
//
// ======================== gRPC 服务定义 ========================
type OperationValidationServiceClient interface {
// 单个请求,服务端流式返回进度与最终结果
ValidateOperation(ctx context.Context, in *ValidationReq, opts ...grpc.CallOption) (grpc.ServerStreamingClient[ValidationStreamRes], error)
// 分页查询操作记录
ListOperations(ctx context.Context, in *ListOperationReq, opts ...grpc.CallOption) (*ListOperationRes, error)
}
type operationValidationServiceClient struct {
cc grpc.ClientConnInterface
}
func NewOperationValidationServiceClient(cc grpc.ClientConnInterface) OperationValidationServiceClient {
return &operationValidationServiceClient{cc}
}
func (c *operationValidationServiceClient) ValidateOperation(ctx context.Context, in *ValidationReq, opts ...grpc.CallOption) (grpc.ServerStreamingClient[ValidationStreamRes], error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
stream, err := c.cc.NewStream(ctx, &OperationValidationService_ServiceDesc.Streams[0], OperationValidationService_ValidateOperation_FullMethodName, cOpts...)
if err != nil {
return nil, err
}
x := &grpc.GenericClientStream[ValidationReq, ValidationStreamRes]{ClientStream: stream}
if err := x.ClientStream.SendMsg(in); err != nil {
return nil, err
}
if err := x.ClientStream.CloseSend(); err != nil {
return nil, err
}
return x, nil
}
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type OperationValidationService_ValidateOperationClient = grpc.ServerStreamingClient[ValidationStreamRes]
func (c *operationValidationServiceClient) ListOperations(ctx context.Context, in *ListOperationReq, opts ...grpc.CallOption) (*ListOperationRes, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(ListOperationRes)
err := c.cc.Invoke(ctx, OperationValidationService_ListOperations_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// OperationValidationServiceServer is the server API for OperationValidationService service.
// All implementations must embed UnimplementedOperationValidationServiceServer
// for forward compatibility.
//
// ======================== gRPC 服务定义 ========================
type OperationValidationServiceServer interface {
// 单个请求,服务端流式返回进度与最终结果
ValidateOperation(*ValidationReq, grpc.ServerStreamingServer[ValidationStreamRes]) error
// 分页查询操作记录
ListOperations(context.Context, *ListOperationReq) (*ListOperationRes, error)
mustEmbedUnimplementedOperationValidationServiceServer()
}
// UnimplementedOperationValidationServiceServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedOperationValidationServiceServer struct{}
func (UnimplementedOperationValidationServiceServer) ValidateOperation(*ValidationReq, grpc.ServerStreamingServer[ValidationStreamRes]) error {
return status.Errorf(codes.Unimplemented, "method ValidateOperation not implemented")
}
func (UnimplementedOperationValidationServiceServer) ListOperations(context.Context, *ListOperationReq) (*ListOperationRes, error) {
return nil, status.Errorf(codes.Unimplemented, "method ListOperations not implemented")
}
func (UnimplementedOperationValidationServiceServer) mustEmbedUnimplementedOperationValidationServiceServer() {
}
func (UnimplementedOperationValidationServiceServer) testEmbeddedByValue() {}
// UnsafeOperationValidationServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to OperationValidationServiceServer will
// result in compilation errors.
type UnsafeOperationValidationServiceServer interface {
mustEmbedUnimplementedOperationValidationServiceServer()
}
func RegisterOperationValidationServiceServer(s grpc.ServiceRegistrar, srv OperationValidationServiceServer) {
// If the following call pancis, it indicates UnimplementedOperationValidationServiceServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&OperationValidationService_ServiceDesc, srv)
}
func _OperationValidationService_ValidateOperation_Handler(srv interface{}, stream grpc.ServerStream) error {
m := new(ValidationReq)
if err := stream.RecvMsg(m); err != nil {
return err
}
return srv.(OperationValidationServiceServer).ValidateOperation(m, &grpc.GenericServerStream[ValidationReq, ValidationStreamRes]{ServerStream: stream})
}
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type OperationValidationService_ValidateOperationServer = grpc.ServerStreamingServer[ValidationStreamRes]
func _OperationValidationService_ListOperations_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ListOperationReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(OperationValidationServiceServer).ListOperations(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: OperationValidationService_ListOperations_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(OperationValidationServiceServer).ListOperations(ctx, req.(*ListOperationReq))
}
return interceptor(ctx, in, info, handler)
}
// OperationValidationService_ServiceDesc is the grpc.ServiceDesc for OperationValidationService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var OperationValidationService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "operation.OperationValidationService",
HandlerType: (*OperationValidationServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "ListOperations",
Handler: _OperationValidationService_ListOperations_Handler,
},
},
Streams: []grpc.StreamDesc{
{
StreamName: "ValidateOperation",
Handler: _OperationValidationService_ValidateOperation_Handler,
ServerStreams: true,
},
},
Metadata: "operation.proto",
}

489
api/grpc/pb/record.pb.go Normal file
View File

@@ -0,0 +1,489 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.10
// protoc v3.21.12
// source: record.proto
package pb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// ======================== 公共数据结构 ========================
type RecordData struct {
state protoimpl.MessageState `protogen:"open.v1"`
// 记录核心信息
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` // 记录唯一标识符(必填)
DoPrefix string `protobuf:"bytes,2,opt,name=do_prefix,json=doPrefix,proto3" json:"do_prefix,omitempty"` // 数据前缀标识符
ProducerId string `protobuf:"bytes,3,opt,name=producer_id,json=producerId,proto3" json:"producer_id,omitempty"` // 生产者ID
Timestamp *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=timestamp,proto3" json:"timestamp,omitempty"` // 记录时间戳
Operator string `protobuf:"bytes,5,opt,name=operator,proto3" json:"operator,omitempty"` // 操作执行者标识
Extra []byte `protobuf:"bytes,6,opt,name=extra,proto3" json:"extra,omitempty"` // 额外数据字段
RcType string `protobuf:"bytes,7,opt,name=rc_type,json=rcType,proto3" json:"rc_type,omitempty"` // 记录类型
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *RecordData) Reset() {
*x = RecordData{}
mi := &file_record_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *RecordData) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*RecordData) ProtoMessage() {}
func (x *RecordData) ProtoReflect() protoreflect.Message {
mi := &file_record_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use RecordData.ProtoReflect.Descriptor instead.
func (*RecordData) Descriptor() ([]byte, []int) {
return file_record_proto_rawDescGZIP(), []int{0}
}
func (x *RecordData) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *RecordData) GetDoPrefix() string {
if x != nil {
return x.DoPrefix
}
return ""
}
func (x *RecordData) GetProducerId() string {
if x != nil {
return x.ProducerId
}
return ""
}
func (x *RecordData) GetTimestamp() *timestamppb.Timestamp {
if x != nil {
return x.Timestamp
}
return nil
}
func (x *RecordData) GetOperator() string {
if x != nil {
return x.Operator
}
return ""
}
func (x *RecordData) GetExtra() []byte {
if x != nil {
return x.Extra
}
return nil
}
func (x *RecordData) GetRcType() string {
if x != nil {
return x.RcType
}
return ""
}
// ======================== 列表查询请求 & 返回 ========================
type ListRecordReq struct {
state protoimpl.MessageState `protogen:"open.v1"`
// 分页条件
PageSize uint64 `protobuf:"varint,1,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"` // 页面大小
PreTime *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=pre_time,json=preTime,proto3" json:"pre_time,omitempty"` // 上一页最后一个时间
// 可选过滤条件
DoPrefix string `protobuf:"bytes,3,opt,name=do_prefix,json=doPrefix,proto3" json:"do_prefix,omitempty"` // 数据前缀过滤
RcType string `protobuf:"bytes,4,opt,name=rc_type,json=rcType,proto3" json:"rc_type,omitempty"` // 记录类型过滤
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *ListRecordReq) Reset() {
*x = ListRecordReq{}
mi := &file_record_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *ListRecordReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ListRecordReq) ProtoMessage() {}
func (x *ListRecordReq) ProtoReflect() protoreflect.Message {
mi := &file_record_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ListRecordReq.ProtoReflect.Descriptor instead.
func (*ListRecordReq) Descriptor() ([]byte, []int) {
return file_record_proto_rawDescGZIP(), []int{1}
}
func (x *ListRecordReq) GetPageSize() uint64 {
if x != nil {
return x.PageSize
}
return 0
}
func (x *ListRecordReq) GetPreTime() *timestamppb.Timestamp {
if x != nil {
return x.PreTime
}
return nil
}
func (x *ListRecordReq) GetDoPrefix() string {
if x != nil {
return x.DoPrefix
}
return ""
}
func (x *ListRecordReq) GetRcType() string {
if x != nil {
return x.RcType
}
return ""
}
type ListRecordRes struct {
state protoimpl.MessageState `protogen:"open.v1"`
Count int64 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` // 数据总量
Data []*RecordData `protobuf:"bytes,2,rep,name=data,proto3" json:"data,omitempty"` // 记录数据列表
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *ListRecordRes) Reset() {
*x = ListRecordRes{}
mi := &file_record_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *ListRecordRes) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ListRecordRes) ProtoMessage() {}
func (x *ListRecordRes) ProtoReflect() protoreflect.Message {
mi := &file_record_proto_msgTypes[2]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ListRecordRes.ProtoReflect.Descriptor instead.
func (*ListRecordRes) Descriptor() ([]byte, []int) {
return file_record_proto_rawDescGZIP(), []int{2}
}
func (x *ListRecordRes) GetCount() int64 {
if x != nil {
return x.Count
}
return 0
}
func (x *ListRecordRes) GetData() []*RecordData {
if x != nil {
return x.Data
}
return nil
}
// ======================== 记录验证请求 & 流式响应 ========================
type RecordValidationReq struct {
state protoimpl.MessageState `protogen:"open.v1"`
Timestamp *timestamppb.Timestamp `protobuf:"bytes,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` // 记录时间戳
RecordId string `protobuf:"bytes,2,opt,name=record_id,json=recordId,proto3" json:"record_id,omitempty"` // 要验证的记录ID
DoPrefix string `protobuf:"bytes,3,opt,name=do_prefix,json=doPrefix,proto3" json:"do_prefix,omitempty"` // 数据前缀(可选)
RcType string `protobuf:"bytes,4,opt,name=rc_type,json=rcType,proto3" json:"rc_type,omitempty"` // 记录类型
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *RecordValidationReq) Reset() {
*x = RecordValidationReq{}
mi := &file_record_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *RecordValidationReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*RecordValidationReq) ProtoMessage() {}
func (x *RecordValidationReq) ProtoReflect() protoreflect.Message {
mi := &file_record_proto_msgTypes[3]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use RecordValidationReq.ProtoReflect.Descriptor instead.
func (*RecordValidationReq) Descriptor() ([]byte, []int) {
return file_record_proto_rawDescGZIP(), []int{3}
}
func (x *RecordValidationReq) GetTimestamp() *timestamppb.Timestamp {
if x != nil {
return x.Timestamp
}
return nil
}
func (x *RecordValidationReq) GetRecordId() string {
if x != nil {
return x.RecordId
}
return ""
}
func (x *RecordValidationReq) GetDoPrefix() string {
if x != nil {
return x.DoPrefix
}
return ""
}
func (x *RecordValidationReq) GetRcType() string {
if x != nil {
return x.RcType
}
return ""
}
type RecordValidationStreamRes struct {
state protoimpl.MessageState `protogen:"open.v1"`
Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` // 状态码100处理中200完成400客户端错误500服务器错误
Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` // 消息描述
Progress string `protobuf:"bytes,3,opt,name=progress,proto3" json:"progress,omitempty"` // 验证进度(如 "30%", "验证哈希完成"
// 验证结果详情(仅在完成时返回)
Result *RecordData `protobuf:"bytes,4,opt,name=result,proto3" json:"result,omitempty"`
Proof *Proof `protobuf:"bytes,5,opt,name=proof,proto3" json:"proof,omitempty"` // 取证证明(仅在完成时返回)
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *RecordValidationStreamRes) Reset() {
*x = RecordValidationStreamRes{}
mi := &file_record_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *RecordValidationStreamRes) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*RecordValidationStreamRes) ProtoMessage() {}
func (x *RecordValidationStreamRes) ProtoReflect() protoreflect.Message {
mi := &file_record_proto_msgTypes[4]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use RecordValidationStreamRes.ProtoReflect.Descriptor instead.
func (*RecordValidationStreamRes) Descriptor() ([]byte, []int) {
return file_record_proto_rawDescGZIP(), []int{4}
}
func (x *RecordValidationStreamRes) GetCode() int32 {
if x != nil {
return x.Code
}
return 0
}
func (x *RecordValidationStreamRes) GetMsg() string {
if x != nil {
return x.Msg
}
return ""
}
func (x *RecordValidationStreamRes) GetProgress() string {
if x != nil {
return x.Progress
}
return ""
}
func (x *RecordValidationStreamRes) GetResult() *RecordData {
if x != nil {
return x.Result
}
return nil
}
func (x *RecordValidationStreamRes) GetProof() *Proof {
if x != nil {
return x.Proof
}
return nil
}
var File_record_proto protoreflect.FileDescriptor
const file_record_proto_rawDesc = "" +
"\n" +
"\frecord.proto\x12\x06record\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\fcommon.proto\"\xdf\x01\n" +
"\n" +
"RecordData\x12\x0e\n" +
"\x02id\x18\x01 \x01(\tR\x02id\x12\x1b\n" +
"\tdo_prefix\x18\x02 \x01(\tR\bdoPrefix\x12\x1f\n" +
"\vproducer_id\x18\x03 \x01(\tR\n" +
"producerId\x128\n" +
"\ttimestamp\x18\x04 \x01(\v2\x1a.google.protobuf.TimestampR\ttimestamp\x12\x1a\n" +
"\boperator\x18\x05 \x01(\tR\boperator\x12\x14\n" +
"\x05extra\x18\x06 \x01(\fR\x05extra\x12\x17\n" +
"\arc_type\x18\a \x01(\tR\x06rcType\"\x99\x01\n" +
"\rListRecordReq\x12\x1b\n" +
"\tpage_size\x18\x01 \x01(\x04R\bpageSize\x125\n" +
"\bpre_time\x18\x02 \x01(\v2\x1a.google.protobuf.TimestampR\apreTime\x12\x1b\n" +
"\tdo_prefix\x18\x03 \x01(\tR\bdoPrefix\x12\x17\n" +
"\arc_type\x18\x04 \x01(\tR\x06rcType\"M\n" +
"\rListRecordRes\x12\x14\n" +
"\x05count\x18\x01 \x01(\x03R\x05count\x12&\n" +
"\x04data\x18\x02 \x03(\v2\x12.record.RecordDataR\x04data\"\xa2\x01\n" +
"\x13RecordValidationReq\x128\n" +
"\ttimestamp\x18\x01 \x01(\v2\x1a.google.protobuf.TimestampR\ttimestamp\x12\x1b\n" +
"\trecord_id\x18\x02 \x01(\tR\brecordId\x12\x1b\n" +
"\tdo_prefix\x18\x03 \x01(\tR\bdoPrefix\x12\x17\n" +
"\arc_type\x18\x04 \x01(\tR\x06rcType\"\xae\x01\n" +
"\x19RecordValidationStreamRes\x12\x12\n" +
"\x04code\x18\x01 \x01(\x05R\x04code\x12\x10\n" +
"\x03msg\x18\x02 \x01(\tR\x03msg\x12\x1a\n" +
"\bprogress\x18\x03 \x01(\tR\bprogress\x12*\n" +
"\x06result\x18\x04 \x01(\v2\x12.record.RecordDataR\x06result\x12#\n" +
"\x05proof\x18\x05 \x01(\v2\r.common.ProofR\x05proof2\xaa\x01\n" +
"\x17RecordValidationService\x12;\n" +
"\vListRecords\x12\x15.record.ListRecordReq\x1a\x15.record.ListRecordRes\x12R\n" +
"\x0eValidateRecord\x12\x1b.record.RecordValidationReq\x1a!.record.RecordValidationStreamRes0\x01B4Z2go.yandata.net/iod/iod/trustlog-sdk/api/grpc/pb;pbb\x06proto3"
var (
file_record_proto_rawDescOnce sync.Once
file_record_proto_rawDescData []byte
)
func file_record_proto_rawDescGZIP() []byte {
file_record_proto_rawDescOnce.Do(func() {
file_record_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_record_proto_rawDesc), len(file_record_proto_rawDesc)))
})
return file_record_proto_rawDescData
}
var file_record_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
var file_record_proto_goTypes = []any{
(*RecordData)(nil), // 0: record.RecordData
(*ListRecordReq)(nil), // 1: record.ListRecordReq
(*ListRecordRes)(nil), // 2: record.ListRecordRes
(*RecordValidationReq)(nil), // 3: record.RecordValidationReq
(*RecordValidationStreamRes)(nil), // 4: record.RecordValidationStreamRes
(*timestamppb.Timestamp)(nil), // 5: google.protobuf.Timestamp
(*Proof)(nil), // 6: common.Proof
}
var file_record_proto_depIdxs = []int32{
5, // 0: record.RecordData.timestamp:type_name -> google.protobuf.Timestamp
5, // 1: record.ListRecordReq.pre_time:type_name -> google.protobuf.Timestamp
0, // 2: record.ListRecordRes.data:type_name -> record.RecordData
5, // 3: record.RecordValidationReq.timestamp:type_name -> google.protobuf.Timestamp
0, // 4: record.RecordValidationStreamRes.result:type_name -> record.RecordData
6, // 5: record.RecordValidationStreamRes.proof:type_name -> common.Proof
1, // 6: record.RecordValidationService.ListRecords:input_type -> record.ListRecordReq
3, // 7: record.RecordValidationService.ValidateRecord:input_type -> record.RecordValidationReq
2, // 8: record.RecordValidationService.ListRecords:output_type -> record.ListRecordRes
4, // 9: record.RecordValidationService.ValidateRecord:output_type -> record.RecordValidationStreamRes
8, // [8:10] is the sub-list for method output_type
6, // [6:8] is the sub-list for method input_type
6, // [6:6] is the sub-list for extension type_name
6, // [6:6] is the sub-list for extension extendee
0, // [0:6] is the sub-list for field type_name
}
func init() { file_record_proto_init() }
func file_record_proto_init() {
if File_record_proto != nil {
return
}
file_common_proto_init()
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_record_proto_rawDesc), len(file_record_proto_rawDesc)),
NumEnums: 0,
NumMessages: 5,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_record_proto_goTypes,
DependencyIndexes: file_record_proto_depIdxs,
MessageInfos: file_record_proto_msgTypes,
}.Build()
File_record_proto = out.File
file_record_proto_goTypes = nil
file_record_proto_depIdxs = nil
}

View File

@@ -0,0 +1,172 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc v3.21.12
// source: record.proto
package pb
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
RecordValidationService_ListRecords_FullMethodName = "/record.RecordValidationService/ListRecords"
RecordValidationService_ValidateRecord_FullMethodName = "/record.RecordValidationService/ValidateRecord"
)
// RecordValidationServiceClient is the client API for RecordValidationService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
//
// ======================== gRPC 服务定义 ========================
type RecordValidationServiceClient interface {
// 分页查询记录列表
ListRecords(ctx context.Context, in *ListRecordReq, opts ...grpc.CallOption) (*ListRecordRes, error)
// 单个记录验证,服务端流式返回验证进度与结果
ValidateRecord(ctx context.Context, in *RecordValidationReq, opts ...grpc.CallOption) (grpc.ServerStreamingClient[RecordValidationStreamRes], error)
}
type recordValidationServiceClient struct {
cc grpc.ClientConnInterface
}
func NewRecordValidationServiceClient(cc grpc.ClientConnInterface) RecordValidationServiceClient {
return &recordValidationServiceClient{cc}
}
func (c *recordValidationServiceClient) ListRecords(ctx context.Context, in *ListRecordReq, opts ...grpc.CallOption) (*ListRecordRes, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(ListRecordRes)
err := c.cc.Invoke(ctx, RecordValidationService_ListRecords_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *recordValidationServiceClient) ValidateRecord(ctx context.Context, in *RecordValidationReq, opts ...grpc.CallOption) (grpc.ServerStreamingClient[RecordValidationStreamRes], error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
stream, err := c.cc.NewStream(ctx, &RecordValidationService_ServiceDesc.Streams[0], RecordValidationService_ValidateRecord_FullMethodName, cOpts...)
if err != nil {
return nil, err
}
x := &grpc.GenericClientStream[RecordValidationReq, RecordValidationStreamRes]{ClientStream: stream}
if err := x.ClientStream.SendMsg(in); err != nil {
return nil, err
}
if err := x.ClientStream.CloseSend(); err != nil {
return nil, err
}
return x, nil
}
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type RecordValidationService_ValidateRecordClient = grpc.ServerStreamingClient[RecordValidationStreamRes]
// RecordValidationServiceServer is the server API for RecordValidationService service.
// All implementations must embed UnimplementedRecordValidationServiceServer
// for forward compatibility.
//
// ======================== gRPC 服务定义 ========================
type RecordValidationServiceServer interface {
// 分页查询记录列表
ListRecords(context.Context, *ListRecordReq) (*ListRecordRes, error)
// 单个记录验证,服务端流式返回验证进度与结果
ValidateRecord(*RecordValidationReq, grpc.ServerStreamingServer[RecordValidationStreamRes]) error
mustEmbedUnimplementedRecordValidationServiceServer()
}
// UnimplementedRecordValidationServiceServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedRecordValidationServiceServer struct{}
func (UnimplementedRecordValidationServiceServer) ListRecords(context.Context, *ListRecordReq) (*ListRecordRes, error) {
return nil, status.Errorf(codes.Unimplemented, "method ListRecords not implemented")
}
func (UnimplementedRecordValidationServiceServer) ValidateRecord(*RecordValidationReq, grpc.ServerStreamingServer[RecordValidationStreamRes]) error {
return status.Errorf(codes.Unimplemented, "method ValidateRecord not implemented")
}
func (UnimplementedRecordValidationServiceServer) mustEmbedUnimplementedRecordValidationServiceServer() {
}
func (UnimplementedRecordValidationServiceServer) testEmbeddedByValue() {}
// UnsafeRecordValidationServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to RecordValidationServiceServer will
// result in compilation errors.
type UnsafeRecordValidationServiceServer interface {
mustEmbedUnimplementedRecordValidationServiceServer()
}
func RegisterRecordValidationServiceServer(s grpc.ServiceRegistrar, srv RecordValidationServiceServer) {
// If the following call pancis, it indicates UnimplementedRecordValidationServiceServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&RecordValidationService_ServiceDesc, srv)
}
func _RecordValidationService_ListRecords_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ListRecordReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RecordValidationServiceServer).ListRecords(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: RecordValidationService_ListRecords_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RecordValidationServiceServer).ListRecords(ctx, req.(*ListRecordReq))
}
return interceptor(ctx, in, info, handler)
}
func _RecordValidationService_ValidateRecord_Handler(srv interface{}, stream grpc.ServerStream) error {
m := new(RecordValidationReq)
if err := stream.RecvMsg(m); err != nil {
return err
}
return srv.(RecordValidationServiceServer).ValidateRecord(m, &grpc.GenericServerStream[RecordValidationReq, RecordValidationStreamRes]{ServerStream: stream})
}
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type RecordValidationService_ValidateRecordServer = grpc.ServerStreamingServer[RecordValidationStreamRes]
// RecordValidationService_ServiceDesc is the grpc.ServiceDesc for RecordValidationService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var RecordValidationService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "record.RecordValidationService",
HandlerType: (*RecordValidationServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "ListRecords",
Handler: _RecordValidationService_ListRecords_Handler,
},
},
Streams: []grpc.StreamDesc{
{
StreamName: "ValidateRecord",
Handler: _RecordValidationService_ValidateRecord_Handler,
ServerStreams: true,
},
},
Metadata: "record.proto",
}

67
api/grpc/record.proto Normal file
View File

@@ -0,0 +1,67 @@
syntax = "proto3";
package record;
option go_package = "go.yandata.net/iod/iod/trustlog-sdk/api/grpc/pb;pb";
import "google/protobuf/timestamp.proto";
import "common.proto";
// ======================== 公共数据结构 ========================
message RecordData {
// 记录核心信息
string id = 1; // 记录唯一标识符(必填)
string do_prefix = 2; // 数据前缀标识符
string producer_id = 3; // 生产者ID
google.protobuf.Timestamp timestamp = 4;// 记录时间戳
string operator = 5; // 操作执行者标识
bytes extra = 6; // 额外数据字段
string rc_type = 7; // 记录类型
}
// ======================== 列表查询请求 & 返回 ========================
message ListRecordReq {
// 分页条件
uint64 page_size = 1; // 页面大小
google.protobuf.Timestamp pre_time = 2; // 上一页最后一个时间
// 可选过滤条件
string do_prefix = 3; // 数据前缀过滤
string rc_type = 4; // 记录类型过滤
}
message ListRecordRes {
int64 count = 1; // 数据总量
repeated RecordData data = 2; // 记录数据列表
}
// ======================== 记录验证请求 & 流式响应 ========================
message RecordValidationReq {
google.protobuf.Timestamp timestamp = 1;// 记录时间戳
string record_id = 2; // 要验证的记录ID
string do_prefix = 3; // 数据前缀(可选)
string rc_type = 4; // 记录类型
}
message RecordValidationStreamRes {
int32 code = 1; // 状态码100处理中200完成400客户端错误500服务器错误
string msg = 2; // 消息描述
string progress = 3; // 验证进度(如 "30%", "验证哈希完成"
// 验证结果详情(仅在完成时返回)
RecordData result = 4;
common.Proof proof = 5; // 取证证明(仅在完成时返回)
}
// ======================== gRPC 服务定义 ========================
service RecordValidationService {
// 分页查询记录列表
rpc ListRecords (ListRecordReq) returns (ListRecordRes);
// 单个记录验证,服务端流式返回验证进度与结果
rpc ValidateRecord (RecordValidationReq) returns (stream RecordValidationStreamRes);
}