func merkleRoot(data [][]byte) (types.Hash, error) { tree := merkle.NewTree() err := tree.Generate(data, fastsha256.New()) if err != nil { return types.EmptyHash(), err } return tree.Root().Hash, err }
// DoubleSha256 calculates sha256(sha256(b)) and returns the resulting bytes. func DoubleSha256(b []byte) []byte { hasher := fastsha256.New() hasher.Write(b) sum := hasher.Sum(nil) hasher.Reset() hasher.Write(sum) return hasher.Sum(nil) }
func merkleRoot(data [][]byte) (types.Hash, error) { if len(data) == 1 { // FIXME: a workaround for trees with one element data = append(data, []byte{}) } tree := merkle.NewTree() err := tree.Generate(data, fastsha256.New()) if err != nil { return types.EmptyHash(), err } return types.NewHash(tree.Root().Hash), err }
func NewCoin(index int64, value btcutil.Amount, numConfs int64) coinset.Coin { h := fastsha256.New() h.Write([]byte(fmt.Sprintf("%d", index))) hash, _ := btcwire.NewShaHash(h.Sum(nil)) c := &TestCoin{ TxHash: hash, TxIndex: 0, TxValue: value, TxNumConfs: numConfs, } return coinset.Coin(c) }
func main() { lines := bufio.NewReader(os.Stdin) hasher := fastsha256.New() for { line, _, err := lines.ReadLine() if err != nil { break } hasher.Reset() hasher.Write(line) sum := hasher.Sum(nil) _, pub := btcec.PrivKeyFromBytes(btcec.S256(), sum) var apk, _ = btcutil.NewAddressPubKey(pub.SerializeUncompressed(), btcwire.MainNet) fmt.Println(apk.EncodeAddress()) apk, _ = btcutil.NewAddressPubKey(pub.SerializeCompressed(), btcwire.MainNet) fmt.Println(apk.EncodeAddress()) } }
// Hash160 calculates the hash ripemd160(sha256(b)). func Hash160(buf []byte) []byte { return calcHash(calcHash(buf, fastsha256.New()), ripemd160.New()) }