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