From 6f17ebc8cbf06c525c19a99d578c79c020a88254 Mon Sep 17 00:00:00 2001 From: David Hill Date: Wed, 2 Jul 2014 23:52:34 -0400 Subject: [PATCH] Implement validateaddress. validateaddress will simply return whether the given address is valid or not. For the full implementation, one should query btcwallet instead. --- rpcserver.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/rpcserver.go b/rpcserver.go index 5a830a8a..e6faf2d7 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -114,6 +114,7 @@ var rpcHandlersBeforeInit = map[string]commandHandler{ "setgenerate": handleSetGenerate, "stop": handleStop, "submitblock": handleSubmitBlock, + "validateaddress": handleValidateAddress, "verifychain": handleVerifyChain, } @@ -165,7 +166,6 @@ var rpcAskWallet = map[string]struct{}{ "settxfee": struct{}{}, "signmessage": struct{}{}, "signrawtransaction": struct{}{}, - "validateaddress": struct{}{}, "verifymessage": struct{}{}, "walletlock": struct{}{}, "walletpassphrase": struct{}{}, @@ -2168,6 +2168,24 @@ func verifyChain(db btcdb.Db, level, depth int32) error { return nil } +// handleValidateAddress implements the validateaddress command. +func handleValidateAddress(s *rpcServer, cmd btcjson.Cmd, closeChan <-chan struct{}) (interface{}, error) { + c := cmd.(*btcjson.ValidateAddressCmd) + + result := btcjson.ValidateAddressResult{} + addr, err := btcutil.DecodeAddress(c.Address, activeNetParams.Params) + if err != nil { + // Return the default value (false) for IsValid. + return result, nil + } + + result.Address = addr.EncodeAddress() + result.IsValid = true + + return result, nil +} + +// handleVerifyChain implements the verifychain command. func handleVerifyChain(s *rpcServer, cmd btcjson.Cmd, closeChan <-chan struct{}) (interface{}, error) { c := cmd.(*btcjson.VerifyChainCmd)