Skip to content

Commit

Permalink
change to string as gql query is a string and avoid unncesseary conve…
Browse files Browse the repository at this point in the history
…rsion
  • Loading branch information
Siddharth More authored and Siddharth More committed Apr 23, 2024
1 parent 5e5a18e commit 9692cb5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
8 changes: 5 additions & 3 deletions disperser/dataapi/subgraph/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type (
QueryBatchNonSigningInfo(ctx context.Context, startTime, endTime int64) ([]*BatchNonSigningInfo, error)
QueryDeregisteredOperatorsGreaterThanBlockTimestamp(ctx context.Context, blockTimestamp uint64) ([]*Operator, error)
QueryRegisteredOperatorsGreaterThanBlockTimestamp(ctx context.Context, blockTimestamp uint64) ([]*Operator, error)
QueryOperatorInfoByOperatorIdAtBlockNumber(ctx context.Context, operatorId []byte, blockNumber uint32) (*IndexedOperatorInfo, error)
QueryOperatorInfoByOperatorIdAtBlockNumber(ctx context.Context, operatorId string, blockNumber uint32) (*IndexedOperatorInfo, error)
QueryOperatorAddedToQuorum(ctx context.Context, startBlock, endBlock uint32) ([]*OperatorQuorum, error)
QueryOperatorRemovedFromQuorum(ctx context.Context, startBlock, endBlock uint32) ([]*OperatorQuorum, error)
}
Expand Down Expand Up @@ -194,11 +194,13 @@ func (a *api) QueryDeregisteredOperatorsGreaterThanBlockTimestamp(ctx context.Co
return query.OperatorDeregistereds, nil
}

func (a *api) QueryOperatorInfoByOperatorIdAtBlockNumber(ctx context.Context, operatorId []byte, blockNumber uint32) (*IndexedOperatorInfo, error) {
func (a *api) QueryOperatorInfoByOperatorIdAtBlockNumber(ctx context.Context, operatorId string, blockNumber uint32) (*IndexedOperatorInfo, error) {
fmt.Printf("==QueryOperatorInfoByOperatorIdAtBlockNumber ==== operatorId: %v\n", operatorId)

var (
query queryOperatorById
variables = map[string]any{
"id": graphql.String(fmt.Sprintf("0x%s", string(operatorId[:]))),
"id": graphql.String(fmt.Sprintf("0x%s", operatorId)),
}
)
err := a.operatorStateGql.Query(context.Background(), &query, variables)
Expand Down
2 changes: 1 addition & 1 deletion disperser/dataapi/subgraph/mock/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (m *MockSubgraphApi) QueryDeregisteredOperatorsGreaterThanBlockTimestamp(ct
return value, args.Error(1)
}

func (m *MockSubgraphApi) QueryOperatorInfoByOperatorIdAtBlockNumber(ctx context.Context, operatorId []byte, blockNumber uint32) (*subgraph.IndexedOperatorInfo, error) {
func (m *MockSubgraphApi) QueryOperatorInfoByOperatorIdAtBlockNumber(ctx context.Context, operatorId string, blockNumber uint32) (*subgraph.IndexedOperatorInfo, error) {
args := m.Called()

var value *subgraph.IndexedOperatorInfo
Expand Down
16 changes: 8 additions & 8 deletions disperser/dataapi/subgraph_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ type (
TxFee uint64
}
Operator struct {
Id []byte
OperatorId []byte
Operator []byte
Id string
OperatorId string
Operator string
BlockTimestamp uint64
BlockNumber uint64
TransactionHash []byte
TransactionHash string
}
OperatorQuorum struct {
Operator string
Expand Down Expand Up @@ -334,12 +334,12 @@ func convertOperator(operator *subgraph.Operator) (*Operator, error) {
}

return &Operator{
Id: []byte(operator.Id),
OperatorId: []byte(operator.OperatorId),
Operator: []byte(operator.Operator),
Id: string(operator.Id),
OperatorId: string(operator.OperatorId),
Operator: string(operator.Operator),
BlockTimestamp: timestamp,
BlockNumber: blockNum,
TransactionHash: []byte(operator.TransactionHash),
TransactionHash: string(operator.TransactionHash),
}, nil
}

Expand Down
20 changes: 10 additions & 10 deletions disperser/dataapi/subgraph_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,20 +440,20 @@ func TestQueryOperators(t *testing.T) {
assert.Equal(t, 2, len(operators))

assert.NotNil(t, operators[0])
assert.Equal(t, []byte("0x000763fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f211"), operators[0].Id)
assert.Equal(t, []byte("0x000563fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f211"), operators[0].Operator)
assert.Equal(t, []byte("0xe1cdae12a0074f20b8fc96a0489376db34075e545ef60c4845d264a732568311"), operators[0].OperatorId)
assert.Equal(t, "0x000763fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f211", operators[0].Id)
assert.Equal(t, "0x000563fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f211", operators[0].Operator)
assert.Equal(t, "0xe1cdae12a0074f20b8fc96a0489376db34075e545ef60c4845d264a732568311", operators[0].OperatorId)
assert.Equal(t, uint64(1696975449), operators[0].BlockTimestamp)
assert.Equal(t, uint64(87), operators[0].BlockNumber)
assert.Equal(t, []byte("0x000163fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f211"), operators[0].TransactionHash)
assert.Equal(t, "0x000163fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f211", operators[0].TransactionHash)

assert.NotNil(t, operators[1])
assert.Equal(t, []byte("0x000763fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f212"), operators[1].Id)
assert.Equal(t, []byte("0x000563fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f212"), operators[1].Operator)
assert.Equal(t, []byte("0xe1cdae12a0074f20b8fc96a0489376db34075e545ef60c4845d264a732568310"), operators[1].OperatorId)
assert.Equal(t, "0x000763fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f212", operators[1].Id)
assert.Equal(t, "0x000563fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f212", operators[1].Operator)
assert.Equal(t, "0xe1cdae12a0074f20b8fc96a0489376db34075e545ef60c4845d264a732568310", operators[1].OperatorId)
assert.Equal(t, uint64(1696975459), operators[1].BlockTimestamp)
assert.Equal(t, uint64(88), operators[1].BlockNumber)
assert.Equal(t, []byte("0x000163fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f212"), operators[1].TransactionHash)
assert.Equal(t, "0x000163fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f212", operators[1].TransactionHash)
}

func TestQueryIndexedDeregisteredOperatorsForTimeWindow(t *testing.T) {
Expand All @@ -480,8 +480,8 @@ func TestQueryIndexedDeregisteredOperatorsForTimeWindow(t *testing.T) {
assert.Equal(t, expectedIndexedOperatorInfo.PubkeyG2, operator.IndexedOperatorInfo.PubkeyG2)
assert.Equal(t, "localhost:32006;32007", operator.IndexedOperatorInfo.Socket)
assert.Equal(t, uint64(22), uint64(operator.BlockNumber))
assert.Equal(t, []byte("0xe22dae12a0074f20b8fc96a0489376db34075e545ef60c4845d264a732568311"), operator.Metadata.OperatorId)
assert.Equal(t, []byte("0x000223fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f211"), operator.Metadata.TransactionHash)
assert.Equal(t, "0xe22dae12a0074f20b8fc96a0489376db34075e545ef60c4845d264a732568311", operator.Metadata.OperatorId)
assert.Equal(t, "0x000223fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f211", operator.Metadata.TransactionHash)
assert.Equal(t, uint64(22), uint64(operator.Metadata.BlockNumber))
}

Expand Down

0 comments on commit 9692cb5

Please sign in to comment.