ListCheckpoints gRPC Method
参数
start_checkpoint
字符串
正在加载...
end_checkpoint
字符串
正在加载...
read_mask
对象
正在加载...
paths
array<string>
正在加载...
filter
对象
正在加载...
terms
数组
正在加载...
选项
对象
正在加载...
上限
整数
正在加载...
after
字符串
正在加载...
之前
字符串
正在加载...
ordering
字符串
正在加载...
退货
checkpoint
对象
正在加载...
sequenceNumber
字符串
正在加载...
摘要
字符串
正在加载...
summary
对象
正在加载...
watermark
对象
正在加载...
cursor
字符串
正在加载...
checkpoint
字符串
正在加载...
结束
对象
正在加载...
reason
字符串
正在加载...
请求
1grpcurl \2-import-path . \3-proto sui/rpc/v2/ledger_service.proto \4-H "x-token: YOUR_TOKEN_VALUE" \5-d '{6"start_checkpoint": "306133000",7"read_mask": {8"paths": [9"sequence_number",10"digest",11"summary"12]13},14"options": {15"limit": 316}17}' \18docs-demo.mainnet.quiknode.pro:9000 \19sui.rpc.v2.LedgerService/ListCheckpoints20
1grpcurl \2-import-path . \3-proto sui/rpc/v2/ledger_service.proto \4-H "x-token: YOUR_TOKEN_VALUE" \5-d '{6"start_checkpoint": "306133000",7"read_mask": {8"paths": [9"sequence_number",10"digest",11"summary"12]13},14"options": {15"limit": 316}17}' \18docs-demo.mainnet.quiknode.pro:9000 \19sui.rpc.v2.LedgerService/ListCheckpoints20
1包 main23import (4"上下文"5"crypto/tls"6"encoding/json"7"fmt"8"io"9“日志”10“时间”1112"google.golang.grpc"13"google.golang.grpc"14"google.golang.org/protobuf/encoding/protojson"15"google.golang.org/protobuf/types/known/fieldmaskpb"1617pb "sui" // 您生成的 .pb.go 文件路径18)1920// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token21// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678922// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}23// token will be : abcde1234567892425var (26token = "您的令牌编号"27endpoint = "您的QN端点:9000"28)2930// Auth structure for x-token31类型 auth 结构体 {32token 字符串33}3435func (a *auth) GetRequestMetadata(ctx 上下文.Context, uri ...字符串) (map[字符串]字符串, error) {36return map[string]string{"x-token": a.token}, nil37}38func (a *auth) RequireTransportSecurity() bool {39返回 true40}4142func main() {43creds := credentials.NewTLS(&tls.Config{})44opts := []grpc.DialOption{45grpc.WithTransportCredentials(creds),46grpc.WithPerRPCCredentials(&auth{令牌}),47}4849conn, err := grpc.Dial(endpoint, opts...)50如果 err != nil {51log.Fatalf("连接失败:%v", err)52}53推迟 conn.关闭()5455client := pb.NewLedgerServiceClient(conn)5657startCheckpoint := uint64(306133000)58limit := uint32(3)5960req := &pb.ListCheckpointsRequest{61StartCheckpoint: &startCheckpoint,62ReadMask: &fieldmaskpb.FieldMask{63Paths: []string{"sequence_number", "digest", "summary"},64},65Options: &pb.QueryOptions{66Limit: &limit,67},68}6970// ListCheckpoints is bounded by start/end checkpoint and options.limit, so the71// stream terminates on its own once the QueryEnd frame is sent.72ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)73推迟 取消()7475stream, err := client.ListCheckpoints(ctx, req)76如果 err != nil {77log.Fatalf("ListCheckpoints failed: %v", err)78}7980marshaler := protojson.MarshalOptions{81UseProtoNames: true,82EmitUnpopulated: true,83缩进: " ",84}8586fmt.Println("Streaming checkpoints...")8788for {89resp, err := stream.Recv()90if err == io.EOF {91fmt.Println("Stream ended")92换行93}94如果 err != nil {95log.Fatalf("Stream error: %v", err)96}9798jsonBytes, err := marshaler.Marshal(resp)99如果 err != nil {100log.Printf("Failed to marshal: %v", err)101继续102}103104var pretty map[string]interface{}105if err := json.Unmarshal(jsonBytes, &pretty); err != nil {106log.Printf("Failed to parse JSON: %v", err)107继续108}109110out, _ := json.MarshalIndent(pretty, "", " ")111fmt.Printf("Received frame:\n%s\n", string(out))112113if resp.GetEnd() != nil {114fmt.Printf("Query ended: %s\n", resp.GetEnd().GetReason())115}116}117}118
1包 main23import (4"上下文"5"crypto/tls"6"encoding/json"7"fmt"8"io"9“日志”10“时间”1112"google.golang.grpc"13"google.golang.grpc"14"google.golang.org/protobuf/encoding/protojson"15"google.golang.org/protobuf/types/known/fieldmaskpb"1617pb "sui" // 您生成的 .pb.go 文件路径18)1920// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token21// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678922// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}23// token will be : abcde1234567892425var (26token = "您的令牌编号"27endpoint = "您的QN端点:9000"28)2930// Auth structure for x-token31类型 auth 结构体 {32token 字符串33}3435func (a *auth) GetRequestMetadata(ctx 上下文.Context, uri ...字符串) (map[字符串]字符串, error) {36return map[string]string{"x-token": a.token}, nil37}38func (a *auth) RequireTransportSecurity() bool {39返回 true40}4142func main() {43creds := credentials.NewTLS(&tls.Config{})44opts := []grpc.DialOption{45grpc.WithTransportCredentials(creds),46grpc.WithPerRPCCredentials(&auth{令牌}),47}4849conn, err := grpc.Dial(endpoint, opts...)50如果 err != nil {51log.Fatalf("连接失败:%v", err)52}53推迟 conn.关闭()5455client := pb.NewLedgerServiceClient(conn)5657startCheckpoint := uint64(306133000)58limit := uint32(3)5960req := &pb.ListCheckpointsRequest{61StartCheckpoint: &startCheckpoint,62ReadMask: &fieldmaskpb.FieldMask{63Paths: []string{"sequence_number", "digest", "summary"},64},65Options: &pb.QueryOptions{66Limit: &limit,67},68}6970// ListCheckpoints is bounded by start/end checkpoint and options.limit, so the71// stream terminates on its own once the QueryEnd frame is sent.72ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)73推迟 取消()7475stream, err := client.ListCheckpoints(ctx, req)76如果 err != nil {77log.Fatalf("ListCheckpoints failed: %v", err)78}7980marshaler := protojson.MarshalOptions{81UseProtoNames: true,82EmitUnpopulated: true,83缩进: " ",84}8586fmt.Println("Streaming checkpoints...")8788for {89resp, err := stream.Recv()90if err == io.EOF {91fmt.Println("Stream ended")92换行93}94如果 err != nil {95log.Fatalf("Stream error: %v", err)96}9798jsonBytes, err := marshaler.Marshal(resp)99如果 err != nil {100log.Printf("Failed to marshal: %v", err)101继续102}103104var pretty map[string]interface{}105if err := json.Unmarshal(jsonBytes, &pretty); err != nil {106log.Printf("Failed to parse JSON: %v", err)107继续108}109110out, _ := json.MarshalIndent(pretty, "", " ")111fmt.Printf("Received frame:\n%s\n", string(out))112113if resp.GetEnd() != nil {114fmt.Printf("Query ended: %s\n", resp.GetEnd().GetReason())115}116}117}118
1import * 作为 grpc from grpc;2import * 作为 protoLoader from grpc;3import * 作为 路径 from '路径';45// Configuration6const PROTO_PATH = path.join(__dirname, 'protos/proto/sui/rpc/v2/ledger_service.proto');78// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token9// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678910// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}11// token will be : abcde1234567891213const endpoint = 'docs-demo.mainnet.quiknode.pro:9000';14const 令牌 = 'abcde123456789';1516// Load protobuf definitions17const 包定义 = protoLoader.loadSync(PROTO_PATH, {18keepCase: true,19多头: 字符串,20枚举: 字符串,21默认值: true,22oneofs: true,23includeDirs: [路径.join(__dirname, 'protos/proto')],24});2526const proto = grpc.loadPackageDefinition(packageDefinition) 作为 any;27const LedgerService = proto.sui.rpc.v2.LedgerService;2829// Create secure client30const client = new LedgerService(endpoint, grpc.credentials.createSsl());3132// Add token metadata33const 元数据 = new grpc.元数据();34元数据.添加('x-token', token);3536// Request payload37// ListCheckpoints is bounded by start/end_checkpoint and options.limit, so the38// stream ends on its own — no Ctrl+C handling needed.39const 请求 = {40start_checkpoint: '306133000',41read_mask: {42paths: ['sequence_number', 'digest', 'summary'],43},44options: {45limit: 3,46},47};4849const call = client.ListCheckpoints(request, metadata);5051console.log('Streaming checkpoints...');5253call.on('data', (response: any) => {54console.log('Received frame:', JSON.stringify(response, null, 2));55if (response.end) {56console.log('Query ended:', response.end.reason);57}58});5960call.on('error', (error: any) => {61console.error('Stream error:', error);62});6364call.on('end', () => {65console.log('Stream ended');66});67
1import * 作为 grpc from grpc;2import * 作为 protoLoader from grpc;3import * 作为 路径 from '路径';45// Configuration6const PROTO_PATH = path.join(__dirname, 'protos/proto/sui/rpc/v2/ledger_service.proto');78// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token9// For eg: QN Endpoint: https://docs-demo.sui-mainnet.quiknode.pro/abcde12345678910// endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}11// token will be : abcde1234567891213const endpoint = 'docs-demo.mainnet.quiknode.pro:9000';14const 令牌 = 'abcde123456789';1516// Load protobuf definitions17const 包定义 = protoLoader.loadSync(PROTO_PATH, {18keepCase: true,19多头: 字符串,20枚举: 字符串,21默认值: true,22oneofs: true,23includeDirs: [路径.join(__dirname, 'protos/proto')],24});2526const proto = grpc.loadPackageDefinition(packageDefinition) 作为 any;27const LedgerService = proto.sui.rpc.v2.LedgerService;2829// Create secure client30const client = new LedgerService(endpoint, grpc.credentials.createSsl());3132// Add token metadata33const 元数据 = new grpc.元数据();34元数据.添加('x-token', token);3536// Request payload37// ListCheckpoints is bounded by start/end_checkpoint and options.limit, so the38// stream ends on its own — no Ctrl+C handling needed.39const 请求 = {40start_checkpoint: '306133000',41read_mask: {42paths: ['sequence_number', 'digest', 'summary'],43},44options: {45limit: 3,46},47};4849const call = client.ListCheckpoints(request, metadata);5051console.log('Streaming checkpoints...');5253call.on('data', (response: any) => {54console.log('Received frame:', JSON.stringify(response, null, 2));55if (response.end) {56console.log('Query ended:', response.end.reason);57}58});5960call.on('error', (error: any) => {61console.error('Stream error:', error);62});6364call.on('end', () => {65console.log('Stream ended');66});67
1import grpc2导入 json3来源 谷歌.protobuf.field_mask_pb2 导入 FieldMask4来源 谷歌.protobuf.json_format import MessageToDict5from sui.rpc.v2 import ledger_service_pb2, ledger_service_pb2_grpc, query_options_pb267def list_checkpoints():8#Quicknode 由两个关键组成部分构成:endpoint 和相应的令牌9# 例如:QNEndpoint:mainnet10# endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}11# token will be : abcde1234567891213endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000';14token = 'abcde123456789';1516频道 = grpc.secure_channel(endpoint, grpc.ssl_channel_credentials())17stub = ledger_service_pb2_grpc.LedgerServiceStub(channel)1819read_mask = FieldMask(paths=["sequence_number", "digest", "summary"])2021# ListCheckpoints is bounded by start/end_checkpoint and options.limit, so22# the stream ends on its own once the server sends the QueryEnd frame.23request = ledger_service_pb2.ListCheckpointsRequest(24start_checkpoint=306133000,25read_mask=read_mask,26options=query_options_pb2.QueryOptions(limit=3)27)2829元数据 = [("x-token", token)]3031return stub.ListCheckpoints(request, metadata=metadata)3233def parse_response_to_json(response):34返回 json.dumps(35MessageToDict(response, 保留_proto_字段_名称=True),36缩进=237)3839def main():40print("Streaming checkpoints...")4142试一试:43response_stream = list_checkpoints()4445for response in response_stream:46print("Received frame:")47print(parse_response_to_json(response))48if response.HasField("end"):49reason = query_options_pb2.QueryEndReason.Name(response.end.reason)50print(f"Query ended: {reason}")5152print("Stream ended")5354除了 grpc。RpcError 作为 e:55print(f"{e.code().name}: {e.details()}")5657如果 __name__ == "__main__":58主()59
1import grpc2导入 json3来源 谷歌.protobuf.field_mask_pb2 导入 FieldMask4来源 谷歌.protobuf.json_format import MessageToDict5from sui.rpc.v2 import ledger_service_pb2, ledger_service_pb2_grpc, query_options_pb267def list_checkpoints():8#Quicknode 由两个关键组成部分构成:endpoint 和相应的令牌9# 例如:QNEndpoint:mainnet10# endpoint will be: docs-demo.sui-mainnet.quiknode.pro:9000 {9000 is the port number for Sui gRPC}11# token will be : abcde1234567891213endpoint = 'docs-demo.sui-mainnet.quiknode.pro:9000';14token = 'abcde123456789';1516频道 = grpc.secure_channel(endpoint, grpc.ssl_channel_credentials())17stub = ledger_service_pb2_grpc.LedgerServiceStub(channel)1819read_mask = FieldMask(paths=["sequence_number", "digest", "summary"])2021# ListCheckpoints is bounded by start/end_checkpoint and options.limit, so22# the stream ends on its own once the server sends the QueryEnd frame.23request = ledger_service_pb2.ListCheckpointsRequest(24start_checkpoint=306133000,25read_mask=read_mask,26options=query_options_pb2.QueryOptions(limit=3)27)2829元数据 = [("x-token", token)]3031return stub.ListCheckpoints(request, metadata=metadata)3233def parse_response_to_json(response):34返回 json.dumps(35MessageToDict(response, 保留_proto_字段_名称=True),36缩进=237)3839def main():40print("Streaming checkpoints...")4142试一试:43response_stream = list_checkpoints()4445for response in response_stream:46print("Received frame:")47print(parse_response_to_json(response))48if response.HasField("end"):49reason = query_options_pb2.QueryEndReason.Name(response.end.reason)50print(f"Query ended: {reason}")5152print("Stream ended")5354除了 grpc。RpcError 作为 e:55print(f"{e.code().name}: {e.details()}")5657如果 __name__ == "__main__":58主()59