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.
This commit is contained in:
Dave Collins 2014-01-04 12:42:50 -06:00
parent 92eee5cb96
commit 8a73f9b245

View file

@ -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. // Generate and return the reply.
reply := btcjson.DecodeScriptResult{ reply := btcjson.DecodeScriptResult{
Asm: disbuf, Asm: disbuf,
ReqSigs: reqSigs, ReqSigs: reqSigs,
Type: scriptType.String(), Type: scriptType.String(),
Addresses: addresses, Addresses: addresses,
P2sh: hex.EncodeToString(btcutil.Hash160(script)), P2sh: p2sh.EncodeAddress(),
} }
return reply, nil return reply, nil
} }