From 8a73f9b2458767a284e34a21fb4798c84e7a6259 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sat, 4 Jan 2014 12:42:50 -0600 Subject: [PATCH] Correct p2sh field of decodescript RPC result. The p2sh field in the result should be the encoded address which includes the network (human-readable address) instead of just the raw hash. --- rpcserver.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/rpcserver.go b/rpcserver.go index 9793429c..124415fa 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -741,13 +741,22 @@ func handleDecodeScript(s *rpcServer, cmd btcjson.Cmd) (interface{}, error) { } } + // Convert the script itself to a pay-to-script-hash address. + p2sh, err := btcutil.NewAddressScriptHash(script, net) + if err != nil { + return nil, btcjson.Error{ + Code: btcjson.ErrInternal.Code, + Message: err.Error(), + } + } + // Generate and return the reply. reply := btcjson.DecodeScriptResult{ Asm: disbuf, ReqSigs: reqSigs, Type: scriptType.String(), Addresses: addresses, - P2sh: hex.EncodeToString(btcutil.Hash160(script)), + P2sh: p2sh.EncodeAddress(), } return reply, nil }