diff --git a/cmd/http/oraclebuilder/api.go b/cmd/http/oraclebuilder/api.go index 913983ea6..a07afa8bf 100644 --- a/cmd/http/oraclebuilder/api.go +++ b/cmd/http/oraclebuilder/api.go @@ -59,11 +59,13 @@ func (ob *Env) Create(context *gin.Context) { deviationPermille := context.PostForm("deviationpermille") blockchainnode := context.PostForm("blockchainnode") + feedSelection := context.PostForm("feedselection") + mandatoryFrequency := context.PostForm("mandatoryfrequency") k := make(map[string]string) - log.Infof("Creating oracle: oracleAddress: %s, ChainID: %s, Creator: %s, Symbols: %s, frequency: %s, sleepSeconds: %s blockchainnode: %s,", oracleaddress, chainID, creator, symbols, frequency, sleepSeconds, blockchainnode) + log.Infof("Creating oracle: oracleAddress: %s, ChainID: %s, Creator: %s, Symbols: %s, frequency: %s, sleepSeconds: %s blockchainnode: %s, feedSelection %s", oracleaddress, chainID, creator, symbols, frequency, sleepSeconds, blockchainnode, feedSelection) log.Infoln("Creating oracle: chainID", chainID) log.Infoln("Creating oracle: creator", creator) @@ -80,10 +82,10 @@ func (ob *Env) Create(context *gin.Context) { } // validations - // check for symbols + // check for symbols and feedSelection - if symbols == "" { - handleError(context, http.StatusBadRequest, "no symbols", "Creating oracle: no symbols", symbols) + if symbols == "" && feedSelection == "" { + handleError(context, http.StatusBadRequest, "no symbols", "Creating oracle: no symbols or feedSelection", symbols) } symbolsArray := strings.Split(symbols, ",") @@ -108,7 +110,8 @@ func (ob *Env) Create(context *gin.Context) { mandatoryFrequencyInt, err := strconv.Atoi(mandatoryFrequency) if err != nil { - handleError(context, http.StatusBadRequest, "invalid mandatoryFrequencyInt", "Creating oracle: invalid mandatoryFrequencyInt", err) + mandatoryFrequencyInt = 0 + // handleError(context, http.StatusBadRequest, "invalid mandatoryFrequencyInt", "Creating oracle: invalid mandatoryFrequencyInt", err) } if frequencyInt != 0 || mandatoryFrequencyInt == 0 { @@ -200,7 +203,7 @@ func (ob *Env) Create(context *gin.Context) { address = keypair.GetPublickey() if !isUpdate { - err = ob.PodHelper.CreateOracleFeeder(context, feederID, address, oracleaddress, chainID, symbols, blockchainnode, frequency, sleepSeconds, deviationPermille, mandatoryFrequency) + err = ob.PodHelper.CreateOracleFeeder(context, feederID, address, oracleaddress, chainID, symbols, feedSelection, blockchainnode, frequency, sleepSeconds, deviationPermille, mandatoryFrequency) if err != nil { log.Errorln("error CreateOracleFeeder ", err) context.JSON(http.StatusInternalServerError, errors.New("error creating oraclefeeder")) @@ -209,7 +212,7 @@ func (ob *Env) Create(context *gin.Context) { } - err = ob.RelDB.SetOracleConfig(oracleaddress, feederID, creator, address, symbols, chainID, frequency, sleepSeconds, deviationPermille, blockchainnode, mandatoryFrequency) + err = ob.RelDB.SetOracleConfig(oracleaddress, feederID, creator, address, symbols, feedSelection, chainID, frequency, sleepSeconds, deviationPermille, blockchainnode, mandatoryFrequency) if err != nil { log.Errorln("error SetOracleConfig ", err) context.JSON(http.StatusInternalServerError, err) diff --git a/cmd/http/oraclebuilder/go.sum b/cmd/http/oraclebuilder/go.sum index 65b747452..e0722626a 100644 --- a/cmd/http/oraclebuilder/go.sum +++ b/cmd/http/oraclebuilder/go.sum @@ -165,6 +165,10 @@ github.com/deepmap/oapi-codegen v1.8.2/go.mod h1:YLgSKSDv/bZQB7N4ws6luhozi3cEdRk github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-bitstream v0.0.0-20180413035011-3522498ce2c8/go.mod h1:VMaSuZ+SZcx/wljOQKvp5srsbCiKDEb6K2wC4+PiBmQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/diadata-org/diadata v1.4.172 h1:64qG9jl/nWJcabgOqo5HvYrZHr9R0kjeci6l+YLMqfk= +github.com/diadata-org/diadata v1.4.172/go.mod h1:ikGdMNjV36ZcpxGa/bmjsiWDNuNY8oB29nH3Tm6A9y0= +github.com/diadata-org/diadata v1.4.334 h1:wsGvzjQD1RKP0tW/JTnaeDni44P/A4GhzLGVm/R8yds= +github.com/diadata-org/diadata v1.4.334/go.mod h1:qrtMmpXAViwIlMzMFwYlZC+Rr/d8nUBpqtupg98hncw= github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= diff --git a/cmd/http/oraclebuilder/utils/podhelper.go b/cmd/http/oraclebuilder/utils/podhelper.go index 85ec071ac..e84213e3a 100644 --- a/cmd/http/oraclebuilder/utils/podhelper.go +++ b/cmd/http/oraclebuilder/utils/podhelper.go @@ -54,7 +54,7 @@ func NewPodHelper(image, namespace string) *PodHelper { return &PodHelper{k8sclient: client, Image: image, NameSpace: namespace} } -func (kh *PodHelper) CreateOracleFeeder(ctx context.Context, feederID string, owner string, oracle string, chainID string, symbols, blockchainnode string, frequency, sleepSeconds, deviationPermille, mandatoryFrequency string) error { +func (kh *PodHelper) CreateOracleFeeder(ctx context.Context, feederID string, owner string, oracle string, chainID string, symbols, feedSelection, blockchainnode string, frequency, sleepSeconds, deviationPermille, mandatoryFrequency string) error { // -- oracle config publickeyenv := corev1.EnvVar{Name: "ORACLE_PUBLICKEY", ValueFrom: &corev1.EnvVarSource{SecretKeyRef: &corev1.SecretKeySelector{Key: ".public", LocalObjectReference: corev1.LocalObjectReference{Name: feederID}}}} @@ -69,6 +69,7 @@ func (kh *PodHelper) CreateOracleFeeder(ctx context.Context, feederID string, ow oraclefeederid := corev1.EnvVar{Name: "ORACLE_FEEDERID", Value: feederID} blockchainnodeenv := corev1.EnvVar{Name: "ORACLE_BLOCKCHAINNODE", Value: blockchainnode} mandatoryfrequencyenv := corev1.EnvVar{Name: "ORACLE_MANDATORYFREQUENCY", Value: mandatoryFrequency} + feedSelectionenv := corev1.EnvVar{Name: "ORACLE_FEEDSELECTION", Value: feedSelection} // -- oracle config ends here @@ -101,7 +102,7 @@ func (kh *PodHelper) CreateOracleFeeder(ctx context.Context, feederID string, ow Env: []corev1.EnvVar{publickeyenv, deployedcontractenv, chainidenv, sleepsecondenv, deviationenv, frequencyseconds, oracletype, oraclesymbols, oraclefeederid, postgreshost, postgresuser, signerservice, - postgrespassword, postgresdb, updateconfigseconds, useenv, blockchainnodeenv, mandatoryfrequencyenv}, + postgrespassword, postgresdb, updateconfigseconds, useenv, blockchainnodeenv, mandatoryfrequencyenv, feedSelectionenv}, }, }, ImagePullSecrets: []corev1.LocalObjectReference{imagepullrequest}, @@ -137,7 +138,7 @@ func (kh *PodHelper) CreateOracleFeeder(ctx context.Context, feederID string, ow } -func (kh *PodHelper) UpdateOracleFeeder(ctx context.Context, feederID string, owner string, oracle string, chainID string, symbols, blockchainnode string, frequency, sleepSeconds, deviationPermille, mandatoryFrequency string) error { +func (kh *PodHelper) UpdateOracleFeeder(ctx context.Context, feederID string, owner string, oracle string, chainID string, symbols, feedSelection, blockchainnode string, frequency, sleepSeconds, deviationPermille, mandatoryFrequency string) error { fields := make(map[string]string) fields["oracle"] = oracle fields["chainID"] = chainID @@ -156,6 +157,7 @@ func (kh *PodHelper) UpdateOracleFeeder(ctx context.Context, feederID string, ow oraclefeederid := corev1.EnvVar{Name: "ORACLE_FEEDERID", Value: feederID} blockchainnodeenv := corev1.EnvVar{Name: "ORACLE_BLOCKCHAINNODE", Value: blockchainnode} mandatoryfrequencyenv := corev1.EnvVar{Name: "ORACLE_MANDATORYFREQUENCY", Value: mandatoryFrequency} + feedSelectionenv := corev1.EnvVar{Name: "ORACLE_FEEDSELECTION", Value: feedSelection} // -- oracle config ends here @@ -183,7 +185,7 @@ func (kh *PodHelper) UpdateOracleFeeder(ctx context.Context, feederID string, ow Env: []corev1.EnvVar{publickeyenv, deployedcontractenv, chainidenv, sleepsecondenv, deviationenv, frequencyseconds, oracletype, oraclesymbols, oraclefeederid, postgreshost, postgresuser, signerservice, - postgrespassword, postgresdb, updateconfigseconds, useenv, blockchainnodeenv, mandatoryfrequencyenv}, + postgrespassword, postgresdb, updateconfigseconds, useenv, blockchainnodeenv, mandatoryfrequencyenv, feedSelectionenv}, }, }, ImagePullSecrets: []corev1.LocalObjectReference{imagepullrequest}, @@ -232,7 +234,7 @@ func (kh *PodHelper) RestartOracleFeeder(ctx context.Context, feederID string, o } else { return err } - err = kh.CreateOracleFeeder(ctx, feederID, oracleconfig.Owner, oracleconfig.Address, oracleconfig.ChainID, strings.Join(oracleconfig.Symbols[:], ","), oracleconfig.BlockchainNode, oracleconfig.Frequency, oracleconfig.SleepSeconds, oracleconfig.DeviationPermille, oracleconfig.MandatoryFrequency) + err = kh.CreateOracleFeeder(ctx, feederID, oracleconfig.Owner, oracleconfig.Address, oracleconfig.ChainID, strings.Join(oracleconfig.Symbols[:], ","), oracleconfig.FeederSelection, oracleconfig.BlockchainNode, oracleconfig.Frequency, oracleconfig.SleepSeconds, oracleconfig.DeviationPermille, oracleconfig.MandatoryFrequency) if err != nil { log.Errorf("Pod %s start err\n", err) return @@ -245,7 +247,7 @@ func (kh *PodHelper) RestartOracleFeeder(ctx context.Context, feederID string, o //} kh.waitPodDeleted(ctx, oracleconfig.Address, func() { time.Sleep(1000 * time.Millisecond) - err = kh.CreateOracleFeeder(ctx, feederID, oracleconfig.Owner, oracleconfig.Address, oracleconfig.ChainID, strings.Join(oracleconfig.Symbols[:], ","), oracleconfig.BlockchainNode, oracleconfig.Frequency, oracleconfig.SleepSeconds, oracleconfig.DeviationPermille, oracleconfig.MandatoryFrequency) + err = kh.CreateOracleFeeder(ctx, feederID, oracleconfig.Owner, oracleconfig.Address, oracleconfig.ChainID, strings.Join(oracleconfig.Symbols[:], ","), oracleconfig.FeederSelection, oracleconfig.BlockchainNode, oracleconfig.Frequency, oracleconfig.SleepSeconds, oracleconfig.DeviationPermille, oracleconfig.MandatoryFrequency) if err != nil { log.Errorf("Pod %s start err\n", err) return diff --git a/cmd/oraclebuildertools/utils/podhelper.go b/cmd/oraclebuildertools/utils/podhelper.go index 85ec071ac..c2bb8c25c 100644 --- a/cmd/oraclebuildertools/utils/podhelper.go +++ b/cmd/oraclebuildertools/utils/podhelper.go @@ -54,7 +54,7 @@ func NewPodHelper(image, namespace string) *PodHelper { return &PodHelper{k8sclient: client, Image: image, NameSpace: namespace} } -func (kh *PodHelper) CreateOracleFeeder(ctx context.Context, feederID string, owner string, oracle string, chainID string, symbols, blockchainnode string, frequency, sleepSeconds, deviationPermille, mandatoryFrequency string) error { +func (kh *PodHelper) CreateOracleFeeder(ctx context.Context, feederID string, owner string, oracle string, chainID string, symbols, feedSelection, blockchainnode string, frequency, sleepSeconds, deviationPermille, mandatoryFrequency string) error { // -- oracle config publickeyenv := corev1.EnvVar{Name: "ORACLE_PUBLICKEY", ValueFrom: &corev1.EnvVarSource{SecretKeyRef: &corev1.SecretKeySelector{Key: ".public", LocalObjectReference: corev1.LocalObjectReference{Name: feederID}}}} @@ -69,6 +69,7 @@ func (kh *PodHelper) CreateOracleFeeder(ctx context.Context, feederID string, ow oraclefeederid := corev1.EnvVar{Name: "ORACLE_FEEDERID", Value: feederID} blockchainnodeenv := corev1.EnvVar{Name: "ORACLE_BLOCKCHAINNODE", Value: blockchainnode} mandatoryfrequencyenv := corev1.EnvVar{Name: "ORACLE_MANDATORYFREQUENCY", Value: mandatoryFrequency} + feedSelectionenv := corev1.EnvVar{Name: "ORACLE_FEEDSELECTION", Value: feedSelection} // -- oracle config ends here @@ -101,7 +102,7 @@ func (kh *PodHelper) CreateOracleFeeder(ctx context.Context, feederID string, ow Env: []corev1.EnvVar{publickeyenv, deployedcontractenv, chainidenv, sleepsecondenv, deviationenv, frequencyseconds, oracletype, oraclesymbols, oraclefeederid, postgreshost, postgresuser, signerservice, - postgrespassword, postgresdb, updateconfigseconds, useenv, blockchainnodeenv, mandatoryfrequencyenv}, + postgrespassword, postgresdb, updateconfigseconds, useenv, blockchainnodeenv, mandatoryfrequencyenv, feedSelectionenv}, }, }, ImagePullSecrets: []corev1.LocalObjectReference{imagepullrequest}, @@ -137,7 +138,7 @@ func (kh *PodHelper) CreateOracleFeeder(ctx context.Context, feederID string, ow } -func (kh *PodHelper) UpdateOracleFeeder(ctx context.Context, feederID string, owner string, oracle string, chainID string, symbols, blockchainnode string, frequency, sleepSeconds, deviationPermille, mandatoryFrequency string) error { +func (kh *PodHelper) UpdateOracleFeeder(ctx context.Context, feederID string, owner string, oracle string, chainID string, symbols, feedSelection, blockchainnode string, frequency, sleepSeconds, deviationPermille, mandatoryFrequency string) error { fields := make(map[string]string) fields["oracle"] = oracle fields["chainID"] = chainID @@ -156,6 +157,7 @@ func (kh *PodHelper) UpdateOracleFeeder(ctx context.Context, feederID string, ow oraclefeederid := corev1.EnvVar{Name: "ORACLE_FEEDERID", Value: feederID} blockchainnodeenv := corev1.EnvVar{Name: "ORACLE_BLOCKCHAINNODE", Value: blockchainnode} mandatoryfrequencyenv := corev1.EnvVar{Name: "ORACLE_MANDATORYFREQUENCY", Value: mandatoryFrequency} + feedSelectionenv := corev1.EnvVar{Name: "ORACLE_FEEDSELECTION", Value: feedSelection} // -- oracle config ends here @@ -183,7 +185,7 @@ func (kh *PodHelper) UpdateOracleFeeder(ctx context.Context, feederID string, ow Env: []corev1.EnvVar{publickeyenv, deployedcontractenv, chainidenv, sleepsecondenv, deviationenv, frequencyseconds, oracletype, oraclesymbols, oraclefeederid, postgreshost, postgresuser, signerservice, - postgrespassword, postgresdb, updateconfigseconds, useenv, blockchainnodeenv, mandatoryfrequencyenv}, + postgrespassword, postgresdb, updateconfigseconds, useenv, blockchainnodeenv, mandatoryfrequencyenv, feedSelectionenv}, }, }, ImagePullSecrets: []corev1.LocalObjectReference{imagepullrequest}, diff --git a/deployments/config/pginit.sql b/deployments/config/pginit.sql index e235d8c2e..b51577f1d 100644 --- a/deployments/config/pginit.sql +++ b/deployments/config/pginit.sql @@ -279,7 +279,7 @@ CREATE TABLE oracleconfig ( frequency text , sleepseconds text, deviationpermille text, - blochchainnode text, + blockchainnode text, mandatory_frequency text, createddate TIMESTAMP NOT NULL DEFAULT NOW(), lastupdate TIMESTAMP NOT NULL, @@ -288,6 +288,11 @@ CREATE TABLE oracleconfig ( ); ALTER TABLE oracleconfig ADD COLUMN creation_block_time TIMESTAMP DEFAULT 'epoch'::timestamp; +ALTER TABLE oracleconfig ADD COLUMN feedSelection TEXT ; + + + + diff --git a/pkg/dia/Messages.go b/pkg/dia/Messages.go index 0d2326869..5c388d4cb 100644 --- a/pkg/dia/Messages.go +++ b/pkg/dia/Messages.go @@ -736,6 +736,7 @@ type OracleConfig struct { CreatedDate time.Time LastUpdate time.Time Deleted bool `json:"Deleted,omitempty"` + FeederSelection string } type OracleUpdate struct { diff --git a/pkg/model/oracle.go b/pkg/model/oracle.go index b70c76bd2..70be44ea4 100644 --- a/pkg/model/oracle.go +++ b/pkg/model/oracle.go @@ -41,16 +41,16 @@ func (rdb *RelDB) GetKeyPairID(publicKey string) string { return keypairId } -func (rdb *RelDB) SetOracleConfig(address, feederID, owner, feederAddress, symbols, chainID, frequency, sleepseconds, deviationpermille, blockchainnode, mandatoryFrequency string) error { +func (rdb *RelDB) SetOracleConfig(address, feederID, owner, feederAddress, symbols, feedSelection, chainID, frequency, sleepseconds, deviationpermille, blockchainnode, mandatoryFrequency string) error { currentTime := time.Now() query := fmt.Sprintf(`INSERT INTO %s - (address,feeder_id,owner,symbols,chainID,frequency,sleepseconds, deviationpermille,blockchainnode, mandatory_frequency,feeder_address,createddate, lastupdate) - VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13) + (address,feeder_id,owner,symbols,chainID,frequency,sleepseconds, deviationpermille,blockchainnode, mandatory_frequency,feeder_address,createddate, lastupdate,feedSelection) + VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14) on CONFLICT(feeder_id) - DO UPDATE SET symbols=$4,frequency=$6,sleepseconds=$7, deviationpermille=$8, blockchainnode=$9, mandatory_frequency=$10, feeder_address=$11, lastupdate=$13`, oracleconfigTable) + DO UPDATE SET symbols=$4,frequency=$6,sleepseconds=$7, deviationpermille=$8, blockchainnode=$9, mandatory_frequency=$10, feeder_address=$11, lastupdate=$13, feedSelection=$14`, oracleconfigTable) log.Infoln("SetOracleConfig Query", query) - _, err := rdb.postgresClient.Exec(context.Background(), query, address, feederID, owner, symbols, chainID, frequency, sleepseconds, deviationpermille, blockchainnode, mandatoryFrequency, feederAddress, currentTime, currentTime) + _, err := rdb.postgresClient.Exec(context.Background(), query, address, feederID, owner, symbols, chainID, frequency, sleepseconds, deviationpermille, blockchainnode, mandatoryFrequency, feederAddress, currentTime, currentTime, feedSelection) if err != nil { return err }