mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-24 06:52:32 +00:00
Fix deserialization of script version in UTXOSet deserialization (#1395)
* Initalize protoUTXOSetIterator with index = -1 * Handle error when failed to deserialize Script version * Add support for (de)serialization of (u)int16 * Log the error when converting it into ErrMalformedUTXO
This commit is contained in:
parent
434cf45112
commit
c7deda41c6
@ -161,7 +161,7 @@ func (p *protoUTXOSetIterator) Get() (outpoint *externalapi.DomainOutpoint, utxo
|
|||||||
entry, outpoint, err := utxo.DeserializeUTXO(p.utxoSet.Utxos[p.index].EntryOutpointPair)
|
entry, outpoint, err := utxo.DeserializeUTXO(p.utxoSet.Utxos[p.index].EntryOutpointPair)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if serialization.IsMalformedError(err) {
|
if serialization.IsMalformedError(err) {
|
||||||
return nil, nil, errors.Wrap(ruleerrors.ErrMalformedUTXO, "malformed utxo")
|
return nil, nil, errors.Wrapf(ruleerrors.ErrMalformedUTXO, "malformed utxo: %s", err)
|
||||||
}
|
}
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@ -170,5 +170,5 @@ func (p *protoUTXOSetIterator) Get() (outpoint *externalapi.DomainOutpoint, utxo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func protoUTXOSetToReadOnlyUTXOSetIterator(protoUTXOSet *utxoserialization.ProtoUTXOSet) model.ReadOnlyUTXOSetIterator {
|
func protoUTXOSetToReadOnlyUTXOSetIterator(protoUTXOSet *utxoserialization.ProtoUTXOSet) model.ReadOnlyUTXOSetIterator {
|
||||||
return &protoUTXOSetIterator{utxoSet: protoUTXOSet}
|
return &protoUTXOSetIterator{utxoSet: protoUTXOSet, index: -1}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,12 @@ func WriteElement(w io.Writer, element interface{}) error {
|
|||||||
// Attempt to write the element based on the concrete type via fast
|
// Attempt to write the element based on the concrete type via fast
|
||||||
// type assertions first.
|
// type assertions first.
|
||||||
switch e := element.(type) {
|
switch e := element.(type) {
|
||||||
|
case int16:
|
||||||
|
err := binaryserializer.PutUint16(w, uint16(e))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
case uint16:
|
case uint16:
|
||||||
err := binaryserializer.PutUint16(w, e)
|
err := binaryserializer.PutUint16(w, e)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -121,6 +127,21 @@ func ReadElement(r io.Reader, element interface{}) error {
|
|||||||
// Attempt to read the element based on the concrete type via fast
|
// Attempt to read the element based on the concrete type via fast
|
||||||
// type assertions first.
|
// type assertions first.
|
||||||
switch e := element.(type) {
|
switch e := element.(type) {
|
||||||
|
case *int16:
|
||||||
|
rv, err := binaryserializer.Uint16(r)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*e = int16(rv)
|
||||||
|
return nil
|
||||||
|
|
||||||
|
case *uint16:
|
||||||
|
rv, err := binaryserializer.Uint16(r)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*e = rv
|
||||||
|
return nil
|
||||||
case *int32:
|
case *int32:
|
||||||
rv, err := binaryserializer.Uint32(r)
|
rv, err := binaryserializer.Uint32(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -114,7 +114,10 @@ func deserializeUTXOEntry(r io.Reader) (externalapi.UTXOEntry, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var version uint16
|
var version uint16
|
||||||
err = serialization.ReadElement(r, version)
|
err = serialization.ReadElement(r, &version)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
var scriptPubKeyLen uint64
|
var scriptPubKeyLen uint64
|
||||||
err = serialization.ReadElement(r, &scriptPubKeyLen)
|
err = serialization.ReadElement(r, &scriptPubKeyLen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user