Ignore error in script disassembly for RPC results.

This commit modifies the creation of RPC results to ignore errors in
script disassembly since they already contain the error string inline and
the RPC results must still be generated regardless.

This was already done in the decodescript RPC, however the same thing was
not being done in the higher level verbose transaction results.  This
applies to both the createrawtransaction and decoderawtransaction RPCs.

Also, since this was the only thing that could error within those
functions, the error returns and caller checking of now non-existent
errors have been removed.

Fixes #210.
This commit is contained in:
Dave Collins 2015-01-07 16:21:10 -06:00
parent e5a825324c
commit 4b727d2035

View file

@ -834,7 +834,7 @@ func handleDebugLevel(s *rpcServer, cmd btcjson.Cmd, closeChan <-chan struct{})
// createVinList returns a slice of JSON objects for the inputs of the passed // createVinList returns a slice of JSON objects for the inputs of the passed
// transaction. // transaction.
func createVinList(mtx *btcwire.MsgTx) ([]btcjson.Vin, error) { func createVinList(mtx *btcwire.MsgTx) []btcjson.Vin {
tx := btcutil.NewTx(mtx) tx := btcutil.NewTx(mtx)
vinList := make([]btcjson.Vin, len(mtx.TxIn)) vinList := make([]btcjson.Vin, len(mtx.TxIn))
for i, v := range mtx.TxIn { for i, v := range mtx.TxIn {
@ -844,13 +844,10 @@ func createVinList(mtx *btcwire.MsgTx) ([]btcjson.Vin, error) {
vinList[i].Txid = v.PreviousOutPoint.Hash.String() vinList[i].Txid = v.PreviousOutPoint.Hash.String()
vinList[i].Vout = v.PreviousOutPoint.Index vinList[i].Vout = v.PreviousOutPoint.Index
disbuf, err := btcscript.DisasmString(v.SignatureScript) // The disassembled string will contain [error] inline
if err != nil { // if the script doesn't fully parse, so ignore the
return nil, btcjson.Error{ // error here.
Code: btcjson.ErrInternal.Code, disbuf, _ := btcscript.DisasmString(v.SignatureScript)
Message: err.Error(),
}
}
vinList[i].ScriptSig = new(btcjson.ScriptSig) vinList[i].ScriptSig = new(btcjson.ScriptSig)
vinList[i].ScriptSig.Asm = disbuf vinList[i].ScriptSig.Asm = disbuf
vinList[i].ScriptSig.Hex = hex.EncodeToString(v.SignatureScript) vinList[i].ScriptSig.Hex = hex.EncodeToString(v.SignatureScript)
@ -858,24 +855,20 @@ func createVinList(mtx *btcwire.MsgTx) ([]btcjson.Vin, error) {
vinList[i].Sequence = v.Sequence vinList[i].Sequence = v.Sequence
} }
return vinList, nil return vinList
} }
// createVoutList returns a slice of JSON objects for the outputs of the passed // createVoutList returns a slice of JSON objects for the outputs of the passed
// transaction. // transaction.
func createVoutList(mtx *btcwire.MsgTx, net *btcnet.Params) ([]btcjson.Vout, error) { func createVoutList(mtx *btcwire.MsgTx, net *btcnet.Params) []btcjson.Vout {
voutList := make([]btcjson.Vout, len(mtx.TxOut)) voutList := make([]btcjson.Vout, len(mtx.TxOut))
for i, v := range mtx.TxOut { for i, v := range mtx.TxOut {
voutList[i].N = uint32(i) voutList[i].N = uint32(i)
voutList[i].Value = float64(v.Value) / btcutil.SatoshiPerBitcoin voutList[i].Value = float64(v.Value) / btcutil.SatoshiPerBitcoin
disbuf, err := btcscript.DisasmString(v.PkScript) // The disassembled string will contain [error] inline if the
if err != nil { // script doesn't fully parse, so ignore the error here.
return nil, btcjson.Error{ disbuf, _ := btcscript.DisasmString(v.PkScript)
Code: btcjson.ErrInternal.Code,
Message: err.Error(),
}
}
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)
@ -896,7 +889,7 @@ func createVoutList(mtx *btcwire.MsgTx, net *btcnet.Params) ([]btcjson.Vout, err
} }
} }
return voutList, nil return voutList
} }
// createTxRawResult converts the passed transaction and associated parameters // createTxRawResult converts the passed transaction and associated parameters
@ -910,20 +903,11 @@ func createTxRawResult(net *btcnet.Params, txSha string, mtx *btcwire.MsgTx,
return nil, err return nil, err
} }
vin, err := createVinList(mtx)
if err != nil {
return nil, err
}
vout, err := createVoutList(mtx, net)
if err != nil {
return nil, err
}
txReply := &btcjson.TxRawResult{ txReply := &btcjson.TxRawResult{
Hex: mtxHex, Hex: mtxHex,
Txid: txSha, Txid: txSha,
Vout: vout, Vout: createVoutList(mtx, net),
Vin: vin, Vin: createVinList(mtx),
Version: mtx.Version, Version: mtx.Version,
LockTime: mtx.LockTime, LockTime: mtx.LockTime,
} }
@ -969,22 +953,13 @@ func handleDecodeRawTransaction(s *rpcServer, cmd btcjson.Cmd, closeChan <-chan
} }
txSha, _ := mtx.TxSha() txSha, _ := mtx.TxSha()
vin, err := createVinList(&mtx)
if err != nil {
return nil, err
}
vout, err := createVoutList(&mtx, s.server.netParams)
if err != nil {
return nil, err
}
// Create and return the result. // Create and return the result.
txReply := btcjson.TxRawDecodeResult{ txReply := btcjson.TxRawDecodeResult{
Txid: txSha.String(), Txid: txSha.String(),
Version: mtx.Version, Version: mtx.Version,
Locktime: mtx.LockTime, Locktime: mtx.LockTime,
Vin: vin, Vin: createVinList(&mtx),
Vout: vout, Vout: createVoutList(&mtx, s.server.netParams),
} }
return txReply, nil return txReply, nil
} }