github.com/pslzym/go-ethereum@v1.8.17-0.20180926104442-4b6824e07b1b/cmd/swarm/hash.go (about) 1 // Copyright 2016 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 func hash(ctx *cli.Context) { 31 args := ctx.Args() 32 if len(args) < 1 { 33 utils.Fatalf("Usage: swarm hash <file name>") 34 } 35 f, err := os.Open(args[0]) 36 if err != nil { 37 utils.Fatalf("Error opening file " + args[1]) 38 } 39 defer f.Close() 40 41 stat, _ := f.Stat() 42 fileStore := storage.NewFileStore(&storage.FakeChunkStore{}, storage.NewFileStoreParams()) 43 addr, _, err := fileStore.Store(context.TODO(), f, stat.Size(), false) 44 if err != nil { 45 utils.Fatalf("%v\n", err) 46 } else { 47 fmt.Printf("%v\n", addr) 48 } 49 }