Beispiel #1
0
func ProcessTransactionImpl(transaction *Transaction, balances bitrie.Bitrie, c comp.C) bitrie.Bitrie {
	c.Use(transaction, balances)

	for _, input := range transaction.MsgTx.TxIn {
		if (input.PreviousOutpoint.Hash == btcwire.ShaHash{}) {
			continue
		}

		balances = ProcessOutpoint(input.PreviousOutpoint, balances, c)
	}

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

	c.Use(oi)

	oi = oi.Add(len(transaction.MsgTx.TxOut))
	return balances.Set(loc, oi, c)
}
Beispiel #2
0
func randomBalance(balances bitrie.Bitrie, c comp.C) int {
	key := core.RandomKey(bitrie.Bits{}, balances, c)

	trackc := verified.NewTrackC(c)
	info, found := balances.Get(key, trackc)
	if !found {
		panic(key)
	}

	oi := info.(*core.OutpointInfo)
	trackc.Use(oi)

	return computeSize(balances, trackc)
}
Beispiel #3
0
func ProcessTxnImpl(txn *core.Transaction, txns, regs bitrie.Bitrie, c comp.C) (bitrie.Bitrie, bitrie.Bitrie) {
	c.Use(txn)

	txns = txns.Set(bitrie.MakeBits(txn.ComputeHash()), txn, c)

	if len(txn.MsgTx.TxOut) != 1 {
		return txns, regs
	}

	script := txn.MsgTx.TxOut[0].PkScript
	if len(script) < 1 || script[0] != btcscript.OP_RETURN {
		return txns, regs
	}

	data := script[1:]
	if len(data) != 40 {
		return txns, regs
	}

	if !bytes.Equal(data[0:8], tag) {
		return txns, regs
	}

	loc := bitrie.MakeBits(sha.Sum(data[8:40]))

	ads, found := regs.Get(loc, c)
	claim := ads.(*Claim)

	// two types of txns: register and transfer
	if len(txn.MsgTx.TxIn) == 1 {
		if found {
			return txns, regs
		}

		key := GetKey(txns, txn.MsgTx.TxIn[0].PreviousOutpoint, c)
		regs = regs.Set(loc, &Claim{Key: key}, c)
	}

	if len(txn.MsgTx.TxIn) == 2 {
		if !found {
			return txns, regs
		}

		from := GetKey(txns, txn.MsgTx.TxIn[0].PreviousOutpoint, c)

		if !bytes.Equal(from, claim.Key) {
			return txns, regs
		}

		to := GetKey(txns, txn.MsgTx.TxIn[1].PreviousOutpoint, c)
		regs = regs.Set(loc, &Claim{Key: to}, c)
	}

	return txns, regs
}
Beispiel #4
0
func ProcessOutputImpl(t *core.Transaction, output *btcwire.TxOut, txns bitrie.Bitrie, c comp.C) bitrie.Bitrie {
	hash := sha.Sum(output.PkScript)

	loc := bitrie.MakeBits(hash)

	x, found := txns.Get(loc, c)
	var tc *TxnChain
	if found {
		tc = x.(*TxnChain)
	} else {
		tc = nil
	}

	tc = &TxnChain{
		Next: tc,
		Txn:  t,
	}
	return txns.Set(loc, tc, c)
}
Beispiel #5
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)
	}
}
Beispiel #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
}