[DEV-257] Include transaction acceptance status in getBlock RPC call (#123)

* [DEV-257] Include transaction acceptance status in getBlock RPC call

* [DEV-257] change txRawResult-accepted to camel case

* [DEV-257] gofmt

* [DEV-257] change getBlock-acceptedtx help entry to getBlock-acceptedTx

* [DEV-257] delete TxRawResult.accepted and instead create TxRawResult.acceptedBy
This commit is contained in:
Ori Newman 2018-11-08 13:19:53 +02:00 committed by Svarog
parent 225f349e6a
commit 45c212deb4
5 changed files with 31 additions and 17 deletions

View File

@ -438,18 +438,19 @@ type InfoDAGResult struct {
// TxRawResult models the data from the getrawtransaction command. // TxRawResult models the data from the getrawtransaction command.
type TxRawResult struct { type TxRawResult struct {
Hex string `json:"hex"` Hex string `json:"hex"`
TxID string `json:"txId"` TxID string `json:"txId"`
Hash string `json:"hash,omitempty"` Hash string `json:"hash,omitempty"`
Size int32 `json:"size,omitempty"` Size int32 `json:"size,omitempty"`
Version int32 `json:"version"` Version int32 `json:"version"`
LockTime uint64 `json:"lockTime"` LockTime uint64 `json:"lockTime"`
Vin []Vin `json:"vin"` Vin []Vin `json:"vin"`
Vout []Vout `json:"vout"` Vout []Vout `json:"vout"`
BlockHash string `json:"blockHash,omitempty"` BlockHash string `json:"blockHash,omitempty"`
Confirmations uint64 `json:"confirmations,omitempty"` Confirmations uint64 `json:"confirmations,omitempty"`
Time uint64 `json:"time,omitempty"` AcceptedBy *string `json:"acceptedBy"`
BlockTime uint64 `json:"blockTime,omitempty"` Time uint64 `json:"time,omitempty"`
BlockTime uint64 `json:"blockTime,omitempty"`
} }
// SearchRawTransactionsResult models the data from the searchrawtransaction // SearchRawTransactionsResult models the data from the searchrawtransaction

View File

@ -199,7 +199,7 @@ func TestDAGSvrWsNtfns(t *testing.T) {
} }
return btcjson.NewTxAcceptedVerboseNtfn(txResult) 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{ unmarshalled: &btcjson.TxAcceptedVerboseNtfn{
RawTx: btcjson.TxRawResult{ RawTx: btcjson.TxRawResult{
Hex: "001122", Hex: "001122",

View File

@ -741,7 +741,7 @@ func createVoutList(mtx *wire.MsgTx, chainParams *dagconfig.Params, filterAddrMa
// to a raw transaction JSON object. // to a raw transaction JSON object.
func createTxRawResult(chainParams *dagconfig.Params, mtx *wire.MsgTx, func createTxRawResult(chainParams *dagconfig.Params, mtx *wire.MsgTx,
txHash string, blkHeader *wire.BlockHeader, blkHash string, 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) mtxHex, err := messageToHex(mtx)
if err != nil { if err != nil {
@ -767,6 +767,10 @@ func createTxRawResult(chainParams *dagconfig.Params, mtx *wire.MsgTx,
txReply.Confirmations = uint64(1 + chainHeight - blkHeight) txReply.Confirmations = uint64(1 + chainHeight - blkHeight)
} }
if acceptedBy != nil {
txReply.AcceptedBy = btcjson.String(acceptedBy.String())
}
return txReply, nil return txReply, nil
} }
@ -1160,9 +1164,16 @@ func handleGetBlock(s *Server, cmd interface{}, closeChan <-chan struct{}) (inte
txns := blk.Transactions() txns := blk.Transactions()
rawTxns := make([]btcjson.TxRawResult, len(txns)) rawTxns := make([]btcjson.TxRawResult, len(txns))
for i, tx := range 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(), rawTxn, err := createTxRawResult(params, tx.MsgTx(),
tx.Hash().String(), blockHeader, hash.String(), 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 { if err != nil {
return nil, err 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(), rawTxn, err := createTxRawResult(s.cfg.DAGParams, mtx, txHash.String(),
blkHeader, blkHashStr, blkHeight, dagHeight) blkHeader, blkHashStr, blkHeight, dagHeight, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -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-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--condition0": "verbose=false",
"getBlock--condition1": "verbose=true", "getBlock--condition1": "verbose=true",
"getBlock-acceptedTx": "Specifies if the transaction got accepted",
"getBlock--result0": "Hex-encoded bytes of the serialized block", "getBlock--result0": "Hex-encoded bytes of the serialized block",
// GetBlockChainInfoCmd help. // GetBlockChainInfoCmd help.
@ -212,6 +213,7 @@ var helpDescsEnUS = map[string]string{
"txRawResult-blockTime": "Block time in seconds since the 1 Jan 1970 GMT", "txRawResult-blockTime": "Block time in seconds since the 1 Jan 1970 GMT",
"txRawResult-size": "The size of the transaction in bytes", "txRawResult-size": "The size of the transaction in bytes",
"txRawResult-hash": "The wtxid of the transaction", "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 help.
"searchRawTransactionsResult-hex": "Hex-encoded transaction", "searchRawTransactionsResult-hex": "Hex-encoded transaction",

View File

@ -847,7 +847,7 @@ func (m *wsNotificationManager) notifyForNewTx(clients map[chan struct{}]*wsClie
net := m.server.cfg.DAGParams net := m.server.cfg.DAGParams
rawTx, err := createTxRawResult(net, mtx, txHashStr, nil, rawTx, err := createTxRawResult(net, mtx, txHashStr, nil,
"", 0, 0) "", 0, 0, nil)
if err != nil { if err != nil {
return return
} }