Skip to content

Commit

Permalink
get agg api update
Browse files Browse the repository at this point in the history
  • Loading branch information
tkernell committed Apr 9, 2024
1 parent c51827a commit 02035eb
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 186 deletions.
36 changes: 17 additions & 19 deletions api/layer/bridge/query.pulsar.go

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

62 changes: 21 additions & 41 deletions evm/test/Bridge-TestsAuto.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,35 +563,27 @@ describe("BlobstreamO - Auto Function and e2e Tests", function () {

ethUsdRep0 = await h.getCurrentAggregateReport(ETH_USD_QUERY_ID)
console.log("ethUsdRep0: ", ethUsdRep0)
// snapshots = await h.getSnapshotsByReport(ETH_USD_QUERY_ID, ethUsdRep0.report.timestamp)
// console.log("snapshots: ", snapshots)
// lastSnapshot = snapshots[snapshots.length - 1]
// attestationData = await h.getAttestationDataBySnapshot(lastSnapshot)
// console.log("attestationData: ", attestationData)

// oattests = await h.getAttestationsBySnapshot(lastSnapshot, valSet1)
// if (oattests.length == 0) {
// sleeptime = 2
// console.log("no attestations found, sleeping for ", sleeptime, " seconds...")
// await h.sleep(2)
// oattests = await h.getAttestationsBySnapshot(lastSnapshot, valSet1)
// }
// console.log("oattests: ", oattests)

// console.log("verifying oracle data...")
// await bridge.verifyOracleData(
// attestationData,
// valSet1,
// oattests,
// )

// // request new attestations
// currentBlock = await h.getBlock()
// currentTime = currentBlock.timestamp
// console.log("currentTime: ", currentTime)
// pastReport = await h.getDataBefore(ETH_USD_QUERY_ID, currentTime)
// console.log("pastReport: ", pastReport)
// // await h.requestAttestations(ETH_USD_QUERY_ID, pastReport.timestamp)
snapshots = await h.getSnapshotsByReport(ETH_USD_QUERY_ID, ethUsdRep0.report.timestamp)
console.log("snapshots: ", snapshots)
lastSnapshot = snapshots[snapshots.length - 1]
attestationData = await h.getAttestationDataBySnapshot(lastSnapshot)
console.log("attestationData: ", attestationData)

oattests = await h.getAttestationsBySnapshot(lastSnapshot, valSet1)
if (oattests.length == 0) {
sleeptime = 2
console.log("no attestations found, sleeping for ", sleeptime, " seconds...")
await h.sleep(2)
oattests = await h.getAttestationsBySnapshot(lastSnapshot, valSet1)
}
console.log("oattests: ", oattests)

console.log("verifying oracle data...")
await bridge.verifyOracleData(
attestationData,
valSet1,
oattests,
)
})

it("query layer api, deploy and verify with real params", async function () {
Expand Down Expand Up @@ -647,16 +639,4 @@ describe("BlobstreamO - Auto Function and e2e Tests", function () {
)

})

it("try wallet", async function () {
wallet = await h.createCosmosWallet()
console.log("wallet: ", wallet)

currentBlock = await h.getBlock()
currentTime = currentBlock.timestamp - 100
pastReport = await h.getDataBefore(ETH_USD_QUERY_ID, currentTime)
console.log("pastReport: ", pastReport)

await h.requestAttestations(ETH_USD_QUERY_ID, pastReport.timestamp)
})
})
2 changes: 1 addition & 1 deletion proto/layer/bridge/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ message QueryGetValsetByTimestampResponse {
}

message QueryGetCurrentAggregateReportRequest {
bytes query_id = 1;
string query_id = 1;
}

message QueryGetCurrentAggregateReportResponse {
Expand Down
8 changes: 1 addition & 7 deletions x/bridge/client/cli/query_get_current_aggregate_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"
"github.com/tellor-io/layer/utils"
"github.com/tellor-io/layer/x/bridge/types"
)

Expand All @@ -28,12 +27,7 @@ func CmdGetCurrentAggregateReport() *cobra.Command {

queryClient := types.NewQueryClient(clientCtx)

qIdBz, err := utils.QueryBytesFromString(queryId)
if err != nil {
return err
}

params := &types.QueryGetCurrentAggregateReportRequest{QueryId: qIdBz}
params := &types.QueryGetCurrentAggregateReportRequest{QueryId: queryId}

res, err := queryClient.GetCurrentAggregateReport(cmd.Context(), params)
if err != nil {
Expand Down
9 changes: 7 additions & 2 deletions x/bridge/keeper/query_get_current_aggregate_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"encoding/hex"

"github.com/tellor-io/layer/x/bridge/types"
"google.golang.org/grpc/codes"
Expand All @@ -13,7 +14,11 @@ func (k Keeper) GetCurrentAggregateReport(ctx context.Context, req *types.QueryG
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

aggregate, timestamp := k.oracleKeeper.GetCurrentAggregateReport(ctx, req.QueryId)
queryId, err := hex.DecodeString(req.QueryId)
if err != nil {
return nil, status.Error(codes.InvalidArgument, "invalid query id")
}
aggregate, timestamp := k.oracleKeeper.GetCurrentAggregateReport(ctx, queryId)
if aggregate == nil {
return nil, status.Error(codes.NotFound, "aggregate not found")
}
Expand All @@ -30,7 +35,7 @@ func (k Keeper) GetCurrentAggregateReport(ctx context.Context, req *types.QueryG

// convert oracletypes.Aggregate to bridgetypes.Aggregate
bridgeAggregate := types.Aggregate{
QueryId: req.QueryId,
QueryId: aggregate.QueryId,
AggregateValue: aggregate.AggregateValue,
AggregateReporter: aggregate.AggregateReporter,
ReporterPower: aggregate.ReporterPower,
Expand Down
Loading

0 comments on commit 02035eb

Please sign in to comment.