/
server.go
122 lines (100 loc) · 5.53 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main
import (
"context"
"github.com/cosmos/ibc-go/modules/core/exported"
pb "github.com/datachainlab/fabric-ibc-lightclientd/types"
"github.com/golang/protobuf/ptypes/empty"
"google.golang.org/protobuf/types/known/emptypb"
)
type server struct{}
var _ pb.LightClientServer = (*server)(nil)
func (server) ClientType(_ context.Context, req *pb.ClientTypeRequest) (*pb.ClientTypeResponse, error) {
lc := NewLightclient(req.State)
return &pb.ClientTypeResponse{ClientType: lc.ClientType()}, nil
}
func (server) GetLatestHeight(_ context.Context, req *pb.GetLatestHeightRequest) (*pb.GetLatestHeightResponse, error) {
lc := NewLightclient(req.State)
height := lc.GetLatestHeight()
return &pb.GetLatestHeightResponse{Height: &height}, nil
}
func (server) Validate(_ context.Context, req *pb.ValidateRequest) (*emptypb.Empty, error) {
lc := NewLightclient(req.State)
return &empty.Empty{}, lc.Validate()
}
func (server) GetProofSpecs(_ context.Context, req *pb.GetProofSpecsRequest) (*pb.GetProofSpecsResponse, error) {
lc := NewLightclient(req.State)
return &pb.GetProofSpecsResponse{ProofSpecs: lc.GetProofSpecs()}, nil
}
func (server) Initialize(_ context.Context, req *pb.InitializeRequest) (*pb.InitializeResponse, error) {
lc := NewLightclient(req.State)
if err := lc.Initialize(req.ConsensusState); err != nil {
return nil, err
}
return &pb.InitializeResponse{State: lc.State()}, nil
}
func (server) Status(_ context.Context, req *pb.StatusRequest) (*pb.StatusResponse, error) {
lc := NewLightclient(req.State)
return &pb.StatusResponse{Status: lc.Status().String()}, nil
}
func (server) ExportMetadata(_ context.Context, req *pb.ExportMetadataRequest) (*pb.ExportMetadataResponse, error) {
lc := NewLightclient(req.State)
return &pb.ExportMetadataResponse{GenesisMetadatas: lc.ExportMetadata()}, nil
}
func (server) CheckHeaderAndUpdateState(_ context.Context, req *pb.CheckHeaderAndUpdateStateRequest) (*pb.CheckHeaderAndUpdateStateResponse, error) {
lc := NewLightclient(req.State)
if err := lc.CheckHeaderAndUpdateState(req.Header); err != nil {
return nil, err
}
return &pb.CheckHeaderAndUpdateStateResponse{State: lc.State()}, nil
}
func (server) VerifyUpgradeAndUpdateState(_ context.Context, req *pb.VerifyUpgradeAndUpdateStateRequest) (*pb.VerifyUpgradeAndUpdateStateResponse, error) {
lc := NewLightclient(req.State)
if err := lc.VerifyUpgradeAndUpdateState(req.NewClient, req.NewConsState, req.ProofUpgradeClient, req.ProofUpgradeConsState); err != nil {
return nil, err
}
return &pb.VerifyUpgradeAndUpdateStateResponse{State: lc.State()}, nil
}
func (server) ZeroCustomFields(_ context.Context, req *pb.ZeroCustomFieldsRequest) (*pb.ZeroCustomFieldsResponse, error) {
lc := NewLightclient(req.State)
return &pb.ZeroCustomFieldsResponse{ClientState: lc.ZeroCustomFields()}, nil
}
func (server) VerifyClientState(_ context.Context, req *pb.VerifyClientStateRequest) (*emptypb.Empty, error) {
lc := NewLightclient(req.State)
var clientState exported.ClientState
if err := lc.cdc.UnpackAny(req.ClientState, &clientState); err != nil {
return nil, err
}
return &empty.Empty{}, lc.VerifyClientState(*req.Height, req.Prefix, req.CounterpartyClientIdentifier, req.Proof, clientState)
}
func (server) VerifyClientConsensusState(_ context.Context, req *pb.VerifyClientConsensusStateRequest) (*emptypb.Empty, error) {
lc := NewLightclient(req.State)
var consensusState exported.ConsensusState
if err := lc.cdc.UnpackAny(req.ConsensusState, &consensusState); err != nil {
return nil, err
}
return &empty.Empty{}, lc.VerifyClientConsensusState(*req.Height, req.CounterpartyClientIdentifier, *req.ConsensusHeight, req.Prefix, req.Proof, consensusState)
}
func (server) VerifyConnectionState(_ context.Context, req *pb.VerifyConnectionStateRequest) (*emptypb.Empty, error) {
lc := NewLightclient(req.State)
return &emptypb.Empty{}, lc.VerifyConnectionState(*req.Height, req.Prefix, req.Proof, req.ConnectionId, *req.ConnectionEnd)
}
func (server) VerifyChannelState(_ context.Context, req *pb.VerifyChannelStateRequest) (*emptypb.Empty, error) {
lc := NewLightclient(req.State)
return &empty.Empty{}, lc.VerifyChannelState(*req.Height, req.Prefix, req.Proof, req.PortId, req.ChannelId, *req.Channel)
}
func (server) VerifyPacketCommitment(_ context.Context, req *pb.VerifyPacketCommitmentRequest) (*emptypb.Empty, error) {
lc := NewLightclient(req.State)
return &empty.Empty{}, lc.VerifyPacketCommitment(*req.Height, req.DelayTimePeriod, req.DelayBlockPeriod, req.Prefix, req.Proof, req.PortId, req.ChannelId, req.Sequence, req.CommitmentBytes)
}
func (server) VerifyPacketAcknowledgement(_ context.Context, req *pb.VerifyPacketAcknowledgementRequest) (*emptypb.Empty, error) {
lc := NewLightclient(req.State)
return &empty.Empty{}, lc.VerifyPacketAcknowledgement(*req.Height, req.DelayTimePeriod, req.DelayBlockPeriod, req.Prefix, req.Proof, req.PortId, req.ChannelId, req.Sequence, req.Acknowledgement)
}
func (server) VerifyPacketReceiptAbsence(_ context.Context, req *pb.VerifyPacketReceiptAbsenceRequest) (*emptypb.Empty, error) {
lc := NewLightclient(req.State)
return &empty.Empty{}, lc.VerifyPacketReceiptAbsence(*req.Height, req.DelayTimePeriod, req.DelayBlockPeriod, req.Prefix, req.Proof, req.PortId, req.ChannelId, req.Sequence)
}
func (server) VerifyNextSequenceRecv(_ context.Context, req *pb.VerifyNextSequenceRecvRequest) (*emptypb.Empty, error) {
lc := NewLightclient(req.State)
return &empty.Empty{}, lc.VerifyNextSequenceRecv(*req.Height, req.DelayTimePeriod, req.DelayBlockPeriod, req.Prefix, req.Proof, req.PortId, req.ChannelId, req.NextSequenceRecv)
}