From 17ffccc8d478ff9791eb4f5079796edf72213e4e Mon Sep 17 00:00:00 2001 From: zale144 Date: Tue, 17 Sep 2024 23:47:45 +0200 Subject: [PATCH] Fix fee parsing --- order_eventer.go | 13 ++++++++----- order_fulfiller.go | 2 +- order_poller.go | 11 +++++++---- types.go | 3 +++ 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/order_eventer.go b/order_eventer.go index a338b8e..860f520 100644 --- a/order_eventer.go +++ b/order_eventer.go @@ -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 { @@ -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) { diff --git a/order_fulfiller.go b/order_fulfiller.go index 7e291c4..23952d0 100644 --- a/order_fulfiller.go +++ b/order_fulfiller.go @@ -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...) diff --git a/order_poller.go b/order_poller.go index b728fe9..b385ee8 100644 --- a/order_poller.go +++ b/order_poller.go @@ -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{ diff --git a/types.go b/types.go index 97fab3d..e9fbd5f 100644 --- a/types.go +++ b/types.go @@ -16,6 +16,7 @@ type demandOrder struct { denom string amount sdk.Coins fee sdk.Coins + feeStr string rollappId string status string blockHeight uint64 @@ -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