explore.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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/storage"
  24. "gopkg.in/urfave/cli.v1"
  25. )
  26. var hashesCommand = cli.Command{
  27. Action: hashes,
  28. CustomHelpTemplate: helpTemplate,
  29. Name: "hashes",
  30. Usage: "print all hashes of a file to STDOUT",
  31. ArgsUsage: "<file>",
  32. Description: "Prints all hashes of a file to STDOUT",
  33. }
  34. func hashes(ctx *cli.Context) {
  35. args := ctx.Args()
  36. if len(args) < 1 {
  37. utils.Fatalf("Usage: swarm hashes <file name>")
  38. }
  39. f, err := os.Open(args[0])
  40. if err != nil {
  41. utils.Fatalf("Error opening file " + args[1])
  42. }
  43. defer f.Close()
  44. fileStore := storage.NewFileStore(&storage.FakeChunkStore{}, storage.NewFileStoreParams())
  45. refs, err := fileStore.GetAllReferences(context.TODO(), f, false)
  46. if err != nil {
  47. utils.Fatalf("%v\n", err)
  48. } else {
  49. for _, r := range refs {
  50. fmt.Println(r.String())
  51. }
  52. }
  53. }