mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[DEV-316] Update JSON-RPC API to include new transaction fields (#186)
* [DEV-316] Update JSON-RPC API to include new transaction fields * [DEV-316] Fix tests * [DEV-316] Add txAcceptedVerbose test with subnetwork, gas and paylaod
This commit is contained in:
parent
d5f393872c
commit
b74dc9dfd1
@ -444,6 +444,9 @@ type TxRawResult struct {
|
||||
Size int32 `json:"size,omitempty"`
|
||||
Version int32 `json:"version"`
|
||||
LockTime uint64 `json:"lockTime"`
|
||||
Subnetwork string `json:"subnetwork"`
|
||||
Gas uint64 `json:"gas"`
|
||||
Payload string `json:"payload"`
|
||||
Vin []Vin `json:"vin"`
|
||||
Vout []Vout `json:"vout"`
|
||||
BlockHash string `json:"blockHash,omitempty"`
|
||||
|
@ -12,7 +12,10 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/daglabs/btcd/util/subnetworkid"
|
||||
|
||||
"github.com/daglabs/btcd/btcjson"
|
||||
"github.com/daglabs/btcd/wire"
|
||||
)
|
||||
|
||||
// TestDAGSvrWsNtfns tests all of the dag server websocket-specific
|
||||
@ -185,7 +188,7 @@ func TestDAGSvrWsNtfns(t *testing.T) {
|
||||
{
|
||||
name: "txAcceptedVerbose",
|
||||
newNtfn: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("txAcceptedVerbose", `{"hex":"001122","txid":"123","version":1,"locktime":4294967295,"vin":null,"vout":null,"confirmations":0}`)
|
||||
return btcjson.NewCmd("txAcceptedVerbose", `{"hex":"001122","txid":"123","version":1,"locktime":4294967295,"subnetwork":"0000000000000000000000000000000000000001","gas":0,"payload":"","vin":null,"vout":null,"confirmations":0}`)
|
||||
},
|
||||
staticNtfn: func() interface{} {
|
||||
txResult := btcjson.TxRawResult{
|
||||
@ -193,19 +196,57 @@ func TestDAGSvrWsNtfns(t *testing.T) {
|
||||
TxID: "123",
|
||||
Version: 1,
|
||||
LockTime: 4294967295,
|
||||
Subnetwork: wire.SubnetworkIDNative.String(),
|
||||
Vin: nil,
|
||||
Vout: nil,
|
||||
Confirmations: 0,
|
||||
}
|
||||
return btcjson.NewTxAcceptedVerboseNtfn(txResult)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"txAcceptedVerbose","params":[{"hex":"001122","txId":"123","version":1,"lockTime":4294967295,"vin":null,"vout":null,"acceptedBy":null}],"id":null}`,
|
||||
marshalled: `{"jsonrpc":"1.0","method":"txAcceptedVerbose","params":[{"hex":"001122","txId":"123","version":1,"lockTime":4294967295,"subnetwork":"0000000000000000000000000000000000000001","gas":0,"payload":"","vin":null,"vout":null,"acceptedBy":null}],"id":null}`,
|
||||
unmarshalled: &btcjson.TxAcceptedVerboseNtfn{
|
||||
RawTx: btcjson.TxRawResult{
|
||||
Hex: "001122",
|
||||
TxID: "123",
|
||||
Version: 1,
|
||||
LockTime: 4294967295,
|
||||
Subnetwork: wire.SubnetworkIDNative.String(),
|
||||
Vin: nil,
|
||||
Vout: nil,
|
||||
Confirmations: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "txAcceptedVerbose with subnetwork, gas and paylaod",
|
||||
newNtfn: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("txAcceptedVerbose", `{"hex":"001122","txId":"123","version":1,"lockTime":4294967295,"subnetwork":"000000000000000000000000000000000000432d","gas":10,"payload":"102030","vin":null,"vout":null,"acceptedBy":null}`)
|
||||
},
|
||||
staticNtfn: func() interface{} {
|
||||
txResult := btcjson.TxRawResult{
|
||||
Hex: "001122",
|
||||
TxID: "123",
|
||||
Version: 1,
|
||||
LockTime: 4294967295,
|
||||
Subnetwork: subnetworkid.SubnetworkID{45, 67}.String(),
|
||||
Payload: "102030",
|
||||
Gas: 10,
|
||||
Vin: nil,
|
||||
Vout: nil,
|
||||
Confirmations: 0,
|
||||
}
|
||||
return btcjson.NewTxAcceptedVerboseNtfn(txResult)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"txAcceptedVerbose","params":[{"hex":"001122","txId":"123","version":1,"lockTime":4294967295,"subnetwork":"000000000000000000000000000000000000432d","gas":10,"payload":"102030","vin":null,"vout":null,"acceptedBy":null}],"id":null}`,
|
||||
unmarshalled: &btcjson.TxAcceptedVerboseNtfn{
|
||||
RawTx: btcjson.TxRawResult{
|
||||
Hex: "001122",
|
||||
TxID: "123",
|
||||
Version: 1,
|
||||
LockTime: 4294967295,
|
||||
Subnetwork: subnetworkid.SubnetworkID{45, 67}.String(),
|
||||
Payload: "102030",
|
||||
Gas: 10,
|
||||
Vin: nil,
|
||||
Vout: nil,
|
||||
Confirmations: 0,
|
||||
|
@ -751,14 +751,17 @@ func createTxRawResult(dagParams *dagconfig.Params, mtx *wire.MsgTx,
|
||||
}
|
||||
|
||||
txReply := &btcjson.TxRawResult{
|
||||
Hex: mtxHex,
|
||||
TxID: txID,
|
||||
Hash: mtx.TxHash().String(),
|
||||
Size: int32(mtx.SerializeSize()),
|
||||
Vin: createVinList(mtx),
|
||||
Vout: createVoutList(mtx, dagParams, nil),
|
||||
Version: mtx.Version,
|
||||
LockTime: mtx.LockTime,
|
||||
Hex: mtxHex,
|
||||
TxID: txID,
|
||||
Hash: mtx.TxHash().String(),
|
||||
Size: int32(mtx.SerializeSize()),
|
||||
Vin: createVinList(mtx),
|
||||
Vout: createVoutList(mtx, dagParams, nil),
|
||||
Version: mtx.Version,
|
||||
LockTime: mtx.LockTime,
|
||||
Subnetwork: mtx.SubnetworkID.String(),
|
||||
Gas: mtx.Gas,
|
||||
Payload: hex.EncodeToString(mtx.Payload),
|
||||
}
|
||||
|
||||
if blkHeader != nil {
|
||||
|
@ -206,6 +206,9 @@ var helpDescsEnUS = map[string]string{
|
||||
"txRawResult-txId": "The hash of the transaction",
|
||||
"txRawResult-version": "The transaction version",
|
||||
"txRawResult-lockTime": "The transaction lock time",
|
||||
"txRawResult-subnetwork": "The transaction subnetwork",
|
||||
"txRawResult-gas": "The transaction gas",
|
||||
"txRawResult-payload": "The transaction payload",
|
||||
"txRawResult-vin": "The transaction inputs as JSON objects",
|
||||
"txRawResult-vout": "The transaction outputs as JSON objects",
|
||||
"txRawResult-blockHash": "Hash of the block the transaction is part of",
|
||||
|
Loading…
x
Reference in New Issue
Block a user