mirror of
https://github.com/btcsuite/btcd.git
synced 2024-11-19 09:50:08 +01:00
Add gettxoutproof and verifytxoutproof JSON-RPC infrastructure.
From Bitcoin Core commit 59ed61b3895b022f61970ea7aac0c20e8ba38886
This commit is contained in:
parent
9350b939bc
commit
6d15b04128
@ -434,6 +434,24 @@ func NewGetTxOutCmd(txHash string, vout uint32, includeMempool *bool) *GetTxOutC
|
||||
}
|
||||
}
|
||||
|
||||
// GetTxOutProofCmd defines the gettxoutproof JSON-RPC command.
|
||||
type GetTxOutProofCmd struct {
|
||||
TxIDs []string
|
||||
BlockHash *string
|
||||
}
|
||||
|
||||
// NewGetTxOutProofCmd returns a new instance which can be used to issue a
|
||||
// gettxoutproof JSON-RPC command.
|
||||
//
|
||||
// The parameters which are pointers indicate they are optional. Passing nil
|
||||
// for optional parameters will use the default value.
|
||||
func NewGetTxOutProofCmd(txIDs []string, blockHash *string) *GetTxOutProofCmd {
|
||||
return &GetTxOutProofCmd{
|
||||
TxIDs: txIDs,
|
||||
BlockHash: blockHash,
|
||||
}
|
||||
}
|
||||
|
||||
// GetTxOutSetInfoCmd defines the gettxoutsetinfo JSON-RPC command.
|
||||
type GetTxOutSetInfoCmd struct{}
|
||||
|
||||
@ -650,6 +668,19 @@ func NewVerifyMessageCmd(address, signature, message string) *VerifyMessageCmd {
|
||||
}
|
||||
}
|
||||
|
||||
// VerifyTxOutProofCmd defines the verifytxoutproof JSON-RPC command.
|
||||
type VerifyTxOutProofCmd struct {
|
||||
Proof string
|
||||
}
|
||||
|
||||
// NewVerifyTxOutProofCmd returns a new instance which can be used to issue a
|
||||
// verifytxoutproof JSON-RPC command.
|
||||
func NewVerifyTxOutProofCmd(proof string) *VerifyTxOutProofCmd {
|
||||
return &VerifyTxOutProofCmd{
|
||||
Proof: proof,
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
// No special flags for commands in this file.
|
||||
flags := UsageFlag(0)
|
||||
@ -680,6 +711,7 @@ func init() {
|
||||
MustRegisterCmd("getrawmempool", (*GetRawMempoolCmd)(nil), flags)
|
||||
MustRegisterCmd("getrawtransaction", (*GetRawTransactionCmd)(nil), flags)
|
||||
MustRegisterCmd("gettxout", (*GetTxOutCmd)(nil), flags)
|
||||
MustRegisterCmd("gettxoutproof", (*GetTxOutProofCmd)(nil), flags)
|
||||
MustRegisterCmd("gettxoutsetinfo", (*GetTxOutSetInfoCmd)(nil), flags)
|
||||
MustRegisterCmd("getwork", (*GetWorkCmd)(nil), flags)
|
||||
MustRegisterCmd("help", (*HelpCmd)(nil), flags)
|
||||
@ -694,4 +726,5 @@ func init() {
|
||||
MustRegisterCmd("validateaddress", (*ValidateAddressCmd)(nil), flags)
|
||||
MustRegisterCmd("verifychain", (*VerifyChainCmd)(nil), flags)
|
||||
MustRegisterCmd("verifymessage", (*VerifyMessageCmd)(nil), flags)
|
||||
MustRegisterCmd("verifytxoutproof", (*VerifyTxOutProofCmd)(nil), flags)
|
||||
}
|
||||
|
@ -529,6 +529,36 @@ func TestChainSvrCmds(t *testing.T) {
|
||||
IncludeMempool: btcjson.Bool(true),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "gettxoutproof",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("gettxoutproof", []string{"123", "456"})
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewGetTxOutProofCmd([]string{"123", "456"}, nil)
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"gettxoutproof","params":[["123","456"]],"id":1}`,
|
||||
unmarshalled: &btcjson.GetTxOutProofCmd{
|
||||
TxIDs: []string{"123", "456"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "gettxoutproof optional",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("gettxoutproof", []string{"123", "456"},
|
||||
btcjson.String("000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf"))
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewGetTxOutProofCmd([]string{"123", "456"},
|
||||
btcjson.String("000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf"))
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"gettxoutproof","params":[["123","456"],` +
|
||||
`"000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf"],"id":1}`,
|
||||
unmarshalled: &btcjson.GetTxOutProofCmd{
|
||||
TxIDs: []string{"123", "456"},
|
||||
BlockHash: btcjson.String("000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "gettxoutsetinfo",
|
||||
newCmd: func() (interface{}, error) {
|
||||
@ -866,6 +896,19 @@ func TestChainSvrCmds(t *testing.T) {
|
||||
Message: "test",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "verifytxoutproof",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("verifytxoutproof", "test")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewVerifyTxOutProofCmd("test")
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"verifytxoutproof","params":["test"],"id":1}`,
|
||||
unmarshalled: &btcjson.VerifyTxOutProofCmd{
|
||||
Proof: "test",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
t.Logf("Running %d tests", len(tests))
|
||||
|
Loading…
Reference in New Issue
Block a user