github.com/XinFinOrg/xdcchain@v1.1.0/cmd/swarm/explore.go (about) 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 17 // Command bzzhash computes a swarm tree hash. 18 package main 19 20 import ( 21 "context" 22 "fmt" 23 "os" 24 25 "github.com/ethereum/go-ethereum/cmd/utils" 26 "github.com/ethereum/go-ethereum/swarm/storage" 27 "gopkg.in/urfave/cli.v1" 28 ) 29 30 var hashesCommand = cli.Command{ 31 Action: hashes, 32 CustomHelpTemplate: helpTemplate, 33 Name: "hashes", 34 Usage: "print all hashes of a file to STDOUT", 35 ArgsUsage: "<file>", 36 Description: "Prints all hashes of a file to STDOUT", 37 } 38 39 func hashes(ctx *cli.Context) { 40 args := ctx.Args() 41 if len(args) < 1 { 42 utils.Fatalf("Usage: swarm hashes <file name>") 43 } 44 f, err := os.Open(args[0]) 45 if err != nil { 46 utils.Fatalf("Error opening file " + args[1]) 47 } 48 defer f.Close() 49 50 fileStore := storage.NewFileStore(&storage.FakeChunkStore{}, storage.NewFileStoreParams()) 51 refs, err := fileStore.GetAllReferences(context.TODO(), f, false) 52 if err != nil { 53 utils.Fatalf("%v\n", err) 54 } else { 55 for _, r := range refs { 56 fmt.Println(r.String()) 57 } 58 } 59 }