Lookup input transactions in mempool

pull/1/head
Martin Boehm 2018-02-03 19:14:27 +01:00
parent 2598dff10d
commit 7c71876c12
3 changed files with 13 additions and 7 deletions

View File

@ -274,8 +274,8 @@ func waitForSignalAndShutdown(s *server.HTTPServer, mq *bchain.MQ, timeout time.
}
}
func printResult(txid string) error {
glog.Info(txid)
func printResult(txid string, vout uint32, isOutput bool) error {
glog.Info(txid, vout, isOutput)
return nil
}

View File

@ -85,7 +85,7 @@ func (d *RocksDB) Close() error {
// GetTransactions finds all input/output transactions for address specified by outputScript.
// Transaction are passed to callback function.
func (d *RocksDB) GetTransactions(outputScript []byte, lower uint32, higher uint32, fn func(txid string) error) (err error) {
func (d *RocksDB) GetTransactions(outputScript []byte, lower uint32, higher uint32, fn func(txid string, vout uint32, isOutput bool) error) (err error) {
if glog.V(1) {
glog.Infof("rocksdb: address get %s %d-%d ", unpackOutputScript(outputScript), lower, higher)
}
@ -116,7 +116,7 @@ func (d *RocksDB) GetTransactions(outputScript []byte, lower uint32, higher uint
glog.Infof("rocksdb: output %s: %s", hex.EncodeToString(key), hex.EncodeToString(val))
}
for _, o := range outpoints {
if err := fn(o.txid); err != nil {
if err := fn(o.txid, o.vout, true); err != nil {
return err
}
boutpoint, err := packOutpoint(o.txid, o.vout)
@ -136,7 +136,7 @@ func (d *RocksDB) GetTransactions(outputScript []byte, lower uint32, higher uint
return err
}
for _, i := range inpoints {
if err := fn(i.txid); err != nil {
if err := fn(i.txid, i.vout, false); err != nil {
return err
}
}

View File

@ -168,7 +168,7 @@ func (s *HTTPServer) confirmedTransactions(w http.ResponseWriter, r *http.Reques
respondError(w, err, fmt.Sprint("confirmedTransactions for address", address))
}
txList := transactionList{}
err = s.db.GetTransactions(script, lower, higher, func(txid string) error {
err = s.db.GetTransactions(script, lower, higher, func(txid string, vout uint32, isOutput bool) error {
txList.Txid = append(txList.Txid, txid)
return nil
})
@ -184,8 +184,14 @@ func (s *HTTPServer) transactions(w http.ResponseWriter, r *http.Request) {
respondError(w, err, fmt.Sprint("transactions for address", address))
}
txList := transactionList{}
err = s.db.GetTransactions(script, lower, higher, func(txid string) error {
err = s.db.GetTransactions(script, lower, higher, func(txid string, vout uint32, isOutput bool) error {
txList.Txid = append(txList.Txid, txid)
if isOutput {
input := s.mempool.GetInput(txid, vout)
if input != "" {
txList.Txid = append(txList.Txid, txid)
}
}
return nil
})
if err != nil {