neoneo-go/pkg/core/transaction/witness.go
Anthony De Meulemeester a67728628e
Persist blockchain with leveldb on disk (#48)
* Created test_data folder with block json files for testing + create separate file for block base.

* Fixed bug in WriteVarUint + Trim logic + unit tests

* Refactored store and add more tests for it.

* restore headerList from chain file

* Fix tx decode bug + lots of housekeeping.

* Implemented Node restore state from chain file.

* Created standalone package for storage. Added couple more methods to Batch and Store interfaces.

* Block persisting + tests

* bumped version -> 0.31.0
2018-03-17 12:53:21 +01:00

40 lines
1.1 KiB
Go

package transaction
import (
"encoding/binary"
"io"
"github.com/CityOfZion/neo-go/pkg/util"
)
// Witness contains 2 scripts.
type Witness struct {
InvocationScript []byte
VerificationScript []byte
}
// DecodeBinary implements the payload interface.
func (wit *Witness) DecodeBinary(r io.Reader) error {
lenb := util.ReadVarUint(r)
wit.InvocationScript = make([]byte, lenb)
if err := binary.Read(r, binary.LittleEndian, wit.InvocationScript); err != nil {
return err
}
lenb = util.ReadVarUint(r)
wit.VerificationScript = make([]byte, lenb)
return binary.Read(r, binary.LittleEndian, wit.VerificationScript)
}
// EncodeBinary implements the payload interface.
func (wit *Witness) EncodeBinary(w io.Writer) error {
if err := util.WriteVarUint(w, uint64(len(wit.InvocationScript))); err != nil {
return err
}
if err := binary.Write(w, binary.LittleEndian, wit.InvocationScript); err != nil {
return err
}
if err := util.WriteVarUint(w, uint64(len(wit.VerificationScript))); err != nil {
return err
}
return binary.Write(w, binary.LittleEndian, wit.VerificationScript)
}