Skip to content

Commit

Permalink
Merge pull request #114 from CheesecakeLabs/feat_log_fee_charged
Browse files Browse the repository at this point in the history
Fee charged log
  • Loading branch information
lucasmagnus authored Feb 19, 2024
2 parents bb60c38 + c5d5558 commit b7e80ec
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 22 deletions.
30 changes: 21 additions & 9 deletions backend/internal/controller/http/v1/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ import (
"github.com/gin-gonic/gin"
)



type assetsRoutes struct {
w usecase.WalletUseCase
as usecase.AssetUseCase
m HTTPControllerMessenger
a usecase.AuthUseCase
l usecase.LogTransactionUseCase
logger *logger.Logger
pf profanity.ProfanityFilter
pf profanity.ProfanityFilter
}

func newAssetTomlRoutes(handler *gin.RouterGroup, w usecase.WalletUseCase, as usecase.AssetUseCase, m HTTPControllerMessenger, a usecase.AuthUseCase, l usecase.LogTransactionUseCase, logger *logger.Logger, pf profanity.ProfanityFilter) {
Expand Down Expand Up @@ -256,7 +254,7 @@ func (r *assetsRoutes) createAsset(c *gin.Context) {
}

Id := generateID()
_, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
response, err := r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
Id: Id,
MainSource: sponsor.Key.PublicKey,
PublicKeys: []string{sponsor.Key.PublicKey, distPk, issuerPk},
Expand Down Expand Up @@ -317,6 +315,7 @@ func (r *assetsRoutes) createAsset(c *gin.Context) {
return
}

feeCharged := response.Message.(entity.EnvelopeResponse).FeeCharged
amount, err := strconv.ParseFloat(request.Amount, 64)
if err != nil {
amount = 0
Expand All @@ -327,6 +326,7 @@ func (r *assetsRoutes) createAsset(c *gin.Context) {
TransactionTypeID: entity.CreateAsset,
UserID: userID,
Description: createLogDescription(entity.CreateAsset, asset.Code, nil, nil),
FeeCharged: &feeCharged,
})
if err != nil {
r.logger.Error(err, "http - v1 - create asset - create log transaction")
Expand Down Expand Up @@ -429,7 +429,7 @@ func (r *assetsRoutes) mintAsset(c *gin.Context) {
},
}
Id := generateID()
_, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
response, err := r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
Id: Id,
MainSource: asset.Issuer.Key.PublicKey,
PublicKeys: []string{asset.Issuer.Key.PublicKey},
Expand All @@ -442,6 +442,7 @@ func (r *assetsRoutes) mintAsset(c *gin.Context) {
return
}

feeCharged := response.Message.(entity.EnvelopeResponse).FeeCharged
amount, err := strconv.ParseFloat(request.Amount, 64)
if err != nil {
amount = 0
Expand All @@ -455,6 +456,7 @@ func (r *assetsRoutes) mintAsset(c *gin.Context) {
Description: createLogDescription(entity.MintAsset, asset.Code, nil, nil),
CurrentSupply: &request.CurrentSupply,
CurrentMainVault: &request.CurrentMainVault,
FeeCharged: &feeCharged,
})
if err != nil {
r.logger.Error(err, "http - v1 - mint asset - create log transaction")
Expand Down Expand Up @@ -532,7 +534,7 @@ func (r *assetsRoutes) burnAsset(c *gin.Context) {
}

Id := generateID()
_, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
response, err := r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
Id: Id,
MainSource: asset.Distributor.Key.PublicKey,
PublicKeys: []string{asset.Distributor.Key.PublicKey},
Expand All @@ -545,6 +547,7 @@ func (r *assetsRoutes) burnAsset(c *gin.Context) {
return
}

feeCharged := response.Message.(entity.EnvelopeResponse).FeeCharged
amount, err := strconv.ParseFloat(request.Amount, 64)
if err != nil {
amount = 0
Expand All @@ -557,6 +560,7 @@ func (r *assetsRoutes) burnAsset(c *gin.Context) {
Description: createLogDescription(entity.BurnAsset, asset.Code, nil, nil),
CurrentSupply: &request.CurrentSupply,
CurrentMainVault: &request.CurrentMainVault,
FeeCharged: &feeCharged,
})
if err != nil {
r.logger.Error(err, "http - v1 - burn asset - create log transaction")
Expand Down Expand Up @@ -643,7 +647,7 @@ func (r *assetsRoutes) transferAsset(c *gin.Context) {
}

Id := generateID()
_, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
response, err := r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
Id: Id,
MainSource: sourceWallet.Key.PublicKey,
PublicKeys: []string{sourceWallet.Key.PublicKey},
Expand All @@ -656,6 +660,7 @@ func (r *assetsRoutes) transferAsset(c *gin.Context) {
return
}

feeCharged := response.Message.(entity.EnvelopeResponse).FeeCharged
amount, err := strconv.ParseFloat(request.Amount, 64)
if err != nil {
amount = 0
Expand All @@ -670,6 +675,7 @@ func (r *assetsRoutes) transferAsset(c *gin.Context) {
DestinationPK: &request.DestinationWalletPK,
CurrentSupply: &request.CurrentSupply,
CurrentMainVault: &request.CurrentMainVault,
FeeCharged: &feeCharged,
})
if err != nil {
r.logger.Error(err, "http - v1 - transfer asset - create log transaction")
Expand Down Expand Up @@ -750,7 +756,7 @@ func (r *assetsRoutes) clawbackAsset(c *gin.Context) {
}

Id := generateID()
_, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
response, err := r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
Id: Id,
MainSource: sponsor.Key.PublicKey,
PublicKeys: []string{asset.Issuer.Key.PublicKey, sponsor.Key.PublicKey},
Expand All @@ -763,6 +769,7 @@ func (r *assetsRoutes) clawbackAsset(c *gin.Context) {
return
}

feeCharged := response.Message.(entity.EnvelopeResponse).FeeCharged
amount, err := strconv.ParseFloat(request.Amount, 64)
if err != nil {
amount = 0
Expand All @@ -775,6 +782,8 @@ func (r *assetsRoutes) clawbackAsset(c *gin.Context) {
Description: createLogDescription(entity.ClawbackAsset, asset.Code, nil, nil),
CurrentSupply: &request.CurrentSupply,
CurrentMainVault: &request.CurrentMainVault,
DestinationPK: &request.From,
FeeCharged: &feeCharged,
})
if err != nil {
r.logger.Error(err, "http - v1 - clawback asset - create log transaction")
Expand Down Expand Up @@ -859,7 +868,7 @@ func (r *assetsRoutes) updateAuthFlags(c *gin.Context) {
}

Id := generateID()
_, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
response, err := r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
Id: Id,
MainSource: sponsor.Key.PublicKey,
PublicKeys: []string{asset.Issuer.Key.PublicKey, sponsor.Key.PublicKey},
Expand All @@ -873,11 +882,14 @@ func (r *assetsRoutes) updateAuthFlags(c *gin.Context) {

}

feeCharged := response.Message.(entity.EnvelopeResponse).FeeCharged
err = r.l.CreateLogTransaction(entity.LogTransaction{
Asset: asset,
TransactionTypeID: entity.UpdateAuthFlags,
UserID: userID,
Description: createLogDescription(entity.UpdateAuthFlags, asset.Code, request.SetFlags, request.ClearFlags),
DestinationPK: &request.TrustorPK,
FeeCharged: &feeCharged,
})
if err != nil {
r.logger.Error(err, "http - v1 - update auth flags - create log transaction")
Expand Down
10 changes: 4 additions & 6 deletions backend/internal/controller/http/v1/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/gin-gonic/gin"
)


type vaultRoutes struct {
m HTTPControllerMessenger
a usecase.AuthUseCase
Expand Down Expand Up @@ -133,12 +132,12 @@ func (r *vaultRoutes) createVault(c *gin.Context) {
},
})


ops := []entity.Operation{
{
Type: entity.CreateAccountOp,
Target: walletPk,
Amount: _startingBalance,
Type: entity.CreateAccountOp,
Target: walletPk,
//Amount: _startingBalance,
Amount: "10",
Sponsor: sponsor.Key.PublicKey,
Origin: sponsor.Key.PublicKey,
},
Expand All @@ -163,7 +162,6 @@ func (r *vaultRoutes) createVault(c *gin.Context) {
})
}


Id := generateID()
res, err = r.m.SendMessage(entity.EnvelopeChannel, entity.EnvelopeRequest{
Id: Id,
Expand Down
11 changes: 7 additions & 4 deletions backend/internal/entity/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type (
Hash string `json:"hash"`
StatusCode int `json:"statusCode"`
Error interface{} `json:"error"`
FeeCharged int64 `json:"feeCharged"`
}

Operation struct {
Expand Down Expand Up @@ -77,10 +78,12 @@ type (
}

SignTransactionRequest struct {
Id int `json:"id"`
Envelope string `json:"envelope"`
PublicKeys []string `json:"publicKeys"`
Hash string `json:"hash"`
Id int `json:"id"`
Envelope string `json:"envelope"`
PublicKeys []string `json:"publicKeys"`
Hash string `json:"hash"`
FeeBump bool `json:"feeBump"`
FeeBumpProcessingState string `json:"feeBumpProcessingState"`
}

SorobanTransactionResponse struct {
Expand Down
1 change: 1 addition & 0 deletions backend/internal/entity/transaction_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type LogTransaction struct {
DestinationPK *string `json:"destination_pk" example:"GSDC..."`
CurrentSupply *float64 `json:"current_supply" example:"1000"`
CurrentMainVault *float64 `json:"current_main_vault" example:"1000"`
FeeCharged *int64 `json:"fee_charged" example:"1000"`
}

type SumLogTransaction struct {
Expand Down
6 changes: 3 additions & 3 deletions backend/internal/usecase/repo/log_transaction_postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func NewLogTransactionRepo(postgres *postgres.Postgres) *LogTransactionRepo {
}

func (repo *LogTransactionRepo) StoreLogTransaction(log entity.LogTransaction) error {
stmp := `INSERT INTO logtransactions (user_id, transaction_type_id, asset_id, amount, description, origin_pk, destination_pk, current_supply, current_main_vault)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`
stmp := `INSERT INTO logtransactions (user_id, transaction_type_id, asset_id, amount, description, origin_pk, destination_pk, current_supply, current_main_vault, fee_charged)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`
_, err := repo.Db.Exec(stmp, log.UserID, log.TransactionTypeID, log.Asset.Id, log.Amount, log.Description, log.OriginPK, log.DestinationPK,
log.CurrentSupply, log.CurrentMainVault)
log.CurrentSupply, log.CurrentMainVault, log.FeeCharged)
if err != nil {
fmt.Println(err)
return err
Expand Down
2 changes: 2 additions & 0 deletions backend/migrations/000045_add_column_fee_transaction.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Migration Down Script
ALTER TABLE LogTransactions DROP COLUMN fee_charged;
2 changes: 2 additions & 0 deletions backend/migrations/000045_add_column_fee_transaction.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Migration Up Script
ALTER TABLE LogTransactions ADD COLUMN fee_charged FLOAT;

0 comments on commit b7e80ec

Please sign in to comment.