diff --git a/btcjson/chainsvrresults.go b/btcjson/chainsvrresults.go index 811883c7..ffa0a103 100644 --- a/btcjson/chainsvrresults.go +++ b/btcjson/chainsvrresults.go @@ -323,6 +323,7 @@ type GetMempoolEntryResult struct { WTxId string `json:"wtxid"` Fees MempoolFees `json:"fees"` Depends []string `json:"depends"` + SpentBy []string `json:"spentby"` } // GetChainTipsResult models the data returns from the getchaintips command. diff --git a/mempool/mempool.go b/mempool/mempool.go index a2dc5c20..45cf602b 100644 --- a/mempool/mempool.go +++ b/mempool/mempool.go @@ -1507,36 +1507,42 @@ func (mp *TxPool) MiningDescs() []*mining.TxDesc { // populated btcjson result. // // This function is safe for concurrent access. -func (mp *TxPool) RawMempoolVerbose() map[string]*btcjson.GetRawMempoolVerboseResult { +func (mp *TxPool) RawMempoolVerbose() map[string]*btcjson.GetMempoolEntryResult { mp.mtx.RLock() defer mp.mtx.RUnlock() - result := make(map[string]*btcjson.GetRawMempoolVerboseResult, + result := make(map[string]*btcjson.GetMempoolEntryResult, len(mp.pool)) - bestHeight := mp.cfg.BestHeight() for _, desc := range mp.pool { // Calculate the current priority based on the inputs to // the transaction. Use zero if one or more of the // input transactions can't be found for some reason. tx := desc.Tx - var currentPriority float64 - utxos, err := mp.fetchInputUtxos(tx) - if err == nil { - currentPriority = mining.CalcPriority(tx.MsgTx(), utxos, - bestHeight+1) - } - mpd := &btcjson.GetRawMempoolVerboseResult{ - Size: int32(tx.MsgTx().SerializeSize()), - Vsize: int32(GetTxVirtualSize(tx)), - Weight: int32(blockchain.GetTransactionWeight(tx)), - Fee: btcutil.Amount(desc.Fee).ToBTC(), - Time: desc.Added.Unix(), - Height: int64(desc.Height), - StartingPriority: desc.StartingPriority, - CurrentPriority: currentPriority, - Depends: make([]string, 0), + mpd := &btcjson.GetMempoolEntryResult{ + VSize: int32(GetTxVirtualSize(tx)), + Size: int32(tx.MsgTx().SerializeSize()), + Weight: blockchain.GetTransactionWeight(tx), + Fee: btcutil.Amount(desc.Fee).ToBTC(), + ModifiedFee: btcutil.Amount(desc.Fee).ToBTC(), // TODO, Deprecated + Time: desc.Added.Unix(), + Height: int64(desc.Height), + DescendantCount: 1, // TODO + DescendantSize: GetTxVirtualSize(tx), // TODO + DescendantFees: btcutil.Amount(desc.Fee).ToBTC(), // TODO, Deprecated + AncestorCount: 1, // TODO + AncestorSize: GetTxVirtualSize(tx), // TODO + AncestorFees: btcutil.Amount(desc.Fee).ToBTC(), // TODO, Deprecated + WTxId: desc.Tx.WitnessHash().String(), + Fees: btcjson.MempoolFees{ + Base: btcutil.Amount(desc.Fee).ToBTC(), + Modified: btcutil.Amount(desc.Fee).ToBTC(), // TODO + Ancestor: btcutil.Amount(desc.Fee).ToBTC(), // TODO + Descendant: btcutil.Amount(desc.Fee).ToBTC(), // TODO + }, + Depends: make([]string, 0), // TODO + SpentBy: make([]string, 0), // TODO } for _, txIn := range tx.MsgTx().TxIn { hash := &txIn.PreviousOutPoint.Hash diff --git a/mempool/mempool_test.go b/mempool/mempool_test.go index b4070dd7..17d2d452 100644 --- a/mempool/mempool_test.go +++ b/mempool/mempool_test.go @@ -560,7 +560,7 @@ func TestOrphanReject(t *testing.T) { // Ensure no transactions were reported as accepted. if len(acceptedTxns) != 0 { - t.Fatal("ProcessTransaction: reported %d accepted "+ + t.Fatalf("ProcessTransaction: reported %d accepted "+ "transactions from failed orphan attempt", len(acceptedTxns)) } diff --git a/rpcserver.go b/rpcserver.go index f2796ba6..0724a757 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -161,6 +161,7 @@ var rpcHandlersBeforeInit = map[string]commandHandler{ "getheaders": handleGetHeaders, "getinfo": handleGetInfo, "getmempoolinfo": handleGetMempoolInfo, + "getmempoolentry": handleGetMempoolEntry, "getmininginfo": handleGetMiningInfo, "getnettotals": handleGetNetTotals, "getnetworkhashps": handleGetNetworkHashPS, @@ -239,8 +240,6 @@ var rpcAskWallet = map[string]struct{}{ // Commands that are currently unimplemented, but should ultimately be. var rpcUnimplemented = map[string]struct{}{ "estimatepriority": {}, - "getchaintips": {}, - "getmempoolentry": {}, "getwork": {}, "preciousblock": {}, } @@ -2483,6 +2482,56 @@ func handleGetMempoolInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct return ret, nil } +// handleGetMempoolEntry implements the getmempoolentry command. +func handleGetMempoolEntry(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) { + + c := cmd.(*btcjson.GetMempoolEntryCmd) + txHash, err := chainhash.NewHashFromStr(c.TxID) + if err != nil { + if err != nil { + return nil, rpcDecodeHexError(c.TxID) + } + } + + mp := s.cfg.TxMemPool + for _, desc := range mp.TxDescs() { + tx := desc.Tx + if tx.Hash().IsEqual(txHash) { + continue + } + desc.Tx.WitnessHash() + + ret := &btcjson.GetMempoolEntryResult{ + VSize: int32(mempool.GetTxVirtualSize(tx)), + Size: int32(tx.MsgTx().SerializeSize()), + Weight: blockchain.GetTransactionWeight(tx), + Fee: btcutil.Amount(desc.Fee).ToBTC(), + ModifiedFee: btcutil.Amount(desc.Fee).ToBTC(), // TODO, Deprecated + Time: desc.Added.Unix(), + Height: int64(desc.Height), + DescendantCount: 1, // TODO + DescendantSize: mempool.GetTxVirtualSize(tx), // TODO + DescendantFees: btcutil.Amount(desc.Fee).ToBTC(), // TODO, Deprecated + AncestorCount: 1, // TODO + AncestorSize: mempool.GetTxVirtualSize(tx), // TODO + AncestorFees: btcutil.Amount(desc.Fee).ToBTC(), // TODO, Deprecated + WTxId: desc.Tx.WitnessHash().String(), + Fees: btcjson.MempoolFees{ + Base: btcutil.Amount(desc.Fee).ToBTC(), + Modified: btcutil.Amount(desc.Fee).ToBTC(), // TODO + Ancestor: btcutil.Amount(desc.Fee).ToBTC(), // TODO + Descendant: btcutil.Amount(desc.Fee).ToBTC(), // TODO + }, + Depends: make([]string, 0), // TODO + SpentBy: make([]string, 0), // TODO + } + + return ret, nil + } + + return nil, rpcNoTxInfoError(txHash) +} + // handleGetMiningInfo implements the getmininginfo command. We only return the // fields that are not related to wallet functionality. func handleGetMiningInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) { diff --git a/rpcserverhelp.go b/rpcserverhelp.go index 881cfeb5..4cfde4d3 100644 --- a/rpcserverhelp.go +++ b/rpcserverhelp.go @@ -470,6 +470,34 @@ var helpDescsEnUS = map[string]string{ "getmininginforesult-pooledtx": "Number of transactions in the memory pool", "getmininginforesult-testnet": "Whether or not server is using testnet", + "mempoolfees-base": "Transaction fee in LBC", + "mempoolfees-modified": "Transaction fee with fee deltas used for mining priority in LBC", + "mempoolfees-ancestor": "Modified fees (see above) of in-mempool ancestors (including this one) in LBC", + "mempoolfees-descendant": "modified fees (see above) of in-mempool descendants (including this one) in LBC", + + // GetMempoolEntryCmd help. + "getmempoolentry--synopsis": "Returns mempool data for given transaction.", + "getmempoolentry-txid": "The hash of the transaction", + + // GetMempoolEntryResult help. + "getmempoolentryresult-vsize": "Virtual transaction size as defined in BIP 141. This is different from actual serialized size for witness transactions as witness data is discounted.", + "getmempoolentryresult-size": "(DEPRECATED) same as vsize. ", + "getmempoolentryresult-weight": "Transaction weight as defined in BIP 141.", + "getmempoolentryresult-fee": "(DEPRECATED)Transaction fee in LBC", + "getmempoolentryresult-modifiedfee": "(DEPRECATED)Transaction fee with fee deltas used for mining priority", + "getmempoolentryresult-time": "Local time transaction entered pool in seconds since 1 Jan 1970 GMT", + "getmempoolentryresult-height": "Block height when transaction entered pool", + "getmempoolentryresult-descendantcount": "Number of in-mempool descendant transactions (including this one)", + "getmempoolentryresult-descendantsize": "Virtual transaction size of in-mempool descendants (including this one)", + "getmempoolentryresult-descendantfees": "(DEPRECATED)Modified fees (see above) of in-mempool descendants (including this one)", + "getmempoolentryresult-ancestorcount": "Number of in-mempool ancestor transactions (including this one)", + "getmempoolentryresult-ancestorsize": "Virtual transaction size of in-mempool ancestors (including this one)", + "getmempoolentryresult-ancestorfees": "(DEPRECATED)Modified fees (see above) of in-mempool ancestors (including this one)", + "getmempoolentryresult-wtxid": "hash of serialized transaction, including witness data", + "getmempoolentryresult-fees": "(json object)", + "getmempoolentryresult-depends": "Unconfirmed transactions used as inputs for this transaction", + "getmempoolentryresult-spentby": "Unconfirmed transactions spending outputs from this transaction", + // GetMiningInfoCmd help. "getmininginfo--synopsis": "Returns a JSON object containing mining-related information.", @@ -872,6 +900,7 @@ var rpcResultTypes = map[string][]interface{}{ "gethashespersec": {(*float64)(nil)}, "getheaders": {(*[]string)(nil)}, "getinfo": {(*btcjson.InfoChainResult)(nil)}, + "getmempoolentry": {(*btcjson.GetMempoolEntryResult)(nil)}, "getmempoolinfo": {(*btcjson.GetMempoolInfoResult)(nil)}, "getmininginfo": {(*btcjson.GetMiningInfoResult)(nil)}, "getnettotals": {(*btcjson.GetNetTotalsResult)(nil)},