Updated createVoutList to support scripthash/multisig outputs

Used updates in btcscript/btcutil to support decoding scripthash and
multisig outputs for display in getrawtransactions/decoderawtransaction
This commit is contained in:
Francis Lam 2014-01-02 00:30:00 -05:00 committed by Dave Collins
parent aeec39c1ff
commit 082ad7caf2

View file

@ -527,28 +527,32 @@ func createVoutList(mtx *btcwire.MsgTx, net btcwire.BitcoinNet) ([]btcjson.Vout,
} }
voutList[i].ScriptPubKey.Asm = disbuf voutList[i].ScriptPubKey.Asm = disbuf
voutList[i].ScriptPubKey.Hex = hex.EncodeToString(v.PkScript) voutList[i].ScriptPubKey.Hex = hex.EncodeToString(v.PkScript)
voutList[i].ScriptPubKey.Type = btcscript.NonStandardTy.String()
scriptType := btcscript.GetScriptClass(v.PkScript) scriptType, reqSigs, addrHashes := btcscript.CalcPkScriptAddrHashes(v.PkScript)
if scriptType == btcscript.NonStandardTy || scriptType == btcscript.NullDataTy {
continue
}
_, addrhash, err := btcscript.ScriptToAddrHash(v.PkScript)
if err != nil {
txSha, _ := mtx.TxSha()
// TODO: set and return error?
rpcsLog.Errorf("Error getting address hash for %v: %v", txSha, err)
continue
}
if addr, err := btcutil.EncodeAddress(addrhash, net); err == nil {
// TODO: set and return error?
addrList := make([]string, 1)
addrList[0] = addr
voutList[i].ScriptPubKey.Type = scriptType.String() voutList[i].ScriptPubKey.Type = scriptType.String()
voutList[i].ScriptPubKey.Addresses = addrList voutList[i].ScriptPubKey.ReqSigs = reqSigs
// TODO: replace with proper multisig handling
voutList[i].ScriptPubKey.ReqSigs = 1 if addrHashes == nil {
voutList[i].ScriptPubKey.Addresses = nil
} else {
voutList[i].ScriptPubKey.Addresses = make([]string, len(addrHashes))
for j := 0; j < len(addrHashes); j++ {
var addr string
if scriptType == btcscript.ScriptHashTy {
addr, err = btcutil.EncodeScriptHash(addrHashes[j], net)
if err != nil {
continue
} }
} else {
addr, err = btcutil.EncodeAddress(addrHashes[j], net)
if err != nil {
continue
}
}
voutList[i].ScriptPubKey.Addresses[j] = addr
}
}
} }
return voutList, nil return voutList, nil