Send the side of address (input/output) for a new tx notification
This commit is contained in:
parent
f829d21eeb
commit
6dcf3fd45d
@ -191,7 +191,7 @@ func (c *blockChainWithMetrics) SendRawTransaction(tx string) (v string, err err
|
|||||||
return c.b.SendRawTransaction(tx)
|
return c.b.SendRawTransaction(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *blockChainWithMetrics) ResyncMempool(onNewTxAddr func(txid string, addr string)) (count int, err error) {
|
func (c *blockChainWithMetrics) ResyncMempool(onNewTxAddr func(txid string, addr string, isOutput bool)) (count int, err error) {
|
||||||
defer func(s time.Time) { c.observeRPCLatency("ResyncMempool", s, err) }(time.Now())
|
defer func(s time.Time) { c.observeRPCLatency("ResyncMempool", s, err) }(time.Now())
|
||||||
count, err = c.b.ResyncMempool(onNewTxAddr)
|
count, err = c.b.ResyncMempool(onNewTxAddr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
@ -607,7 +607,7 @@ func (b *BitcoinRPC) GetTransaction(txid string) (*bchain.Tx, error) {
|
|||||||
// ResyncMempool gets mempool transactions and maps output scripts to transactions.
|
// ResyncMempool gets mempool transactions and maps output scripts to transactions.
|
||||||
// ResyncMempool is not reentrant, it should be called from a single thread.
|
// ResyncMempool is not reentrant, it should be called from a single thread.
|
||||||
// It returns number of transactions in mempool
|
// It returns number of transactions in mempool
|
||||||
func (b *BitcoinRPC) ResyncMempool(onNewTxAddr func(txid string, addr string)) (int, error) {
|
func (b *BitcoinRPC) ResyncMempool(onNewTxAddr func(txid string, addr string, isOutput bool)) (int, error) {
|
||||||
return b.Mempool.Resync(onNewTxAddr)
|
return b.Mempool.Resync(onNewTxAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -530,7 +530,7 @@ func (b *EthereumRPC) SendRawTransaction(hex string) (string, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *EthereumRPC) ResyncMempool(onNewTxAddr func(txid string, addr string)) (int, error) {
|
func (b *EthereumRPC) ResyncMempool(onNewTxAddr func(txid string, addr string, isOutput bool)) (int, error) {
|
||||||
return b.Mempool.Resync(onNewTxAddr)
|
return b.Mempool.Resync(onNewTxAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -47,7 +47,7 @@ func (m *NonUTXOMempool) updateMappings(newTxToInputOutput map[string][]addrInde
|
|||||||
// Resync gets mempool transactions and maps outputs to transactions.
|
// Resync gets mempool transactions and maps outputs to transactions.
|
||||||
// Resync is not reentrant, it should be called from a single thread.
|
// Resync is not reentrant, it should be called from a single thread.
|
||||||
// Read operations (GetTransactions) are safe.
|
// Read operations (GetTransactions) are safe.
|
||||||
func (m *NonUTXOMempool) Resync(onNewTxAddr func(txid string, addr string)) (int, error) {
|
func (m *NonUTXOMempool) Resync(onNewTxAddr func(txid string, addr string, isOutput bool)) (int, error) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
glog.V(1).Info("Mempool: resync")
|
glog.V(1).Info("Mempool: resync")
|
||||||
txs, err := m.chain.GetMempool()
|
txs, err := m.chain.GetMempool()
|
||||||
@ -79,7 +79,7 @@ func (m *NonUTXOMempool) Resync(onNewTxAddr func(txid string, addr string)) (int
|
|||||||
io = append(io, addrIndex{string(addrID), int32(output.N)})
|
io = append(io, addrIndex{string(addrID), int32(output.N)})
|
||||||
}
|
}
|
||||||
if onNewTxAddr != nil && len(output.ScriptPubKey.Addresses) == 1 {
|
if onNewTxAddr != nil && len(output.ScriptPubKey.Addresses) == 1 {
|
||||||
onNewTxAddr(tx.Txid, output.ScriptPubKey.Addresses[0])
|
onNewTxAddr(tx.Txid, output.ScriptPubKey.Addresses[0], true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, input := range tx.Vin {
|
for _, input := range tx.Vin {
|
||||||
@ -92,7 +92,7 @@ func (m *NonUTXOMempool) Resync(onNewTxAddr func(txid string, addr string)) (int
|
|||||||
}
|
}
|
||||||
io = append(io, addrIndex{string(addrID), int32(^i)})
|
io = append(io, addrIndex{string(addrID), int32(^i)})
|
||||||
if onNewTxAddr != nil {
|
if onNewTxAddr != nil {
|
||||||
onNewTxAddr(tx.Txid, a)
|
onNewTxAddr(tx.Txid, a, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,7 @@ type UTXOMempool struct {
|
|||||||
addrIDToTx map[string][]outpoint
|
addrIDToTx map[string][]outpoint
|
||||||
chanTxid chan string
|
chanTxid chan string
|
||||||
chanAddrIndex chan txidio
|
chanAddrIndex chan txidio
|
||||||
onNewTxAddr func(txid string, addr string)
|
onNewTxAddr func(txid string, addr string, isOutput bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUTXOMempool creates new mempool handler.
|
// NewUTXOMempool creates new mempool handler.
|
||||||
@ -129,7 +129,7 @@ func (m *UTXOMempool) getTxAddrs(txid string, chanInput chan outpoint, chanResul
|
|||||||
io = append(io, addrIndex{string(addrID), int32(output.N)})
|
io = append(io, addrIndex{string(addrID), int32(output.N)})
|
||||||
}
|
}
|
||||||
if m.onNewTxAddr != nil && len(output.ScriptPubKey.Addresses) == 1 {
|
if m.onNewTxAddr != nil && len(output.ScriptPubKey.Addresses) == 1 {
|
||||||
m.onNewTxAddr(tx.Txid, output.ScriptPubKey.Addresses[0])
|
m.onNewTxAddr(tx.Txid, output.ScriptPubKey.Addresses[0], true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dispatched := 0
|
dispatched := 0
|
||||||
@ -166,7 +166,7 @@ func (m *UTXOMempool) getTxAddrs(txid string, chanInput chan outpoint, chanResul
|
|||||||
// Resync gets mempool transactions and maps outputs to transactions.
|
// Resync gets mempool transactions and maps outputs to transactions.
|
||||||
// Resync is not reentrant, it should be called from a single thread.
|
// Resync is not reentrant, it should be called from a single thread.
|
||||||
// Read operations (GetTransactions) are safe.
|
// Read operations (GetTransactions) are safe.
|
||||||
func (m *UTXOMempool) Resync(onNewTxAddr func(txid string, addr string)) (int, error) {
|
func (m *UTXOMempool) Resync(onNewTxAddr func(txid string, addr string, isOutput bool)) (int, error) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
glog.V(1).Info("mempool: resync")
|
glog.V(1).Info("mempool: resync")
|
||||||
m.onNewTxAddr = onNewTxAddr
|
m.onNewTxAddr = onNewTxAddr
|
||||||
|
|||||||
@ -136,7 +136,7 @@ type BlockChain interface {
|
|||||||
EstimateFee(blocks int) (float64, error)
|
EstimateFee(blocks int) (float64, error)
|
||||||
SendRawTransaction(tx string) (string, error)
|
SendRawTransaction(tx string) (string, error)
|
||||||
// mempool
|
// mempool
|
||||||
ResyncMempool(onNewTxAddr func(txid string, addr string)) (int, error)
|
ResyncMempool(onNewTxAddr func(txid string, addr string, isOutput bool)) (int, error)
|
||||||
GetMempoolTransactions(address string) ([]string, error)
|
GetMempoolTransactions(address string) ([]string, error)
|
||||||
GetMempoolEntry(txid string) (*MempoolEntry, error)
|
GetMempoolEntry(txid string) (*MempoolEntry, error)
|
||||||
// parser
|
// parser
|
||||||
|
|||||||
@ -86,7 +86,7 @@ var (
|
|||||||
syncWorker *db.SyncWorker
|
syncWorker *db.SyncWorker
|
||||||
internalState *common.InternalState
|
internalState *common.InternalState
|
||||||
callbacksOnNewBlockHash []func(hash string)
|
callbacksOnNewBlockHash []func(hash string)
|
||||||
callbacksOnNewTxAddr []func(txid string, addr string)
|
callbacksOnNewTxAddr []func(txid string, addr string, isOutput bool)
|
||||||
chanOsSignal chan os.Signal
|
chanOsSignal chan os.Signal
|
||||||
inShutdown int32
|
inShutdown int32
|
||||||
)
|
)
|
||||||
@ -444,9 +444,9 @@ func storeInternalStateLoop() {
|
|||||||
glog.Info("storeInternalStateLoop stopped")
|
glog.Info("storeInternalStateLoop stopped")
|
||||||
}
|
}
|
||||||
|
|
||||||
func onNewTxAddr(txid string, addr string) {
|
func onNewTxAddr(txid string, addr string, isOutput bool) {
|
||||||
for _, c := range callbacksOnNewTxAddr {
|
for _, c := range callbacksOnNewTxAddr {
|
||||||
c(txid, addr)
|
c(txid, addr, isOutput)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -145,8 +145,8 @@ func (s *PublicServer) OnNewBlockHash(hash string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OnNewTxAddr notifies users subscribed to bitcoind/addresstxid about new block
|
// OnNewTxAddr notifies users subscribed to bitcoind/addresstxid about new block
|
||||||
func (s *PublicServer) OnNewTxAddr(txid string, addr string) {
|
func (s *PublicServer) OnNewTxAddr(txid string, addr string, isOutput bool) {
|
||||||
s.socketio.OnNewTxAddr(txid, addr)
|
s.socketio.OnNewTxAddr(txid, addr, isOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
func splitBinding(binding string) (addr string, path string) {
|
func splitBinding(binding string) (addr string, path string) {
|
||||||
|
|||||||
@ -694,8 +694,12 @@ func (s *SocketIoServer) OnNewBlockHash(hash string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OnNewTxAddr notifies users subscribed to bitcoind/addresstxid about new block
|
// OnNewTxAddr notifies users subscribed to bitcoind/addresstxid about new block
|
||||||
func (s *SocketIoServer) OnNewTxAddr(txid string, addr string) {
|
func (s *SocketIoServer) OnNewTxAddr(txid string, addr string, isOutput bool) {
|
||||||
c := s.server.BroadcastTo("bitcoind/addresstxid-"+addr, "bitcoind/addresstxid", map[string]string{"address": addr, "txid": txid})
|
data := map[string]interface{}{"address": addr, "txid": txid}
|
||||||
|
if !isOutput {
|
||||||
|
data["input"] = true
|
||||||
|
}
|
||||||
|
c := s.server.BroadcastTo("bitcoind/addresstxid-"+addr, "bitcoind/addresstxid", data)
|
||||||
if c > 0 {
|
if c > 0 {
|
||||||
glog.Info("broadcasting new txid ", txid, " for addr ", addr, " to ", c, " channels")
|
glog.Info("broadcasting new txid ", txid, " for addr ", addr, " to ", c, " channels")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user