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:
parent
aeec39c1ff
commit
082ad7caf2
1 changed files with 24 additions and 20 deletions
44
rpcserver.go
44
rpcserver.go
|
@ -527,28 +527,32 @@ func createVoutList(mtx *btcwire.MsgTx, net btcwire.BitcoinNet) ([]btcjson.Vout,
|
|||
}
|
||||
voutList[i].ScriptPubKey.Asm = disbuf
|
||||
voutList[i].ScriptPubKey.Hex = hex.EncodeToString(v.PkScript)
|
||||
voutList[i].ScriptPubKey.Type = btcscript.NonStandardTy.String()
|
||||
|
||||
scriptType := btcscript.GetScriptClass(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.Addresses = addrList
|
||||
// TODO: replace with proper multisig handling
|
||||
voutList[i].ScriptPubKey.ReqSigs = 1
|
||||
scriptType, reqSigs, addrHashes := btcscript.CalcPkScriptAddrHashes(v.PkScript)
|
||||
voutList[i].ScriptPubKey.Type = scriptType.String()
|
||||
voutList[i].ScriptPubKey.ReqSigs = reqSigs
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue