transaction: add binary encoding for publish

And expand the test to check for it. Fixes #319.
This commit is contained in:
Roman Khimov 2019-08-30 19:19:43 +03:00
parent af212f496e
commit 203aab6a7e
2 changed files with 21 additions and 1 deletions

View file

@ -56,7 +56,22 @@ func (tx *PublishTX) DecodeBinary(r io.Reader) error {
// EncodeBinary implements the Payload interface.
func (tx *PublishTX) EncodeBinary(w io.Writer) error {
return nil
bw := util.BinWriter{W: w}
bw.WriteBytes(tx.Script)
bw.WriteVarUint(uint64(len(tx.ParamList)))
for _, param := range tx.ParamList {
bw.WriteLE(uint8(param))
}
bw.WriteLE(uint8(tx.ReturnType))
if tx.Version >= 1 {
bw.WriteLE(tx.NeedStorage)
}
bw.WriteString(tx.Name)
bw.WriteString(tx.CodeVersion)
bw.WriteString(tx.Author)
bw.WriteString(tx.Email)
bw.WriteString(tx.Description)
return bw.Err
}
func (tx *PublishTX) Size() int {

View file

@ -144,4 +144,9 @@ func TestDecodePublishTX(t *testing.T) {
assert.Equal(t, expectedTX.Data, actualTX.Data)
assert.Equal(t, expectedTX.Type, actualTX.Type)
assert.Equal(t, expectedTX.Version, actualTX.Version)
buf := new(bytes.Buffer)
err := actualTX.EncodeBinary(buf)
assert.Nil(t, err)
assert.Equal(t, rawPublishTX, hex.EncodeToString(buf.Bytes()))
}