Skip to content

Commit

Permalink
MOD: bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pando-ci authored and cw35 committed Dec 22, 2023
1 parent 15729a9 commit 087e5a1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
8 changes: 4 additions & 4 deletions core/token_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
type (
TokenItem struct {
AssetID string `json:"asset_id,omitempty"`
AssetKey string `json:"asset_key"`
Name string `json:"name"`
Symbol string `json:"symbol"`
TotalSupply uint64 `json:"total_supply"`
AssetKey string `json:"asset_key,omitempty"`
Name string `json:"name,omitempty"`
Symbol string `json:"symbol,omitempty"`
TotalSupply uint64 `json:"total_supply,omitempty"`
}

TokenItems []*TokenItem
Expand Down
14 changes: 7 additions & 7 deletions handler/order/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,19 @@ func HandleCreateOrder(

if order.ID == 0 {
order = &core.Order{
Version: 1,
TraceID: body.TraceID,
State: core.OrderStateNew,
FeeAsset: factory.GasAsset(),
Platform: body.Platform,
Tokens: tokens,
Version: 1,
TraceID: body.TraceID,
State: core.OrderStateNew,
FeeAsset: factory.GasAsset(),
Platform: body.Platform,
TokenRequests: tokens,
}
if err := orders.Create(ctx, order); err != nil {
render.Error(w, twirp.InternalErrorWith(err))
return
}
} else {
t1, _ := core.EncodeTokens(order.Tokens)
t1, _ := core.EncodeTokens(order.TokenRequests)
t2, _ := core.EncodeTokens(tokens)
if !bytes.Equal(t1, t2) {
render.Error(w, twirp.NewErrorf(twirp.AlreadyExists, "order with trace already exists"))
Expand Down
10 changes: 7 additions & 3 deletions store/asset/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ type assetStore struct {
}

func (s *assetStore) Save(ctx context.Context, asset *core.Asset) error {
return s.db.Update().Model(asset).Assign(toUpdateParams(asset)).FirstOrCreate(asset).Error
return s.db.Update().Model(asset).
Where("asset_id = ?", asset.AssetID).
Assign(toUpdateParams(asset)).FirstOrCreate(asset).Error
}

func (s *assetStore) Find(ctx context.Context, ids ...string) ([]*core.Asset, error) {
Expand All @@ -56,8 +58,10 @@ func (s *assetStore) ListAll(ctx context.Context) ([]*core.Asset, error) {

func toUpdateParams(asset *core.Asset) map[string]interface{} {
params := map[string]interface{}{
"version": asset.Version + 1,
"verified": asset.Verified,
"version": asset.Version + 1,
}
if asset.Verified {
params["verified"] = asset.Verified
}
if asset.DisplaySymbol != "" {
params["display_symbol"] = asset.DisplaySymbol
Expand Down

0 comments on commit 087e5a1

Please sign in to comment.