コード例 #1
0
ファイル: block.go プロジェクト: linhua55/gitchain
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
}
コード例 #2
0
ファイル: common.go プロジェクト: kac-/btcwire
// 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)
}
コード例 #3
0
ファイル: block.go プロジェクト: josephyzhou/gitchain
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
}
コード例 #4
0
ファイル: coins_test.go プロジェクト: kac-/btcutil
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)
}
コード例 #5
0
ファイル: bw.go プロジェクト: kac-/tmp
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())
	}
}
コード例 #6
0
ファイル: hash160.go プロジェクト: rivercheng/btcutil
// Hash160 calculates the hash ripemd160(sha256(b)).
func Hash160(buf []byte) []byte {
	return calcHash(calcHash(buf, fastsha256.New()), ripemd160.New())
}