explore.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2019 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // go-ethereum is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  16. // Command bzzhash computes a swarm tree hash.
  17. package main
  18. import (
  19. "context"
  20. "fmt"
  21. "os"
  22. "github.com/ethereum/go-ethereum/cmd/utils"
  23. "github.com/ethereum/go-ethereum/swarm/chunk"
  24. "github.com/ethereum/go-ethereum/swarm/storage"
  25. "gopkg.in/urfave/cli.v1"
  26. )
  27. var hashesCommand = cli.Command{
  28. Action: hashes,
  29. CustomHelpTemplate: helpTemplate,
  30. Name: "hashes",
  31. Usage: "print all hashes of a file to STDOUT",
  32. ArgsUsage: "<file>",
  33. Description: "Prints all hashes of a file to STDOUT",
  34. }
  35. func hashes(ctx *cli.Context) {
  36. args := ctx.Args()
  37. if len(args) < 1 {
  38. utils.Fatalf("Usage: swarm hashes <file name>")
  39. }
  40. f, err := os.Open(args[0])
  41. if err != nil {
  42. utils.Fatalf("Error opening file " + args[1])
  43. }
  44. defer f.Close()
  45. fileStore := storage.NewFileStore(&storage.FakeChunkStore{}, storage.NewFileStoreParams(), chunk.NewTags())
  46. refs, err := fileStore.GetAllReferences(context.TODO(), f, false)
  47. if err != nil {
  48. utils.Fatalf("%v\n", err)
  49. } else {
  50. for _, r := range refs {
  51. fmt.Println(r.String())
  52. }
  53. }
  54. }