mirror of
https://github.com/FlipsideCrypto/dcrd.git
synced 2026-02-06 10:56:47 +00:00
dcrjson: Introduce v2 module without wallet types.
This removes all wallet-specific type definitions and tests from the dcrjson module since they are being moved into their own module that lives in the dcrwallet repository. Since this constitutes a major break to the API, it also bumps the module version to version 2.
This commit is contained in:
parent
3ce1ee9652
commit
8ad612b642
@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2015 The btcsuite developers
|
||||
// Copyright (c) 2015-2016 The Decred developers
|
||||
// Copyright (c) 2015-2019 The Decred developers
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
@ -90,9 +90,9 @@ func TestMethodUsageFlags(t *testing.T) {
|
||||
flags: 0,
|
||||
},
|
||||
{
|
||||
name: "walletpassphrase",
|
||||
method: "walletpassphrase",
|
||||
flags: UFWalletOnly,
|
||||
name: "session",
|
||||
method: "session",
|
||||
flags: UFWebsocketOnly,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
module github.com/decred/dcrd/dcrjson
|
||||
module github.com/decred/dcrd/dcrjson/v2
|
||||
|
||||
require github.com/decred/dcrd/chaincfg/chainhash v1.0.1
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,421 +0,0 @@
|
||||
// Copyright (c) 2014 The btcsuite developers
|
||||
// Copyright (c) 2015-2018 The Decred developers
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package dcrjson
|
||||
|
||||
// FundRawTransactionResult models the data from the fundrawtransaction command.
|
||||
type FundRawTransactionResult struct {
|
||||
Hex string `json:"hex"`
|
||||
Fee float64 `json:"fee"`
|
||||
}
|
||||
|
||||
// GenerateVoteResult models the data from the generatevote command.
|
||||
type GenerateVoteResult struct {
|
||||
Hex string `json:"hex"`
|
||||
}
|
||||
|
||||
// GetAccountBalanceResult models the account data from the getbalance command.
|
||||
type GetAccountBalanceResult struct {
|
||||
AccountName string `json:"accountname"`
|
||||
ImmatureCoinbaseRewards float64 `json:"immaturecoinbaserewards"`
|
||||
ImmatureStakeGeneration float64 `json:"immaturestakegeneration"`
|
||||
LockedByTickets float64 `json:"lockedbytickets"`
|
||||
Spendable float64 `json:"spendable"`
|
||||
Total float64 `json:"total"`
|
||||
Unconfirmed float64 `json:"unconfirmed"`
|
||||
VotingAuthority float64 `json:"votingauthority"`
|
||||
}
|
||||
|
||||
// GetBalanceResult models the data from the getbalance command.
|
||||
type GetBalanceResult struct {
|
||||
Balances []GetAccountBalanceResult `json:"balances"`
|
||||
BlockHash string `json:"blockhash"`
|
||||
TotalImmatureCoinbaseRewards float64 `json:"totalimmaturecoinbaserewards,omitempty"`
|
||||
TotalImmatureStakeGeneration float64 `json:"totalimmaturestakegeneration,omitempty"`
|
||||
TotalLockedByTickets float64 `json:"totallockedbytickets,omitempty"`
|
||||
TotalSpendable float64 `json:"totalspendable,omitempty"`
|
||||
CumulativeTotal float64 `json:"cumulativetotal,omitempty"`
|
||||
TotalUnconfirmed float64 `json:"totalunconfirmed,omitempty"`
|
||||
TotalVotingAuthority float64 `json:"totalvotingauthority,omitempty"`
|
||||
}
|
||||
|
||||
// GetContractHashResult models the data from the getcontracthash command.
|
||||
type GetContractHashResult struct {
|
||||
ContractHash string `json:"contracthash"`
|
||||
}
|
||||
|
||||
// GetMultisigOutInfoResult models the data returned from the getmultisigoutinfo
|
||||
// command.
|
||||
type GetMultisigOutInfoResult struct {
|
||||
Address string `json:"address"`
|
||||
RedeemScript string `json:"redeemscript"`
|
||||
M uint8 `json:"m"`
|
||||
N uint8 `json:"n"`
|
||||
Pubkeys []string `json:"pubkeys"`
|
||||
TxHash string `json:"txhash"`
|
||||
BlockHeight uint32 `json:"blockheight"`
|
||||
BlockHash string `json:"blockhash"`
|
||||
Spent bool `json:"spent"`
|
||||
SpentBy string `json:"spentby"`
|
||||
SpentByIndex uint32 `json:"spentbyindex"`
|
||||
Amount float64 `json:"amount"`
|
||||
}
|
||||
|
||||
// GetPayToContractHashResult models the data returned from the getpaytocontracthash
|
||||
// command.
|
||||
type GetPayToContractHashResult struct {
|
||||
Address string `json:"address"`
|
||||
}
|
||||
|
||||
// GetStakeInfoResult models the data returned from the getstakeinfo
|
||||
// command.
|
||||
type GetStakeInfoResult struct {
|
||||
BlockHeight int64 `json:"blockheight"`
|
||||
Difficulty float64 `json:"difficulty"`
|
||||
TotalSubsidy float64 `json:"totalsubsidy"`
|
||||
|
||||
OwnMempoolTix uint32 `json:"ownmempooltix"`
|
||||
Immature uint32 `json:"immature"`
|
||||
Unspent uint32 `json:"unspent"`
|
||||
Voted uint32 `json:"voted"`
|
||||
Revoked uint32 `json:"revoked"`
|
||||
UnspentExpired uint32 `json:"unspentexpired"`
|
||||
|
||||
// Not available to SPV wallets
|
||||
PoolSize uint32 `json:"poolsize,omitempty"`
|
||||
AllMempoolTix uint32 `json:"allmempooltix,omitempty"`
|
||||
Live uint32 `json:"live,omitempty"`
|
||||
ProportionLive float64 `json:"proportionlive,omitempty"`
|
||||
Missed uint32 `json:"missed,omitempty"`
|
||||
ProportionMissed float64 `json:"proportionmissed,omitempty"`
|
||||
Expired uint32 `json:"expired,omitempty"`
|
||||
}
|
||||
|
||||
// GetTicketsResult models the data returned from the gettickets
|
||||
// command.
|
||||
type GetTicketsResult struct {
|
||||
Hashes []string `json:"hashes"`
|
||||
}
|
||||
|
||||
// GetTransactionDetailsResult models the details data from the gettransaction command.
|
||||
//
|
||||
// This models the "short" version of the ListTransactionsResult type, which
|
||||
// excludes fields common to the transaction. These common fields are instead
|
||||
// part of the GetTransactionResult.
|
||||
type GetTransactionDetailsResult struct {
|
||||
Account string `json:"account"`
|
||||
Address string `json:"address,omitempty"`
|
||||
Amount float64 `json:"amount"`
|
||||
Category string `json:"category"`
|
||||
InvolvesWatchOnly bool `json:"involveswatchonly,omitempty"`
|
||||
Fee *float64 `json:"fee,omitempty"`
|
||||
Vout uint32 `json:"vout"`
|
||||
}
|
||||
|
||||
// GetTransactionResult models the data from the gettransaction command.
|
||||
type GetTransactionResult struct {
|
||||
Amount float64 `json:"amount"`
|
||||
Fee float64 `json:"fee,omitempty"`
|
||||
Confirmations int64 `json:"confirmations"`
|
||||
BlockHash string `json:"blockhash"`
|
||||
BlockIndex int64 `json:"blockindex"`
|
||||
BlockTime int64 `json:"blocktime"`
|
||||
TxID string `json:"txid"`
|
||||
WalletConflicts []string `json:"walletconflicts"`
|
||||
Time int64 `json:"time"`
|
||||
TimeReceived int64 `json:"timereceived"`
|
||||
Details []GetTransactionDetailsResult `json:"details"`
|
||||
Hex string `json:"hex"`
|
||||
Type string `json:"type"`
|
||||
TicketStatus string `json:"ticketstatus,omitempty"`
|
||||
}
|
||||
|
||||
// VoteChoice models the data for a vote choice in the getvotechoices result.
|
||||
type VoteChoice struct {
|
||||
AgendaID string `json:"agendaid"`
|
||||
AgendaDescription string `json:"agendadescription"`
|
||||
ChoiceID string `json:"choiceid"`
|
||||
ChoiceDescription string `json:"choicedescription"`
|
||||
}
|
||||
|
||||
// GetVoteChoicesResult models the data returned by the getvotechoices command.
|
||||
type GetVoteChoicesResult struct {
|
||||
Version uint32 `json:"version"`
|
||||
Choices []VoteChoice `json:"choices"`
|
||||
}
|
||||
|
||||
// InfoWalletResult models the data returned by the wallet server getinfo
|
||||
// command.
|
||||
type InfoWalletResult struct {
|
||||
Version int32 `json:"version"`
|
||||
ProtocolVersion int32 `json:"protocolversion"`
|
||||
WalletVersion int32 `json:"walletversion"`
|
||||
Balance float64 `json:"balance"`
|
||||
Blocks int32 `json:"blocks"`
|
||||
TimeOffset int64 `json:"timeoffset"`
|
||||
Connections int32 `json:"connections"`
|
||||
Proxy string `json:"proxy"`
|
||||
Difficulty float64 `json:"difficulty"`
|
||||
TestNet bool `json:"testnet"`
|
||||
KeypoolOldest int64 `json:"keypoololdest"`
|
||||
KeypoolSize int32 `json:"keypoolsize"`
|
||||
UnlockedUntil int64 `json:"unlocked_until"`
|
||||
PaytxFee float64 `json:"paytxfee"`
|
||||
RelayFee float64 `json:"relayfee"`
|
||||
Errors string `json:"errors"`
|
||||
}
|
||||
|
||||
// ScriptInfo is the structure representing a redeem script, its hash,
|
||||
// and its address.
|
||||
type ScriptInfo struct {
|
||||
Hash160 string `json:"hash160"`
|
||||
Address string `json:"address"`
|
||||
RedeemScript string `json:"redeemscript"`
|
||||
}
|
||||
|
||||
// ListScriptsResult models the data returned from the listscripts
|
||||
// command.
|
||||
type ListScriptsResult struct {
|
||||
Scripts []ScriptInfo `json:"scripts"`
|
||||
}
|
||||
|
||||
// ListTicketsTransactionSummaryInput defines the type used in the listtickets JSON-RPC
|
||||
// result for the MyInputs field of Ticket and Spender command field.
|
||||
type ListTicketsTransactionSummaryInput struct {
|
||||
Index uint32 `json:"index"`
|
||||
PreviousAccount string `json:"previousaccount"`
|
||||
PreviousAmount float64 `json:"previousamount"`
|
||||
}
|
||||
|
||||
// ListTicketsTransactionSummaryOutput defines the type used in the listtickets JSON-RPC
|
||||
// result for the MyOutputs field of Ticket and Spender command field.
|
||||
type ListTicketsTransactionSummaryOutput struct {
|
||||
Index uint32 `json:"index"`
|
||||
Account string `json:"account"`
|
||||
Internal bool `json:"internal"`
|
||||
Amount float64 `json:"amount"`
|
||||
Address string `json:"address"`
|
||||
OutputScript string `json:"outputscript"`
|
||||
}
|
||||
|
||||
// ListTicketsTransactionSummary defines the type used in the listtickets JSON-RPC
|
||||
// result for the Ticket and Spender command fields.
|
||||
type ListTicketsTransactionSummary struct {
|
||||
Hash string `json:"hash"`
|
||||
Transaction string `json:"transaction"`
|
||||
MyInputs []ListTicketsTransactionSummaryInput `json:"myinputs"`
|
||||
MyOutputs []ListTicketsTransactionSummaryOutput `json:"myoutputs"`
|
||||
Fee float64 `json:"fee"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// ListTicketsResult models the data from the listtickets command.
|
||||
type ListTicketsResult struct {
|
||||
Ticket *ListTicketsTransactionSummary `json:"ticket"`
|
||||
Spender *ListTicketsTransactionSummary `json:"spender"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
// ListTransactionsTxType defines the type used in the listtransactions JSON-RPC
|
||||
// result for the TxType command field.
|
||||
type ListTransactionsTxType string
|
||||
|
||||
const (
|
||||
// LTTTRegular indicates a regular transaction.
|
||||
LTTTRegular ListTransactionsTxType = "regular"
|
||||
|
||||
// LTTTTicket indicates a ticket.
|
||||
LTTTTicket ListTransactionsTxType = "ticket"
|
||||
|
||||
// LTTTVote indicates a vote.
|
||||
LTTTVote ListTransactionsTxType = "vote"
|
||||
|
||||
// LTTTRevocation indicates a revocation.
|
||||
LTTTRevocation ListTransactionsTxType = "revocation"
|
||||
)
|
||||
|
||||
// ListTransactionsResult models the data from the listtransactions command.
|
||||
type ListTransactionsResult struct {
|
||||
Account string `json:"account"`
|
||||
Address string `json:"address,omitempty"`
|
||||
Amount float64 `json:"amount"`
|
||||
BlockHash string `json:"blockhash,omitempty"`
|
||||
BlockIndex *int64 `json:"blockindex,omitempty"`
|
||||
BlockTime int64 `json:"blocktime,omitempty"`
|
||||
Category string `json:"category"`
|
||||
Confirmations int64 `json:"confirmations"`
|
||||
Fee *float64 `json:"fee,omitempty"`
|
||||
Generated bool `json:"generated,omitempty"`
|
||||
InvolvesWatchOnly bool `json:"involveswatchonly,omitempty"`
|
||||
Time int64 `json:"time"`
|
||||
TimeReceived int64 `json:"timereceived"`
|
||||
TxID string `json:"txid"`
|
||||
TxType *ListTransactionsTxType `json:"txtype,omitempty"`
|
||||
Vout uint32 `json:"vout"`
|
||||
WalletConflicts []string `json:"walletconflicts"`
|
||||
Comment string `json:"comment,omitempty"`
|
||||
OtherAccount string `json:"otheraccount,omitempty"`
|
||||
}
|
||||
|
||||
// ListReceivedByAccountResult models the data from the listreceivedbyaccount
|
||||
// command.
|
||||
type ListReceivedByAccountResult struct {
|
||||
Account string `json:"account"`
|
||||
Amount float64 `json:"amount"`
|
||||
Confirmations uint64 `json:"confirmations"`
|
||||
}
|
||||
|
||||
// ListReceivedByAddressResult models the data from the listreceivedbyaddress
|
||||
// command.
|
||||
type ListReceivedByAddressResult struct {
|
||||
Account string `json:"account"`
|
||||
Address string `json:"address"`
|
||||
Amount float64 `json:"amount"`
|
||||
Confirmations uint64 `json:"confirmations"`
|
||||
TxIDs []string `json:"txids,omitempty"`
|
||||
InvolvesWatchonly bool `json:"involvesWatchonly,omitempty"`
|
||||
}
|
||||
|
||||
// ListSinceBlockResult models the data from the listsinceblock command.
|
||||
type ListSinceBlockResult struct {
|
||||
Transactions []ListTransactionsResult `json:"transactions"`
|
||||
LastBlock string `json:"lastblock"`
|
||||
}
|
||||
|
||||
// ListUnspentResult models a successful response from the listunspent request.
|
||||
// Contains Decred additions.
|
||||
type ListUnspentResult struct {
|
||||
TxID string `json:"txid"`
|
||||
Vout uint32 `json:"vout"`
|
||||
Tree int8 `json:"tree"`
|
||||
TxType int `json:"txtype"`
|
||||
Address string `json:"address"`
|
||||
Account string `json:"account"`
|
||||
ScriptPubKey string `json:"scriptPubKey"`
|
||||
RedeemScript string `json:"redeemScript,omitempty"`
|
||||
Amount float64 `json:"amount"`
|
||||
Confirmations int64 `json:"confirmations"`
|
||||
Spendable bool `json:"spendable"`
|
||||
}
|
||||
|
||||
// RedeemMultiSigOutResult models the data returned from the redeemmultisigout
|
||||
// command.
|
||||
type RedeemMultiSigOutResult struct {
|
||||
Hex string `json:"hex"`
|
||||
Complete bool `json:"complete"`
|
||||
Errors []SignRawTransactionError `json:"errors,omitempty"`
|
||||
}
|
||||
|
||||
// RedeemMultiSigOutsResult models the data returned from the redeemmultisigouts
|
||||
// command.
|
||||
type RedeemMultiSigOutsResult struct {
|
||||
Results []RedeemMultiSigOutResult `json:"results"`
|
||||
}
|
||||
|
||||
// SendToMultiSigResult models the data returned from the sendtomultisig
|
||||
// command.
|
||||
type SendToMultiSigResult struct {
|
||||
TxHash string `json:"txhash"`
|
||||
Address string `json:"address"`
|
||||
RedeemScript string `json:"redeemscript"`
|
||||
}
|
||||
|
||||
// SignRawTransactionError models the data that contains script verification
|
||||
// errors from the signrawtransaction request.
|
||||
type SignRawTransactionError struct {
|
||||
TxID string `json:"txid"`
|
||||
Vout uint32 `json:"vout"`
|
||||
ScriptSig string `json:"scriptSig"`
|
||||
Sequence uint32 `json:"sequence"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
// SignRawTransactionResult models the data from the signrawtransaction
|
||||
// command.
|
||||
type SignRawTransactionResult struct {
|
||||
Hex string `json:"hex"`
|
||||
Complete bool `json:"complete"`
|
||||
Errors []SignRawTransactionError `json:"errors,omitempty"`
|
||||
}
|
||||
|
||||
// SignedTransaction is a signed transaction resulting from a signrawtransactions
|
||||
// command.
|
||||
type SignedTransaction struct {
|
||||
SigningResult SignRawTransactionResult `json:"signingresult"`
|
||||
Sent bool `json:"sent"`
|
||||
TxHash *string `json:"txhash,omitempty"`
|
||||
}
|
||||
|
||||
// SignRawTransactionsResult models the data returned from the signrawtransactions
|
||||
// command.
|
||||
type SignRawTransactionsResult struct {
|
||||
Results []SignedTransaction `json:"results"`
|
||||
}
|
||||
|
||||
// PoolUserTicket is the JSON struct corresponding to a stake pool user ticket
|
||||
// object.
|
||||
type PoolUserTicket struct {
|
||||
Status string `json:"status"`
|
||||
Ticket string `json:"ticket"`
|
||||
TicketHeight uint32 `json:"ticketheight"`
|
||||
SpentBy string `json:"spentby"`
|
||||
SpentByHeight uint32 `json:"spentbyheight"`
|
||||
}
|
||||
|
||||
// StakePoolUserInfoResult models the data returned from the stakepooluserinfo
|
||||
// command.
|
||||
type StakePoolUserInfoResult struct {
|
||||
Tickets []PoolUserTicket `json:"tickets"`
|
||||
InvalidTickets []string `json:"invalid"`
|
||||
}
|
||||
|
||||
// SweepAccountResult models the data returned from the sweepaccount
|
||||
// command.
|
||||
type SweepAccountResult struct {
|
||||
UnsignedTransaction string `json:"unsignedtransaction"`
|
||||
TotalPreviousOutputAmount float64 `json:"totalpreviousoutputamount"`
|
||||
TotalOutputAmount float64 `json:"totaloutputamount"`
|
||||
EstimatedSignedSize uint32 `json:"estimatedsignedsize"`
|
||||
}
|
||||
|
||||
// ValidateAddressWalletResult models the data returned by the wallet server
|
||||
// validateaddress command.
|
||||
type ValidateAddressWalletResult struct {
|
||||
IsValid bool `json:"isvalid"`
|
||||
Address string `json:"address,omitempty"`
|
||||
IsMine bool `json:"ismine,omitempty"`
|
||||
IsWatchOnly bool `json:"iswatchonly,omitempty"`
|
||||
IsScript bool `json:"isscript,omitempty"`
|
||||
PubKeyAddr string `json:"pubkeyaddr,omitempty"`
|
||||
PubKey string `json:"pubkey,omitempty"`
|
||||
IsCompressed bool `json:"iscompressed,omitempty"`
|
||||
Account string `json:"account,omitempty"`
|
||||
Addresses []string `json:"addresses,omitempty"`
|
||||
Hex string `json:"hex,omitempty"`
|
||||
Script string `json:"script,omitempty"`
|
||||
SigsRequired int32 `json:"sigsrequired,omitempty"`
|
||||
}
|
||||
|
||||
// VerifySeedResult models the data returned by the wallet server verify
|
||||
// seed command.
|
||||
type VerifySeedResult struct {
|
||||
Result bool `json:"keyresult"`
|
||||
CoinType uint32 `json:"cointype"`
|
||||
}
|
||||
|
||||
// WalletInfoResult models the data returned from the walletinfo command.
|
||||
type WalletInfoResult struct {
|
||||
DaemonConnected bool `json:"daemonconnected"`
|
||||
Unlocked bool `json:"unlocked"`
|
||||
CoinType uint32 `json:"cointype,omitempty"`
|
||||
TxFee float64 `json:"txfee"`
|
||||
TicketFee float64 `json:"ticketfee"`
|
||||
TicketPurchasing bool `json:"ticketpurchasing"`
|
||||
VoteBits uint16 `json:"votebits"`
|
||||
VoteBitsExtended string `json:"votebitsextended"`
|
||||
VoteVersion uint32 `json:"voteversion"`
|
||||
Voting bool `json:"voting"`
|
||||
}
|
||||
@ -1,129 +0,0 @@
|
||||
// Copyright (c) 2014 The btcsuite developers
|
||||
// Copyright (c) 2015-2016 The Decred developers
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package dcrjson
|
||||
|
||||
// NOTE: This file is intended to house the RPC commands that are supported by
|
||||
// a wallet server, but are only available via websockets.
|
||||
|
||||
// CreateEncryptedWalletCmd defines the createencryptedwallet JSON-RPC command.
|
||||
type CreateEncryptedWalletCmd struct {
|
||||
Passphrase string
|
||||
}
|
||||
|
||||
// NewCreateEncryptedWalletCmd returns a new instance which can be used to issue
|
||||
// a createencryptedwallet JSON-RPC command.
|
||||
func NewCreateEncryptedWalletCmd(passphrase string) *CreateEncryptedWalletCmd {
|
||||
return &CreateEncryptedWalletCmd{
|
||||
Passphrase: passphrase,
|
||||
}
|
||||
}
|
||||
|
||||
// ExportWatchingWalletCmd defines the exportwatchingwallet JSON-RPC command.
|
||||
type ExportWatchingWalletCmd struct {
|
||||
Account *string
|
||||
Download *bool `jsonrpcdefault:"false"`
|
||||
}
|
||||
|
||||
// NewExportWatchingWalletCmd returns a new instance which can be used to issue
|
||||
// a exportwatchingwallet JSON-RPC command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewExportWatchingWalletCmd(account *string, download *bool) *ExportWatchingWalletCmd {
|
||||
return &ExportWatchingWalletCmd{
|
||||
Account: account,
|
||||
Download: download,
|
||||
}
|
||||
}
|
||||
|
||||
// GetUnconfirmedBalanceCmd defines the getunconfirmedbalance JSON-RPC command.
|
||||
type GetUnconfirmedBalanceCmd struct {
|
||||
Account *string
|
||||
}
|
||||
|
||||
// NewGetUnconfirmedBalanceCmd returns a new instance which can be used to issue
|
||||
// a getunconfirmedbalance JSON-RPC command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewGetUnconfirmedBalanceCmd(account *string) *GetUnconfirmedBalanceCmd {
|
||||
return &GetUnconfirmedBalanceCmd{
|
||||
Account: account,
|
||||
}
|
||||
}
|
||||
|
||||
// ListAddressTransactionsCmd defines the listaddresstransactions JSON-RPC
|
||||
// command.
|
||||
type ListAddressTransactionsCmd struct {
|
||||
Addresses []string
|
||||
Account *string
|
||||
}
|
||||
|
||||
// NewListAddressTransactionsCmd returns a new instance which can be used to
|
||||
// issue a listaddresstransactions JSON-RPC command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewListAddressTransactionsCmd(addresses []string, account *string) *ListAddressTransactionsCmd {
|
||||
return &ListAddressTransactionsCmd{
|
||||
Addresses: addresses,
|
||||
Account: account,
|
||||
}
|
||||
}
|
||||
|
||||
// ListAllTransactionsCmd defines the listalltransactions JSON-RPC command.
|
||||
type ListAllTransactionsCmd struct {
|
||||
Account *string
|
||||
}
|
||||
|
||||
// NewListAllTransactionsCmd returns a new instance which can be used to issue a
|
||||
// listalltransactions JSON-RPC command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewListAllTransactionsCmd(account *string) *ListAllTransactionsCmd {
|
||||
return &ListAllTransactionsCmd{
|
||||
Account: account,
|
||||
}
|
||||
}
|
||||
|
||||
// RecoverAddressesCmd defines the recoveraddresses JSON-RPC command.
|
||||
type RecoverAddressesCmd struct {
|
||||
Account string
|
||||
N int
|
||||
}
|
||||
|
||||
// NewRecoverAddressesCmd returns a new instance which can be used to issue a
|
||||
// recoveraddresses JSON-RPC command.
|
||||
func NewRecoverAddressesCmd(account string, n int) *RecoverAddressesCmd {
|
||||
return &RecoverAddressesCmd{
|
||||
Account: account,
|
||||
N: n,
|
||||
}
|
||||
}
|
||||
|
||||
// WalletIsLockedCmd defines the walletislocked JSON-RPC command.
|
||||
type WalletIsLockedCmd struct{}
|
||||
|
||||
// NewWalletIsLockedCmd returns a new instance which can be used to issue a
|
||||
// walletislocked JSON-RPC command.
|
||||
func NewWalletIsLockedCmd() *WalletIsLockedCmd {
|
||||
return &WalletIsLockedCmd{}
|
||||
}
|
||||
|
||||
func init() {
|
||||
// The commands in this file are only usable with a wallet server via
|
||||
// websockets.
|
||||
flags := UFWalletOnly | UFWebsocketOnly
|
||||
|
||||
MustRegisterCmd("createencryptedwallet", (*CreateEncryptedWalletCmd)(nil), flags)
|
||||
MustRegisterCmd("exportwatchingwallet", (*ExportWatchingWalletCmd)(nil), flags)
|
||||
MustRegisterCmd("getunconfirmedbalance", (*GetUnconfirmedBalanceCmd)(nil), flags)
|
||||
MustRegisterCmd("listaddresstransactions", (*ListAddressTransactionsCmd)(nil), flags)
|
||||
MustRegisterCmd("listalltransactions", (*ListAllTransactionsCmd)(nil), flags)
|
||||
MustRegisterCmd("recoveraddresses", (*RecoverAddressesCmd)(nil), flags)
|
||||
MustRegisterCmd("walletislocked", (*WalletIsLockedCmd)(nil), flags)
|
||||
}
|
||||
@ -1,258 +0,0 @@
|
||||
// Copyright (c) 2014 The btcsuite developers
|
||||
// Copyright (c) 2015-2016 The Decred developers
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package dcrjson
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestWalletSvrWsCmds tests all of the wallet 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 TestWalletSvrWsCmds(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testID := int(1)
|
||||
tests := []struct {
|
||||
name string
|
||||
newCmd func() (interface{}, error)
|
||||
staticCmd func() interface{}
|
||||
marshalled string
|
||||
unmarshalled interface{}
|
||||
}{
|
||||
{
|
||||
name: "createencryptedwallet",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return NewCmd("createencryptedwallet", "pass")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return NewCreateEncryptedWalletCmd("pass")
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"createencryptedwallet","params":["pass"],"id":1}`,
|
||||
unmarshalled: &CreateEncryptedWalletCmd{Passphrase: "pass"},
|
||||
},
|
||||
{
|
||||
name: "exportwatchingwallet",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return NewCmd("exportwatchingwallet")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return NewExportWatchingWalletCmd(nil, nil)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"exportwatchingwallet","params":[],"id":1}`,
|
||||
unmarshalled: &ExportWatchingWalletCmd{
|
||||
Account: nil,
|
||||
Download: Bool(false),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "exportwatchingwallet optional1",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return NewCmd("exportwatchingwallet", "acct")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return NewExportWatchingWalletCmd(String("acct"), nil)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"exportwatchingwallet","params":["acct"],"id":1}`,
|
||||
unmarshalled: &ExportWatchingWalletCmd{
|
||||
Account: String("acct"),
|
||||
Download: Bool(false),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "exportwatchingwallet optional2",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return NewCmd("exportwatchingwallet", "acct", true)
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return NewExportWatchingWalletCmd(String("acct"),
|
||||
Bool(true))
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"exportwatchingwallet","params":["acct",true],"id":1}`,
|
||||
unmarshalled: &ExportWatchingWalletCmd{
|
||||
Account: String("acct"),
|
||||
Download: Bool(true),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "getunconfirmedbalance",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return NewCmd("getunconfirmedbalance")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return NewGetUnconfirmedBalanceCmd(nil)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"getunconfirmedbalance","params":[],"id":1}`,
|
||||
unmarshalled: &GetUnconfirmedBalanceCmd{
|
||||
Account: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "getunconfirmedbalance optional1",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return NewCmd("getunconfirmedbalance", "acct")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return NewGetUnconfirmedBalanceCmd(String("acct"))
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"getunconfirmedbalance","params":["acct"],"id":1}`,
|
||||
unmarshalled: &GetUnconfirmedBalanceCmd{
|
||||
Account: String("acct"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "listaddresstransactions",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return NewCmd("listaddresstransactions", `["1Address"]`)
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return NewListAddressTransactionsCmd([]string{"1Address"}, nil)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"listaddresstransactions","params":[["1Address"]],"id":1}`,
|
||||
unmarshalled: &ListAddressTransactionsCmd{
|
||||
Addresses: []string{"1Address"},
|
||||
Account: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "listaddresstransactions optional1",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return NewCmd("listaddresstransactions", `["1Address"]`, "acct")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return NewListAddressTransactionsCmd([]string{"1Address"},
|
||||
String("acct"))
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"listaddresstransactions","params":[["1Address"],"acct"],"id":1}`,
|
||||
unmarshalled: &ListAddressTransactionsCmd{
|
||||
Addresses: []string{"1Address"},
|
||||
Account: String("acct"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "listalltransactions",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return NewCmd("listalltransactions")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return NewListAllTransactionsCmd(nil)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"listalltransactions","params":[],"id":1}`,
|
||||
unmarshalled: &ListAllTransactionsCmd{
|
||||
Account: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "listalltransactions optional",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return NewCmd("listalltransactions", "acct")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return NewListAllTransactionsCmd(String("acct"))
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"listalltransactions","params":["acct"],"id":1}`,
|
||||
unmarshalled: &ListAllTransactionsCmd{
|
||||
Account: String("acct"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "recoveraddresses",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return NewCmd("recoveraddresses", "acct", 10)
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return NewRecoverAddressesCmd("acct", 10)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"recoveraddresses","params":["acct",10],"id":1}`,
|
||||
unmarshalled: &RecoverAddressesCmd{
|
||||
Account: "acct",
|
||||
N: 10,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "walletislocked",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return NewCmd("walletislocked")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return NewWalletIsLockedCmd()
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"walletislocked","params":[],"id":1}`,
|
||||
unmarshalled: &WalletIsLockedCmd{},
|
||||
},
|
||||
}
|
||||
|
||||
t.Logf("Running %d tests", len(tests))
|
||||
for i, test := range tests {
|
||||
// Marshal the command as created by the new static command
|
||||
// creation function.
|
||||
marshalled, err := MarshalCmd("1.0", testID, test.staticCmd())
|
||||
if err != nil {
|
||||
t.Errorf("MarshalCmd #%d (%s) unexpected error: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !bytes.Equal(marshalled, []byte(test.marshalled)) {
|
||||
t.Errorf("Test #%d (%s) unexpected marshalled data - "+
|
||||
"got %s, want %s", i, test.name, marshalled,
|
||||
test.marshalled)
|
||||
continue
|
||||
}
|
||||
|
||||
// Ensure the command is created without error via the generic
|
||||
// new command creation function.
|
||||
cmd, err := test.newCmd()
|
||||
if err != nil {
|
||||
t.Errorf("Test #%d (%s) unexpected NewCmd error: %v ",
|
||||
i, test.name, err)
|
||||
}
|
||||
|
||||
// Marshal the command as created by the generic new command
|
||||
// creation function.
|
||||
marshalled, err = MarshalCmd("1.0", testID, cmd)
|
||||
if err != nil {
|
||||
t.Errorf("MarshalCmd #%d (%s) unexpected error: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !bytes.Equal(marshalled, []byte(test.marshalled)) {
|
||||
t.Errorf("Test #%d (%s) unexpected marshalled data - "+
|
||||
"got %s, want %s", i, test.name, marshalled,
|
||||
test.marshalled)
|
||||
continue
|
||||
}
|
||||
|
||||
var request Request
|
||||
if err := json.Unmarshal(marshalled, &request); err != nil {
|
||||
t.Errorf("Test #%d (%s) unexpected error while "+
|
||||
"unmarshalling JSON-RPC request: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
cmd, err = UnmarshalCmd(&request)
|
||||
if err != nil {
|
||||
t.Errorf("UnmarshalCmd #%d (%s) unexpected error: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(cmd, test.unmarshalled) {
|
||||
t.Errorf("Test #%d (%s) unexpected unmarshalled command "+
|
||||
"- got %s, want %s", i, test.name,
|
||||
fmt.Sprintf("(%T) %+[1]v", cmd),
|
||||
fmt.Sprintf("(%T) %+[1]v\n", test.unmarshalled))
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,162 +0,0 @@
|
||||
// Copyright (c) 2014 The btcsuite developers
|
||||
// Copyright (c) 2015-2016 The Decred developers
|
||||
// Use of this source code is governed by an ISC
|
||||
// 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 wallet server.
|
||||
|
||||
package dcrjson
|
||||
|
||||
const (
|
||||
// AccountBalanceNtfnMethod is the method used for account balance
|
||||
// notifications.
|
||||
AccountBalanceNtfnMethod = "accountbalance"
|
||||
|
||||
// DcrdConnectedNtfnMethod is the method used for notifications when
|
||||
// a wallet server is connected to a chain server.
|
||||
DcrdConnectedNtfnMethod = "dcrdconnected"
|
||||
|
||||
// NewTxNtfnMethod is the method used to notify that a wallet server has
|
||||
// added a new transaction to the transaction store.
|
||||
NewTxNtfnMethod = "newtx"
|
||||
|
||||
// RevocationCreatedNtfnMethod is the method of the dcrwallet
|
||||
// revocationcreated notification.
|
||||
RevocationCreatedNtfnMethod = "revocationcreated"
|
||||
|
||||
// TicketPurchasedNtfnMethod is the method of the dcrwallet
|
||||
// ticketpurchased notification.
|
||||
TicketPurchasedNtfnMethod = "ticketpurchased"
|
||||
|
||||
// VoteCreatedNtfnMethod is the method of the dcrwallet
|
||||
// votecreated notification.
|
||||
VoteCreatedNtfnMethod = "votecreated"
|
||||
|
||||
// WalletLockStateNtfnMethod is the method used to notify the lock state
|
||||
// of a wallet has changed.
|
||||
WalletLockStateNtfnMethod = "walletlockstate"
|
||||
)
|
||||
|
||||
// AccountBalanceNtfn defines the accountbalance JSON-RPC notification.
|
||||
type AccountBalanceNtfn struct {
|
||||
Account string
|
||||
Balance float64 // In DCR
|
||||
Confirmed bool // Whether Balance is confirmed or unconfirmed.
|
||||
}
|
||||
|
||||
// NewAccountBalanceNtfn returns a new instance which can be used to issue an
|
||||
// accountbalance JSON-RPC notification.
|
||||
func NewAccountBalanceNtfn(account string, balance float64, confirmed bool) *AccountBalanceNtfn {
|
||||
return &AccountBalanceNtfn{
|
||||
Account: account,
|
||||
Balance: balance,
|
||||
Confirmed: confirmed,
|
||||
}
|
||||
}
|
||||
|
||||
// DcrdConnectedNtfn defines the dcrddconnected JSON-RPC notification.
|
||||
type DcrdConnectedNtfn struct {
|
||||
Connected bool
|
||||
}
|
||||
|
||||
// NewDcrdConnectedNtfn returns a new instance which can be used to issue a
|
||||
// dcrddconnected JSON-RPC notification.
|
||||
func NewDcrdConnectedNtfn(connected bool) *DcrdConnectedNtfn {
|
||||
return &DcrdConnectedNtfn{
|
||||
Connected: connected,
|
||||
}
|
||||
}
|
||||
|
||||
// NewTxNtfn defines the newtx JSON-RPC notification.
|
||||
type NewTxNtfn struct {
|
||||
Account string
|
||||
Details ListTransactionsResult
|
||||
}
|
||||
|
||||
// NewNewTxNtfn returns a new instance which can be used to issue a newtx
|
||||
// JSON-RPC notification.
|
||||
func NewNewTxNtfn(account string, details ListTransactionsResult) *NewTxNtfn {
|
||||
return &NewTxNtfn{
|
||||
Account: account,
|
||||
Details: details,
|
||||
}
|
||||
}
|
||||
|
||||
// TicketPurchasedNtfn is a type handling custom marshaling and
|
||||
// unmarshaling of ticketpurchased JSON websocket notifications.
|
||||
type TicketPurchasedNtfn struct {
|
||||
TxHash string
|
||||
Amount int64 // SStx only
|
||||
}
|
||||
|
||||
// NewTicketPurchasedNtfn creates a new TicketPurchasedNtfn.
|
||||
func NewTicketPurchasedNtfn(txHash string, amount int64) *TicketPurchasedNtfn {
|
||||
return &TicketPurchasedNtfn{
|
||||
TxHash: txHash,
|
||||
Amount: amount,
|
||||
}
|
||||
}
|
||||
|
||||
// RevocationCreatedNtfn is a type handling custom marshaling and
|
||||
// unmarshaling of ticketpurchased JSON websocket notifications.
|
||||
type RevocationCreatedNtfn struct {
|
||||
TxHash string
|
||||
SStxIn string
|
||||
}
|
||||
|
||||
// NewRevocationCreatedNtfn creates a new RevocationCreatedNtfn.
|
||||
func NewRevocationCreatedNtfn(txHash string, sstxIn string) *RevocationCreatedNtfn {
|
||||
return &RevocationCreatedNtfn{
|
||||
TxHash: txHash,
|
||||
SStxIn: sstxIn,
|
||||
}
|
||||
}
|
||||
|
||||
// VoteCreatedNtfn is a type handling custom marshaling and
|
||||
// unmarshaling of ticketpurchased JSON websocket notifications.
|
||||
type VoteCreatedNtfn struct {
|
||||
TxHash string
|
||||
BlockHash string
|
||||
Height int32
|
||||
SStxIn string
|
||||
VoteBits uint16
|
||||
}
|
||||
|
||||
// NewVoteCreatedNtfn creates a new VoteCreatedNtfn.
|
||||
func NewVoteCreatedNtfn(txHash string, blockHash string, height int32, sstxIn string, voteBits uint16) *VoteCreatedNtfn {
|
||||
return &VoteCreatedNtfn{
|
||||
TxHash: txHash,
|
||||
BlockHash: blockHash,
|
||||
Height: height,
|
||||
SStxIn: sstxIn,
|
||||
VoteBits: voteBits,
|
||||
}
|
||||
}
|
||||
|
||||
// WalletLockStateNtfn defines the walletlockstate JSON-RPC notification.
|
||||
type WalletLockStateNtfn struct {
|
||||
Locked bool
|
||||
}
|
||||
|
||||
// NewWalletLockStateNtfn returns a new instance which can be used to issue a
|
||||
// walletlockstate JSON-RPC notification.
|
||||
func NewWalletLockStateNtfn(locked bool) *WalletLockStateNtfn {
|
||||
return &WalletLockStateNtfn{
|
||||
Locked: locked,
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
// The commands in this file are only usable with a wallet server via
|
||||
// websockets and are notifications.
|
||||
flags := UFWalletOnly | UFWebsocketOnly | UFNotification
|
||||
|
||||
MustRegisterCmd(AccountBalanceNtfnMethod, (*AccountBalanceNtfn)(nil), flags)
|
||||
MustRegisterCmd(DcrdConnectedNtfnMethod, (*DcrdConnectedNtfn)(nil), flags)
|
||||
MustRegisterCmd(NewTxNtfnMethod, (*NewTxNtfn)(nil), flags)
|
||||
MustRegisterCmd(TicketPurchasedNtfnMethod, (*TicketPurchasedNtfn)(nil), flags)
|
||||
MustRegisterCmd(RevocationCreatedNtfnMethod, (*RevocationCreatedNtfn)(nil), flags)
|
||||
MustRegisterCmd(VoteCreatedNtfnMethod, (*VoteCreatedNtfn)(nil), flags)
|
||||
MustRegisterCmd(WalletLockStateNtfnMethod, (*WalletLockStateNtfn)(nil), flags)
|
||||
}
|
||||
@ -1,225 +0,0 @@
|
||||
// Copyright (c) 2014 The btcsuite developers
|
||||
// Copyright (c) 2015-2016 The Decred developers
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package dcrjson
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestWalletSvrWsNtfns tests all of the chain 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 TestWalletSvrWsNtfns(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
newNtfn func() (interface{}, error)
|
||||
staticNtfn func() interface{}
|
||||
marshalled string
|
||||
unmarshalled interface{}
|
||||
}{
|
||||
{
|
||||
name: "accountbalance",
|
||||
newNtfn: func() (interface{}, error) {
|
||||
return NewCmd("accountbalance", "acct", 1.25, true)
|
||||
},
|
||||
staticNtfn: func() interface{} {
|
||||
return NewAccountBalanceNtfn("acct", 1.25, true)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"accountbalance","params":["acct",1.25,true],"id":null}`,
|
||||
unmarshalled: &AccountBalanceNtfn{
|
||||
Account: "acct",
|
||||
Balance: 1.25,
|
||||
Confirmed: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "dcrdconnected",
|
||||
newNtfn: func() (interface{}, error) {
|
||||
return NewCmd("dcrdconnected", true)
|
||||
},
|
||||
staticNtfn: func() interface{} {
|
||||
return NewDcrdConnectedNtfn(true)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"dcrdconnected","params":[true],"id":null}`,
|
||||
unmarshalled: &DcrdConnectedNtfn{
|
||||
Connected: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "newtx",
|
||||
newNtfn: func() (interface{}, error) {
|
||||
return NewCmd("newtx", "acct", `{"account":"acct","address":"1Address","category":"send","amount":1.5,"fee":0.0001,"confirmations":1,"txid":"456","walletconflicts":[],"time":12345678,"timereceived":12345876,"vout":789,"otheraccount":"otheracct"}`)
|
||||
},
|
||||
staticNtfn: func() interface{} {
|
||||
result := ListTransactionsResult{
|
||||
Account: "acct",
|
||||
Address: "1Address",
|
||||
Category: "send",
|
||||
Amount: 1.5,
|
||||
Fee: Float64(0.0001),
|
||||
Confirmations: 1,
|
||||
TxID: "456",
|
||||
WalletConflicts: []string{},
|
||||
Time: 12345678,
|
||||
TimeReceived: 12345876,
|
||||
Vout: 789,
|
||||
OtherAccount: "otheracct",
|
||||
}
|
||||
return NewNewTxNtfn("acct", result)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"newtx","params":["acct",{"account":"acct","address":"1Address","amount":1.5,"category":"send","confirmations":1,"fee":0.0001,"time":12345678,"timereceived":12345876,"txid":"456","vout":789,"walletconflicts":[],"otheraccount":"otheracct"}],"id":null}`,
|
||||
unmarshalled: &NewTxNtfn{
|
||||
Account: "acct",
|
||||
Details: ListTransactionsResult{
|
||||
Account: "acct",
|
||||
Address: "1Address",
|
||||
Category: "send",
|
||||
Amount: 1.5,
|
||||
Fee: Float64(0.0001),
|
||||
Confirmations: 1,
|
||||
TxID: "456",
|
||||
WalletConflicts: []string{},
|
||||
Time: 12345678,
|
||||
TimeReceived: 12345876,
|
||||
Vout: 789,
|
||||
OtherAccount: "otheracct",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "revocationcreated",
|
||||
newNtfn: func() (interface{}, error) {
|
||||
return NewCmd("revocationcreated", "123", "1234")
|
||||
},
|
||||
staticNtfn: func() interface{} {
|
||||
return NewRevocationCreatedNtfn("123", "1234")
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"revocationcreated","params":["123","1234"],"id":null}`,
|
||||
unmarshalled: &RevocationCreatedNtfn{
|
||||
TxHash: "123",
|
||||
SStxIn: "1234",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ticketpurchase",
|
||||
newNtfn: func() (interface{}, error) {
|
||||
return NewCmd("ticketpurchased", "123", 5)
|
||||
},
|
||||
staticNtfn: func() interface{} {
|
||||
return NewTicketPurchasedNtfn("123", 5)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"ticketpurchased","params":["123",5],"id":null}`,
|
||||
unmarshalled: &TicketPurchasedNtfn{
|
||||
TxHash: "123",
|
||||
Amount: 5,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "votecreated",
|
||||
newNtfn: func() (interface{}, error) {
|
||||
return NewCmd("votecreated", "123", "1234", 100, "12345", 1)
|
||||
},
|
||||
staticNtfn: func() interface{} {
|
||||
return NewVoteCreatedNtfn("123", "1234", 100, "12345", 1)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"votecreated","params":["123","1234",100,"12345",1],"id":null}`,
|
||||
unmarshalled: &VoteCreatedNtfn{
|
||||
TxHash: "123",
|
||||
BlockHash: "1234",
|
||||
Height: 100,
|
||||
SStxIn: "12345",
|
||||
VoteBits: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "walletlockstate",
|
||||
newNtfn: func() (interface{}, error) {
|
||||
return NewCmd("walletlockstate", true)
|
||||
},
|
||||
staticNtfn: func() interface{} {
|
||||
return NewWalletLockStateNtfn(true)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"walletlockstate","params":[true],"id":null}`,
|
||||
unmarshalled: &WalletLockStateNtfn{
|
||||
Locked: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
t.Logf("Running %d tests", len(tests))
|
||||
for i, test := range tests {
|
||||
// Marshal the notification as created by the new static
|
||||
// creation function. The ID is nil for notifications.
|
||||
marshalled, err := MarshalCmd("1.0", nil, test.staticNtfn())
|
||||
if err != nil {
|
||||
t.Errorf("MarshalCmd #%d (%s) unexpected error: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !bytes.Equal(marshalled, []byte(test.marshalled)) {
|
||||
t.Errorf("Test #%d (%s) unexpected marshalled data - "+
|
||||
"got %s, want %s", i, test.name, marshalled,
|
||||
test.marshalled)
|
||||
continue
|
||||
}
|
||||
|
||||
// Ensure the notification is created without error via the
|
||||
// generic new notification creation function.
|
||||
cmd, err := test.newNtfn()
|
||||
if err != nil {
|
||||
t.Errorf("Test #%d (%s) unexpected NewCmd error: %v ",
|
||||
i, test.name, err)
|
||||
}
|
||||
|
||||
// Marshal the notification as created by the generic new
|
||||
// notification creation function. The ID is nil for
|
||||
// notifications.
|
||||
marshalled, err = MarshalCmd("1.0", nil, cmd)
|
||||
if err != nil {
|
||||
t.Errorf("MarshalCmd #%d (%s) unexpected error: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !bytes.Equal(marshalled, []byte(test.marshalled)) {
|
||||
t.Errorf("Test #%d (%s) unexpected marshalled data - "+
|
||||
"got %s, want %s", i, test.name, marshalled,
|
||||
test.marshalled)
|
||||
continue
|
||||
}
|
||||
|
||||
var request Request
|
||||
if err := json.Unmarshal(marshalled, &request); err != nil {
|
||||
t.Errorf("Test #%d (%s) unexpected error while "+
|
||||
"unmarshalling JSON-RPC request: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
cmd, err = UnmarshalCmd(&request)
|
||||
if err != nil {
|
||||
t.Errorf("UnmarshalCmd #%d (%s) unexpected error: %v", i,
|
||||
test.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(cmd, test.unmarshalled) {
|
||||
t.Errorf("Test #%d (%s) unexpected unmarshalled command "+
|
||||
"- got %s, want %s", i, test.name,
|
||||
fmt.Sprintf("(%T) %+[1]v", cmd),
|
||||
fmt.Sprintf("(%T) %+[1]v\n", test.unmarshalled))
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
1
go.mod
1
go.mod
@ -52,7 +52,6 @@ replace (
|
||||
github.com/decred/dcrd/dcrec => ./dcrec
|
||||
github.com/decred/dcrd/dcrec/edwards => ./dcrec/edwards
|
||||
github.com/decred/dcrd/dcrec/secp256k1 => ./dcrec/secp256k1
|
||||
github.com/decred/dcrd/dcrjson => ./dcrjson
|
||||
github.com/decred/dcrd/dcrutil => ./dcrutil
|
||||
github.com/decred/dcrd/fees => ./fees
|
||||
github.com/decred/dcrd/gcs => ./gcs
|
||||
|
||||
Loading…
Reference in New Issue
Block a user