Exemplo n.º 1
0
// NotifyBlockConnected creates and marshalls a JSON message to notify
// of a new block connected to the main chain.  The notification is sent
// to each connected wallet.
func (s *rpcServer) NotifyBlockConnected(block *btcutil.Block) {
	hash, err := block.Sha()
	if err != nil {
		rpcsLog.Error("Bad block; connected block notification dropped.")
		return
	}

	// TODO: remove int32 type conversion.
	ntfn := btcws.NewBlockConnectedNtfn(hash.String(),
		int32(block.Height()))
	mntfn, _ := json.Marshal(ntfn)
	s.ws.walletNotificationMaster <- mntfn

	// Inform any interested parties about txs mined in this block.
	s.ws.Lock()
	for _, tx := range block.Transactions() {
		if clist, ok := s.ws.minedTxNotifications[*tx.Sha()]; ok {
			var enext *list.Element
			for e := clist.Front(); e != nil; e = enext {
				enext = e.Next()
				c := e.Value.(walletChan)
				// TODO: remove int32 type conversion after
				// the int64 -> int32 switch is made.
				ntfn := btcws.NewTxMinedNtfn(tx.Sha().String(),
					hash.String(), int32(block.Height()),
					block.MsgBlock().Header.Timestamp.Unix(),
					tx.Index())
				mntfn, _ := json.Marshal(ntfn)
				c <- mntfn
				s.ws.removeMinedTxRequest(c, tx.Sha())
			}
		}
	}
	s.ws.Unlock()
}
Exemplo n.º 2
0
// NotifyMinedTxSender reads received transactions from in, notifying
// frontends that the tx has now been confirmed in a block.  Duplicates
// are filtered out.
func NotifyMinedTxSender(in chan *tx.RecvTx) {
	// Create a map to hold a set of already notified
	// txids.  Do not send duplicates.
	m := make(map[btcwire.ShaHash]struct{})

	for recv := range in {
		if _, ok := m[recv.TxID]; !ok {
			ntfn := btcws.NewTxMinedNtfn(recv.TxID.String(),
				recv.BlockHash.String(), recv.BlockHeight,
				recv.BlockTime, int(recv.BlockIndex))
			mntfn, _ := ntfn.MarshalJSON()
			frontendNotificationMaster <- mntfn

			// Mark as sent.
			m[recv.TxID] = struct{}{}
		}
	}
}
Exemplo n.º 3
0
			TxID:        "851f5c0652e785c5ed80aafaf2d918e5cbe5c307dbba3680808ada1d01f36886",
			TxOutIndex:  1,
			PkScript:    "76a9141e127eda7cd71b9724085f588840a3e9d697ae9888ac",
			BlockHash:   "000000004811dda1c320ad5d0ea184a20a53acd92292c5f1cb926c3ee82abf70",
			BlockHeight: 153469,
			BlockIndex:  1,
			BlockTime:   1386944019,
			Spent:       true,
		},
	},
	{
		name: "txmined",
		f: func() btcjson.Cmd {
			return btcws.NewTxMinedNtfn(
				"062f2b5f7d28c787e0f3aee382132241cd590efb7b83bd2c7f506de5aa4ef275",
				"000000004811dda1c320ad5d0ea184a20a53acd92292c5f1cb926c3ee82abf70",
				153469,
				1386944019,
				0)
		},
		result: &btcws.TxMinedNtfn{
			TxID:        "062f2b5f7d28c787e0f3aee382132241cd590efb7b83bd2c7f506de5aa4ef275",
			BlockHash:   "000000004811dda1c320ad5d0ea184a20a53acd92292c5f1cb926c3ee82abf70",
			BlockHeight: 153469,
			BlockTime:   1386944019,
			Index:       0,
		},
	},
	{
		name: "txspent",
		f: func() btcjson.Cmd {
			return btcws.NewTxSpentNtfn(