Skip to content

Commit

Permalink
🎨 Improve the Id request messages
Browse files Browse the repository at this point in the history
  • Loading branch information
wjuniorbh92 committed Nov 1, 2023
1 parent 7fb67cb commit ed05036
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
23 changes: 18 additions & 5 deletions backend/internal/controller/http/v1/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,15 @@ func (r *assetsRoutes) createAsset(c *gin.Context) {
})
}

Id := generateID()
_, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
Id: Id,
MainSource: sponsor.Key.PublicKey,
PublicKeys: []string{sponsor.Key.PublicKey, distPk, issuerPk},
Operations: ops,
})
if err != nil {
r.logger.Error(err, "http - v1 - create asset - send message")
r.logger.Error(err, fmt.Sprintf("http - v1 - create asset - send message %d", Id))
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err)
return
}
Expand Down Expand Up @@ -376,13 +378,15 @@ func (r *assetsRoutes) mintAsset(c *gin.Context) {
Origin: asset.Issuer.Key.PublicKey,
},
}
Id := generateID()
_, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
Id: Id,
MainSource: asset.Issuer.Key.PublicKey,
PublicKeys: []string{asset.Issuer.Key.PublicKey},
Operations: ops,
})
if err != nil {
r.logger.Error(err, "http - v1 - mint asset - send message")
r.logger.Error(err, fmt.Sprintf("http - v1 - mint asset - send message %d", Id))
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err)
return
}
Expand Down Expand Up @@ -474,12 +478,15 @@ func (r *assetsRoutes) burnAsset(c *gin.Context) {
},
}

Id := generateID()
_, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
Id: Id,
MainSource: asset.Distributor.Key.PublicKey,
PublicKeys: []string{asset.Distributor.Key.PublicKey},
Operations: ops,
})
if err != nil {
r.logger.Error(err, fmt.Sprintf("http - v1 - burn asset - send message %d", Id))
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err)
return

Expand Down Expand Up @@ -580,13 +587,15 @@ func (r *assetsRoutes) transferAsset(c *gin.Context) {
},
}

Id := generateID()
_, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
Id: Id,
MainSource: sourceWallet.Key.PublicKey,
PublicKeys: []string{sourceWallet.Key.PublicKey},
Operations: ops,
})
if err != nil {
r.logger.Error(err, "http - v1 - transfer asset - send message")
r.logger.Error(err, fmt.Sprintf("http - v1 - transfer asset - send message %d", Id))
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err)
return
}
Expand Down Expand Up @@ -684,13 +693,15 @@ func (r *assetsRoutes) clawbackAsset(c *gin.Context) {
},
}

Id := generateID()
_, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
Id: Id,
MainSource: sponsor.Key.PublicKey,
PublicKeys: []string{asset.Issuer.Key.PublicKey, sponsor.Key.PublicKey},
Operations: ops,
})
if err != nil {
r.logger.Error(err, "http - v1 - clawback asset - send message")
r.logger.Error(err, fmt.Sprintf("http - v1 - clawback asset - send message %d", Id))
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err)
return
}
Expand Down Expand Up @@ -789,13 +800,15 @@ func (r *assetsRoutes) updateAuthFlags(c *gin.Context) {
return
}

Id := generateID()
_, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
Id: Id,
MainSource: sponsor.Key.PublicKey,
PublicKeys: []string{asset.Issuer.Key.PublicKey, sponsor.Key.PublicKey},
Operations: []entity.Operation{op},
})
if err != nil {
r.logger.Error(err, "http - v1 - update auth flags - send message")
r.logger.Error(err, fmt.Sprintf("http - v1 - update auth flags- send message %d", Id))
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err)
return

Expand Down
7 changes: 7 additions & 0 deletions backend/internal/controller/http/v1/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"strings"
"time"

"github.com/CheesecakeLabs/token-factory-v2/backend/internal/entity"
"github.com/bitly/go-notify"
Expand Down Expand Up @@ -109,3 +110,9 @@ func createLogDescription(transaction int, assetCode string, setFlags, clearFlag
return "Unrecognized transaction type"
}
}

// Generate ID
func generateID() int {
currentTimeInMillis := int(time.Now().UnixNano() / int64(time.Millisecond))
return currentTimeInMillis
}
8 changes: 6 additions & 2 deletions backend/internal/controller/http/v1/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,15 @@ func (r *vaultRoutes) createVault(c *gin.Context) {
})
}

Id := generateID()
res, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
Id: Id,
MainSource: sponsor.Key.PublicKey,
PublicKeys: []string{sponsor.Key.PublicKey, walletPk},
Operations: ops,
})
if err != nil {
r.l.Error(err, "http - v1 - create vault - SendMessage")
r.l.Error(err, fmt.Sprintf("http - v1 - create vault - send message %d", Id))
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err)
return
}
Expand Down Expand Up @@ -352,13 +354,15 @@ func (r *vaultRoutes) updateVaultAsset(c *gin.Context) {
}
}

Id := generateID()
res, err := r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
Id: Id,
MainSource: sponsor.Key.PublicKey,
PublicKeys: []string{sponsor.Key.PublicKey, vault.Wallet.Key.PublicKey},
Operations: ops,
})
if err != nil {
r.l.Error(err, "http - v1 - update vault asset - SendMessage")
r.l.Error(err, fmt.Sprintf("http - v1 - update vault - send message %d", Id))
errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err)
return
}
Expand Down

0 comments on commit ed05036

Please sign in to comment.