Added Error message type to wire protocol

This commit is contained in:
Joseph Poon authored and Olaoluwa Osuntokun committed 2016-01-14 23:56:10 -08:00
1 parent f3849f5c10
commit b4c644c99a
5 files changed
+144 -6

No files matched your search

+33
View File
@@ -202,6 +202,21 @@ func writeElement(w io.Writer, element interface{}) error {
return err
}
return nil
case string:
strlen := len(e)
if strlen > 65535 {
return fmt.Errorf("String too long!")
}
//Write the size (2-bytes)
err = writeElement(w, uint16(strlen))
if err != nil {
return err
}
//Write the data
_, err = w.Write([]byte(e))
if err != nil {
return err
}
case []*wire.TxIn:
//Append the unsigned(!!!) txins
//Write the size (1-byte)
@@ -453,6 +468,24 @@ func readElement(r io.Reader, element interface{}) error {
return fmt.Errorf("EOF: Signature length mismatch.")
}
return nil
case *string:
//Get the string length first
var strlen uint16
err = readElement(r, &strlen)
if err != nil {
return err
}
//Read the string for the length
l := io.LimitReader(r, int64(strlen))
b, err := ioutil.ReadAll(l)
if len(b) != int(strlen) {
return fmt.Errorf("EOF: String length mismatch.")
}
*e = string(b)
if err != nil {
return err
}
return nil
case *[]*wire.TxIn:
//Read the size (1-byte number of txins)
var numScripts uint8