Skip to content

Commit

Permalink
Merge pull request #1 from Switcheo/feat/oracle-reactor
Browse files Browse the repository at this point in the history
Feat/oracle reactor
  • Loading branch information
yan-soon authored Jun 11, 2024
2 parents e10b1f0 + d947aab commit 9387a39
Show file tree
Hide file tree
Showing 46 changed files with 5,159 additions and 472 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ GOOS ?= linux
GOARCH ?= amd64
GOARM ?=

DOCKER := $(shell which docker)

ifeq (linux/arm,$(findstring linux/arm,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=arm
Expand Down
12 changes: 12 additions & 0 deletions abci/client/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,15 @@ func (cli *grpcClient) VerifyVoteExtension(ctx context.Context, req *types.Reque
func (cli *grpcClient) FinalizeBlock(ctx context.Context, req *types.RequestFinalizeBlock) (*types.ResponseFinalizeBlock, error) {
return cli.client.FinalizeBlock(ctx, types.ToRequestFinalizeBlock(req).GetFinalizeBlock(), grpc.WaitForReady(true))
}

func (cli *grpcClient) CreateOracleResultTx(ctx context.Context, req *types.RequestCreateOracleResultTx) (*types.ResponseCreateOracleResultTx, error) {
return cli.client.CreateOracleResultTx(ctx, types.ToRequestCreateOracleResultTx(req).GetCreateOracleResultTx(), grpc.WaitForReady(true))
}

func (cli *grpcClient) FetchOracleVotes(ctx context.Context, req *types.RequestFetchOracleVotes) (*types.ResponseFetchOracleVotes, error) {
return cli.client.FetchOracleVotes(ctx, types.ToRequestFetchOracleVotes(req).GetFetchOracleVotes(), grpc.WaitForReady(true))
}

func (cli *grpcClient) ValidateOracleVotes(ctx context.Context, req *types.RequestValidateOracleVotes) (*types.ResponseValidateOracleVotes, error) {
return cli.client.ValidateOracleVotes(ctx, types.ToRequestValidateOracleVotes(req).GetValidateOracleVotes(), grpc.WaitForReady(true))
}
78 changes: 78 additions & 0 deletions abci/client/mocks/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions abci/client/socket_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,39 @@ func (cli *socketClient) FinalizeBlock(ctx context.Context, req *types.RequestFi
return reqRes.Response.GetFinalizeBlock(), cli.Error()
}

func (cli *socketClient) CreateOracleResultTx(ctx context.Context, req *types.RequestCreateOracleResultTx) (*types.ResponseCreateOracleResultTx, error) {
reqRes, err := cli.queueRequest(ctx, types.ToRequestCreateOracleResultTx(req))
if err != nil {
return nil, err
}
if err := cli.Flush(ctx); err != nil {
return nil, err
}
return reqRes.Response.GetCreateOracleResultTx(), cli.Error()
}

func (cli *socketClient) FetchOracleVotes(ctx context.Context, req *types.RequestFetchOracleVotes) (*types.ResponseFetchOracleVotes, error) {
reqRes, err := cli.queueRequest(ctx, types.ToRequestFetchOracleVotes(req))
if err != nil {
return nil, err
}
if err := cli.Flush(ctx); err != nil {
return nil, err
}
return reqRes.Response.GetFetchOracleVotes(), cli.Error()
}

func (cli *socketClient) ValidateOracleVotes(ctx context.Context, req *types.RequestValidateOracleVotes) (*types.ResponseValidateOracleVotes, error) {
reqRes, err := cli.queueRequest(ctx, types.ToRequestValidateOracleVotes(req))
if err != nil {
return nil, err
}
if err := cli.Flush(ctx); err != nil {
return nil, err
}
return reqRes.Response.GetValidateOracleVotes(), cli.Error()
}

func (cli *socketClient) queueRequest(ctx context.Context, req *types.Request) (*ReqRes, error) {
reqres := NewReqRes(req)

Expand Down Expand Up @@ -493,6 +526,12 @@ func resMatchesReq(req *types.Request, res *types.Response) (ok bool) {
_, ok = res.Value.(*types.Response_ProcessProposal)
case *types.Request_FinalizeBlock:
_, ok = res.Value.(*types.Response_FinalizeBlock)
case *types.Request_CreateOracleResultTx:
_, ok = res.Value.(*types.Response_CreateOracleResultTx)
case *types.Request_ValidateOracleVotes:
_, ok = res.Value.(*types.Response_ValidateOracleVotes)
case *types.Request_FetchOracleVotes:
_, ok = res.Value.(*types.Response_FetchOracleVotes)
}
return ok
}
Expand Down
21 changes: 20 additions & 1 deletion abci/types/application.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import "context"
import (
"context"
)

//go:generate ../../scripts/mockery_generate.sh Application

Expand Down Expand Up @@ -32,6 +34,11 @@ type Application interface {
OfferSnapshot(context.Context, *RequestOfferSnapshot) (*ResponseOfferSnapshot, error) // Offer a snapshot to the application
LoadSnapshotChunk(context.Context, *RequestLoadSnapshotChunk) (*ResponseLoadSnapshotChunk, error) // Load a snapshot chunk
ApplySnapshotChunk(context.Context, *RequestApplySnapshotChunk) (*ResponseApplySnapshotChunk, error) // Apply a shapshot chunk

// Hooks
CreateOracleResultTx(context.Context, *RequestCreateOracleResultTx) (*ResponseCreateOracleResultTx, error)
FetchOracleVotes(context.Context, *RequestFetchOracleVotes) (*ResponseFetchOracleVotes, error)
ValidateOracleVotes(context.Context, *RequestValidateOracleVotes) (*ResponseValidateOracleVotes, error)
}

//-------------------------------------------------------
Expand Down Expand Up @@ -117,3 +124,15 @@ func (BaseApplication) FinalizeBlock(_ context.Context, req *RequestFinalizeBloc
TxResults: txs,
}, nil
}

func (BaseApplication) CreateOracleResultTx(_ context.Context, req *RequestCreateOracleResultTx) (*ResponseCreateOracleResultTx, error) {
return &ResponseCreateOracleResultTx{}, nil
}

func (BaseApplication) FetchOracleVotes(_ context.Context, req *RequestFetchOracleVotes) (*ResponseFetchOracleVotes, error) {
return &ResponseFetchOracleVotes{}, nil
}

func (BaseApplication) ValidateOracleVotes(_ context.Context, req *RequestValidateOracleVotes) (*ResponseValidateOracleVotes, error) {
return &ResponseValidateOracleVotes{}, nil
}
24 changes: 24 additions & 0 deletions abci/types/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,24 @@ func ToRequestFinalizeBlock(req *RequestFinalizeBlock) *Request {
}
}

func ToRequestCreateOracleResultTx(req *RequestCreateOracleResultTx) *Request {
return &Request{
Value: &Request_CreateOracleResultTx{req},
}
}

func ToRequestFetchOracleVotes(req *RequestFetchOracleVotes) *Request {
return &Request{
Value: &Request_FetchOracleVotes{req},
}
}

func ToRequestValidateOracleVotes(req *RequestValidateOracleVotes) *Request {
return &Request{
Value: &Request_ValidateOracleVotes{req},
}
}

//----------------------------------------

func ToResponseException(errStr string) *Response {
Expand Down Expand Up @@ -227,3 +245,9 @@ func ToResponseFinalizeBlock(res *ResponseFinalizeBlock) *Response {
Value: &Response_FinalizeBlock{res},
}
}

func ToResponseCreateOracleResultTx(res *ResponseCreateOracleResultTx) *Response {
return &Response{
Value: &Response_CreateOracleResultTx{res},
}
}
78 changes: 78 additions & 0 deletions abci/types/mocks/application.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9387a39

Please sign in to comment.