mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
Include more data in tx-to-wallet-address notifications.
This updates the replies for rescan and tx notifications with additional information that is needed for wallet to properly support the listtransactions command. While here, drastically improve rescan performance by not looking up every sha in rescan's block range.
This commit is contained in:
parent
dfbb9446c4
commit
d1570c5d87
70
rpcserver.go
70
rpcserver.go
@ -1225,18 +1225,13 @@ func handleRescan(s *rpcServer, cmd btcjson.Cmd,
|
|||||||
for i := range blkshalist {
|
for i := range blkshalist {
|
||||||
blk, err := s.server.db.FetchBlockBySha(&blkshalist[i])
|
blk, err := s.server.db.FetchBlockBySha(&blkshalist[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
rpcsLog.Errorf("Error looking up block sha: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
txShaList, err := blk.TxShas()
|
txs := blk.Transactions()
|
||||||
if err != nil {
|
for _, tx := range txs {
|
||||||
return err
|
var txReply *btcdb.TxListReply
|
||||||
}
|
for txOutIdx, txout := range tx.MsgTx().TxOut {
|
||||||
txList := s.server.db.FetchTxByShaList(txShaList)
|
|
||||||
for _, txReply := range txList {
|
|
||||||
if txReply.Err != nil || txReply.Tx == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for txOutIdx, txout := range txReply.Tx.TxOut {
|
|
||||||
st, txaddrhash, err := btcscript.ScriptToAddrHash(txout.PkScript)
|
st, txaddrhash, err := btcscript.ScriptToAddrHash(txout.PkScript)
|
||||||
if st != btcscript.ScriptAddr || err != nil {
|
if st != btcscript.ScriptAddr || err != nil {
|
||||||
continue
|
continue
|
||||||
@ -1246,24 +1241,45 @@ func handleRescan(s *rpcServer, cmd btcjson.Cmd,
|
|||||||
rpcsLog.Errorf("Error encoding address: %v", err)
|
rpcsLog.Errorf("Error encoding address: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := rescanCmd.Addresses[txaddr]; ok {
|
if _, ok := rescanCmd.Addresses[txaddr]; ok {
|
||||||
|
// TODO(jrick): This lookup is expensive and can be avoided
|
||||||
|
// if the wallet is sent the previous outpoints for all inputs
|
||||||
|
// of the tx, so any can removed from the utxo set (since
|
||||||
|
// they are, as of this tx, now spent).
|
||||||
|
if txReply == nil {
|
||||||
|
txReplyList, err := s.server.db.FetchTxBySha(tx.Sha())
|
||||||
|
if err != nil {
|
||||||
|
rpcsLog.Errorf("Tx Sha %v not found by db.", tx.Sha())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for i := range txReplyList {
|
||||||
|
if txReplyList[i].Height == blk.Height() {
|
||||||
|
txReply = txReplyList[i]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
reply.Result = struct {
|
reply.Result = struct {
|
||||||
Sender string `json:"sender"`
|
|
||||||
Receiver string `json:"receiver"`
|
Receiver string `json:"receiver"`
|
||||||
BlockHash string `json:"blockhash"`
|
|
||||||
Height int64 `json:"height"`
|
Height int64 `json:"height"`
|
||||||
TxHash string `json:"txhash"`
|
BlockHash string `json:"blockhash"`
|
||||||
Index uint32 `json:"index"`
|
BlockIndex int `json:"blockindex"`
|
||||||
|
BlockTime int64 `json:"blocktime"`
|
||||||
|
TxID string `json:"txid"`
|
||||||
|
TxOutIndex uint32 `json:"txoutindex"`
|
||||||
Amount int64 `json:"amount"`
|
Amount int64 `json:"amount"`
|
||||||
PkScript string `json:"pkscript"`
|
PkScript string `json:"pkscript"`
|
||||||
Spent bool `json:"spent"`
|
Spent bool `json:"spent"`
|
||||||
}{
|
}{
|
||||||
Sender: "Unknown", // TODO(jrick)
|
|
||||||
Receiver: txaddr,
|
Receiver: txaddr,
|
||||||
BlockHash: blkshalist[i].String(),
|
|
||||||
Height: blk.Height(),
|
Height: blk.Height(),
|
||||||
TxHash: txReply.Sha.String(),
|
BlockHash: blkshalist[i].String(),
|
||||||
Index: uint32(txOutIdx),
|
BlockIndex: tx.Index(),
|
||||||
|
BlockTime: blk.MsgBlock().Header.Timestamp.Unix(),
|
||||||
|
TxID: tx.Sha().String(),
|
||||||
|
TxOutIndex: uint32(txOutIdx),
|
||||||
Amount: txout.Value,
|
Amount: txout.Value,
|
||||||
PkScript: btcutil.Base58Encode(txout.PkScript),
|
PkScript: btcutil.Base58Encode(txout.PkScript),
|
||||||
Spent: txReply.TxSpent[txOutIdx],
|
Spent: txReply.TxSpent[txOutIdx],
|
||||||
@ -1643,21 +1659,23 @@ func (s *rpcServer) newBlockNotifyCheckTxOut(block *btcutil.Block,
|
|||||||
}
|
}
|
||||||
reply := &btcjson.Reply{
|
reply := &btcjson.Reply{
|
||||||
Result: struct {
|
Result: struct {
|
||||||
Sender string `json:"sender"`
|
|
||||||
Receiver string `json:"receiver"`
|
Receiver string `json:"receiver"`
|
||||||
BlockHash string `json:"blockhash"`
|
|
||||||
Height int64 `json:"height"`
|
Height int64 `json:"height"`
|
||||||
TxHash string `json:"txhash"`
|
BlockHash string `json:"blockhash"`
|
||||||
Index uint32 `json:"index"`
|
BlockIndex int `json:"blockindex"`
|
||||||
|
BlockTime int64 `json:"blocktime"`
|
||||||
|
TxID string `json:"txid"`
|
||||||
|
TxOutIndex uint32 `json:"txoutindex"`
|
||||||
Amount int64 `json:"amount"`
|
Amount int64 `json:"amount"`
|
||||||
PkScript string `json:"pkscript"`
|
PkScript string `json:"pkscript"`
|
||||||
}{
|
}{
|
||||||
Sender: "Unknown", // TODO(jrick)
|
|
||||||
Receiver: txaddr,
|
Receiver: txaddr,
|
||||||
BlockHash: blkhash.String(),
|
|
||||||
Height: block.Height(),
|
Height: block.Height(),
|
||||||
TxHash: tx.Sha().String(),
|
BlockHash: blkhash.String(),
|
||||||
Index: uint32(i),
|
BlockIndex: tx.Index(),
|
||||||
|
BlockTime: block.MsgBlock().Header.Timestamp.Unix(),
|
||||||
|
TxID: tx.Sha().String(),
|
||||||
|
TxOutIndex: uint32(i),
|
||||||
Amount: txout.Value,
|
Amount: txout.Value,
|
||||||
PkScript: btcutil.Base58Encode(txout.PkScript),
|
PkScript: btcutil.Base58Encode(txout.PkScript),
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user