示例#1
0
func MakeBlock(block *btcutil.Block, previous *Block) *Block {
	transactions := make([]ads.ADS, 0)
	for _, transaction := range block.Transactions() {
		t := &Transaction{
			MsgTx: *transaction.MsgTx(),
		}
		t.SetCachedHash(sha.Hash(*transaction.Sha()))

		transactions = append(transactions, t)
	}

	b := &Block{
		Header:       block.MsgBlock().Header,
		Previous:     previous,
		Transactions: transactions,
	}
	hash, _ := block.Sha()
	b.SetCachedHash(sha.Hash(*hash))

	return b
}
示例#2
0
func ProcessOutpointImpl(outpoint btcwire.OutPoint, balances bitrie.Bitrie, c comp.C) bitrie.Bitrie {
	loc := bitrie.MakeBits(sha.Hash(outpoint.Hash))

	x, found := balances.Get(loc, c)
	var oi *OutpointInfo
	if found {
		oi = x.(*OutpointInfo)
	} else {
		oi = &OutpointInfo{}
	}

	c.Use(oi)
	oi = oi.Spend(int(outpoint.Index))

	if oi.Empty() {
		return balances.Delete(loc, c)
	} else {
		return balances.Set(loc, oi, c)
	}
}
示例#3
0
文件: wire.go 项目: Roasbeef/versum
func (d *Decoder) decodePtr(v reflect.Value) {
	if value, ok := v.Interface().(ADS); ok {
		var typ int8
		d.readLE(&typ)

		if typ == 0 {
			var bytes [32]byte
			d.Read(bytes[:])
			value.SetCachedHash(sha.Hash(bytes))
			value.MakeOpaque()
			return
		}
	}

	if encodeable, ok := v.Interface().(Encodeable); ok {
		encodeable.Decode(d)
		return
	}

	d.decode(v.Elem())
}
示例#4
0
func (b *Block) ComputeHash() sha.Hash {
	hash, _ := b.Header.BlockSha()
	return sha.Hash(hash)
}
示例#5
0
func (t *Transaction) ComputeHash() sha.Hash {
	hash, _ := t.MsgTx.TxSha()
	return sha.Hash(hash)
}
示例#6
0
func GetKey(txns bitrie.Bitrie, outpoint btcwire.OutPoint, c comp.C) []byte {
	ads, _ := txns.Get(bitrie.MakeBits(sha.Hash(outpoint.Hash)), c)
	return ads.(*core.Transaction).MsgTx.TxOut[outpoint.Index].PkScript
}