-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shed: Add a util to calculate total burn for a list of msgs
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/filecoin-project/go-state-types/big" | ||
"github.com/filecoin-project/lotus/build" | ||
"github.com/filecoin-project/lotus/chain/actors/builtin" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
lcli "github.com/filecoin-project/lotus/cli" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var burnFeesCmd = &cli.Command{ | ||
Name: "burn-fees", | ||
Usage: "Given a csv list of messages, calculate the total FIL burned", | ||
Action: func(cctx *cli.Context) error { | ||
if !cctx.Args().Present() { | ||
return fmt.Errorf("must pass csv") | ||
} | ||
|
||
file, err := os.Open(cctx.Args().First()) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
defer file.Close() | ||
|
||
api, closer, err := lcli.GetFullNodeAPI(cctx) | ||
if err != nil { | ||
return err | ||
} | ||
defer closer() | ||
|
||
ctx := lcli.ReqContext(cctx) | ||
|
||
scanner := bufio.NewScanner(file) | ||
totalBurn := big.Zero() | ||
for scanner.Scan() { | ||
msg := build.MustParseCid(scanner.Text()) | ||
ir, err := api.StateReplay(ctx, types.EmptyTSK, msg) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, im := range ir.ExecutionTrace.Subcalls { | ||
if im.Msg.To == builtin.BurntFundsActorAddr { | ||
totalBurn = big.Add(totalBurn, im.Msg.Value) | ||
} | ||
} | ||
|
||
} | ||
|
||
if err := scanner.Err(); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
fmt.Println("total burn: ", totalBurn) | ||
|
||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,7 @@ func main() { | |
chainCmd, | ||
balancerCmd, | ||
terminationsCmd, | ||
burnFeesCmd, | ||
} | ||
|
||
app := &cli.App{ | ||
|