-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shed: util: get all msig #9322
Merged
Merged
shed: util: get all msig #9322
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -73,6 +73,7 @@ func main() { | |
migrationsCmd, | ||
diffCmd, | ||
itestdCmd, | ||
msigCmd, | ||
} | ||
|
||
app := &cli.App{ | ||
|
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,131 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
|
||
"github.com/filecoin-project/lotus/chain/actors/builtin" | ||
"github.com/filecoin-project/lotus/chain/actors/builtin/multisig" | ||
|
||
"github.com/filecoin-project/lotus/chain/actors/adt" | ||
"github.com/filecoin-project/lotus/chain/consensus/filcns" | ||
"github.com/filecoin-project/lotus/chain/state" | ||
"github.com/filecoin-project/lotus/chain/store" | ||
"github.com/filecoin-project/lotus/node/repo" | ||
cbor "github.com/ipfs/go-ipld-cbor" | ||
|
||
"github.com/ipfs/go-cid" | ||
"github.com/urfave/cli/v2" | ||
|
||
"github.com/filecoin-project/go-address" | ||
"github.com/filecoin-project/go-state-types/abi" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
) | ||
|
||
type msigBriefInfo struct { | ||
ID address.Address | ||
Signer interface{} | ||
Balance abi.TokenAmount | ||
Threshold uint64 | ||
} | ||
|
||
var msigCmd = &cli.Command{ | ||
Name: "msig", | ||
Subcommands: []*cli.Command{ | ||
multisigGetAllCmd, | ||
}, | ||
} | ||
|
||
var multisigGetAllCmd = &cli.Command{ | ||
Name: "all", | ||
Usage: "get all multisig actor on chain with id, siigners, threshold and balance at a tipset", | ||
ArgsUsage: "[state root]", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "repo", | ||
Value: "~/.lotus", | ||
}, | ||
}, | ||
Action: func(cctx *cli.Context) error { | ||
ctx := context.TODO() | ||
if !cctx.Args().Present() { | ||
return fmt.Errorf("must pass state root") | ||
} | ||
|
||
sroot, err := cid.Decode(cctx.Args().First()) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse input: %w", err) | ||
} | ||
|
||
fsrepo, err := repo.NewFS(cctx.String("repo")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
lkrepo, err := fsrepo.Lock(repo.FullNode) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer lkrepo.Close() //nolint:errcheck | ||
|
||
bs, err := lkrepo.Blockstore(ctx, repo.UniversalBlockstore) | ||
if err != nil { | ||
return fmt.Errorf("failed to open blockstore: %w", err) | ||
} | ||
|
||
defer func() { | ||
if c, ok := bs.(io.Closer); ok { | ||
if err := c.Close(); err != nil { | ||
log.Warnf("failed to close blockstore: %s", err) | ||
} | ||
} | ||
}() | ||
|
||
mds, err := lkrepo.Datastore(context.Background(), "/metadata") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cs := store.NewChainStore(bs, bs, mds, filcns.Weight, nil) | ||
defer cs.Close() //nolint:errcheck | ||
|
||
cst := cbor.NewCborStore(bs) | ||
store := adt.WrapStore(ctx, cst) | ||
|
||
tree, err := state.LoadStateTree(cst, sroot) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var msigActorsInfo []msigBriefInfo | ||
err = tree.ForEach(func(addr address.Address, act *types.Actor) error { | ||
if builtin.IsMultisigActor(act.Code) { | ||
ms, err := multisig.Load(store, act) | ||
if err != nil { | ||
return err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make it a practice to always wrap errors? It speeds things up when 🕵️♀️ issues. |
||
} | ||
|
||
signers, _ := ms.Signers() | ||
threshold, _ := ms.Threshold() | ||
info := msigBriefInfo{ | ||
ID: addr, | ||
Signer: signers, | ||
Balance: act.Balance, | ||
Threshold: threshold, | ||
} | ||
msigActorsInfo = append(msigActorsInfo, info) | ||
|
||
} | ||
return nil | ||
}) | ||
out, err := json.MarshalIndent(msigActorsInfo, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(string(out)) | ||
return nil | ||
}, | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.