This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: import car and dispatch result (#210)
- Loading branch information
Showing
9 changed files
with
464 additions
and
15 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
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,59 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"flag" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/myelnet/pop/node" | ||
"github.com/peterbourgon/ff/v3/ffcli" | ||
) | ||
|
||
var importArgs struct { | ||
cacheRF int | ||
} | ||
|
||
var importCmd = &ffcli.Command{ | ||
Name: "import", | ||
ShortUsage: "import <path>", | ||
ShortHelp: "Import a CAR file to the blockstore", | ||
LongHelp: strings.TrimSpace(` | ||
The 'pop import <path-to-car>' directly imports archived DAGs to the blockstore. | ||
`), | ||
Exec: runImport, | ||
FlagSet: (func() *flag.FlagSet { | ||
fs := flag.NewFlagSet("import", flag.ExitOnError) | ||
fs.IntVar(&importArgs.cacheRF, "cache-rf", 0, "number of providers to replicate the content to") | ||
return fs | ||
})(), | ||
} | ||
|
||
func runImport(ctx context.Context, args []string) error { | ||
c, cc, ctx, cancel := connect(ctx) | ||
defer cancel() | ||
|
||
irc := make(chan *node.ImportResult, 1) | ||
cc.SetNotifyCallback(func(n node.Notify) { | ||
if ir := n.ImportResult; ir != nil { | ||
irc <- ir | ||
} | ||
}) | ||
go receive(ctx, cc, c) | ||
|
||
cc.Import(&node.ImportArgs{Path: args[0], CacheRF: importArgs.cacheRF}) | ||
select { | ||
case ir := <-irc: | ||
if ir.Err != "" { | ||
return errors.New(ir.Err) | ||
} | ||
|
||
fmt.Println("Imported car with roots", ir.Roots) | ||
return nil | ||
case <-ctx.Done(): | ||
return ctx.Err() | ||
} | ||
} |
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
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
Binary file not shown.
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
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
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