Skip to content

Commit

Permalink
add feedselection for oraclebuilder api
Browse files Browse the repository at this point in the history
  • Loading branch information
nnn-gif committed Aug 30, 2023
1 parent e2ff7ad commit 23ee0b9
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 23 deletions.
17 changes: 10 additions & 7 deletions cmd/http/oraclebuilder/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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, ",")
Expand All @@ -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 {
Expand Down Expand Up @@ -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"))
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions cmd/http/oraclebuilder/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
14 changes: 8 additions & 6 deletions cmd/http/oraclebuilder/utils/podhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}}
Expand All @@ -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

Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions cmd/oraclebuildertools/utils/podhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}}
Expand All @@ -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

Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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},
Expand Down
7 changes: 6 additions & 1 deletion deployments/config/pginit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 ;







Expand Down
1 change: 1 addition & 0 deletions pkg/dia/Messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ type OracleConfig struct {
CreatedDate time.Time
LastUpdate time.Time
Deleted bool `json:"Deleted,omitempty"`
FeederSelection string
}

type OracleUpdate struct {
Expand Down
10 changes: 5 additions & 5 deletions pkg/model/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 23ee0b9

Please sign in to comment.