示例#1
0
func (inv *Inventory) addTxData(hash []byte, data *messages.Transaction) {
	version, found := inv.txHashes[string(hash)]
	if !found {
		id := data.Fingerprint()
		log.Printf("Adding transaction hash %x for transaction %x", hash, id)
		version = &TxVersion{Hash: hash, tx: data}
		inv.txHashes[string(hash)] = version
		inv.config.Database.StoreNewTransaction(version)
	} else if version.tx == nil {
		version.tx = data
		inv.config.Database.StoreNewTransaction(version)
		if version.Block != nil {
			// This tx was confirmed earlier, but couldn't
			// invalidate duplicates until now; confirm it again.
			inv.transactionVersionConfirmed(version)
		}
	}
	tx, found := inv.transactions[string(version.Id())]
	if !found {
		log.Printf("Adding hash %x to transaction %x", hash, version.Id())
		tx = &Transaction{
			id:        version.Id(),
			timestamp: time.Now(),
			versions:  make(map[string]*messages.Transaction),
			block:     version.Block,
		}
		inv.transactions[string(version.Id())] = tx
	} else if tx.block != nil {
		// Another version of this transaction has already been confirmed.
		return
	}
	tx.versions[string(hash)] = data
	inv.UpdateTxOutputs(version)

	// Add transaction to filter. Remote nodes will do the same, so there's
	// no need to update them.
	inv.filter.Watch(hash, filterNoUpdateNeeded)
	// TODO verify TX
}