88 "strings"
99 "time"
1010
11+ "github.com/MinterTeam/minter-go-node/coreV2/events"
1112 "github.com/MinterTeam/minter-go-node/coreV2/state/coins"
1213 "github.com/MinterTeam/minter-go-node/coreV2/types"
1314 pb "github.com/MinterTeam/node-grpc-gateway/api_pb"
@@ -17,6 +18,8 @@ import (
1718 tmTypes "github.com/tendermint/tendermint/types"
1819 "google.golang.org/grpc/codes"
1920 "google.golang.org/grpc/status"
21+ "google.golang.org/protobuf/proto"
22+ "google.golang.org/protobuf/types/known/anypb"
2023)
2124
2225// Block returns block data at given height.
@@ -42,7 +45,7 @@ func (s *Service) Block(ctx context.Context, req *pb.BlockRequest) (*pb.BlockRes
4245 if _ , ok := fields [pb .BlockField_transactions ]; ok {
4346 blockResults , err = s .client .BlockResults (ctx , & height )
4447 if err != nil {
45- return nil , status .Error (codes .NotFound , "Block results not found" )
48+ return nil , status .Error (codes .NotFound , "Block results not found" ) // fmt.Sprintf("Block results not found: %v", err))
4649 }
4750 }
4851
@@ -73,6 +76,121 @@ func (s *Service) Block(ctx context.Context, req *pb.BlockRequest) (*pb.BlockRes
7376 TransactionCount : uint64 (len (block .Block .Txs )),
7477 }
7578
79+ if req .Events {
80+ loadEvents := s .blockchain .GetEventsDB ().LoadEvents (uint32 (req .Height ))
81+ for _ , event := range loadEvents {
82+ var m proto.Message
83+ switch e := event .(type ) {
84+ case * events.JailEvent :
85+ m = & pb.JailEvent {
86+ ValidatorPubKey : e .ValidatorPubKeyString (),
87+ JailedUntil : e .JailedUntil ,
88+ }
89+ case * events.OrderExpiredEvent :
90+ m = & pb.OrderExpiredEvent {
91+ Id : e .ID ,
92+ Address : e .AddressString (),
93+ Coin : e .Coin ,
94+ Amount : e .Amount ,
95+ }
96+ case * events.RewardEvent :
97+ m = & pb.RewardEvent {
98+ Role : pb .RewardEvent_Role (pb .RewardEvent_Role_value [e .Role ]),
99+ Address : e .AddressString (),
100+ Amount : e .Amount ,
101+ ForCoin : e .ForCoin ,
102+ ValidatorPubKey : e .ValidatorPubKeyString (),
103+ }
104+ case * events.SlashEvent :
105+ m = & pb.SlashEvent {
106+ Address : e .AddressString (),
107+ Amount : e .Amount ,
108+ Coin : e .Coin ,
109+ ValidatorPubKey : e .ValidatorPubKeyString (),
110+ }
111+ case * events.StakeKickEvent :
112+ m = & pb.StakeKickEvent {
113+ Address : e .AddressString (),
114+ Amount : e .Amount ,
115+ Coin : e .Coin ,
116+ ValidatorPubKey : e .ValidatorPubKeyString (),
117+ }
118+ case * events.UnbondEvent :
119+ m = & pb.UnbondEvent {
120+ Address : e .AddressString (),
121+ Amount : e .Amount ,
122+ Coin : e .Coin ,
123+ ValidatorPubKey : e .ValidatorPubKeyString (),
124+ }
125+ case * events.RemoveCandidateEvent :
126+ m = & pb.RemoveCandidateEvent {
127+ CandidatePubKey : e .CandidatePubKeyString (),
128+ }
129+ case * events.UpdateNetworkEvent :
130+ m = & pb.UpdateNetworkEvent {
131+ Version : e .Version ,
132+ }
133+ case * events.UpdateCommissionsEvent :
134+ m = & pb.UpdateCommissionsEvent {
135+ Coin : e .Coin ,
136+ PayloadByte : e .PayloadByte ,
137+ Send : e .Send ,
138+ BuyBancor : e .BuyBancor ,
139+ SellBancor : e .SellBancor ,
140+ SellAllBancor : e .SellAllBancor ,
141+ BuyPoolBase : e .BuyPoolBase ,
142+ BuyPoolDelta : e .BuyPoolDelta ,
143+ SellPoolBase : e .SellPoolBase ,
144+ SellPoolDelta : e .SellPoolDelta ,
145+ SellAllPoolBase : e .SellAllPoolBase ,
146+ SellAllPoolDelta : e .SellAllPoolDelta ,
147+ CreateTicker3 : e .CreateTicker3 ,
148+ CreateTicker4 : e .CreateTicker4 ,
149+ CreateTicker5 : e .CreateTicker5 ,
150+ CreateTicker6 : e .CreateTicker6 ,
151+ CreateTicker7_10 : e .CreateTicker7_10 ,
152+ CreateCoin : e .CreateCoin ,
153+ CreateToken : e .CreateToken ,
154+ RecreateCoin : e .RecreateCoin ,
155+ RecreateToken : e .RecreateToken ,
156+ DeclareCandidacy : e .DeclareCandidacy ,
157+ Delegate : e .Delegate ,
158+ Unbond : e .Unbond ,
159+ RedeemCheck : e .RedeemCheck ,
160+ SetCandidateOn : e .SetCandidateOn ,
161+ SetCandidateOff : e .SetCandidateOff ,
162+ CreateMultisig : e .CreateMultisig ,
163+ MultisendBase : e .MultisendBase ,
164+ MultisendDelta : e .MultisendDelta ,
165+ EditCandidate : e .EditCandidate ,
166+ SetHaltBlock : e .SetHaltBlock ,
167+ EditTickerOwner : e .EditTickerOwner ,
168+ EditMultisig : e .EditMultisig ,
169+ EditCandidatePublicKey : e .EditCandidatePublicKey ,
170+ CreateSwapPool : e .CreateSwapPool ,
171+ AddLiquidity : e .AddLiquidity ,
172+ RemoveLiquidity : e .RemoveLiquidity ,
173+ EditCandidateCommission : e .EditCandidateCommission ,
174+ MintToken : e .MintToken ,
175+ BurnToken : e .BurnToken ,
176+ VoteCommission : e .VoteCommission ,
177+ VoteUpdate : e .VoteUpdate ,
178+ FailedTx : e .FailedTx ,
179+ AddLimitOrder : e .AddLimitOrder ,
180+ RemoveLimitOrder : e .RemoveLimitOrder ,
181+ }
182+ default :
183+ return nil , status .Error (codes .Internal , "unknown event type" )
184+ }
185+
186+ a , err := anypb .New (m )
187+ if err != nil {
188+ return nil , status .Error (codes .Internal , err .Error ())
189+ }
190+ response .Events = append (response .Events , a )
191+ }
192+ }
193+
76194 for field := range fields {
77195 if timeoutStatus := s .checkTimeout (ctx ); timeoutStatus != nil {
78196 return nil , timeoutStatus .Err ()
0 commit comments