This repository has been archived by the owner on Nov 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into patch-google-cloud-function
- Loading branch information
Showing
39 changed files
with
2,051 additions
and
1,901 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package ante | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/bandprotocol/bandchain/chain/x/oracle" | ||
"github.com/bandprotocol/bandchain/chain/x/oracle/keeper" | ||
) | ||
|
||
func checkValidReportMsg(ctx sdk.Context, oracleKeeper oracle.Keeper, msg sdk.Msg) bool { | ||
rep, ok := msg.(oracle.MsgReportData) | ||
if !ok { | ||
return false | ||
} | ||
if !oracleKeeper.IsReporter(ctx, rep.Validator, rep.Reporter) { | ||
return false | ||
} | ||
if rep.RequestID <= oracleKeeper.GetRequestLastExpired(ctx) { | ||
return false | ||
} | ||
|
||
req, err := oracleKeeper.GetRequest(ctx, rep.RequestID) | ||
if err != nil { | ||
return false | ||
} | ||
if !keeper.ContainsVal(req.RequestedValidators, rep.Validator) { | ||
return false | ||
} | ||
if len(rep.RawReports) != len(req.RawRequests) { | ||
return false | ||
} | ||
for _, report := range rep.RawReports { | ||
if !keeper.ContainsEID(req.RawRequests, report.ExternalID) { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
// NewFeelessReportsAnteHandler returns a new ante handler that waives minimum gas price requirement | ||
// if the incoming tx is a valid report transaction. | ||
func NewFeelessReportsAnteHandler(ante sdk.AnteHandler, oracleKeeper oracle.Keeper) sdk.AnteHandler { | ||
return func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) { | ||
if ctx.IsCheckTx() && !simulate { | ||
isValidReportTx := true | ||
for _, msg := range tx.GetMsgs() { | ||
if !checkValidReportMsg(ctx, oracleKeeper, msg) { | ||
isValidReportTx = false | ||
break | ||
} | ||
} | ||
if isValidReportTx { | ||
minGas := ctx.MinGasPrices() | ||
newCtx, err := ante(ctx.WithMinGasPrices(sdk.DecCoins{}), tx, simulate) | ||
// Set minimum gas price context and return context to caller. | ||
return newCtx.WithMinGasPrices(minGas), err | ||
} | ||
} | ||
return ante(ctx, tx, simulate) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.