mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 14:16:43 +00:00
[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:
parent
225f349e6a
commit
45c212deb4
@ -448,6 +448,7 @@ type TxRawResult struct {
|
||||
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"`
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user