Skip to content

Commit

Permalink
update default access level
Browse files Browse the repository at this point in the history
  • Loading branch information
nnn-gif committed Aug 22, 2024
1 parent 8943dcf commit 163defa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
10 changes: 7 additions & 3 deletions cmd/http/oraclebuilder/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type CustomerInput struct {
type AddWalletInput struct {
WalletPublicKeys []string `form:"wallet_public_keys[]"`
Creator string `form:"creator"`
AccessLevel string `form:"access_level" binding:"required,oneof=read read_write"`
}
type UpdateAccessInput struct {
WalletPublicKey string `form:"wallet_public_key"`
Expand Down Expand Up @@ -59,16 +60,19 @@ func (ob *Env) ViewAccount(context *gin.Context) {
}

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

var input AddWalletInput
if err := context.ShouldBind(&input); err != nil {
log.Errorln("ShouldBind", err)
log.Errorf("Request ID: %s, ShouldBind err %v ", requestId, err)

context.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
//TODO check permission
err := ob.RelDB.AddWalletKeys(input.Creator, input.WalletPublicKeys)
err := ob.RelDB.AddWalletKeys(input.Creator, input.AccessLevel, input.WalletPublicKeys)
if err != nil {
log.Errorln("AddWalletKeys", err)
log.Errorf("Request ID: %s, AddWalletKeys err %v ", requestId, err)

context.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
Expand Down
8 changes: 4 additions & 4 deletions pkg/model/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ func (datastore *DB) GetOracleConfigCache(key string) (dia.OracleConfig, error)
return oc, err
}

func (reldb *RelDB) AddWalletKeys(owner string, publicKey []string) error {
func (reldb *RelDB) AddWalletKeys(owner, accessLevel string, publicKey []string) error {
var err error

customerID, err := reldb.GetCustomerIDByWalletPublicKey(owner)
Expand All @@ -1149,9 +1149,9 @@ func (reldb *RelDB) AddWalletKeys(owner string, publicKey []string) error {

for _, publicKey := range publicKey {
_, err = tx.Exec(context.Background(), `
INSERT INTO wallet_public_keys (customer_id, public_key)
VALUES ($1, $2)
`, customerID, publicKey)
INSERT INTO wallet_public_keys (customer_id, public_key, access_level)
VALUES ($1, $2,$3)
`, customerID, publicKey, accessLevel)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/relDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ type RelDatastore interface {
DeleteAssetList(sheetName string) error

CreateCustomer(email string, customerPlan int, paymentStatus string, paymentSource string, numberOfDataFeeds int, walletPublicKeys []string) error
AddWalletKeys(owner string, publicKey []string) error
AddWalletKeys(owner, accessLevel string, publicKey []string) error
UpdateAccessLevel(accessLevel, publicKey string) error
RemoveWalletKeys(publicKey []string) error
GetCustomerIDByWalletPublicKey(publicKey string) (int, error)
Expand Down

0 comments on commit 163defa

Please sign in to comment.