Skip to content

Commit

Permalink
Oraclebuilder Payment Flow (#1150)
Browse files Browse the repository at this point in the history
* Update oracle.go

* add GetOraclesByCustomer

* set customerid while creating oracle

* Update oracle.go

* get total oracle feeder and feed selection

* update default access level

* add username to keys

* update postgres query for addwallet

* return username while view account

* update suername api

* check customer plan

* insert looppayment response

* update customer plan

* update plan on payment complete
  • Loading branch information
nnn-gif authored Aug 28, 2024
1 parent f149f4d commit b4d95a6
Show file tree
Hide file tree
Showing 10 changed files with 1,616 additions and 106 deletions.
75 changes: 62 additions & 13 deletions cmd/http/oraclebuilder/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"net/http"
"strconv"

"github.com/gin-gonic/gin"
)
Expand All @@ -14,47 +15,91 @@ 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"`
UserName string `form:"username"`
}
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"`
UserName string `form:"username"`
}

type ViewInput struct {
Creator string `form:"creator"`
}

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

var input ViewInput
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
customer, err := ob.RelDB.GetCustomerByPublicKey(input.Creator)
if err != nil {
log.Errorln("AddWalletKeys", err)

log.Errorf("Request ID: %s, ViewAccount err %v ", requestId, err)
context.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

context.JSON(http.StatusOK, customer)
totalFeeds, err := ob.totalFeedsUsedByCustomer(strconv.Itoa(customer.CustomerID))
if err != nil {
log.Errorf("Request ID: %s, ViewAccount err %v ", requestId, err)
context.JSON(http.StatusInternalServerError, gin.H{"error": "error while getting totalFeedusedByCustomer"})
return
}
customer.NumberOfDataFeeds = totalFeeds

customer.DeployedOracles = ob.RelDB.GetTotalOracles(strconv.Itoa(customer.CustomerID))

plan, err := ob.RelDB.GetPlan(context, customer.CustomerPlan)
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,
"customer_id": customer.CustomerID,
"email": customer.Email,
"account_creation_date": customer.AccountCreationDate,
"customer_plan": customer.CustomerPlan,
"deployed_oracles": customer.DeployedOracles,
"payment_status": customer.PaymentStatus,
"payment_source": customer.PaymentSource,
"number_of_data_feeds": customer.NumberOfDataFeeds,
"active": customer.Active,
"public_keys": customer.PublicKeys,
}

context.JSON(http.StatusOK, combined)

}

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.UserName, 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 All @@ -65,17 +110,19 @@ func (ob *Env) AddWallet(context *gin.Context) {
}

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

var input UpdateAccessInput
if err := context.ShouldBind(&input); err != nil {
context.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
//TODO check permission, remove self key, check should not be self, min one key has to me read_write
log.Errorln("input", input)
log.Infoln("Request ID: %s, UpdateAccess input err %v ", requestId, input)

err := ob.RelDB.UpdateAccessLevel(input.AccessLevel, input.WalletPublicKey)
err := ob.RelDB.UpdateAccessLevel(input.UserName, input.AccessLevel, input.WalletPublicKey)
if err != nil {
log.Errorln("UpdateAccessLevel", err)
log.Errorf("Request ID: %s, UpdateAccessLevel %v ", requestId, err)

context.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
Expand All @@ -86,17 +133,19 @@ func (ob *Env) UpdateAccess(context *gin.Context) {
}

func (ob *Env) RemoveWallet(context *gin.Context) {
var input AddWalletInput
requestId := context.GetString(REQUEST_ID)

var input RemoveWalletInput
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, remove self key
err := ob.RelDB.RemoveWalletKeys(input.WalletPublicKeys)
if err != nil {
log.Errorln("RemoveWalletKeys", err)

log.Errorf("Request ID: %s, RemoveWalletKeys err %v ", requestId, err)
context.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
Expand Down
Loading

0 comments on commit b4d95a6

Please sign in to comment.