Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
envestcc committed Sep 6, 2024
1 parent a9748dd commit 022b1ab
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions blockchain/filedao/sized.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package filedao

import (
"bytes"
"context"
"math/big"
"os"
"slices"
"sync"

"github.com/holiman/billy"
Expand Down Expand Up @@ -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
}

0 comments on commit 022b1ab

Please sign in to comment.