[DEV-35] Updated btcjson package to work with DAG

* [DEV-35] Updated btcjson package to work with DAG

* [DEV-35] Rename all chainsvr* packages to dagsvr*
This commit is contained in:
Svarog 2018-06-21 16:45:09 +03:00 committed by stasatdaglabs
parent 7ed7685373
commit dbd1aec9b8
14 changed files with 86 additions and 86 deletions

View File

@ -4,7 +4,7 @@
// license that can be found in the LICENSE file.
// NOTE: This file is intended to house the RPC commands that are supported by
// a chain server with btcd extensions.
// a dag server with btcd extensions.
package btcjson

View File

@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.
// NOTE: This file is intended to house the RPC commands that are supported by
// a chain server.
// a dag server.
package btcjson
@ -147,13 +147,13 @@ func NewGetBlockCmd(hash string, verbose, verboseTx *bool) *GetBlockCmd {
}
}
// GetBlockChainInfoCmd defines the getblockchaininfo JSON-RPC command.
type GetBlockChainInfoCmd struct{}
// GetBlockDAGInfoCmd defines the getblockdaginfo JSON-RPC command.
type GetBlockDAGInfoCmd struct{}
// NewGetBlockChainInfoCmd returns a new instance which can be used to issue a
// getblockchaininfo JSON-RPC command.
func NewGetBlockChainInfoCmd() *GetBlockChainInfoCmd {
return &GetBlockChainInfoCmd{}
// NewGetBlockDAGInfoCmd returns a new instance which can be used to issue a
// getblockdaginfo JSON-RPC command.
func NewGetBlockDAGInfoCmd() *GetBlockDAGInfoCmd {
return &GetBlockDAGInfoCmd{}
}
// GetBlockCountCmd defines the getblockcount JSON-RPC command.
@ -312,13 +312,13 @@ func NewGetCFilterHeaderCmd(hash string,
}
}
// GetChainTipsCmd defines the getchaintips JSON-RPC command.
type GetChainTipsCmd struct{}
// GetDAGTipsCmd defines the getdagtips JSON-RPC command.
type GetDAGTipsCmd struct{}
// NewGetChainTipsCmd returns a new instance which can be used to issue a
// getchaintips JSON-RPC command.
func NewGetChainTipsCmd() *GetChainTipsCmd {
return &GetChainTipsCmd{}
// NewGetDAGTipsCmd returns a new instance which can be used to issue a
// getdagtips JSON-RPC command.
func NewGetDAGTipsCmd() *GetDAGTipsCmd {
return &GetDAGTipsCmd{}
}
// GetConnectionCountCmd defines the getconnectioncount JSON-RPC command.
@ -725,19 +725,19 @@ func NewValidateAddressCmd(address string) *ValidateAddressCmd {
}
}
// VerifyChainCmd defines the verifychain JSON-RPC command.
type VerifyChainCmd struct {
// VerifyDAGCmd defines the verifydag JSON-RPC command.
type VerifyDAGCmd struct {
CheckLevel *int32 `jsonrpcdefault:"3"`
CheckDepth *int32 `jsonrpcdefault:"288"` // 0 = all
}
// NewVerifyChainCmd returns a new instance which can be used to issue a
// verifychain JSON-RPC command.
// NewVerifyDAGCmd returns a new instance which can be used to issue a
// verifydag JSON-RPC command.
//
// The parameters which are pointers indicate they are optional. Passing nil
// for optional parameters will use the default value.
func NewVerifyChainCmd(checkLevel, checkDepth *int32) *VerifyChainCmd {
return &VerifyChainCmd{
func NewVerifyDAGCmd(checkLevel, checkDepth *int32) *VerifyDAGCmd {
return &VerifyDAGCmd{
CheckLevel: checkLevel,
CheckDepth: checkDepth,
}
@ -784,14 +784,14 @@ func init() {
MustRegisterCmd("getaddednodeinfo", (*GetAddedNodeInfoCmd)(nil), flags)
MustRegisterCmd("getbestblockhash", (*GetBestBlockHashCmd)(nil), flags)
MustRegisterCmd("getblock", (*GetBlockCmd)(nil), flags)
MustRegisterCmd("getblockchaininfo", (*GetBlockChainInfoCmd)(nil), flags)
MustRegisterCmd("getblockdaginfo", (*GetBlockDAGInfoCmd)(nil), flags)
MustRegisterCmd("getblockcount", (*GetBlockCountCmd)(nil), flags)
MustRegisterCmd("getblockhash", (*GetBlockHashCmd)(nil), flags)
MustRegisterCmd("getblockheader", (*GetBlockHeaderCmd)(nil), flags)
MustRegisterCmd("getblocktemplate", (*GetBlockTemplateCmd)(nil), flags)
MustRegisterCmd("getcfilter", (*GetCFilterCmd)(nil), flags)
MustRegisterCmd("getcfilterheader", (*GetCFilterHeaderCmd)(nil), flags)
MustRegisterCmd("getchaintips", (*GetChainTipsCmd)(nil), flags)
MustRegisterCmd("getdagtips", (*GetDAGTipsCmd)(nil), flags)
MustRegisterCmd("getconnectioncount", (*GetConnectionCountCmd)(nil), flags)
MustRegisterCmd("getdifficulty", (*GetDifficultyCmd)(nil), flags)
MustRegisterCmd("getgenerate", (*GetGenerateCmd)(nil), flags)
@ -822,7 +822,7 @@ func init() {
MustRegisterCmd("submitblock", (*SubmitBlockCmd)(nil), flags)
MustRegisterCmd("uptime", (*UptimeCmd)(nil), flags)
MustRegisterCmd("validateaddress", (*ValidateAddressCmd)(nil), flags)
MustRegisterCmd("verifychain", (*VerifyChainCmd)(nil), flags)
MustRegisterCmd("verifydag", (*VerifyDAGCmd)(nil), flags)
MustRegisterCmd("verifymessage", (*VerifyMessageCmd)(nil), flags)
MustRegisterCmd("verifytxoutproof", (*VerifyTxOutProofCmd)(nil), flags)
}

View File

@ -15,11 +15,11 @@ import (
"github.com/daglabs/btcd/wire"
)
// TestChainSvrCmds tests all of the chain server commands marshal and unmarshal
// TestDAGSvrCmds tests all of the dag server commands marshal and unmarshal
// into valid results include handling of optional fields being omitted in the
// marshalled command, while optional fields with defaults have the default
// assigned on unmarshalled commands.
func TestChainSvrCmds(t *testing.T) {
func TestDAGSvrCmds(t *testing.T) {
t.Parallel()
testID := int(1)
@ -189,15 +189,15 @@ func TestChainSvrCmds(t *testing.T) {
},
},
{
name: "getblockchaininfo",
name: "getblockdaginfo",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("getblockchaininfo")
return btcjson.NewCmd("getblockdaginfo")
},
staticCmd: func() interface{} {
return btcjson.NewGetBlockChainInfoCmd()
return btcjson.NewGetBlockDAGInfoCmd()
},
marshalled: `{"jsonrpc":"1.0","method":"getblockchaininfo","params":[],"id":1}`,
unmarshalled: &btcjson.GetBlockChainInfoCmd{},
marshalled: `{"jsonrpc":"1.0","method":"getblockdaginfo","params":[],"id":1}`,
unmarshalled: &btcjson.GetBlockDAGInfoCmd{},
},
{
name: "getblockcount",
@ -351,15 +351,15 @@ func TestChainSvrCmds(t *testing.T) {
},
},
{
name: "getchaintips",
name: "getdagtips",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("getchaintips")
return btcjson.NewCmd("getdagtips")
},
staticCmd: func() interface{} {
return btcjson.NewGetChainTipsCmd()
return btcjson.NewGetDAGTipsCmd()
},
marshalled: `{"jsonrpc":"1.0","method":"getchaintips","params":[],"id":1}`,
unmarshalled: &btcjson.GetChainTipsCmd{},
marshalled: `{"jsonrpc":"1.0","method":"getdagtips","params":[],"id":1}`,
unmarshalled: &btcjson.GetDAGTipsCmd{},
},
{
name: "getconnectioncount",
@ -1017,43 +1017,43 @@ func TestChainSvrCmds(t *testing.T) {
},
},
{
name: "verifychain",
name: "verifydag",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("verifychain")
return btcjson.NewCmd("verifydag")
},
staticCmd: func() interface{} {
return btcjson.NewVerifyChainCmd(nil, nil)
return btcjson.NewVerifyDAGCmd(nil, nil)
},
marshalled: `{"jsonrpc":"1.0","method":"verifychain","params":[],"id":1}`,
unmarshalled: &btcjson.VerifyChainCmd{
marshalled: `{"jsonrpc":"1.0","method":"verifydag","params":[],"id":1}`,
unmarshalled: &btcjson.VerifyDAGCmd{
CheckLevel: btcjson.Int32(3),
CheckDepth: btcjson.Int32(288),
},
},
{
name: "verifychain optional1",
name: "verifydag optional1",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("verifychain", 2)
return btcjson.NewCmd("verifydag", 2)
},
staticCmd: func() interface{} {
return btcjson.NewVerifyChainCmd(btcjson.Int32(2), nil)
return btcjson.NewVerifyDAGCmd(btcjson.Int32(2), nil)
},
marshalled: `{"jsonrpc":"1.0","method":"verifychain","params":[2],"id":1}`,
unmarshalled: &btcjson.VerifyChainCmd{
marshalled: `{"jsonrpc":"1.0","method":"verifydag","params":[2],"id":1}`,
unmarshalled: &btcjson.VerifyDAGCmd{
CheckLevel: btcjson.Int32(2),
CheckDepth: btcjson.Int32(288),
},
},
{
name: "verifychain optional2",
name: "verifydag optional2",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("verifychain", 2, 500)
return btcjson.NewCmd("verifydag", 2, 500)
},
staticCmd: func() interface{} {
return btcjson.NewVerifyChainCmd(btcjson.Int32(2), btcjson.Int32(500))
return btcjson.NewVerifyDAGCmd(btcjson.Int32(2), btcjson.Int32(500))
},
marshalled: `{"jsonrpc":"1.0","method":"verifychain","params":[2,500],"id":1}`,
unmarshalled: &btcjson.VerifyChainCmd{
marshalled: `{"jsonrpc":"1.0","method":"verifydag","params":[2,500],"id":1}`,
unmarshalled: &btcjson.VerifyDAGCmd{
CheckLevel: btcjson.Int32(2),
CheckDepth: btcjson.Int32(500),
},
@ -1156,9 +1156,9 @@ func TestChainSvrCmds(t *testing.T) {
}
}
// TestChainSvrCmdErrors ensures any errors that occur in the command during
// TestDAGSvrCmdErrors ensures any errors that occur in the command during
// custom mashal and unmarshal are as expected.
func TestChainSvrCmdErrors(t *testing.T) {
func TestDAGSvrCmdErrors(t *testing.T) {
t.Parallel()
tests := []struct {

View File

@ -95,19 +95,19 @@ type Bip9SoftForkDescription struct {
Since int32 `json:"since"`
}
// GetBlockChainInfoResult models the data returned from the getblockchaininfo
// GetBlockDAGInfoResult models the data returned from the getblockdaginfo
// command.
type GetBlockChainInfoResult struct {
Chain string `json:"chain"`
type GetBlockDAGInfoResult struct {
DAG string `json:"dag"`
Blocks int32 `json:"blocks"`
Headers int32 `json:"headers"`
BestBlockHash string `json:"bestblockhash"`
TipHashes []string `json:"tiphashes"`
Difficulty float64 `json:"difficulty"`
MedianTime int64 `json:"mediantime"`
VerificationProgress float64 `json:"verificationprogress,omitempty"`
Pruned bool `json:"pruned"`
PruneHeight int32 `json:"pruneheight,omitempty"`
ChainWork string `json:"chainwork,omitempty"`
DAGWork string `json:"dagwork,omitempty"`
SoftForks []*SoftForkDescription `json:"softforks"`
Bip9SoftForks map[string]*Bip9SoftForkDescription `json:"bip9_softforks"`
}
@ -423,8 +423,8 @@ type GetWorkResult struct {
Target string `json:"target"`
}
// InfoChainResult models the data returned by the chain server getinfo command.
type InfoChainResult struct {
// InfoDAGResult models the data returned by the dag server getinfo command.
type InfoDAGResult struct {
Version int32 `json:"version"`
ProtocolVersion int32 `json:"protocolversion"`
Blocks int32 `json:"blocks"`
@ -479,9 +479,9 @@ type TxRawDecodeResult struct {
Vout []Vout `json:"vout"`
}
// ValidateAddressChainResult models the data returned by the chain server
// ValidateAddressResult models the data returned by the dag server
// validateaddress command.
type ValidateAddressChainResult struct {
type ValidateAddressResult struct {
IsValid bool `json:"isvalid"`
Address string `json:"address,omitempty"`
}

View File

@ -11,10 +11,10 @@ import (
"github.com/daglabs/btcd/btcjson"
)
// TestChainSvrCustomResults ensures any results that have custom marshalling
// TestDAGSvrCustomResults ensures any results that have custom marshalling
// work as inteded.
// and unmarshal code of results are as expected.
func TestChainSvrCustomResults(t *testing.T) {
func TestDAGSvrCustomResults(t *testing.T) {
t.Parallel()
tests := []struct {

View File

@ -4,7 +4,7 @@
// license that can be found in the LICENSE file.
// NOTE: This file is intended to house the RPC commands that are supported by
// a chain server, but are only available via websockets.
// a dag server, but are only available via websockets.
package btcjson

View File

@ -15,11 +15,11 @@ import (
"github.com/daglabs/btcd/btcjson"
)
// TestChainSvrWsCmds tests all of the chain server websocket-specific commands
// TestDAGSvrWsCmds tests all of the dag server websocket-specific commands
// marshal and unmarshal into valid results include handling of optional fields
// being omitted in the marshalled command, while optional fields with defaults
// have the default assigned on unmarshalled commands.
func TestChainSvrWsCmds(t *testing.T) {
func TestDAGSvrWsCmds(t *testing.T) {
t.Parallel()
testID := int(1)

View File

@ -4,35 +4,35 @@
// license that can be found in the LICENSE file.
// NOTE: This file is intended to house the RPC websocket notifications that are
// supported by a chain server.
// supported by a dag server.
package btcjson
const (
// BlockConnectedNtfnMethod is the legacy, deprecated method used for
// notifications from the chain server that a block has been connected.
// notifications from the dag server that a block has been connected.
//
// NOTE: Deprecated. Use FilteredBlockConnectedNtfnMethod instead.
BlockConnectedNtfnMethod = "blockconnected"
// BlockDisconnectedNtfnMethod is the legacy, deprecated method used for
// notifications from the chain server that a block has been
// notifications from the dag server that a block has been
// disconnected.
//
// NOTE: Deprecated. Use FilteredBlockDisconnectedNtfnMethod instead.
BlockDisconnectedNtfnMethod = "blockdisconnected"
// FilteredBlockConnectedNtfnMethod is the new method used for
// notifications from the chain server that a block has been connected.
// notifications from the dag server that a block has been connected.
FilteredBlockConnectedNtfnMethod = "filteredblockconnected"
// FilteredBlockDisconnectedNtfnMethod is the new method used for
// notifications from the chain server that a block has been
// notifications from the dag server that a block has been
// disconnected.
FilteredBlockDisconnectedNtfnMethod = "filteredblockdisconnected"
// RecvTxNtfnMethod is the legacy, deprecated method used for
// notifications from the chain server that a transaction which pays to
// notifications from the dag server that a transaction which pays to
// a registered address has been processed.
//
// NOTE: Deprecated. Use RelevantTxAcceptedNtfnMethod and
@ -40,7 +40,7 @@ const (
RecvTxNtfnMethod = "recvtx"
// RedeemingTxNtfnMethod is the legacy, deprecated method used for
// notifications from the chain server that a transaction which spends a
// notifications from the dag server that a transaction which spends a
// registered outpoint has been processed.
//
// NOTE: Deprecated. Use RelevantTxAcceptedNtfnMethod and
@ -48,31 +48,31 @@ const (
RedeemingTxNtfnMethod = "redeemingtx"
// RescanFinishedNtfnMethod is the legacy, deprecated method used for
// notifications from the chain server that a legacy, deprecated rescan
// notifications from the dag server that a legacy, deprecated rescan
// operation has finished.
//
// NOTE: Deprecated. Not used with rescanblocks command.
RescanFinishedNtfnMethod = "rescanfinished"
// RescanProgressNtfnMethod is the legacy, deprecated method used for
// notifications from the chain server that a legacy, deprecated rescan
// notifications from the dag server that a legacy, deprecated rescan
// operation this is underway has made progress.
//
// NOTE: Deprecated. Not used with rescanblocks command.
RescanProgressNtfnMethod = "rescanprogress"
// TxAcceptedNtfnMethod is the method used for notifications from the
// chain server that a transaction has been accepted into the mempool.
// dag server that a transaction has been accepted into the mempool.
TxAcceptedNtfnMethod = "txaccepted"
// TxAcceptedVerboseNtfnMethod is the method used for notifications from
// the chain server that a transaction has been accepted into the
// the dag server that a transaction has been accepted into the
// mempool. This differs from TxAcceptedNtfnMethod in that it provides
// more details in the notification.
TxAcceptedVerboseNtfnMethod = "txacceptedverbose"
// RelevantTxAcceptedNtfnMethod is the new method used for notifications
// from the chain server that inform a client that a transaction that
// from the dag server that inform a client that a transaction that
// matches the loaded filter was accepted by the mempool.
RelevantTxAcceptedNtfnMethod = "relevanttxaccepted"
)

View File

@ -15,11 +15,11 @@ import (
"github.com/daglabs/btcd/btcjson"
)
// TestChainSvrWsNtfns tests all of the chain server websocket-specific
// TestDAGSvrWsNtfns tests all of the dag server websocket-specific
// notifications marshal and unmarshal into valid results include handling of
// optional fields being omitted in the marshalled command, while optional
// fields with defaults have the default assigned on unmarshalled commands.
func TestChainSvrWsNtfns(t *testing.T) {
func TestDAGSvrWsNtfns(t *testing.T) {
t.Parallel()
tests := []struct {

View File

@ -12,9 +12,9 @@ import (
"github.com/daglabs/btcd/btcjson"
)
// TestChainSvrWsResults ensures any results that have custom marshalling
// TestDAGSvrWsResults ensures any results that have custom marshalling
// work as inteded.
func TestChainSvrWsResults(t *testing.T) {
func TestDAGSvrWsResults(t *testing.T) {
t.Parallel()
tests := []struct {

View File

@ -107,7 +107,7 @@ function.
Command Inspection
All registered commands are registered with flags that identify information such
as whether the command applies to a chain server, wallet server, or is a
as whether the command applies to a dag server, wallet server, or is a
notification along with the method name to use. These flags can be obtained
with the MethodUsageFlags flags, and the method can be obtained with the
CmdMethod function.
@ -143,4 +143,4 @@ The second category of errors (type RPCError), on the other hand, are useful for
returning errors to RPC clients. Consequently, they are used in the previously
described Response type.
*/
package btcjson
package btcjson

View File

@ -13,7 +13,7 @@ const (
AccountBalanceNtfnMethod = "accountbalance"
// BtcdConnectedNtfnMethod is the method used for notifications when
// a wallet server is connected to a chain server.
// a wallet server is connected to a dag server.
BtcdConnectedNtfnMethod = "btcdconnected"
// WalletLockStateNtfnMethod is the method used to notify the lock state

View File

@ -14,7 +14,7 @@ import (
"github.com/daglabs/btcd/btcjson"
)
// TestWalletSvrWsNtfns tests all of the chain server websocket-specific
// TestWalletSvrWsNtfns tests all of the dag server websocket-specific
// notifications marshal and unmarshal into valid results include handling of
// optional fields being omitted in the marshalled command, while optional
// fields with defaults have the default assigned on unmarshalled commands.