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 { voutList[i].ScriptPubKey.Type = scriptType.String()
continue voutList[i].ScriptPubKey.ReqSigs = reqSigs
}
_, addrhash, err := btcscript.ScriptToAddrHash(v.PkScript) if addrHashes == nil {
if err != nil { voutList[i].ScriptPubKey.Addresses = nil
txSha, _ := mtx.TxSha() } else {
// TODO: set and return error? voutList[i].ScriptPubKey.Addresses = make([]string, len(addrHashes))
rpcsLog.Errorf("Error getting address hash for %v: %v", txSha, err) for j := 0; j < len(addrHashes); j++ {
continue var addr string
} if scriptType == btcscript.ScriptHashTy {
if addr, err := btcutil.EncodeAddress(addrhash, net); err == nil { addr, err = btcutil.EncodeScriptHash(addrHashes[j], net)
// TODO: set and return error? if err != nil {
addrList := make([]string, 1) continue
addrList[0] = addr }
voutList[i].ScriptPubKey.Type = scriptType.String() } else {
voutList[i].ScriptPubKey.Addresses = addrList addr, err = btcutil.EncodeAddress(addrHashes[j], net)
// TODO: replace with proper multisig handling if err != nil {
voutList[i].ScriptPubKey.ReqSigs = 1 continue
}
}
voutList[i].ScriptPubKey.Addresses[j] = addr
}
} }
} }
return voutList, nil return voutList, nil