diff --git a/cmd/http/oraclebuilder/account.go b/cmd/http/oraclebuilder/account.go index 540524d25..d4df49167 100644 --- a/cmd/http/oraclebuilder/account.go +++ b/cmd/http/oraclebuilder/account.go @@ -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"` @@ -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, @@ -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 } diff --git a/cmd/http/oraclebuilder/api.go b/cmd/http/oraclebuilder/api.go index c55146275..da1f06203 100644 --- a/cmd/http/oraclebuilder/api.go +++ b/cmd/http/oraclebuilder/api.go @@ -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, @@ -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 @@ -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 } } @@ -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) diff --git a/cmd/http/oraclebuilder/oraclebuilder.go b/cmd/http/oraclebuilder/oraclebuilder.go index c0bf50a5e..b29f1fb16 100644 --- a/cmd/http/oraclebuilder/oraclebuilder.go +++ b/cmd/http/oraclebuilder/oraclebuilder.go @@ -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) diff --git a/deployments/config/pginit.sql b/deployments/config/pginit.sql index 63394fe69..ae0095958 100644 --- a/deployments/config/pginit.sql +++ b/deployments/config/pginit.sql @@ -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 diff --git a/pkg/dia/Messages.go b/pkg/dia/Messages.go index 865997a20..40251978d 100644 --- a/pkg/dia/Messages.go +++ b/pkg/dia/Messages.go @@ -801,6 +801,7 @@ type OracleConfig struct { CustomerID string Billable bool Name string + Ecosystem bool } func (e *OracleConfig) MarshalBinary() ([]byte, error) { diff --git a/pkg/model/oracle.go b/pkg/model/oracle.go index d774193f9..42b52cec9 100644 --- a/pkg/model/oracle.go +++ b/pkg/model/oracle.go @@ -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 @@ -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 @@ -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) } @@ -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(` diff --git a/pkg/model/relDB.go b/pkg/model/relDB.go index eb7321de0..8bd6d9469 100644 --- a/pkg/model/relDB.go +++ b/pkg/model/relDB.go @@ -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 (