Skip to content

Commit

Permalink
add response types, pin protocol-apis version
Browse files Browse the repository at this point in the history
remove comments
  • Loading branch information
seanmcgary committed Jan 10, 2025
1 parent f63e68f commit 27f9c1b
Show file tree
Hide file tree
Showing 12 changed files with 313 additions and 32 deletions.
35 changes: 29 additions & 6 deletions examples/eventSubscriber/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,53 @@ func NewSidecarClient(url string, insecureConn bool) (v1.EventsClient, error) {
return v1.NewEventsClient(grpcClient), nil
}

func main() {
client, err := NewSidecarClient("localhost:7100", true)
func streamIndexedBlocks(client v1.EventsClient) {
stream, err := client.StreamIndexedBlocks(context.Background(), &v1.StreamIndexedBlocksRequest{})
if err != nil {
panic(err)
}

stream, err := client.StreamIndexedBlocks(context.Background(), &v1.StreamIndexedBlocksRequest{})
for {
resp := &v1.StreamIndexedBlocksResponse{}
err := stream.RecvMsg(resp)
if err == io.EOF {
fmt.Printf("Server has finished sending\n")
return
}
if err != nil {
log.Fatalf("failed to receive: %v", err)
}

fmt.Printf("Received: %v\n", resp)
}
}

func streamStateChanges(client v1.EventsClient) {
stream, err := client.StreamEigenStateChanges(context.Background(), &v1.StreamEigenStateChangesRequest{})
if err != nil {
panic(err)
}

for {
resp := &v1.StreamIndexedBlocksResponse{}
resp := &v1.StreamEigenStateChangesResponse{}
err := stream.RecvMsg(resp)
if err == io.EOF {
// Server has finished sending
fmt.Printf("Server has finished sending\n")
return
}
if err != nil {
log.Fatalf("failed to receive: %v", err)
}

// Process your response
fmt.Printf("Received: %v\n", resp)
}
}

func main() {
client, err := NewSidecarClient("localhost:7100", true)
if err != nil {
panic(err)
}

streamStateChanges(client)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/DataDog/datadog-go/v5 v5.5.0
github.com/Layr-Labs/eigenlayer-contracts v0.4.1-holesky-pepe.0.20240813143901-00fc4b95e9c1
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.13
github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20250109222723-376a40434d4e
github.com/Layr-Labs/protocol-apis v1.1.0
github.com/ethereum/go-ethereum v1.14.9
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1
github.com/google/uuid v1.6.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.13 h1:Blb4AE+jC/vddV71w4/MQA
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.13/go.mod h1:PD/HoyzZjxDw1tAcZw3yD0yGddo+yhmwQAi+lk298r4=
github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20250109222723-376a40434d4e h1:IArMOWI0V+2KFexZbJwZvIxVFTJdaDZG8PMcih/GV4A=
github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20250109222723-376a40434d4e/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk=
github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20250109230911-e6fec5ffbd4c h1:uKOEYFWJ6OcCGTMZK8M4rZJHIxdWMuTI7j+LvNe8D84=
github.com/Layr-Labs/protocol-apis v1.0.0-rc.1.0.20250109230911-e6fec5ffbd4c/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk=
github.com/Layr-Labs/protocol-apis v1.1.0 h1:PO6x+Y9ORiac2dkaWJayRFqhyzcvMbvRQkDIpLTNtVc=
github.com/Layr-Labs/protocol-apis v1.1.0/go.mod h1:prNA2/mLO5vpMZ2q78Nsn0m97wm28uiRnwO+/yOxigk=
github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
Expand Down
4 changes: 3 additions & 1 deletion pkg/eigenState/avsOperators/avsOperators.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ func NewAvsOperatorsModel(
return s, nil
}

const AvsOperatorsModelName = "AvsOperatorsModel"

func (a *AvsOperatorsModel) GetModelName() string {
return "AvsOperatorsModel"
return AvsOperatorsModelName
}

// Get the state transitions for the AvsOperatorsModel state model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ func NewDisabledDistributionRootsModel(
return model, nil
}

const MODEL_NAME = "DisabledDistributionRootsModel"
const DisabledDistributionRootsModelName = "DisabledDistributionRootsModel"

func (ddr *DisabledDistributionRootsModel) GetModelName() string {
return MODEL_NAME
return DisabledDistributionRootsModelName
}

func (ddr *DisabledDistributionRootsModel) GetStateTransitions() (types.StateTransitions[*types.DisabledDistributionRoot], []uint64) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/eigenState/operatorShares/operatorShares.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ func NewOperatorSharesModel(
return model, nil
}

const OperatorSharesModelName = "OperatorSharesModel"

func (osm *OperatorSharesModel) GetModelName() string {
return "OperatorSharesModel"
return OperatorSharesModelName
}

type operatorSharesOutput struct {
Expand Down
4 changes: 3 additions & 1 deletion pkg/eigenState/rewardSubmissions/rewardSubmissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ func NewRewardSubmissionsModel(
return model, nil
}

const RewardSubmissionsModelName = "RewardSubmissionsModel"

func (rs *RewardSubmissionsModel) GetModelName() string {
return "RewardSubmissionsModel"
return RewardSubmissionsModelName
}

type genericRewardPaymentData struct {
Expand Down
4 changes: 3 additions & 1 deletion pkg/eigenState/stakerDelegations/stakerDelegations.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ func NewStakerDelegationsModel(
return model, nil
}

const StakerDelegationsModelName = "StakerDelegationsModel"

func (s *StakerDelegationsModel) GetModelName() string {
return "StakerDelegationsModel"
return StakerDelegationsModelName
}

func (s *StakerDelegationsModel) GetStateTransitions() (types.StateTransitions[*StakerDelegationChange], []uint64) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/eigenState/stakerShares/stakerShares.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ func NewStakerSharesModel(
return model, nil
}

const StakerSharesModelName = "StakerSharesModel"

func (ss *StakerSharesModel) GetModelName() string {
return "StakerShares"
return StakerSharesModelName
}

type depositOutputData struct {
Expand Down
8 changes: 8 additions & 0 deletions pkg/eigenState/stateManager/stateManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ func (e *EigenStateManager) encodeModelLeaf(model types.IEigenStateModel, blockN
return append(types.MerkleLeafPrefix_EigenStateRoot, append([]byte(model.GetModelName()), root...)...), nil
}

func (e *EigenStateManager) GetModelsMappedByName() map[string]types.IEigenStateModel {
models := make(map[string]types.IEigenStateModel)
for _, index := range e.GetSortedModelIndexes() {
models[e.StateModels[index].GetModelName()] = e.StateModels[index]
}
return models
}

func (e *EigenStateManager) GetSortedModelIndexes() []int {
indexes := make([]int, 0, len(e.StateModels))
for i := range e.StateModels {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ func NewSubmittedDistributionRootsModel(
return model, nil
}

const MODEL_NAME = "SubmittedDistributionRootsModel"
const SubmittedDistributionRootsModelName = "SubmittedDistributionRootsModel"

func (sdr *SubmittedDistributionRootsModel) GetModelName() string {
return MODEL_NAME
return SubmittedDistributionRootsModelName
}

type distributionRootSubmittedOutput struct {
Expand Down
Loading

0 comments on commit 27f9c1b

Please sign in to comment.