Skip to content

Commit

Permalink
return deleted oracles
Browse files Browse the repository at this point in the history
  • Loading branch information
nnn-gif committed Sep 21, 2023
1 parent 7eed605 commit 5fb36d8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
14 changes: 13 additions & 1 deletion cmd/http/oraclebuilder/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,19 @@ func (ob *Env) Create(context *gin.Context) {
// List: list owner oracles
func (ob *Env) List(context *gin.Context) {
creator := context.Query("creator")
oracles, err := ob.RelDB.GetOraclesByOwner(creator)
deleted := context.Query("deleted")
expired := context.Query("expired")

isDeleted, err := strconv.ParseBool(deleted)
if err != nil {
isDeleted = true
}
isExpired, err := strconv.ParseBool(expired)
if err != nil {
isExpired = true
}

oracles, err := ob.RelDB.GetOraclesByOwner(creator, isDeleted, isExpired)
if err != nil {
log.Errorln("List Oracles: error on getOraclesByOwner ", err)
context.JSON(http.StatusInternalServerError, err)
Expand Down
13 changes: 9 additions & 4 deletions pkg/model/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (rdb *RelDB) GetFeederResources() (addresses []string, err error) {

}

func (rdb *RelDB) GetOraclesByOwner(owner string) (oracleconfigs []dia.OracleConfig, err error) {
func (rdb *RelDB) GetOraclesByOwner(owner string, deleted, expired bool) (oracleconfigs []dia.OracleConfig, err error) {
var (
rows pgx.Rows
deviationFloat float64
Expand All @@ -250,13 +250,13 @@ func (rdb *RelDB) GetOraclesByOwner(owner string) (oracleconfigs []dia.OracleCon
ON t1.address = fu.oracle_address
AND t1.chainID = fu.chain_id
WHERE t1.owner = $1
AND t1.deleted = false
AND t1.deleted = $2
GROUP BY
t1.address, t1.feeder_id, t1.owner, t1.symbols, t1.chainID,
t1.frequency, t1.sleepseconds, t1.deviationpermille, t1.blockchainnode, t1.active,
t1.mandatory_frequency, t1.feeder_address, t1.createddate, t1.feedselection,
t1.lastupdate, t1.expired,t1.expired_time;`, oracleconfigTable, feederupdatesTable)
rows, err = rdb.postgresClient.Query(context.Background(), query, owner)
rows, err = rdb.postgresClient.Query(context.Background(), query, owner, deleted)
if err != nil {
return
}
Expand Down Expand Up @@ -291,7 +291,12 @@ func (rdb *RelDB) GetOraclesByOwner(owner string) (oracleconfigs []dia.OracleCon
oracleconfig.DeviationPermille = fmt.Sprintf("%.2f", deviationFloat/10)
}

oracleconfig.ExpiringDate = oracleconfig.LastOracleUpdate.Add(time.Duration(60 * time.Hour * 24))
lastupdate := oracleconfig.LastOracleUpdate

if oracleconfig.LastOracleUpdate.IsZero() {
lastupdate = oracleconfig.CreatedDate
}
oracleconfig.ExpiringDate = lastupdate.Add(time.Duration(60 * time.Hour * 24))
if oracleconfig.ExpiringDate.Before(time.Now()) {
oracleconfig.Expired = true
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/relDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ type RelDatastore interface {
GetOracleConfig(address, chainid string) (oracleconfig dia.OracleConfig, err error)
ChangeOracleState(feederID string, active bool) (err error)
DeleteOracle(feederID string) (err error)
GetOraclesByOwner(owner string) (oracleconfigs []dia.OracleConfig, err error)
GetOraclesByOwner(owner string, deleted, expired bool) (oracleconfigs []dia.OracleConfig, err error)
GetAllFeeders(bool) (oracleconfigs []dia.OracleConfig, err error)
GetFeederResources() (addresses []string, err error)
GetOracleUpdates(address string, chainid string, offset int) ([]dia.OracleUpdate, error)
Expand Down

0 comments on commit 5fb36d8

Please sign in to comment.