Skip to content

Commit

Permalink
Fix fee parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
zale144 committed Sep 17, 2024
1 parent adaf333 commit 17ffccc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
13 changes: 8 additions & 5 deletions order_eventer.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (e *orderEventer) parseOrdersFromEvents(res tmtypes.ResultEvent) []*demandO
prices := res.Events[createdEvent+".price"]
fees := res.Events[createdEvent+".fee"]
statuses := res.Events[createdEvent+".packet_status"]
rollapps := res.Events[createdEvent+".rollapp_id"]
newOrders := make([]*demandOrder, 0, len(ids))

for i, id := range ids {
Expand All @@ -110,11 +111,13 @@ func (e *orderEventer) parseOrdersFromEvents(res tmtypes.ResultEvent) []*demandO
}

order := &demandOrder{
id: id,
denom: fee.GetDenomByIndex(0),
amount: price,
fee: fee,
status: statuses[i],
id: id,
denom: fee.GetDenomByIndex(0),
amount: price,
fee: fee,
status: statuses[i],
rollappId: rollapps[i],
// blockHeight: height,
}

if !e.canFulfillOrder(order) {
Expand Down
2 changes: 1 addition & 1 deletion order_fulfiller.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (ol *orderFulfiller) fulfillDemandOrders(demandOrder ...*demandOrder) error
msgs := make([]sdk.Msg, len(demandOrder))

for i, order := range demandOrder {
msgs[i] = types.NewMsgFulfillOrder(ol.accountSvc.account.GetAddress().String(), order.id, order.fee.String())
msgs[i] = types.NewMsgFulfillOrder(ol.accountSvc.account.GetAddress().String(), order.id, order.feeStr)
}

_, err := ol.client.BroadcastTx(ol.accountSvc.accountName, msgs...)
Expand Down
11 changes: 7 additions & 4 deletions order_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,13 @@ func (p *orderPoller) convertOrders(demandOrders []Order) (orders []*demandOrder
continue
}

blockHeight, err := strconv.ParseUint(order.BlockHeight, 10, 64)
if err != nil {
p.logger.Error("failed to parse block height", zap.Error(err))
continue
var blockHeight uint64
if order.BlockHeight != "" {
blockHeight, err = strconv.ParseUint(order.BlockHeight, 10, 64)
if err != nil {
p.logger.Error("failed to parse block height", zap.Error(err))
continue
}
}

newOrder := &demandOrder{
Expand Down
3 changes: 3 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type demandOrder struct {
denom string
amount sdk.Coins
fee sdk.Coins
feeStr string
rollappId string
status string
blockHeight uint64
Expand All @@ -37,6 +38,8 @@ func (o *demandOrder) feePercentage() float32 {
panic(err)
}

o.feeStr = fee.String()

feeProportion, _ := new(big.Float).Quo(fee, price).Float32()
feePercent := feeProportion * 100
return feePercent
Expand Down

0 comments on commit 17ffccc

Please sign in to comment.