diff --git a/app/actor/cosmos/grpc.go b/app/actor/cosmos/grpc.go index ed62f10..12f5035 100644 --- a/app/actor/cosmos/grpc.go +++ b/app/actor/cosmos/grpc.go @@ -3,7 +3,7 @@ package cosmos import ( "context" - "okp4/nemeton-leaderboard/app/messages" + "okp4/nemeton-leaderboard/app/message" "github.com/asynkron/protoactor-go/actor" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" @@ -34,7 +34,7 @@ func (client *GrpcClient) Receive(ctx actor.Context) { if err := client.grpcConn.Close(); err != nil { log.Warn().Err(err).Msg("😥 Could not close grpc connection.") } - case *messages.GetBlock: + case *message.GetBlock: goCTX, cancelFunc := context.WithCancel(context.Background()) defer cancelFunc() @@ -42,11 +42,11 @@ func (client *GrpcClient) Receive(ctx actor.Context) { if err != nil { panic(err) } - ctx.Respond(&messages.GetBlockResponse{ + ctx.Respond(&message.GetBlockResponse{ Block: block, }) - case *messages.GetLatestBlock: + case *message.GetLatestBlock: goCTX, cancelFunc := context.WithCancel(context.Background()) defer cancelFunc() @@ -54,7 +54,7 @@ func (client *GrpcClient) Receive(ctx actor.Context) { if err != nil { panic(err) } - ctx.Respond(&messages.GetBlockResponse{ + ctx.Respond(&message.GetBlockResponse{ Block: block, }) } diff --git a/app/actor/synchronization/actor.go b/app/actor/synchronization/actor.go index 7e46df9..623c99f 100644 --- a/app/actor/synchronization/actor.go +++ b/app/actor/synchronization/actor.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "okp4/nemeton-leaderboard/app/messages" + "okp4/nemeton-leaderboard/app/message" "github.com/asynkron/protoactor-go/actor" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" @@ -60,14 +60,14 @@ func (a *Actor) startSynchronization(ctx actor.Context) { func (a *Actor) catchUpSyncBlocks(ctx actor.Context) error { // Check first the latest latestBlock height before sync - result, err := ctx.RequestFuture(a.grpcClient, &messages.GetLatestBlock{}, 5*time.Second).Result() + result, err := ctx.RequestFuture(a.grpcClient, &message.GetLatestBlock{}, 5*time.Second).Result() if err != nil { return err } var latestBlock *tmservice.Block switch resp := result.(type) { - case *messages.GetBlockResponse: + case *message.GetBlockResponse: latestBlock = resp.Block default: return fmt.Errorf("wrong response message") @@ -97,7 +97,7 @@ func (a *Actor) catchUpSyncBlocks(ctx actor.Context) error { } func (a *Actor) getBlock(ctx actor.Context, height int64) (*tmservice.Block, error) { - result, err := ctx.RequestFuture(a.grpcClient, &messages.GetBlock{Height: height}, 5*time.Second).Result() + result, err := ctx.RequestFuture(a.grpcClient, &message.GetBlock{Height: height}, 5*time.Second).Result() if err != nil { log.Err(err).Msg("⚠️ Failed request current block.") return nil, err @@ -105,7 +105,7 @@ func (a *Actor) getBlock(ctx actor.Context, height int64) (*tmservice.Block, err var block *tmservice.Block switch resp := result.(type) { - case *messages.GetBlockResponse: + case *message.GetBlockResponse: block = resp.Block default: return nil, fmt.Errorf("wrong response message") diff --git a/app/message/message.go b/app/message/message.go index fc1eb2b..d0effbd 100644 --- a/app/message/message.go +++ b/app/message/message.go @@ -4,6 +4,7 @@ import ( "okp4/nemeton-leaderboard/app/event" "github.com/asynkron/protoactor-go/actor" + "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" "go.mongodb.org/mongo-driver/bson/primitive" ) @@ -21,3 +22,16 @@ type NewEventMessage struct { } type BrokenStreamMessage struct{} + +// GetBlock Ask to requets a block at a given height +type GetBlock struct { + // Height of the block to get + Height int64 +} + +// GetLatestBlock Request the latest block of the chain. +type GetLatestBlock struct{} + +type GetBlockResponse struct { + Block *tmservice.Block +} diff --git a/app/messages/msg.go b/app/messages/msg.go deleted file mode 100644 index 053cb7d..0000000 --- a/app/messages/msg.go +++ /dev/null @@ -1,15 +0,0 @@ -package messages - -import "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" - -type GetBlock struct { - // Height of the block to get - Height int64 -} - -// GetLatestBlock Request the latest block of the chain. -type GetLatestBlock struct{} - -type GetBlockResponse struct { - Block *tmservice.Block -}