diff --git a/btcjson/dagsvrresults.go b/btcjson/dagsvrresults.go index e8e861187..b75c5824c 100644 --- a/btcjson/dagsvrresults.go +++ b/btcjson/dagsvrresults.go @@ -438,18 +438,19 @@ type InfoDAGResult struct { // TxRawResult models the data from the getrawtransaction command. type TxRawResult struct { - Hex string `json:"hex"` - TxID string `json:"txId"` - Hash string `json:"hash,omitempty"` - Size int32 `json:"size,omitempty"` - Version int32 `json:"version"` - LockTime uint64 `json:"lockTime"` - Vin []Vin `json:"vin"` - Vout []Vout `json:"vout"` - BlockHash string `json:"blockHash,omitempty"` - Confirmations uint64 `json:"confirmations,omitempty"` - Time uint64 `json:"time,omitempty"` - BlockTime uint64 `json:"blockTime,omitempty"` + Hex string `json:"hex"` + TxID string `json:"txId"` + Hash string `json:"hash,omitempty"` + Size int32 `json:"size,omitempty"` + Version int32 `json:"version"` + LockTime uint64 `json:"lockTime"` + Vin []Vin `json:"vin"` + Vout []Vout `json:"vout"` + BlockHash string `json:"blockHash,omitempty"` + Confirmations uint64 `json:"confirmations,omitempty"` + AcceptedBy *string `json:"acceptedBy"` + Time uint64 `json:"time,omitempty"` + BlockTime uint64 `json:"blockTime,omitempty"` } // SearchRawTransactionsResult models the data from the searchrawtransaction diff --git a/btcjson/dagsvrwsntfns_test.go b/btcjson/dagsvrwsntfns_test.go index c50f7d6e4..76329aa50 100644 --- a/btcjson/dagsvrwsntfns_test.go +++ b/btcjson/dagsvrwsntfns_test.go @@ -199,7 +199,7 @@ func TestDAGSvrWsNtfns(t *testing.T) { } return btcjson.NewTxAcceptedVerboseNtfn(txResult) }, - marshalled: `{"jsonrpc":"1.0","method":"txAcceptedVerbose","params":[{"hex":"001122","txId":"123","version":1,"lockTime":4294967295,"vin":null,"vout":null}],"id":null}`, + marshalled: `{"jsonrpc":"1.0","method":"txAcceptedVerbose","params":[{"hex":"001122","txId":"123","version":1,"lockTime":4294967295,"vin":null,"vout":null,"acceptedBy":null}],"id":null}`, unmarshalled: &btcjson.TxAcceptedVerboseNtfn{ RawTx: btcjson.TxRawResult{ Hex: "001122", diff --git a/server/rpc/rpcserver.go b/server/rpc/rpcserver.go index 875454dbe..83b748567 100644 --- a/server/rpc/rpcserver.go +++ b/server/rpc/rpcserver.go @@ -741,7 +741,7 @@ func createVoutList(mtx *wire.MsgTx, chainParams *dagconfig.Params, filterAddrMa // to a raw transaction JSON object. func createTxRawResult(chainParams *dagconfig.Params, mtx *wire.MsgTx, txHash string, blkHeader *wire.BlockHeader, blkHash string, - blkHeight int32, chainHeight int32) (*btcjson.TxRawResult, error) { + blkHeight int32, chainHeight int32, acceptedBy *daghash.Hash) (*btcjson.TxRawResult, error) { mtxHex, err := messageToHex(mtx) if err != nil { @@ -767,6 +767,10 @@ func createTxRawResult(chainParams *dagconfig.Params, mtx *wire.MsgTx, txReply.Confirmations = uint64(1 + chainHeight - blkHeight) } + if acceptedBy != nil { + txReply.AcceptedBy = btcjson.String(acceptedBy.String()) + } + return txReply, nil } @@ -1160,9 +1164,16 @@ func handleGetBlock(s *Server, cmd interface{}, closeChan <-chan struct{}) (inte txns := blk.Transactions() rawTxns := make([]btcjson.TxRawResult, len(txns)) for i, tx := range txns { + var acceptedBy *daghash.Hash + if s.cfg.TxIndex != nil { + acceptedBy, err = s.cfg.TxIndex.BlockThatAcceptedTx(s.cfg.DAG, tx.Hash()) + if err != nil { + return nil, err + } + } rawTxn, err := createTxRawResult(params, tx.MsgTx(), tx.Hash().String(), blockHeader, hash.String(), - blockHeight, s.cfg.DAG.Height()) //TODO: (Ori) This is probably wrong. Done only for compilation + blockHeight, s.cfg.DAG.Height(), acceptedBy) //TODO: (Ori) This is probably wrong. Done only for compilation if err != nil { return nil, err } @@ -2522,7 +2533,7 @@ func handleGetRawTransaction(s *Server, cmd interface{}, closeChan <-chan struct } rawTxn, err := createTxRawResult(s.cfg.DAGParams, mtx, txHash.String(), - blkHeader, blkHashStr, blkHeight, dagHeight) + blkHeader, blkHashStr, blkHeight, dagHeight, nil) if err != nil { return nil, err } diff --git a/server/rpc/rpcserverhelp.go b/server/rpc/rpcserverhelp.go index 5890f4d73..743fcae13 100644 --- a/server/rpc/rpcserverhelp.go +++ b/server/rpc/rpcserverhelp.go @@ -171,6 +171,7 @@ var helpDescsEnUS = map[string]string{ "getBlock-verboseTx": "Specifies that each transaction is returned as a JSON object and only applies if the verbose flag is true (btcd extension)", "getBlock--condition0": "verbose=false", "getBlock--condition1": "verbose=true", + "getBlock-acceptedTx": "Specifies if the transaction got accepted", "getBlock--result0": "Hex-encoded bytes of the serialized block", // GetBlockChainInfoCmd help. @@ -212,6 +213,7 @@ var helpDescsEnUS = map[string]string{ "txRawResult-blockTime": "Block time in seconds since the 1 Jan 1970 GMT", "txRawResult-size": "The size of the transaction in bytes", "txRawResult-hash": "The wtxid of the transaction", + "txRawResult-acceptedBy": "The block in which the transaction got accepted in (Will be 'null' if txindex is not disabled)", // SearchRawTransactionsResult help. "searchRawTransactionsResult-hex": "Hex-encoded transaction", diff --git a/server/rpc/rpcwebsocket.go b/server/rpc/rpcwebsocket.go index f765dd95c..22c0c92dd 100644 --- a/server/rpc/rpcwebsocket.go +++ b/server/rpc/rpcwebsocket.go @@ -847,7 +847,7 @@ func (m *wsNotificationManager) notifyForNewTx(clients map[chan struct{}]*wsClie net := m.server.cfg.DAGParams rawTx, err := createTxRawResult(net, mtx, txHashStr, nil, - "", 0, 0) + "", 0, 0, nil) if err != nil { return }