Skip to content

Commit

Permalink
Merge branch 'dev' into log_transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
wjuniorbh92 committed Aug 23, 2023
2 parents ac20201 + 7190f6a commit 58cad69
Show file tree
Hide file tree
Showing 35 changed files with 455 additions and 1,135 deletions.
6 changes: 4 additions & 2 deletions backend/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions backend/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1931,8 +1931,10 @@
"type": "object",
"properties": {
"error": {
"type": "string",
"example": "message"
"type": "string"
},
"message": {
"type": "string"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion backend/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@ definitions:
v1.response:
properties:
error:
example: message
type: string
message:
type: string
type: object
v1.userResponse:
Expand Down
107 changes: 36 additions & 71 deletions backend/internal/controller/http/v1/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type UpdateAuthFlagsRequest struct {
func (r *assetsRoutes) createAsset(c *gin.Context) {
var request CreateAssetRequest
if err := c.ShouldBindJSON(&request); err != nil {
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()))
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()), err)
return
}

Expand All @@ -110,19 +110,19 @@ func (r *assetsRoutes) createAsset(c *gin.Context) {

sponsor, err := r.w.Get(sponsorID)
if err != nil {
errorResponse(c, http.StatusNotFound, "sponsor wallet not found")
errorResponse(c, http.StatusNotFound, "sponsor wallet not found", err)
return
}

res, err := r.m.SendMessage(entity.CreateKeypairChannel, entity.CreateKeypairRequest{Amount: 2})
if err != nil {
errorResponse(c, http.StatusInternalServerError, "kms messaging problems")
errorResponse(c, http.StatusInternalServerError, "kms messaging problems", err)
return
}

kpRes, ok := res.Message.(entity.CreateKeypairResponse)
if !ok || len(kpRes.PublicKeys) != 2 {
errorResponse(c, http.StatusInternalServerError, "unexpected kms response")
errorResponse(c, http.StatusInternalServerError, "unexpected kms response", err)
return
}
issuerPk := kpRes.PublicKeys[0]
Expand Down Expand Up @@ -182,18 +182,13 @@ func (r *assetsRoutes) createAsset(c *gin.Context) {
})
}

res, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
_, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
MainSource: sponsor.Key.PublicKey,
PublicKeys: []string{sponsor.Key.PublicKey, distPk, issuerPk},
Operations: ops,
})
if err != nil {
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems")
return
}
_, ok = res.Message.(entity.EnvelopeResponse)
if !ok {
errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response")
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err)
return
}

Expand All @@ -220,7 +215,7 @@ func (r *assetsRoutes) createAsset(c *gin.Context) {
}
asset, err = r.as.Create(asset)
if err != nil {
errorResponse(c, http.StatusNotFound, "database problems")
errorResponse(c, http.StatusNotFound, "database problems", err)
return
}

Expand Down Expand Up @@ -269,7 +264,7 @@ func (r *assetsRoutes) createAsset(c *gin.Context) {
func (r *assetsRoutes) mintAsset(c *gin.Context) {
var request MintAssetRequest
if err := c.ShouldBindJSON(&request); err != nil {
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()))
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()), err)
return
}

Expand All @@ -279,13 +274,13 @@ func (r *assetsRoutes) mintAsset(c *gin.Context) {
}
_, err := r.w.Get(request.SponsorId)
if err != nil {
errorResponse(c, http.StatusNotFound, "sponsor wallet not found")
errorResponse(c, http.StatusNotFound, "sponsor wallet not found", err)
return
}

asset, err := r.as.GetById(request.Id)
if err != nil {
errorResponse(c, http.StatusNotFound, "asset not found")
errorResponse(c, http.StatusNotFound, "asset not found", err)
return
}
ops := []entity.Operation{
Expand All @@ -300,19 +295,13 @@ func (r *assetsRoutes) mintAsset(c *gin.Context) {
Origin: asset.Issuer.Key.PublicKey,
},
}
res, err := r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
_, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
MainSource: asset.Issuer.Key.PublicKey,
PublicKeys: []string{asset.Issuer.Key.PublicKey},
Operations: ops,
})
if err != nil {
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems")
return
}

_, ok := res.Message.(entity.EnvelopeResponse)
if !ok {
errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response")
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err)
return
}

Expand Down Expand Up @@ -361,13 +350,13 @@ func (r *assetsRoutes) mintAsset(c *gin.Context) {
func (r *assetsRoutes) burnAsset(c *gin.Context) {
var request BurnAssetRequest
if err := c.ShouldBindJSON(&request); err != nil {
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()))
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()), err)
return
}

asset, err := r.as.GetById(request.Id)
if err != nil {
errorResponse(c, http.StatusNotFound, "asset not found")
errorResponse(c, http.StatusNotFound, "asset not found", err)
return
}

Expand All @@ -377,7 +366,7 @@ func (r *assetsRoutes) burnAsset(c *gin.Context) {
}
_, err = r.w.Get(request.SponsorId)
if err != nil {
errorResponse(c, http.StatusNotFound, "sponsor wallet not found")
errorResponse(c, http.StatusNotFound, "sponsor wallet not found", err)
return
}
ops := []entity.Operation{
Expand All @@ -393,20 +382,15 @@ func (r *assetsRoutes) burnAsset(c *gin.Context) {
},
}

res, err := r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
_, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
MainSource: asset.Distributor.Key.PublicKey,
PublicKeys: []string{asset.Distributor.Key.PublicKey},
Operations: ops,
})
if err != nil {
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems")
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err)
return
}

_, ok := res.Message.(entity.EnvelopeResponse)
if !ok {
errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response")
return
}

token := c.Request.Header.Get("Authorization")
Expand Down Expand Up @@ -456,13 +440,13 @@ func (r *assetsRoutes) burnAsset(c *gin.Context) {
func (r *assetsRoutes) transferAsset(c *gin.Context) {
var request TransferAssetRequest
if err := c.ShouldBindJSON(&request); err != nil {
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()))
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()), err)
return
}

sourceWallet, err := r.w.Get(request.SourceWalletID)
if err != nil {
errorResponse(c, http.StatusNotFound, "source wallet not found")
errorResponse(c, http.StatusNotFound, "source wallet not found", err)
return
}

Expand All @@ -472,13 +456,13 @@ func (r *assetsRoutes) transferAsset(c *gin.Context) {
}
_, err = r.w.Get(request.SponsorId)
if err != nil {
errorResponse(c, http.StatusNotFound, "sponsor wallet not found")
errorResponse(c, http.StatusNotFound, "sponsor wallet not found", err)
return
}

asset, err := r.as.GetById(request.AssetID)
if err != nil {
errorResponse(c, http.StatusNotFound, "asset not found")
errorResponse(c, http.StatusNotFound, "asset not found", err)
return
}
ops := []entity.Operation{
Expand All @@ -494,20 +478,13 @@ func (r *assetsRoutes) transferAsset(c *gin.Context) {
},
}

res, err := r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
_, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
MainSource: sourceWallet.Key.PublicKey,
PublicKeys: []string{sourceWallet.Key.PublicKey},
Operations: ops,
})
if err != nil {
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems")
return
}

_, ok := res.Message.(entity.EnvelopeResponse)
if !ok {
errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response")
return
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err)
}

token := c.Request.Header.Get("Authorization")
Expand Down Expand Up @@ -555,7 +532,7 @@ func (r *assetsRoutes) transferAsset(c *gin.Context) {
func (r *assetsRoutes) clawbackAsset(c *gin.Context) {
var request ClawbackAssetRequest
if err := c.ShouldBindJSON(&request); err != nil {
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()))
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()), err)
return
}

Expand All @@ -565,13 +542,13 @@ func (r *assetsRoutes) clawbackAsset(c *gin.Context) {
}
sponsor, err := r.w.Get(request.SponsorId)
if err != nil {
errorResponse(c, http.StatusNotFound, "sponsor wallet not found")
errorResponse(c, http.StatusNotFound, "sponsor wallet not found", err)
return
}

asset, err := r.as.Get(request.Code)
if err != nil {
errorResponse(c, http.StatusNotFound, "asset not found")
errorResponse(c, http.StatusNotFound, "asset not found", err)
return
}

Expand All @@ -589,20 +566,13 @@ func (r *assetsRoutes) clawbackAsset(c *gin.Context) {
},
}

res, err := r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
_, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
MainSource: sponsor.Key.PublicKey,
PublicKeys: []string{asset.Issuer.Key.PublicKey, sponsor.Key.PublicKey},
Operations: ops,
})
if err != nil {
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems")
return
}

_, ok := res.Message.(entity.EnvelopeResponse)
if !ok {
errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response")
return
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err)
}

token := c.Request.Header.Get("Authorization")
Expand Down Expand Up @@ -650,21 +620,21 @@ func (r *assetsRoutes) clawbackAsset(c *gin.Context) {
func (r *assetsRoutes) updateAuthFlags(c *gin.Context) {
var request UpdateAuthFlagsRequest
if err := c.ShouldBindJSON(&request); err != nil {
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()))
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()), err)
return
}

asset, err := r.as.Get(request.Code)
if err != nil {
errorResponse(c, http.StatusNotFound, "asset not found")
errorResponse(c, http.StatusNotFound, "asset not found", err)
return
}

var trustor entity.Wallet
if request.TrustorId != 0 {
trustor, err = r.w.Get(request.TrustorId)
if err != nil {
errorResponse(c, http.StatusNotFound, "trustor wallet not found")
errorResponse(c, http.StatusNotFound, "trustor wallet not found", err)
return
}
} else if request.TrustorPK != "" {
Expand All @@ -685,24 +655,19 @@ func (r *assetsRoutes) updateAuthFlags(c *gin.Context) {

sponsor, err := r.w.Get(_sponsorId)
if err != nil {
errorResponse(c, http.StatusNotFound, "sponsor wallet not found")
errorResponse(c, http.StatusNotFound, "sponsor wallet not found", err)
return
}

res, err := r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
_, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
MainSource: sponsor.Key.PublicKey,
PublicKeys: []string{asset.Issuer.Key.PublicKey, sponsor.Key.PublicKey},
Operations: []entity.Operation{op},
})
if err != nil {
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems")
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err)
return
}

_, ok := res.Message.(entity.EnvelopeResponse)
if !ok {
errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response")
return
}

token := c.Request.Header.Get("Authorization")
Expand Down Expand Up @@ -742,7 +707,7 @@ func (r *assetsRoutes) updateAuthFlags(c *gin.Context) {
func (r *assetsRoutes) getAllAssets(c *gin.Context) {
assets, err := r.as.GetAll()
if err != nil {
errorResponse(c, http.StatusInternalServerError, "error getting assets")
errorResponse(c, http.StatusInternalServerError, "error getting assets", err)
return
}

Expand All @@ -761,7 +726,7 @@ func (r *assetsRoutes) getAssetById(c *gin.Context) {
assetId := c.Param("id")
assets, err := r.as.GetById(assetId)
if err != nil {
errorResponse(c, http.StatusInternalServerError, "error getting asset")
errorResponse(c, http.StatusInternalServerError, "error getting asset", err)
return
}

Expand Down
2 changes: 1 addition & 1 deletion backend/internal/controller/http/v1/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func ValidateToken(signedToken string, jwtSecretKey string) (err error) {
func GenerateJWT(user entity.User, jwtSecretKey string) (tokenString string, err error) {
expirationTime := time.Now().Add(1440 * time.Minute)
claims := &JWTClaim{
ID: user.ID, // TODO
ID: user.ID,
Name: user.Name,
Email: user.Email,
StandardClaims: jwt.StandardClaims{
Expand Down
Loading

0 comments on commit 58cad69

Please sign in to comment.