clawchain/x/privacy/keeper/query_root_history.go
caelum0x ed1ed54ec3 feat(privacy): expand gRPC surface, batch transfers, view keys, state machine
Adds full QueryServer gRPC with gateway REST, batch private transfers,
view key registration, commitment index/merkle proof/root history queries,
MPC trusted setup ceremony code, state machine for shielded notes, and
comprehensive integration tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 22:13:53 +03:00

58 lines
1.2 KiB
Go

package keeper
import (
"context"
"clawchain/x/privacy/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
const defaultRootHistoryLimit uint64 = 50
func (q queryServer) RootHistory(ctx context.Context, req *types.QueryRootHistoryRequest) (*types.QueryRootHistoryResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
total, err := q.k.RootHistoryCount.Peek(ctx)
if err != nil {
return nil, status.Error(codes.Internal, "failed to query root history count")
}
offset := req.Offset
if offset > total {
offset = total
}
limit := req.Limit
if limit == 0 {
limit = defaultRootHistoryLimit
}
end := offset + limit
if end > total {
end = total
}
roots := make([]string, 0, end-offset)
for i := offset; i < end; i++ {
root, err := q.k.RootHistory.Get(ctx, i)
if err != nil {
return nil, status.Error(codes.Internal, "failed to read root history")
}
roots = append(roots, root)
}
nextOffset := uint64(0)
if end < total {
nextOffset = end
}
return &types.QueryRootHistoryResponse{
Roots: roots,
NextOffset: nextOffset,
Total: total,
}, nil
}