[NOD-738] Move rpcmodel helper functions to pointers package (#629)

* [NOD-738] Move rpcmodel helper functions to copytopointer package

* [NOD-738] Rename copytopointer->pointers
This commit is contained in:
Ori Newman 2020-02-18 14:06:34 +02:00 committed by GitHub
parent e405dd5981
commit 30fe0c279b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 142 additions and 136 deletions

View File

@ -9,6 +9,7 @@ import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"github.com/kaspanet/kaspad/util/pointers"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -99,7 +100,7 @@ func (c *Client) GetBlockAsync(blockHash *daghash.Hash, subnetworkID *string) Fu
hash = blockHash.String() hash = blockHash.String()
} }
cmd := rpcmodel.NewGetBlockCmd(hash, rpcmodel.Bool(false), rpcmodel.Bool(false), subnetworkID) cmd := rpcmodel.NewGetBlockCmd(hash, pointers.Bool(false), pointers.Bool(false), subnetworkID)
return c.sendCmd(cmd) return c.sendCmd(cmd)
} }
@ -178,7 +179,7 @@ func (c *Client) GetBlockVerboseAsync(blockHash *daghash.Hash, subnetworkID *str
hash = blockHash.String() hash = blockHash.String()
} }
cmd := rpcmodel.NewGetBlockCmd(hash, rpcmodel.Bool(true), rpcmodel.Bool(false), subnetworkID) cmd := rpcmodel.NewGetBlockCmd(hash, pointers.Bool(true), pointers.Bool(false), subnetworkID)
return c.sendCmd(cmd) return c.sendCmd(cmd)
} }
@ -202,7 +203,7 @@ func (c *Client) GetBlockVerboseTxAsync(blockHash *daghash.Hash, subnetworkID *s
hash = blockHash.String() hash = blockHash.String()
} }
cmd := rpcmodel.NewGetBlockCmd(hash, rpcmodel.Bool(true), rpcmodel.Bool(true), subnetworkID) cmd := rpcmodel.NewGetBlockCmd(hash, pointers.Bool(true), pointers.Bool(true), subnetworkID)
return c.sendCmd(cmd) return c.sendCmd(cmd)
} }
@ -429,7 +430,7 @@ func (c *Client) GetBlockHeaderAsync(blockHash *daghash.Hash) FutureGetBlockHead
hash = blockHash.String() hash = blockHash.String()
} }
cmd := rpcmodel.NewGetBlockHeaderCmd(hash, rpcmodel.Bool(false)) cmd := rpcmodel.NewGetBlockHeaderCmd(hash, pointers.Bool(false))
return c.sendCmd(cmd) return c.sendCmd(cmd)
} }
@ -474,7 +475,7 @@ func (c *Client) GetBlockHeaderVerboseAsync(blockHash *daghash.Hash) FutureGetBl
hash = blockHash.String() hash = blockHash.String()
} }
cmd := rpcmodel.NewGetBlockHeaderCmd(hash, rpcmodel.Bool(true)) cmd := rpcmodel.NewGetBlockHeaderCmd(hash, pointers.Bool(true))
return c.sendCmd(cmd) return c.sendCmd(cmd)
} }
@ -563,7 +564,7 @@ func (r FutureGetRawMempoolResult) Receive() ([]*daghash.Hash, error) {
// //
// See GetRawMempool for the blocking version and more details. // See GetRawMempool for the blocking version and more details.
func (c *Client) GetRawMempoolAsync() FutureGetRawMempoolResult { func (c *Client) GetRawMempoolAsync() FutureGetRawMempoolResult {
cmd := rpcmodel.NewGetRawMempoolCmd(rpcmodel.Bool(false)) cmd := rpcmodel.NewGetRawMempoolCmd(pointers.Bool(false))
return c.sendCmd(cmd) return c.sendCmd(cmd)
} }
@ -604,7 +605,7 @@ func (r FutureGetRawMempoolVerboseResult) Receive() (map[string]rpcmodel.GetRawM
// //
// See GetRawMempoolVerbose for the blocking version and more details. // See GetRawMempoolVerbose for the blocking version and more details.
func (c *Client) GetRawMempoolVerboseAsync() FutureGetRawMempoolVerboseResult { func (c *Client) GetRawMempoolVerboseAsync() FutureGetRawMempoolVerboseResult {
cmd := rpcmodel.NewGetRawMempoolCmd(rpcmodel.Bool(true)) cmd := rpcmodel.NewGetRawMempoolCmd(pointers.Bool(true))
return c.sendCmd(cmd) return c.sendCmd(cmd)
} }

View File

@ -9,6 +9,7 @@ import (
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"github.com/kaspanet/kaspad/util/daghash" "github.com/kaspanet/kaspad/util/daghash"
"github.com/kaspanet/kaspad/util/pointers"
"github.com/kaspanet/kaspad/wire" "github.com/kaspanet/kaspad/wire"
"github.com/kaspanet/kaspad/rpcmodel" "github.com/kaspanet/kaspad/rpcmodel"
@ -31,7 +32,7 @@ func (r FutureAddNodeResult) Receive() error {
// //
// See AddNode for the blocking version and more details. // See AddNode for the blocking version and more details.
func (c *Client) AddManualNodeAsync(host string) FutureAddNodeResult { func (c *Client) AddManualNodeAsync(host string) FutureAddNodeResult {
cmd := rpcmodel.NewAddManualNodeCmd(host, rpcmodel.Bool(false)) cmd := rpcmodel.NewAddManualNodeCmd(host, pointers.Bool(false))
return c.sendCmd(cmd) return c.sendCmd(cmd)
} }
@ -112,7 +113,7 @@ func (r FutureGetManualNodeInfoNoDNSResult) Receive() ([]string, error) {
// //
// See GetManualNodeInfoNoDNS for the blocking version and more details. // See GetManualNodeInfoNoDNS for the blocking version and more details.
func (c *Client) GetManualNodeInfoNoDNSAsync(peer string) FutureGetManualNodeInfoNoDNSResult { func (c *Client) GetManualNodeInfoNoDNSAsync(peer string) FutureGetManualNodeInfoNoDNSResult {
cmd := rpcmodel.NewGetManualNodeInfoCmd(peer, rpcmodel.Bool(false)) cmd := rpcmodel.NewGetManualNodeInfoCmd(peer, pointers.Bool(false))
return c.sendCmd(cmd) return c.sendCmd(cmd)
} }
@ -349,7 +350,7 @@ func (r FutureGetSelectedTipResult) Receive() (*wire.MsgBlock, error) {
// //
// See GetSelectedTip for the blocking version and more details. // See GetSelectedTip for the blocking version and more details.
func (c *Client) GetSelectedTipAsync() FutureGetSelectedTipResult { func (c *Client) GetSelectedTipAsync() FutureGetSelectedTipResult {
cmd := rpcmodel.NewGetSelectedTipCmd(rpcmodel.Bool(false), rpcmodel.Bool(false)) cmd := rpcmodel.NewGetSelectedTipCmd(pointers.Bool(false), pointers.Bool(false))
return c.sendCmd(cmd) return c.sendCmd(cmd)
} }
@ -385,7 +386,7 @@ func (r FutureGetSelectedTipVerboseResult) Receive() (*rpcmodel.GetBlockVerboseR
// //
// See GeSelectedTipBlockVerbose for the blocking version and more details. // See GeSelectedTipBlockVerbose for the blocking version and more details.
func (c *Client) GetSelectedTipVerboseAsync() FutureGetSelectedTipVerboseResult { func (c *Client) GetSelectedTipVerboseAsync() FutureGetSelectedTipVerboseResult {
cmd := rpcmodel.NewGetSelectedTipCmd(rpcmodel.Bool(true), rpcmodel.Bool(false)) cmd := rpcmodel.NewGetSelectedTipCmd(pointers.Bool(true), pointers.Bool(false))
return c.sendCmd(cmd) return c.sendCmd(cmd)
} }
@ -467,7 +468,7 @@ func (r FutureGetHeadersResult) Receive() ([]wire.BlockHeader, error) {
func (c *Client) GetTopHeadersAsync(highHash *daghash.Hash) FutureGetHeadersResult { func (c *Client) GetTopHeadersAsync(highHash *daghash.Hash) FutureGetHeadersResult {
var hash *string var hash *string
if highHash != nil { if highHash != nil {
hash = rpcmodel.String(highHash.String()) hash = pointers.String(highHash.String())
} }
cmd := rpcmodel.NewGetTopHeadersCmd(hash) cmd := rpcmodel.NewGetTopHeadersCmd(hash)
return c.sendCmd(cmd) return c.sendCmd(cmd)

View File

@ -8,6 +8,7 @@ import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"github.com/kaspanet/kaspad/util/pointers"
"github.com/kaspanet/kaspad/rpcmodel" "github.com/kaspanet/kaspad/rpcmodel"
"github.com/kaspanet/kaspad/util" "github.com/kaspanet/kaspad/util"
@ -59,7 +60,7 @@ func (c *Client) GetRawTransactionAsync(txID *daghash.TxID) FutureGetRawTransact
id = txID.String() id = txID.String()
} }
cmd := rpcmodel.NewGetRawTransactionCmd(id, rpcmodel.Int(0)) cmd := rpcmodel.NewGetRawTransactionCmd(id, pointers.Int(0))
return c.sendCmd(cmd) return c.sendCmd(cmd)
} }
@ -105,7 +106,7 @@ func (c *Client) GetRawTransactionVerboseAsync(txID *daghash.TxID) FutureGetRawT
id = txID.String() id = txID.String()
} }
cmd := rpcmodel.NewGetRawTransactionCmd(id, rpcmodel.Int(1)) cmd := rpcmodel.NewGetRawTransactionCmd(id, pointers.Int(1))
return c.sendCmd(cmd) return c.sendCmd(cmd)
} }
@ -310,7 +311,7 @@ func (r FutureSearchRawTransactionsResult) Receive() ([]*wire.MsgTx, error) {
// See SearchRawTransactions for the blocking version and more details. // See SearchRawTransactions for the blocking version and more details.
func (c *Client) SearchRawTransactionsAsync(address util.Address, skip, count int, reverse bool, filterAddrs []string) FutureSearchRawTransactionsResult { func (c *Client) SearchRawTransactionsAsync(address util.Address, skip, count int, reverse bool, filterAddrs []string) FutureSearchRawTransactionsResult {
addr := address.EncodeAddress() addr := address.EncodeAddress()
verbose := rpcmodel.Bool(false) verbose := pointers.Bool(false)
cmd := rpcmodel.NewSearchRawTransactionsCmd(addr, verbose, &skip, &count, cmd := rpcmodel.NewSearchRawTransactionsCmd(addr, verbose, &skip, &count,
nil, &reverse, &filterAddrs) nil, &reverse, &filterAddrs)
return c.sendCmd(cmd) return c.sendCmd(cmd)
@ -359,10 +360,10 @@ func (c *Client) SearchRawTransactionsVerboseAsync(address util.Address, skip,
count int, includePrevOut, reverse bool, filterAddrs *[]string) FutureSearchRawTransactionsVerboseResult { count int, includePrevOut, reverse bool, filterAddrs *[]string) FutureSearchRawTransactionsVerboseResult {
addr := address.EncodeAddress() addr := address.EncodeAddress()
verbose := rpcmodel.Bool(true) verbose := pointers.Bool(true)
var prevOut *bool var prevOut *bool
if includePrevOut { if includePrevOut {
prevOut = rpcmodel.Bool(true) prevOut = pointers.Bool(true)
} }
cmd := rpcmodel.NewSearchRawTransactionsCmd(addr, verbose, &skip, &count, cmd := rpcmodel.NewSearchRawTransactionsCmd(addr, verbose, &skip, &count,
prevOut, &reverse, filterAddrs) prevOut, &reverse, filterAddrs)

View File

@ -7,6 +7,7 @@ package rpcmodel_test
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/kaspanet/kaspad/util/pointers"
"github.com/kaspanet/kaspad/rpcmodel" "github.com/kaspanet/kaspad/rpcmodel"
) )
@ -17,11 +18,11 @@ func ExampleMarshalCommand() {
// Create a new getblock command. Notice the nil parameter indicates // Create a new getblock command. Notice the nil parameter indicates
// to use the default parameter for that fields. This is a common // to use the default parameter for that fields. This is a common
// pattern used in all of the New<Foo>Cmd functions in this package for // pattern used in all of the New<Foo>Cmd functions in this package for
// optional fields. Also, notice the call to rpcmodel.Bool which is a // optional fields. Also, notice the call to pointers.Bool which is a
// convenience function for creating a pointer out of a primitive for // convenience function for creating a pointer out of a primitive for
// optional parameters. // optional parameters.
blockHash := "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" blockHash := "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
gbCmd := rpcmodel.NewGetBlockCmd(blockHash, rpcmodel.Bool(false), nil, nil) gbCmd := rpcmodel.NewGetBlockCmd(blockHash, pointers.Bool(false), nil, nil)
// Marshal the command to the format suitable for sending to the RPC // Marshal the command to the format suitable for sending to the RPC
// server. Typically the client would increment the id here which is // server. Typically the client would increment the id here which is

View File

@ -9,6 +9,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/kaspanet/kaspad/util/pointers"
"reflect" "reflect"
"testing" "testing"
@ -39,7 +40,7 @@ func TestRPCServerCommands(t *testing.T) {
return rpcmodel.NewAddManualNodeCmd("127.0.0.1", nil) return rpcmodel.NewAddManualNodeCmd("127.0.0.1", nil)
}, },
marshalled: `{"jsonrpc":"1.0","method":"addManualNode","params":["127.0.0.1"],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"addManualNode","params":["127.0.0.1"],"id":1}`,
unmarshalled: &rpcmodel.AddManualNodeCmd{Addr: "127.0.0.1", OneTry: rpcmodel.Bool(false)}, unmarshalled: &rpcmodel.AddManualNodeCmd{Addr: "127.0.0.1", OneTry: pointers.Bool(false)},
}, },
{ {
name: "createRawTransaction", name: "createRawTransaction",
@ -71,13 +72,13 @@ func TestRPCServerCommands(t *testing.T) {
{TxID: "123", Vout: 1}, {TxID: "123", Vout: 1},
} }
amounts := map[string]float64{"456": .0123} amounts := map[string]float64{"456": .0123}
return rpcmodel.NewCreateRawTransactionCmd(txInputs, amounts, rpcmodel.Uint64(12312333333)) return rpcmodel.NewCreateRawTransactionCmd(txInputs, amounts, pointers.Uint64(12312333333))
}, },
marshalled: `{"jsonrpc":"1.0","method":"createRawTransaction","params":[[{"txId":"123","vout":1}],{"456":0.0123},12312333333],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"createRawTransaction","params":[[{"txId":"123","vout":1}],{"456":0.0123},12312333333],"id":1}`,
unmarshalled: &rpcmodel.CreateRawTransactionCmd{ unmarshalled: &rpcmodel.CreateRawTransactionCmd{
Inputs: []rpcmodel.TransactionInput{{TxID: "123", Vout: 1}}, Inputs: []rpcmodel.TransactionInput{{TxID: "123", Vout: 1}},
Amounts: map[string]float64{"456": .0123}, Amounts: map[string]float64{"456": .0123},
LockTime: rpcmodel.Uint64(12312333333), LockTime: pointers.Uint64(12312333333),
}, },
}, },
@ -112,7 +113,7 @@ func TestRPCServerCommands(t *testing.T) {
return rpcmodel.NewGetAllManualNodesInfoCmd(nil) return rpcmodel.NewGetAllManualNodesInfoCmd(nil)
}, },
marshalled: `{"jsonrpc":"1.0","method":"getAllManualNodesInfo","params":[],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"getAllManualNodesInfo","params":[],"id":1}`,
unmarshalled: &rpcmodel.GetAllManualNodesInfoCmd{Details: rpcmodel.Bool(true)}, unmarshalled: &rpcmodel.GetAllManualNodesInfoCmd{Details: pointers.Bool(true)},
}, },
{ {
name: "getSelectedTipHash", name: "getSelectedTipHash",
@ -136,8 +137,8 @@ func TestRPCServerCommands(t *testing.T) {
marshalled: `{"jsonrpc":"1.0","method":"getBlock","params":["123"],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"getBlock","params":["123"],"id":1}`,
unmarshalled: &rpcmodel.GetBlockCmd{ unmarshalled: &rpcmodel.GetBlockCmd{
Hash: "123", Hash: "123",
Verbose: rpcmodel.Bool(true), Verbose: pointers.Bool(true),
VerboseTx: rpcmodel.Bool(false), VerboseTx: pointers.Bool(false),
}, },
}, },
{ {
@ -146,17 +147,17 @@ func TestRPCServerCommands(t *testing.T) {
// Intentionally use a source param that is // Intentionally use a source param that is
// more pointers than the destination to // more pointers than the destination to
// exercise that path. // exercise that path.
verbosePtr := rpcmodel.Bool(true) verbosePtr := pointers.Bool(true)
return rpcmodel.NewCommand("getBlock", "123", &verbosePtr) return rpcmodel.NewCommand("getBlock", "123", &verbosePtr)
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewGetBlockCmd("123", rpcmodel.Bool(true), nil, nil) return rpcmodel.NewGetBlockCmd("123", pointers.Bool(true), nil, nil)
}, },
marshalled: `{"jsonrpc":"1.0","method":"getBlock","params":["123",true],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"getBlock","params":["123",true],"id":1}`,
unmarshalled: &rpcmodel.GetBlockCmd{ unmarshalled: &rpcmodel.GetBlockCmd{
Hash: "123", Hash: "123",
Verbose: rpcmodel.Bool(true), Verbose: pointers.Bool(true),
VerboseTx: rpcmodel.Bool(false), VerboseTx: pointers.Bool(false),
}, },
}, },
{ {
@ -165,13 +166,13 @@ func TestRPCServerCommands(t *testing.T) {
return rpcmodel.NewCommand("getBlock", "123", true, true) return rpcmodel.NewCommand("getBlock", "123", true, true)
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewGetBlockCmd("123", rpcmodel.Bool(true), rpcmodel.Bool(true), nil) return rpcmodel.NewGetBlockCmd("123", pointers.Bool(true), pointers.Bool(true), nil)
}, },
marshalled: `{"jsonrpc":"1.0","method":"getBlock","params":["123",true,true],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"getBlock","params":["123",true,true],"id":1}`,
unmarshalled: &rpcmodel.GetBlockCmd{ unmarshalled: &rpcmodel.GetBlockCmd{
Hash: "123", Hash: "123",
Verbose: rpcmodel.Bool(true), Verbose: pointers.Bool(true),
VerboseTx: rpcmodel.Bool(true), VerboseTx: pointers.Bool(true),
}, },
}, },
{ {
@ -180,14 +181,14 @@ func TestRPCServerCommands(t *testing.T) {
return rpcmodel.NewCommand("getBlock", "123", true, true, "456") return rpcmodel.NewCommand("getBlock", "123", true, true, "456")
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewGetBlockCmd("123", rpcmodel.Bool(true), rpcmodel.Bool(true), rpcmodel.String("456")) return rpcmodel.NewGetBlockCmd("123", pointers.Bool(true), pointers.Bool(true), pointers.String("456"))
}, },
marshalled: `{"jsonrpc":"1.0","method":"getBlock","params":["123",true,true,"456"],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"getBlock","params":["123",true,true,"456"],"id":1}`,
unmarshalled: &rpcmodel.GetBlockCmd{ unmarshalled: &rpcmodel.GetBlockCmd{
Hash: "123", Hash: "123",
Verbose: rpcmodel.Bool(true), Verbose: pointers.Bool(true),
VerboseTx: rpcmodel.Bool(true), VerboseTx: pointers.Bool(true),
Subnetwork: rpcmodel.String("456"), Subnetwork: pointers.String("456"),
}, },
}, },
{ {
@ -196,13 +197,13 @@ func TestRPCServerCommands(t *testing.T) {
return rpcmodel.NewCommand("getBlocks", true, true, "123") return rpcmodel.NewCommand("getBlocks", true, true, "123")
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewGetBlocksCmd(true, true, rpcmodel.String("123")) return rpcmodel.NewGetBlocksCmd(true, true, pointers.String("123"))
}, },
marshalled: `{"jsonrpc":"1.0","method":"getBlocks","params":[true,true,"123"],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"getBlocks","params":[true,true,"123"],"id":1}`,
unmarshalled: &rpcmodel.GetBlocksCmd{ unmarshalled: &rpcmodel.GetBlocksCmd{
IncludeRawBlockData: true, IncludeRawBlockData: true,
IncludeVerboseBlockData: true, IncludeVerboseBlockData: true,
LowHash: rpcmodel.String("123"), LowHash: pointers.String("123"),
}, },
}, },
{ {
@ -238,7 +239,7 @@ func TestRPCServerCommands(t *testing.T) {
marshalled: `{"jsonrpc":"1.0","method":"getBlockHeader","params":["123"],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"getBlockHeader","params":["123"],"id":1}`,
unmarshalled: &rpcmodel.GetBlockHeaderCmd{ unmarshalled: &rpcmodel.GetBlockHeaderCmd{
Hash: "123", Hash: "123",
Verbose: rpcmodel.Bool(true), Verbose: pointers.Bool(true),
}, },
}, },
{ {
@ -330,12 +331,12 @@ func TestRPCServerCommands(t *testing.T) {
return rpcmodel.NewCommand("getChainFromBlock", true, "123") return rpcmodel.NewCommand("getChainFromBlock", true, "123")
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewGetChainFromBlockCmd(true, rpcmodel.String("123")) return rpcmodel.NewGetChainFromBlockCmd(true, pointers.String("123"))
}, },
marshalled: `{"jsonrpc":"1.0","method":"getChainFromBlock","params":[true,"123"],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"getChainFromBlock","params":[true,"123"],"id":1}`,
unmarshalled: &rpcmodel.GetChainFromBlockCmd{ unmarshalled: &rpcmodel.GetChainFromBlockCmd{
IncludeBlocks: true, IncludeBlocks: true,
StartHash: rpcmodel.String("123"), StartHash: pointers.String("123"),
}, },
}, },
{ {
@ -393,7 +394,7 @@ func TestRPCServerCommands(t *testing.T) {
marshalled: `{"jsonrpc":"1.0","method":"getManualNodeInfo","params":["127.0.0.1"],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"getManualNodeInfo","params":["127.0.0.1"],"id":1}`,
unmarshalled: &rpcmodel.GetManualNodeInfoCmd{ unmarshalled: &rpcmodel.GetManualNodeInfoCmd{
Node: "127.0.0.1", Node: "127.0.0.1",
Details: rpcmodel.Bool(true), Details: pointers.Bool(true),
}, },
}, },
{ {
@ -463,7 +464,7 @@ func TestRPCServerCommands(t *testing.T) {
}, },
marshalled: `{"jsonrpc":"1.0","method":"getRawMempool","params":[],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"getRawMempool","params":[],"id":1}`,
unmarshalled: &rpcmodel.GetRawMempoolCmd{ unmarshalled: &rpcmodel.GetRawMempoolCmd{
Verbose: rpcmodel.Bool(false), Verbose: pointers.Bool(false),
}, },
}, },
{ {
@ -472,11 +473,11 @@ func TestRPCServerCommands(t *testing.T) {
return rpcmodel.NewCommand("getRawMempool", false) return rpcmodel.NewCommand("getRawMempool", false)
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewGetRawMempoolCmd(rpcmodel.Bool(false)) return rpcmodel.NewGetRawMempoolCmd(pointers.Bool(false))
}, },
marshalled: `{"jsonrpc":"1.0","method":"getRawMempool","params":[false],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"getRawMempool","params":[false],"id":1}`,
unmarshalled: &rpcmodel.GetRawMempoolCmd{ unmarshalled: &rpcmodel.GetRawMempoolCmd{
Verbose: rpcmodel.Bool(false), Verbose: pointers.Bool(false),
}, },
}, },
{ {
@ -490,7 +491,7 @@ func TestRPCServerCommands(t *testing.T) {
marshalled: `{"jsonrpc":"1.0","method":"getRawTransaction","params":["123"],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"getRawTransaction","params":["123"],"id":1}`,
unmarshalled: &rpcmodel.GetRawTransactionCmd{ unmarshalled: &rpcmodel.GetRawTransactionCmd{
TxID: "123", TxID: "123",
Verbose: rpcmodel.Int(0), Verbose: pointers.Int(0),
}, },
}, },
{ {
@ -499,12 +500,12 @@ func TestRPCServerCommands(t *testing.T) {
return rpcmodel.NewCommand("getRawTransaction", "123", 1) return rpcmodel.NewCommand("getRawTransaction", "123", 1)
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewGetRawTransactionCmd("123", rpcmodel.Int(1)) return rpcmodel.NewGetRawTransactionCmd("123", pointers.Int(1))
}, },
marshalled: `{"jsonrpc":"1.0","method":"getRawTransaction","params":["123",1],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"getRawTransaction","params":["123",1],"id":1}`,
unmarshalled: &rpcmodel.GetRawTransactionCmd{ unmarshalled: &rpcmodel.GetRawTransactionCmd{
TxID: "123", TxID: "123",
Verbose: rpcmodel.Int(1), Verbose: pointers.Int(1),
}, },
}, },
{ {
@ -532,7 +533,7 @@ func TestRPCServerCommands(t *testing.T) {
unmarshalled: &rpcmodel.GetTxOutCmd{ unmarshalled: &rpcmodel.GetTxOutCmd{
TxID: "123", TxID: "123",
Vout: 1, Vout: 1,
IncludeMempool: rpcmodel.Bool(true), IncludeMempool: pointers.Bool(true),
}, },
}, },
{ {
@ -541,13 +542,13 @@ func TestRPCServerCommands(t *testing.T) {
return rpcmodel.NewCommand("getTxOut", "123", 1, true) return rpcmodel.NewCommand("getTxOut", "123", 1, true)
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewGetTxOutCmd("123", 1, rpcmodel.Bool(true)) return rpcmodel.NewGetTxOutCmd("123", 1, pointers.Bool(true))
}, },
marshalled: `{"jsonrpc":"1.0","method":"getTxOut","params":["123",1,true],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"getTxOut","params":["123",1,true],"id":1}`,
unmarshalled: &rpcmodel.GetTxOutCmd{ unmarshalled: &rpcmodel.GetTxOutCmd{
TxID: "123", TxID: "123",
Vout: 1, Vout: 1,
IncludeMempool: rpcmodel.Bool(true), IncludeMempool: pointers.Bool(true),
}, },
}, },
{ {
@ -580,11 +581,11 @@ func TestRPCServerCommands(t *testing.T) {
return rpcmodel.NewCommand("help", "getBlock") return rpcmodel.NewCommand("help", "getBlock")
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewHelpCmd(rpcmodel.String("getBlock")) return rpcmodel.NewHelpCmd(pointers.String("getBlock"))
}, },
marshalled: `{"jsonrpc":"1.0","method":"help","params":["getBlock"],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"help","params":["getBlock"],"id":1}`,
unmarshalled: &rpcmodel.HelpCmd{ unmarshalled: &rpcmodel.HelpCmd{
Command: rpcmodel.String("getBlock"), Command: pointers.String("getBlock"),
}, },
}, },
{ {
@ -620,11 +621,11 @@ func TestRPCServerCommands(t *testing.T) {
marshalled: `{"jsonrpc":"1.0","method":"searchRawTransactions","params":["1Address"],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"searchRawTransactions","params":["1Address"],"id":1}`,
unmarshalled: &rpcmodel.SearchRawTransactionsCmd{ unmarshalled: &rpcmodel.SearchRawTransactionsCmd{
Address: "1Address", Address: "1Address",
Verbose: rpcmodel.Bool(true), Verbose: pointers.Bool(true),
Skip: rpcmodel.Int(0), Skip: pointers.Int(0),
Count: rpcmodel.Int(100), Count: pointers.Int(100),
VinExtra: rpcmodel.Bool(false), VinExtra: pointers.Bool(false),
Reverse: rpcmodel.Bool(false), Reverse: pointers.Bool(false),
FilterAddrs: nil, FilterAddrs: nil,
}, },
}, },
@ -635,16 +636,16 @@ func TestRPCServerCommands(t *testing.T) {
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewSearchRawTransactionsCmd("1Address", return rpcmodel.NewSearchRawTransactionsCmd("1Address",
rpcmodel.Bool(false), nil, nil, nil, nil, nil) pointers.Bool(false), nil, nil, nil, nil, nil)
}, },
marshalled: `{"jsonrpc":"1.0","method":"searchRawTransactions","params":["1Address",false],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"searchRawTransactions","params":["1Address",false],"id":1}`,
unmarshalled: &rpcmodel.SearchRawTransactionsCmd{ unmarshalled: &rpcmodel.SearchRawTransactionsCmd{
Address: "1Address", Address: "1Address",
Verbose: rpcmodel.Bool(false), Verbose: pointers.Bool(false),
Skip: rpcmodel.Int(0), Skip: pointers.Int(0),
Count: rpcmodel.Int(100), Count: pointers.Int(100),
VinExtra: rpcmodel.Bool(false), VinExtra: pointers.Bool(false),
Reverse: rpcmodel.Bool(false), Reverse: pointers.Bool(false),
FilterAddrs: nil, FilterAddrs: nil,
}, },
}, },
@ -655,16 +656,16 @@ func TestRPCServerCommands(t *testing.T) {
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewSearchRawTransactionsCmd("1Address", return rpcmodel.NewSearchRawTransactionsCmd("1Address",
rpcmodel.Bool(false), rpcmodel.Int(5), nil, nil, nil, nil) pointers.Bool(false), pointers.Int(5), nil, nil, nil, nil)
}, },
marshalled: `{"jsonrpc":"1.0","method":"searchRawTransactions","params":["1Address",false,5],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"searchRawTransactions","params":["1Address",false,5],"id":1}`,
unmarshalled: &rpcmodel.SearchRawTransactionsCmd{ unmarshalled: &rpcmodel.SearchRawTransactionsCmd{
Address: "1Address", Address: "1Address",
Verbose: rpcmodel.Bool(false), Verbose: pointers.Bool(false),
Skip: rpcmodel.Int(5), Skip: pointers.Int(5),
Count: rpcmodel.Int(100), Count: pointers.Int(100),
VinExtra: rpcmodel.Bool(false), VinExtra: pointers.Bool(false),
Reverse: rpcmodel.Bool(false), Reverse: pointers.Bool(false),
FilterAddrs: nil, FilterAddrs: nil,
}, },
}, },
@ -675,16 +676,16 @@ func TestRPCServerCommands(t *testing.T) {
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewSearchRawTransactionsCmd("1Address", return rpcmodel.NewSearchRawTransactionsCmd("1Address",
rpcmodel.Bool(false), rpcmodel.Int(5), rpcmodel.Int(10), nil, nil, nil) pointers.Bool(false), pointers.Int(5), pointers.Int(10), nil, nil, nil)
}, },
marshalled: `{"jsonrpc":"1.0","method":"searchRawTransactions","params":["1Address",false,5,10],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"searchRawTransactions","params":["1Address",false,5,10],"id":1}`,
unmarshalled: &rpcmodel.SearchRawTransactionsCmd{ unmarshalled: &rpcmodel.SearchRawTransactionsCmd{
Address: "1Address", Address: "1Address",
Verbose: rpcmodel.Bool(false), Verbose: pointers.Bool(false),
Skip: rpcmodel.Int(5), Skip: pointers.Int(5),
Count: rpcmodel.Int(10), Count: pointers.Int(10),
VinExtra: rpcmodel.Bool(false), VinExtra: pointers.Bool(false),
Reverse: rpcmodel.Bool(false), Reverse: pointers.Bool(false),
FilterAddrs: nil, FilterAddrs: nil,
}, },
}, },
@ -695,16 +696,16 @@ func TestRPCServerCommands(t *testing.T) {
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewSearchRawTransactionsCmd("1Address", return rpcmodel.NewSearchRawTransactionsCmd("1Address",
rpcmodel.Bool(false), rpcmodel.Int(5), rpcmodel.Int(10), rpcmodel.Bool(true), nil, nil) pointers.Bool(false), pointers.Int(5), pointers.Int(10), pointers.Bool(true), nil, nil)
}, },
marshalled: `{"jsonrpc":"1.0","method":"searchRawTransactions","params":["1Address",false,5,10,true],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"searchRawTransactions","params":["1Address",false,5,10,true],"id":1}`,
unmarshalled: &rpcmodel.SearchRawTransactionsCmd{ unmarshalled: &rpcmodel.SearchRawTransactionsCmd{
Address: "1Address", Address: "1Address",
Verbose: rpcmodel.Bool(false), Verbose: pointers.Bool(false),
Skip: rpcmodel.Int(5), Skip: pointers.Int(5),
Count: rpcmodel.Int(10), Count: pointers.Int(10),
VinExtra: rpcmodel.Bool(true), VinExtra: pointers.Bool(true),
Reverse: rpcmodel.Bool(false), Reverse: pointers.Bool(false),
FilterAddrs: nil, FilterAddrs: nil,
}, },
}, },
@ -715,16 +716,16 @@ func TestRPCServerCommands(t *testing.T) {
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewSearchRawTransactionsCmd("1Address", return rpcmodel.NewSearchRawTransactionsCmd("1Address",
rpcmodel.Bool(false), rpcmodel.Int(5), rpcmodel.Int(10), rpcmodel.Bool(true), rpcmodel.Bool(true), nil) pointers.Bool(false), pointers.Int(5), pointers.Int(10), pointers.Bool(true), pointers.Bool(true), nil)
}, },
marshalled: `{"jsonrpc":"1.0","method":"searchRawTransactions","params":["1Address",false,5,10,true,true],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"searchRawTransactions","params":["1Address",false,5,10,true,true],"id":1}`,
unmarshalled: &rpcmodel.SearchRawTransactionsCmd{ unmarshalled: &rpcmodel.SearchRawTransactionsCmd{
Address: "1Address", Address: "1Address",
Verbose: rpcmodel.Bool(false), Verbose: pointers.Bool(false),
Skip: rpcmodel.Int(5), Skip: pointers.Int(5),
Count: rpcmodel.Int(10), Count: pointers.Int(10),
VinExtra: rpcmodel.Bool(true), VinExtra: pointers.Bool(true),
Reverse: rpcmodel.Bool(true), Reverse: pointers.Bool(true),
FilterAddrs: nil, FilterAddrs: nil,
}, },
}, },
@ -735,16 +736,16 @@ func TestRPCServerCommands(t *testing.T) {
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewSearchRawTransactionsCmd("1Address", return rpcmodel.NewSearchRawTransactionsCmd("1Address",
rpcmodel.Bool(false), rpcmodel.Int(5), rpcmodel.Int(10), rpcmodel.Bool(true), rpcmodel.Bool(true), &[]string{"1Address"}) pointers.Bool(false), pointers.Int(5), pointers.Int(10), pointers.Bool(true), pointers.Bool(true), &[]string{"1Address"})
}, },
marshalled: `{"jsonrpc":"1.0","method":"searchRawTransactions","params":["1Address",false,5,10,true,true,["1Address"]],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"searchRawTransactions","params":["1Address",false,5,10,true,true,["1Address"]],"id":1}`,
unmarshalled: &rpcmodel.SearchRawTransactionsCmd{ unmarshalled: &rpcmodel.SearchRawTransactionsCmd{
Address: "1Address", Address: "1Address",
Verbose: rpcmodel.Bool(false), Verbose: pointers.Bool(false),
Skip: rpcmodel.Int(5), Skip: pointers.Int(5),
Count: rpcmodel.Int(10), Count: pointers.Int(10),
VinExtra: rpcmodel.Bool(true), VinExtra: pointers.Bool(true),
Reverse: rpcmodel.Bool(true), Reverse: pointers.Bool(true),
FilterAddrs: &[]string{"1Address"}, FilterAddrs: &[]string{"1Address"},
}, },
}, },
@ -759,7 +760,7 @@ func TestRPCServerCommands(t *testing.T) {
marshalled: `{"jsonrpc":"1.0","method":"sendRawTransaction","params":["1122"],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"sendRawTransaction","params":["1122"],"id":1}`,
unmarshalled: &rpcmodel.SendRawTransactionCmd{ unmarshalled: &rpcmodel.SendRawTransactionCmd{
HexTx: "1122", HexTx: "1122",
AllowHighFees: rpcmodel.Bool(false), AllowHighFees: pointers.Bool(false),
}, },
}, },
{ {
@ -768,12 +769,12 @@ func TestRPCServerCommands(t *testing.T) {
return rpcmodel.NewCommand("sendRawTransaction", "1122", false) return rpcmodel.NewCommand("sendRawTransaction", "1122", false)
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewSendRawTransactionCmd("1122", rpcmodel.Bool(false)) return rpcmodel.NewSendRawTransactionCmd("1122", pointers.Bool(false))
}, },
marshalled: `{"jsonrpc":"1.0","method":"sendRawTransaction","params":["1122",false],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"sendRawTransaction","params":["1122",false],"id":1}`,
unmarshalled: &rpcmodel.SendRawTransactionCmd{ unmarshalled: &rpcmodel.SendRawTransactionCmd{
HexTx: "1122", HexTx: "1122",
AllowHighFees: rpcmodel.Bool(false), AllowHighFees: pointers.Bool(false),
}, },
}, },
{ {
@ -891,13 +892,13 @@ func TestRPCServerCommands(t *testing.T) {
return rpcmodel.NewCommand("node", rpcmodel.NConnect, "1.1.1.1", "perm") return rpcmodel.NewCommand("node", rpcmodel.NConnect, "1.1.1.1", "perm")
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewNodeCmd("connect", "1.1.1.1", rpcmodel.String("perm")) return rpcmodel.NewNodeCmd("connect", "1.1.1.1", pointers.String("perm"))
}, },
marshalled: `{"jsonrpc":"1.0","method":"node","params":["connect","1.1.1.1","perm"],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"node","params":["connect","1.1.1.1","perm"],"id":1}`,
unmarshalled: &rpcmodel.NodeCmd{ unmarshalled: &rpcmodel.NodeCmd{
SubCmd: rpcmodel.NConnect, SubCmd: rpcmodel.NConnect,
Target: "1.1.1.1", Target: "1.1.1.1",
ConnectSubCmd: rpcmodel.String("perm"), ConnectSubCmd: pointers.String("perm"),
}, },
}, },
{ {
@ -906,13 +907,13 @@ func TestRPCServerCommands(t *testing.T) {
return rpcmodel.NewCommand("node", rpcmodel.NConnect, "1.1.1.1", "temp") return rpcmodel.NewCommand("node", rpcmodel.NConnect, "1.1.1.1", "temp")
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewNodeCmd("connect", "1.1.1.1", rpcmodel.String("temp")) return rpcmodel.NewNodeCmd("connect", "1.1.1.1", pointers.String("temp"))
}, },
marshalled: `{"jsonrpc":"1.0","method":"node","params":["connect","1.1.1.1","temp"],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"node","params":["connect","1.1.1.1","temp"],"id":1}`,
unmarshalled: &rpcmodel.NodeCmd{ unmarshalled: &rpcmodel.NodeCmd{
SubCmd: rpcmodel.NConnect, SubCmd: rpcmodel.NConnect,
Target: "1.1.1.1", Target: "1.1.1.1",
ConnectSubCmd: rpcmodel.String("temp"), ConnectSubCmd: pointers.String("temp"),
}, },
}, },
{ {
@ -925,8 +926,8 @@ func TestRPCServerCommands(t *testing.T) {
}, },
marshalled: `{"jsonrpc":"1.0","method":"getSelectedTip","params":[],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"getSelectedTip","params":[],"id":1}`,
unmarshalled: &rpcmodel.GetSelectedTipCmd{ unmarshalled: &rpcmodel.GetSelectedTipCmd{
Verbose: rpcmodel.Bool(true), Verbose: pointers.Bool(true),
VerboseTx: rpcmodel.Bool(false), VerboseTx: pointers.Bool(false),
}, },
}, },
{ {
@ -994,12 +995,12 @@ func TestRPCServerCommands(t *testing.T) {
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewGetTopHeadersCmd( return rpcmodel.NewGetTopHeadersCmd(
rpcmodel.String("000000000000000000ba33b33e1fad70b69e234fc24414dd47113bff38f523f7"), pointers.String("000000000000000000ba33b33e1fad70b69e234fc24414dd47113bff38f523f7"),
) )
}, },
marshalled: `{"jsonrpc":"1.0","method":"getTopHeaders","params":["000000000000000000ba33b33e1fad70b69e234fc24414dd47113bff38f523f7"],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"getTopHeaders","params":["000000000000000000ba33b33e1fad70b69e234fc24414dd47113bff38f523f7"],"id":1}`,
unmarshalled: &rpcmodel.GetTopHeadersCmd{ unmarshalled: &rpcmodel.GetTopHeadersCmd{
HighHash: rpcmodel.String("000000000000000000ba33b33e1fad70b69e234fc24414dd47113bff38f523f7"), HighHash: pointers.String("000000000000000000ba33b33e1fad70b69e234fc24414dd47113bff38f523f7"),
}, },
}, },
{ {

View File

@ -6,6 +6,7 @@ package rpcmodel_test
import ( import (
"encoding/json" "encoding/json"
"github.com/kaspanet/kaspad/util/pointers"
"testing" "testing"
"github.com/kaspanet/kaspad/rpcmodel" "github.com/kaspanet/kaspad/rpcmodel"
@ -53,7 +54,7 @@ func TestRPCServerCustomResults(t *testing.T) {
Hex: "00", Hex: "00",
}, },
PrevOut: &rpcmodel.PrevOut{ PrevOut: &rpcmodel.PrevOut{
Address: rpcmodel.String("addr1"), Address: pointers.String("addr1"),
Value: 0, Value: 0,
}, },
Sequence: 4294967295, Sequence: 4294967295,

View File

@ -9,6 +9,7 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/kaspanet/kaspad/util/pointers"
"reflect" "reflect"
"testing" "testing"
@ -95,7 +96,7 @@ func TestRPCServerWebsocketCommands(t *testing.T) {
}, },
marshalled: `{"jsonrpc":"1.0","method":"notifyNewTransactions","params":[],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"notifyNewTransactions","params":[],"id":1}`,
unmarshalled: &rpcmodel.NotifyNewTransactionsCmd{ unmarshalled: &rpcmodel.NotifyNewTransactionsCmd{
Verbose: rpcmodel.Bool(false), Verbose: pointers.Bool(false),
}, },
}, },
{ {
@ -104,11 +105,11 @@ func TestRPCServerWebsocketCommands(t *testing.T) {
return rpcmodel.NewCommand("notifyNewTransactions", true) return rpcmodel.NewCommand("notifyNewTransactions", true)
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewNotifyNewTransactionsCmd(rpcmodel.Bool(true), nil) return rpcmodel.NewNotifyNewTransactionsCmd(pointers.Bool(true), nil)
}, },
marshalled: `{"jsonrpc":"1.0","method":"notifyNewTransactions","params":[true],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"notifyNewTransactions","params":[true],"id":1}`,
unmarshalled: &rpcmodel.NotifyNewTransactionsCmd{ unmarshalled: &rpcmodel.NotifyNewTransactionsCmd{
Verbose: rpcmodel.Bool(true), Verbose: pointers.Bool(true),
}, },
}, },
{ {
@ -117,12 +118,12 @@ func TestRPCServerWebsocketCommands(t *testing.T) {
return rpcmodel.NewCommand("notifyNewTransactions", true, "0000000000000000000000000000000000000123") return rpcmodel.NewCommand("notifyNewTransactions", true, "0000000000000000000000000000000000000123")
}, },
staticCmd: func() interface{} { staticCmd: func() interface{} {
return rpcmodel.NewNotifyNewTransactionsCmd(rpcmodel.Bool(true), rpcmodel.String("0000000000000000000000000000000000000123")) return rpcmodel.NewNotifyNewTransactionsCmd(pointers.Bool(true), pointers.String("0000000000000000000000000000000000000123"))
}, },
marshalled: `{"jsonrpc":"1.0","method":"notifyNewTransactions","params":[true,"0000000000000000000000000000000000000123"],"id":1}`, marshalled: `{"jsonrpc":"1.0","method":"notifyNewTransactions","params":[true,"0000000000000000000000000000000000000123"],"id":1}`,
unmarshalled: &rpcmodel.NotifyNewTransactionsCmd{ unmarshalled: &rpcmodel.NotifyNewTransactionsCmd{
Verbose: rpcmodel.Bool(true), Verbose: pointers.Bool(true),
Subnetwork: rpcmodel.String("0000000000000000000000000000000000000123"), Subnetwork: pointers.String("0000000000000000000000000000000000000123"),
}, },
}, },
{ {

View File

@ -9,6 +9,7 @@ import (
"github.com/kaspanet/kaspad/txscript" "github.com/kaspanet/kaspad/txscript"
"github.com/kaspanet/kaspad/util" "github.com/kaspanet/kaspad/util"
"github.com/kaspanet/kaspad/util/daghash" "github.com/kaspanet/kaspad/util/daghash"
"github.com/kaspanet/kaspad/util/pointers"
"github.com/kaspanet/kaspad/wire" "github.com/kaspanet/kaspad/wire"
"github.com/pkg/errors" "github.com/pkg/errors"
"math/big" "math/big"
@ -110,7 +111,7 @@ func createVoutList(mtx *wire.MsgTx, dagParams *dagconfig.Params, filterAddrMap
passesFilter := len(filterAddrMap) == 0 passesFilter := len(filterAddrMap) == 0
var encodedAddr *string var encodedAddr *string
if addr != nil { if addr != nil {
encodedAddr = rpcmodel.String(addr.EncodeAddress()) encodedAddr = pointers.String(addr.EncodeAddress())
// If the filter doesn't already pass, make it pass if // If the filter doesn't already pass, make it pass if
// the address exists in the filter. // the address exists in the filter.
@ -177,7 +178,7 @@ func createTxRawResult(dagParams *dagconfig.Params, mtx *wire.MsgTx,
txReply.Confirmations = confirmations txReply.Confirmations = confirmations
txReply.IsInMempool = isInMempool txReply.IsInMempool = isInMempool
if acceptingBlock != nil { if acceptingBlock != nil {
txReply.AcceptedBy = rpcmodel.String(acceptingBlock.String()) txReply.AcceptedBy = pointers.String(acceptingBlock.String())
} }
return txReply, nil return txReply, nil

View File

@ -5,6 +5,7 @@ import (
"github.com/kaspanet/kaspad/rpcmodel" "github.com/kaspanet/kaspad/rpcmodel"
"github.com/kaspanet/kaspad/txscript" "github.com/kaspanet/kaspad/txscript"
"github.com/kaspanet/kaspad/util" "github.com/kaspanet/kaspad/util"
"github.com/kaspanet/kaspad/util/pointers"
) )
// handleDecodeScript handles decodeScript commands. // handleDecodeScript handles decodeScript commands.
@ -32,7 +33,7 @@ func handleDecodeScript(s *Server, cmd interface{}, closeChan <-chan struct{}) (
s.cfg.DAGParams) s.cfg.DAGParams)
var address *string var address *string
if addr != nil { if addr != nil {
address = rpcmodel.String(addr.EncodeAddress()) address = pointers.String(addr.EncodeAddress())
} }
// Convert the script itself to a pay-to-script-hash address. // Convert the script itself to a pay-to-script-hash address.

View File

@ -4,6 +4,7 @@ import (
"github.com/kaspanet/kaspad/logger" "github.com/kaspanet/kaspad/logger"
"github.com/kaspanet/kaspad/rpcmodel" "github.com/kaspanet/kaspad/rpcmodel"
"github.com/kaspanet/kaspad/server/serverutils" "github.com/kaspanet/kaspad/server/serverutils"
"github.com/kaspanet/kaspad/util/pointers"
"net" "net"
) )
@ -64,7 +65,7 @@ func getManualNodesInfo(s *Server, detailsArg *bool, node string) (interface{},
peer := rpcPeer.ToPeer() peer := rpcPeer.ToPeer()
var result rpcmodel.GetManualNodeInfoResult var result rpcmodel.GetManualNodeInfoResult
result.ManualNode = peer.Addr() result.ManualNode = peer.Addr()
result.Connected = rpcmodel.Bool(peer.Connected()) result.Connected = pointers.Bool(peer.Connected())
// Split the address into host and port portions so we can do // Split the address into host and port portions so we can do
// a DNS lookup against the host. When no port is specified in // a DNS lookup against the host. When no port is specified in

View File

@ -7,6 +7,7 @@ import (
"github.com/kaspanet/kaspad/txscript" "github.com/kaspanet/kaspad/txscript"
"github.com/kaspanet/kaspad/util" "github.com/kaspanet/kaspad/util"
"github.com/kaspanet/kaspad/util/daghash" "github.com/kaspanet/kaspad/util/daghash"
"github.com/kaspanet/kaspad/util/pointers"
"github.com/kaspanet/kaspad/wire" "github.com/kaspanet/kaspad/wire"
) )
@ -104,7 +105,7 @@ func handleGetTxOut(s *Server, cmd interface{}, closeChan <-chan struct{}) (inte
s.cfg.DAGParams) s.cfg.DAGParams)
var address *string var address *string
if addr != nil { if addr != nil {
address = rpcmodel.String(addr.EncodeAddress()) address = pointers.String(addr.EncodeAddress())
} }
txOutReply := &rpcmodel.GetTxOutResult{ txOutReply := &rpcmodel.GetTxOutResult{

View File

@ -10,6 +10,7 @@ import (
"github.com/kaspanet/kaspad/txscript" "github.com/kaspanet/kaspad/txscript"
"github.com/kaspanet/kaspad/util" "github.com/kaspanet/kaspad/util"
"github.com/kaspanet/kaspad/util/daghash" "github.com/kaspanet/kaspad/util/daghash"
"github.com/kaspanet/kaspad/util/pointers"
"github.com/kaspanet/kaspad/wire" "github.com/kaspanet/kaspad/wire"
) )
@ -351,7 +352,7 @@ func createVinListPrevOut(s *Server, mtx *wire.MsgTx, dagParams *dagconfig.Param
if addr != nil { if addr != nil {
// Encode the address while checking if the address passes the // Encode the address while checking if the address passes the
// filter when needed. // filter when needed.
encodedAddr = rpcmodel.String(addr.EncodeAddress()) encodedAddr = pointers.String(addr.EncodeAddress())
// If the filter doesn't already pass, make it pass if // If the filter doesn't already pass, make it pass if
// the address exists in the filter. // the address exists in the filter.

View File

@ -1,8 +1,4 @@
// Copyright (c) 2014 The btcsuite developers package pointers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package rpcmodel
// Bool is a helper routine that allocates a new bool value to store v and // Bool is a helper routine that allocates a new bool value to store v and
// returns a pointer to it. This is useful when assigning optional parameters. // returns a pointer to it. This is useful when assigning optional parameters.

View File

@ -2,18 +2,16 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package rpcmodel_test package pointers
import ( import (
"reflect" "reflect"
"testing" "testing"
"github.com/kaspanet/kaspad/rpcmodel"
) )
// TestHelpers tests the various helper functions which create pointers to // TestCopyToPointer tests the various helper functions which create pointers to
// primitive types. // primitive types.
func TestHelpers(t *testing.T) { func TestCopyToPointer(t *testing.T) {
t.Parallel() t.Parallel()
tests := []struct { tests := []struct {
@ -24,7 +22,7 @@ func TestHelpers(t *testing.T) {
{ {
name: "bool", name: "bool",
f: func() interface{} { f: func() interface{} {
return rpcmodel.Bool(true) return Bool(true)
}, },
expected: func() interface{} { expected: func() interface{} {
val := true val := true
@ -34,7 +32,7 @@ func TestHelpers(t *testing.T) {
{ {
name: "int", name: "int",
f: func() interface{} { f: func() interface{} {
return rpcmodel.Int(5) return Int(5)
}, },
expected: func() interface{} { expected: func() interface{} {
val := int(5) val := int(5)
@ -44,7 +42,7 @@ func TestHelpers(t *testing.T) {
{ {
name: "uint", name: "uint",
f: func() interface{} { f: func() interface{} {
return rpcmodel.Uint(5) return Uint(5)
}, },
expected: func() interface{} { expected: func() interface{} {
val := uint(5) val := uint(5)
@ -54,7 +52,7 @@ func TestHelpers(t *testing.T) {
{ {
name: "int32", name: "int32",
f: func() interface{} { f: func() interface{} {
return rpcmodel.Int32(5) return Int32(5)
}, },
expected: func() interface{} { expected: func() interface{} {
val := int32(5) val := int32(5)
@ -64,7 +62,7 @@ func TestHelpers(t *testing.T) {
{ {
name: "uint32", name: "uint32",
f: func() interface{} { f: func() interface{} {
return rpcmodel.Uint32(5) return Uint32(5)
}, },
expected: func() interface{} { expected: func() interface{} {
val := uint32(5) val := uint32(5)
@ -74,7 +72,7 @@ func TestHelpers(t *testing.T) {
{ {
name: "int64", name: "int64",
f: func() interface{} { f: func() interface{} {
return rpcmodel.Int64(5) return Int64(5)
}, },
expected: func() interface{} { expected: func() interface{} {
val := int64(5) val := int64(5)
@ -84,7 +82,7 @@ func TestHelpers(t *testing.T) {
{ {
name: "uint64", name: "uint64",
f: func() interface{} { f: func() interface{} {
return rpcmodel.Uint64(5) return Uint64(5)
}, },
expected: func() interface{} { expected: func() interface{} {
val := uint64(5) val := uint64(5)
@ -94,7 +92,7 @@ func TestHelpers(t *testing.T) {
{ {
name: "string", name: "string",
f: func() interface{} { f: func() interface{} {
return rpcmodel.String("abc") return String("abc")
}, },
expected: func() interface{} { expected: func() interface{} {
val := "abc" val := "abc"