Exemplo n.º 1
0
// Creates an unconfirmed transaction
func (self *UnconfirmedTxnPool) createUnconfirmedTxn(bcUnsp *coin.UnspentPool,
	t coin.Transaction, addrs map[coin.Address]byte) UnconfirmedTxn {
	now := util.Now()
	ut := UnconfirmedTxn{
		Txn:          t,
		Received:     now,
		Checked:      now,
		Announced:    util.ZeroTime(),
		IsOurReceive: false,
		IsOurSpend:   false,
	}

	// Check if this unspent is related to us
	if addrs != nil {
		// Check if this is one of our receiving txns
		for i, _ := range t.Out {
			if _, ok := addrs[t.Out[i].Address]; ok {
				ut.IsOurReceive = true
				break
			}
		}
		// Check if this is one of our spending txns
		for i, _ := range t.In {
			if ux, ok := bcUnsp.Get(t.In[i]); ok {
				if _, ok := addrs[ux.Body.Address]; ok {
					ut.IsOurSpend = true
					break
				}
			}
		}
	}

	return ut
}
Exemplo n.º 2
0
// AllSpendsOutputs returns all spending outputs in unconfirmed tx pool.
func (utp *UnconfirmedTxnPool) AllSpendsOutputs(bcUnspent *coin.UnspentPool) []ReadableOutput {
	outs := []ReadableOutput{}
	for _, tx := range utp.Txns {
		for _, in := range tx.Txn.In {
			if ux, ok := bcUnspent.Get(in); ok {
				outs = append(outs, NewReadableOutput(ux))
			}
		}
	}
	return outs
}
Exemplo n.º 3
0
// Returns all unconfirmed coin.UxOut spends for addresses
// Looks at all inputs for unconfirmed txns, gets their source UxOut from the
// blockchain's unspent pool, and returns as coin.AddressUxOuts
// TODO -- optimize or cache
func (self *UnconfirmedTxnPool) SpendsForAddresses(bcUnspent *coin.UnspentPool,
	a map[coin.Address]byte) coin.AddressUxOuts {
	auxs := make(coin.AddressUxOuts, len(a))
	for _, utx := range self.Txns {
		for _, h := range utx.Txn.In {
			if ux, ok := bcUnspent.Get(h); ok {
				if _, ok := a[ux.Body.Address]; ok {
					auxs[ux.Body.Address] = append(auxs[ux.Body.Address], ux)
				}
			}
		}
	}
	return auxs
}