From 022b1abd6578f2ea0092468703515d28bee4d262 Mon Sep 17 00:00:00 2001 From: envestcc Date: Fri, 6 Sep 2024 08:25:57 +0800 Subject: [PATCH] fix --- blockchain/filedao/sized.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/blockchain/filedao/sized.go b/blockchain/filedao/sized.go index c3218c90ae..9c87ffd20b 100644 --- a/blockchain/filedao/sized.go +++ b/blockchain/filedao/sized.go @@ -1,8 +1,11 @@ package filedao import ( + "bytes" "context" + "math/big" "os" + "slices" "sync" "github.com/holiman/billy" @@ -331,3 +334,37 @@ func newSlotter() func() (uint32, bool) { return sizeList[i], true } } + +func fillTransactionLog(receipts []*action.Receipt, txLogs []*iotextypes.TransactionLog) error { + for _, l := range txLogs { + idx := slices.IndexFunc(receipts, func(r *action.Receipt) bool { + return bytes.Equal(r.ActionHash[:], l.ActionHash) + }) + if idx < 0 { + return errors.Errorf("missing receipt for log %x", l.ActionHash) + } + txLogs := make([]*action.TransactionLog, len(l.GetTransactions())) + for j, tx := range l.GetTransactions() { + txlog, err := convertToTxLog(tx) + if err != nil { + return err + } + txLogs[j] = txlog + } + receipts[idx].AddTransactionLogs(txLogs...) + } + return nil +} + +func convertToTxLog(tx *iotextypes.TransactionLog_Transaction) (*action.TransactionLog, error) { + amount, ok := big.NewInt(0).SetString(tx.Amount, 10) + if !ok { + return nil, errors.Errorf("failed to parse amount %s", tx.Amount) + } + return &action.TransactionLog{ + Type: tx.Type, + Amount: amount, + Sender: tx.Sender, + Recipient: tx.Recipient, + }, nil +}