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 pull request #2792 from bandprotocol/hook-latest-request
Implement hook for request search
- Loading branch information
Showing
8 changed files
with
262 additions
and
59 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,42 @@ | ||
package request | ||
|
||
import ( | ||
"github.com/bandprotocol/bandchain/chain/x/oracle/types" | ||
) | ||
|
||
type Request struct { | ||
RequestID types.RequestID `db:"request_id, primarykey" json:"request_id"` | ||
OracleScriptID types.OracleScriptID `db:"oracle_script_id" json:"oracle_script_id"` | ||
Calldata []byte `db:"calldata" json:"calldata"` | ||
MinCount uint64 `db:"min_count" json:"min_count"` | ||
AskCount uint64 `db:"ask_count" json:"ask_count"` | ||
ResolveTime int64 `db:"resolve_time" json:"resolve_time"` | ||
} | ||
|
||
func (h *RequestHook) insertRequest(requestID types.RequestID, oracleScriptID types.OracleScriptID, calldata []byte, minCount uint64, askCount uint64, resolveTime int64) { | ||
err := h.trans.Insert(&Request{ | ||
RequestID: requestID, | ||
OracleScriptID: oracleScriptID, | ||
Calldata: calldata, | ||
MinCount: minCount, | ||
AskCount: askCount, | ||
ResolveTime: resolveTime, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func (h *RequestHook) getMultiRequestID(oid types.OracleScriptID, calldata []byte, minCount uint64, askCount uint64, limit int64) []types.RequestID { | ||
var requests []Request | ||
h.dbMap.Select(&requests, | ||
`select * from request | ||
where oracle_script_id = ? and calldata = ? and min_count = ? and ask_count = ? | ||
order by resolve_time desc limit ?`, | ||
oid, calldata, minCount, askCount, limit) | ||
requestIDs := make([]types.RequestID, len(requests)) | ||
for idx, request := range requests { | ||
requestIDs[idx] = request.RequestID | ||
} | ||
return requestIDs | ||
} |
Oops, something went wrong.