Skip to content

Commit

Permalink
add string buffer for dumping
Browse files Browse the repository at this point in the history
  • Loading branch information
HanWang233 committed Jul 26, 2022
1 parent 08cee11 commit 0f11ed6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/geth-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: GethPublisher
on:
workflow_dispatch:
push:
branches: [ dev-wenhao ]
branches: [ dev-hanwang ]

env:
# Use docker.io for Docker Hub if empty
Expand Down
19 changes: 17 additions & 2 deletions core/vm/dump_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type ParityLogContext struct {

type ParityLogger struct {
context *ParityLogContext
sb *strings.Builder
encoder *json.Encoder
activePrecompiles []common.Address
file *os.File
Expand All @@ -104,14 +105,18 @@ func NewParityLogger(ctx *ParityLogContext, blockNumber uint64, perFolder, perFi
return nil, err
}

l := &ParityLogger{context: ctx, encoder: json.NewEncoder(file), file: file}
sb := &strings.Builder{}
l := &ParityLogger{context: ctx, sb: sb, encoder: json.NewEncoder(sb), file: file}
if l.context == nil {
l.context = &ParityLogContext{}
}
return l, nil
}

func (l *ParityLogger) Close() error {
if _, err := l.file.WriteString(l.sb.String()); err != nil {
return err
}
return l.file.Close()
}

Expand Down Expand Up @@ -238,7 +243,8 @@ func ReceiptDumpLogger(blockNumber uint64, perFolder, perFile uint64, receipts t
return err
}

encoder := json.NewEncoder(file)
sb := &strings.Builder{}
encoder := json.NewEncoder(sb)
for _, receipt := range receipts {
for _, log := range receipt.Logs {
err := encoder.Encode(log)
Expand All @@ -247,12 +253,16 @@ func ReceiptDumpLogger(blockNumber uint64, perFolder, perFile uint64, receipts t
}
}
}
if _, err := file.WriteString(sb.String()); err != nil {
return err
}
return nil
}

type TxLogger struct {
blockNumber uint64
blockHash common.Hash
sb *strings.Builder
file *os.File
encoder *json.Encoder
signer types.Signer
Expand All @@ -265,10 +275,12 @@ func NewTxLogger(signer types.Signer, isLondon bool, baseFee *big.Int, blockHash
if err != nil {
return nil, err
}
sb := &strings.Builder{}
return &TxLogger{
blockNumber: blockNumber,
blockHash: blockHash,
file: file,
sb: sb,
encoder: json.NewEncoder(file),
signer: signer,
isLondon: isLondon,
Expand Down Expand Up @@ -311,6 +323,9 @@ func (t *TxLogger) Dump(index int, tx *types.Transaction, receipt *types.Receipt
}

func (t *TxLogger) Close() error {
if _, err := t.file.WriteString(t.sb.String()); err != nil {
return err
}
return t.file.Close()
}

Expand Down

0 comments on commit 0f11ed6

Please sign in to comment.