Skip to content

Commit

Permalink
update ecoystem flag for oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
nnn-gif committed Sep 30, 2024
1 parent 091f39b commit 32f89dd
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 12 deletions.
15 changes: 8 additions & 7 deletions cmd/http/oraclebuilder/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type RemoveWalletInput struct {
WalletPublicKeys []string `form:"wallet_public_keys[]"`
Creator string `form:"creator"`
}

type UpdateAccessInput struct {
WalletPublicKey string `form:"wallet_public_key"`
AccessLevel string `form:"access_level" binding:"required,oneof=read read_write"`
Expand Down Expand Up @@ -64,12 +65,12 @@ func (ob *Env) viewAccount(context *gin.Context, publicKey string) (combined map
context.JSON(http.StatusInternalServerError, gin.H{"error": "error while getting plan"})
return
}
pendingPk, err := ob.RelDB.GetPendingPublicKeyByCustomer(context, strconv.Itoa(customer.CustomerID))
if err != nil {
log.Errorf("Request ID: %s, ViewAccount GetPlan err %v ", requestId, err)
context.JSON(http.StatusInternalServerError, gin.H{"error": "error while getting plan"})
return
}
// pendingPk, err := ob.RelDB.GetPendingPublicKeyByCustomer(context, strconv.Itoa(customer.CustomerID))
// if err != nil {
// log.Errorf("Request ID: %s, ViewAccount GetPlan err %v ", requestId, err)
// context.JSON(http.StatusInternalServerError, gin.H{"error": "error while getting plan"})
// return
// }

combined = map[string]interface{}{
"plan": plan,
Expand All @@ -83,7 +84,7 @@ func (ob *Env) viewAccount(context *gin.Context, publicKey string) (combined map
"number_of_data_feeds": customer.NumberOfDataFeeds,
"active": customer.Active,
"public_keys": customer.PublicKeys,
"pending_public_keys": pendingPk,
// "pending_public_keys": pendingPk,
}
return
}
Expand Down
56 changes: 54 additions & 2 deletions cmd/http/oraclebuilder/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ func (ob *Env) ListAndViewAccount(context *gin.Context) {
log.Errorf("Request ID: %s, err GetPendingInvites %v ", requestId, err)

}

account = map[string]interface{}{

"pending_public_keys": pending,
Expand Down Expand Up @@ -964,6 +965,56 @@ func (ob *Env) Pause(context *gin.Context) {
context.JSON(http.StatusOK, oracleconfig)
}

func (ob *Env) SetEcosystem(context *gin.Context) {
requestId := context.GetString(REQUEST_ID)
creator := context.GetString(CREATOR_ADDRESS)

feederID := context.PostForm("feederID")
enable := context.PostForm("enable")

// customerID := context.GetString(CUSTOMER_ID)

customer, err := ob.RelDB.GetCustomerByPublicKey(creator)
if err != nil {
context.JSON(http.StatusUnauthorized, gin.H{"error": "address not associated with any team"})
context.Abort()
return
}

log.Infof("Request ID: %s, , customerID=%d, enable=%s %v ", requestId, customer.CustomerID, enable, feederID)

enableBool, err := strconv.ParseBool(enable)
if err != nil {
context.JSON(http.StatusBadRequest, gin.H{
"error": "Invalid boolean query parameter",
})
return
}

oracleconfig, err := ob.RelDB.GetFeeder(feederID)
if err != nil {
log.Errorf("Request ID: %s, err GetOracleConfig %v ", requestId, err)
context.JSON(http.StatusInternalServerError, gin.H{"error": "error on pause"})
return
}

if oracleconfig.CustomerID != strconv.Itoa(customer.CustomerID) {
log.Errorf("Request ID: %s, not authorised to SetEcosystem, customerID=%s, oracleconfig.CustomerID=%s %v ", requestId, customer.CustomerID, oracleconfig.CustomerID, err)
context.JSON(http.StatusUnauthorized, gin.H{"error": "not part of your team oracle"})
return
}

err = ob.RelDB.ChangeEcosystemConfig(feederID, enableBool)
if err != nil {
log.Errorf("Request ID: %s, ChangeEcosystemConfig err %v ", requestId, err)
context.JSON(http.StatusInternalServerError, gin.H{"error": "error changing ecosystem state wallet"})
return
}

context.JSON(http.StatusOK, gin.H{"message": "ecosystem state changed"})

}

func (ob *Env) Delete(context *gin.Context) {
var (
// address string
Expand Down Expand Up @@ -1261,11 +1312,12 @@ func (ob *Env) Auth(isCustomer bool) gin.HandlerFunc {
return

}
log.Infof("Request ID: %s, setting customer details %s customer id %s", requestId, CUSTOMER_ID, customer.CustomerID)
log.Infof("Request ID: %s, setting customer details %s customer id %d", requestId, CUSTOMER_ID, customer.CustomerID)

context.Set(CUSTOMER_ID, customer.CustomerID)
context.Set(CUSTOMER_PLAN, customer.CustomerPlan)
context.Set(ACCESS_LEVEL, accessLevel)
return
}

}
Expand Down Expand Up @@ -1337,7 +1389,7 @@ func (ob *Env) LoopWebHook(context *gin.Context) {
log.Errorf("Request ID: %s,err %v ,", requestId, err)

if err.Error() == "no rows in result set" {
err := ob.RelDB.CreateCustomer(ldr.Email, 0, "", "", 2, []string{common.HexToAddress(ldr.Subscriber).String()})
err := ob.RelDB.CreateCustomer(ldr.Email, "", 0, "", "", 2, []string{common.HexToAddress(ldr.Subscriber).String()})
if err != nil {
log.Errorf("Request ID: %s,customer err %v", err)

Expand Down
2 changes: 2 additions & 0 deletions cmd/http/oraclebuilder/oraclebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ func setupRouter() *gin.Engine {
routerGroup.POST("/oracle/feeder", authenticate("Verify its your address to create and update oracle"), oracle.Auth(true), oracle.CanWrite, oracle.CreateUpdateOracle)
routerGroup.POST("/oracle/deploy", authenticate("Verify its your address to start feeder"), oracle.Auth(true), oracle.CanWrite, oracle.InitFeeder)

routerGroup.POST("/oracle/ecosystem", authenticate("Verify its your address to update ecosystem config"), oracle.Auth(true), oracle.CanWrite, oracle.SetEcosystem)

// Define routes
routerGroup.POST("create", oracle.CreateOneStep)
routerGroup.GET("/create", oracle.ViewLimit)
Expand Down
3 changes: 3 additions & 0 deletions deployments/config/pginit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ ALTER TABLE oracleconfig ADD COLUMN draft boolean DEFAULT true;
ALTER TABLE oracleconfig ADD COLUMN customer_id int ;
ALTER TABLE oracleconfig ADD COLUMN billable boolean DEFAULT false ;

ALTER TABLE oracleconfig ADD COLUMN ecosystem boolean DEFAULT false;



ALTER TABLE oracleconfig
ADD CONSTRAINT unique_customer_chainid_address
Expand Down
1 change: 1 addition & 0 deletions pkg/dia/Messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ type OracleConfig struct {
CustomerID string
Billable bool
Name string
Ecosystem bool
}

func (e *OracleConfig) MarshalBinary() ([]byte, error) {
Expand Down
23 changes: 20 additions & 3 deletions pkg/model/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@ func (rdb *RelDB) GetOraclesByCustomer(customerId string) (oracleconfigs []dia.O
COALESCE(t1.lastupdate, '0001-01-01 00:00:00'::timestamp) AS lastupdate,
t1.expired, t1.expired_time,
COALESCE(MAX(fu.update_time), '0001-01-01 00:00:00'::timestamp) AS max_update_time,
t1.billable
t1.billable,
t1.ecosystem
FROM %s AS t1
LEFT JOIN %s AS fu
ON t1.address = fu.oracle_address
Expand All @@ -475,7 +476,7 @@ func (rdb *RelDB) GetOraclesByCustomer(customerId string) (oracleconfigs []dia.O
t1.name,t1.address, t1.feeder_id, t1.deleted, 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,t1.billable;`, oracleconfigTable, feederupdatesTable)
t1.lastupdate, t1.expired,t1.expired_time,t1.billable,t1.ecosystem;`, oracleconfigTable, feederupdatesTable)
rows, err = rdb.postgresClient.Query(context.Background(), query, customerId)
if err != nil {
return
Expand All @@ -493,7 +494,8 @@ func (rdb *RelDB) GetOraclesByCustomer(customerId string) (oracleconfigs []dia.O
err := rows.Scan(&name, &oracleconfig.Address, &oracleconfig.FeederID, &oracleconfig.Deleted, &oracleconfig.Owner, &symbols,
&oracleconfig.ChainID, &oracleconfig.Frequency, &oracleconfig.SleepSeconds, &oracleconfig.DeviationPermille,
&oracleconfig.BlockchainNode, &oracleconfig.Active, &oracleconfig.MandatoryFrequency, &oracleconfig.FeederAddress,
&oracleconfig.CreatedDate, &feedSelection, &oracleconfig.LastUpdate, &oracleconfig.Expired, &oracleconfig.ExpiredDate, &oracleconfig.LastOracleUpdate, &oracleconfig.Billable)
&oracleconfig.CreatedDate, &feedSelection, &oracleconfig.LastUpdate, &oracleconfig.Expired, &oracleconfig.ExpiredDate, &oracleconfig.LastOracleUpdate, &oracleconfig.Billable,
&oracleconfig.Ecosystem)
if err != nil {
log.Error(err)
}
Expand Down Expand Up @@ -651,6 +653,21 @@ func (rdb *RelDB) ChangeOracleState(feederID string, active bool) (err error) {
return
}

func (rdb *RelDB) ChangeEcosystemConfig(feederId string, enable bool) (err error) {
currentTime := time.Now()

query := fmt.Sprintf(`
UPDATE %s
SET ecosystem=$1, lastupdate=$3
WHERE feeder_id=$2`, oracleconfigTable)
_, err = rdb.postgresClient.Exec(context.Background(), query, enable, feederId, currentTime)
if err != nil {
return
}

return
}

func (rdb *RelDB) DeleteOracle(feederID string) (err error) {
currentTime := time.Now()
query := fmt.Sprintf(`
Expand Down
2 changes: 2 additions & 0 deletions pkg/model/relDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ type RelDatastore interface {
InsertLoopPaymentTransferProcessed(ctx context.Context, record LoopPaymentTransferProcessed) error
InsertLoopPaymentResponse(ctx context.Context, response LoopPaymentResponse) error
GetLoopPaymentResponseByAgreementID(ctx context.Context, agreementID string) (*LoopPaymentResponse, error)

ChangeEcosystemConfig(oracleAddress string, enable bool) (err error)
}

const (
Expand Down

0 comments on commit 32f89dd

Please sign in to comment.