Skip to content

Commit

Permalink
Add invalidateblock and reconsiderblock.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcvernaleo committed Dec 2, 2014
1 parent 503670f commit e0d5366
Show file tree
Hide file tree
Showing 6 changed files with 399 additions and 201 deletions.
12 changes: 9 additions & 3 deletions cmdhelp.go
Expand Up @@ -416,7 +416,7 @@ following information about txid is returned:
Returns the total amount of BTC received by addresses related to "account".
Only transactions with at least "minconf" confirmations are considered.`,

"getreceivedbyaddress": `getreceivedbyaddress "address" ( minconf=1 )
"getreceivedbyaddress": `getreceivedbyaddress "address" ( minconf=1 )
Returns the total amount of BTC received by the given address. Only transactions
with "minconf" confirmations will be used for the total.`,

Expand Down Expand Up @@ -500,6 +500,9 @@ blockchain will be scanned for transaction.`,
"importwallet": `importwallet "filename"
Imports keys from the wallet dump file in "filename".`,

"invalidateblock": `invalidateblock "hash"
Mark block specified by "hash" as invalid.`,

"keypoolrefill": `keypoolrefill ( newsize=100 )
Refills the wallet pregenerated key pool to a size of "newsize"`,

Expand Down Expand Up @@ -571,7 +574,7 @@ with "minconf" confirmations are listed.
"transactions":[
"account" # String of account related to the transaction.
"address" # String of related address of transaction.
"category":"send|receive" # String detailing whether transaction was a send or receive of funds.
"category":"send|receive" # String detailing whether transaction was a send or receive of funds.
"amount":n, # Numeric value of transaction. Negative if transaction category was "send"
"fee":n, # Numeric value of transaction fee in BTC.
"confirmations":n, # Number of transaction confirmations
Expand All @@ -594,7 +597,7 @@ accounts if none specified) skipping the first "from" transactions.
"transactions":[
"account" # String of account related to the transaction.
"address" # String of related address of transaction.
"category":"send|receive|move" # String detailing whether transaction was a send or receive of funds.Move is a local move between accounts and doesnt touch the blockchain.
"category":"send|receive|move" # String detailing whether transaction was a send or receive of funds.Move is a local move between accounts and doesnt touch the blockchain.
"amount":n, # Numeric value of transaction. Negative if transaction category was "send"
"fee":n, # Numeric value of transaction fee in BTC.
"confirmations":n, # Number of transaction confirmations
Expand Down Expand Up @@ -645,6 +648,9 @@ to denode success.`,
Queues a ping to be sent to each connected peer. Ping times are provided in
getpeerinfo.`,

"reconsiderblock": `reconsiderblock "hash"
Remove invalid mark from block specified by "hash" so it is considered again.`,

"sendfrom": `sendfrom "fromaccount" "tobitcoinaddress" amount ( minconf=1 "comment" "comment-to" )
Sends "amount" (rounded to the nearest 0.00000001) to
"tobitcoindaddress" from "fromaccount". Only funds with at least
Expand Down
3 changes: 2 additions & 1 deletion jsonapi.go
Expand Up @@ -169,7 +169,8 @@ func CreateMessageWithId(message string, id interface{}, args ...interface{}) ([
case "backupwallet", "decoderawtransaction", "dumpprivkey",
"encryptwallet", "getaccount", "getaccountaddress",
"getaddressesbyaccount", "getblock",
"gettransaction", "sendrawtransaction", "validateaddress":
"gettransaction", "sendrawtransaction", "validateaddress",
"invalidateblock", "reconsiderblock":
if len(args) != 1 {
err = fmt.Errorf("%s requires one argument", message)
return finalMessage, err
Expand Down
8 changes: 8 additions & 0 deletions jsonapi_test.go
Expand Up @@ -57,6 +57,14 @@ var cmdtests = []struct {
{"backupwallet", []interface{}{1, 2}, false},
{"backupwallet", []interface{}{1}, false},
{"backupwallet", []interface{}{"testpath"}, true},
{"invalidateblock", nil, false},
{"invalidateblock", []interface{}{1, 2}, false},
{"invalidateblock", []interface{}{1}, false},
{"invalidateblock", []interface{}{"testhash"}, true},
{"reconsiderblock", nil, false},
{"reconsiderblock", []interface{}{1, 2}, false},
{"reconsiderblock", []interface{}{1}, false},
{"reconsiderblock", []interface{}{"testhash"}, true},
{"setaccount", nil, false},
{"setaccount", []interface{}{1}, false},
{"setaccount", []interface{}{1, 2, 3}, false},
Expand Down
146 changes: 146 additions & 0 deletions jsoncmd.go
Expand Up @@ -244,6 +244,9 @@ func ParseMarshaledCmd(b []byte) (Cmd, error) {
case "importwallet":
cmd = new(ImportWalletCmd)

case "invalidateblock":
cmd = new(InvalidateBlockCmd)

case "keypoolrefill":
cmd = new(KeyPoolRefillCmd)

Expand Down Expand Up @@ -280,6 +283,9 @@ func ParseMarshaledCmd(b []byte) (Cmd, error) {
case "ping":
cmd = new(PingCmd)

case "reconsiderblock":
cmd = new(ReconsiderBlockCmd)

case "sendfrom":
cmd = new(SendFromCmd)

Expand Down Expand Up @@ -4018,6 +4024,76 @@ func (cmd *ImportWalletCmd) UnmarshalJSON(b []byte) error {
return nil
}

// InvalidateBlockCmd is a type handling custom marshaling and
// unmarshaling of invalidateblock JSON RPC commands.
type InvalidateBlockCmd struct {
id interface{}
BlockHash string
}

// Enforce that InvalidateBlockCmd satisifies the Cmd interface.
var _ Cmd = &InvalidateBlockCmd{}

// NewInvalidateBlockCmd creates a new InvalidateBlockCmd. Optionally a
// pointer to a TemplateRequest may be provided.
func NewInvalidateBlockCmd(id interface{}, blockhash string) (*InvalidateBlockCmd, error) {
return &InvalidateBlockCmd{
id: id,
BlockHash: blockhash,
}, nil
}

// Id satisfies the Cmd interface by returning the id of the command.
func (cmd *InvalidateBlockCmd) Id() interface{} {
return cmd.id
}

// Method satisfies the Cmd interface by returning the json method.
func (cmd *InvalidateBlockCmd) Method() string {
return "invalidateblock"
}

// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface.
func (cmd *InvalidateBlockCmd) MarshalJSON() ([]byte, error) {
params := []interface{}{
cmd.BlockHash,
}

// Fill and marshal a RawCmd.
raw, err := NewRawCmd(cmd.id, cmd.Method(), params)
if err != nil {
return nil, err
}
return json.Marshal(raw)
}

// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of
// the Cmd interface.
func (cmd *InvalidateBlockCmd) UnmarshalJSON(b []byte) error {
// Unmashal into a RawCmd
var r RawCmd
if err := json.Unmarshal(b, &r); err != nil {
return err
}

if len(r.Params) != 1 {
return ErrWrongNumberOfParams
}

var blockhash string
if err := json.Unmarshal(r.Params[0], &blockhash); err != nil {
return fmt.Errorf("first parameter 'hash' must be a string: %v", err)
}

newCmd, err := NewInvalidateBlockCmd(r.Id, blockhash)
if err != nil {
return err
}

*cmd = *newCmd
return nil
}

// KeyPoolRefillCmd is a type handling custom marshaling and
// unmarshaling of keypoolrefill JSON RPC commands.
type KeyPoolRefillCmd struct {
Expand Down Expand Up @@ -5173,6 +5249,76 @@ func (cmd *PingCmd) UnmarshalJSON(b []byte) error {
return nil
}

// ReconsiderBlockCmd is a type handling custom marshaling and
// unmarshaling of reconsiderblock JSON RPC commands.
type ReconsiderBlockCmd struct {
id interface{}
BlockHash string
}

// Enforce that ReconsiderBlockCmd satisifies the Cmd interface.
var _ Cmd = &ReconsiderBlockCmd{}

// NewReconsiderBlockCmd creates a new ReconsiderBlockCmd. Optionally a
// pointer to a TemplateRequest may be provided.
func NewReconsiderBlockCmd(id interface{}, blockhash string) (*ReconsiderBlockCmd, error) {
return &ReconsiderBlockCmd{
id: id,
BlockHash: blockhash,
}, nil
}

// Id satisfies the Cmd interface by returning the id of the command.
func (cmd *ReconsiderBlockCmd) Id() interface{} {
return cmd.id
}

// Method satisfies the Cmd interface by returning the json method.
func (cmd *ReconsiderBlockCmd) Method() string {
return "reconsiderblock"
}

// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface.
func (cmd *ReconsiderBlockCmd) MarshalJSON() ([]byte, error) {
params := []interface{}{
cmd.BlockHash,
}

// Fill and marshal a RawCmd.
raw, err := NewRawCmd(cmd.id, cmd.Method(), params)
if err != nil {
return nil, err
}
return json.Marshal(raw)
}

// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of
// the Cmd interface.
func (cmd *ReconsiderBlockCmd) UnmarshalJSON(b []byte) error {
// Unmashal into a RawCmd
var r RawCmd
if err := json.Unmarshal(b, &r); err != nil {
return err
}

if len(r.Params) != 1 {
return ErrWrongNumberOfParams
}

var blockhash string
if err := json.Unmarshal(r.Params[0], &blockhash); err != nil {
return fmt.Errorf("first parameter 'hash' must be a string: %v", err)
}

newCmd, err := NewReconsiderBlockCmd(r.Id, blockhash)
if err != nil {
return err
}

*cmd = *newCmd
return nil
}

// SendFromCmd is a type handling custom marshaling and
// unmarshaling of sendfrom JSON RPC commands.
type SendFromCmd struct {
Expand Down
26 changes: 26 additions & 0 deletions jsoncmd_test.go
Expand Up @@ -864,6 +864,18 @@ var jsoncmdtests = []struct {
Filename: "walletfilename.dat",
},
},
{
name: "basic",
cmd: "invalidateblock",
f: func() (Cmd, error) {
return NewInvalidateBlockCmd(testID,
"lotsofhex")
},
result: &InvalidateBlockCmd{
id: testID,
BlockHash: "lotsofhex",
},
},
{
name: "basic",
cmd: "keypoolrefill",
Expand Down Expand Up @@ -1180,6 +1192,18 @@ var jsoncmdtests = []struct {
id: testID,
},
},
{
name: "basic",
cmd: "reconsiderblock",
f: func() (Cmd, error) {
return NewReconsiderBlockCmd(testID,
"lotsofhex")
},
result: &ReconsiderBlockCmd{
id: testID,
BlockHash: "lotsofhex",
},
},
{
name: "basic",
cmd: "sendfrom",
Expand Down Expand Up @@ -1668,6 +1692,7 @@ func TestHelps(t *testing.T) {
"help",
"importprivkey",
"importwallet",
"invalidateblock",
"keypoolrefill",
"listaccounts",
"listaddressgroupings",
Expand All @@ -1680,6 +1705,7 @@ func TestHelps(t *testing.T) {
"lockunspent",
"move",
"ping",
"reconsiderblock",
"sendfrom",
"sendmany",
"sendrawtransaction",
Expand Down

0 comments on commit e0d5366

Please sign in to comment.