Skip to content

Commit 1cbee0d

Browse files
committed
bug fix
1 parent 5434bd0 commit 1cbee0d

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

common/serialize.go

+15
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ func (sn *SimpleNotation) WriteBytesSlice(p [][]byte, escape bool) {
7878
sn.WriteBytes(buf.Bytes(), false)
7979
}
8080

81+
// WriteStringSlice writes a string slice to buffer.
82+
func (sn *SimpleNotation) WriteStringSlice(p []string, escape bool) {
83+
var buf bytes.Buffer
84+
for _, s := range p {
85+
buf.WriteByte(sn.sliceSep)
86+
bs := []byte(s)
87+
if escape {
88+
bs = sn.escape(bs)
89+
}
90+
buf.Write(bs)
91+
}
92+
93+
sn.WriteBytes(buf.Bytes(), false)
94+
}
95+
8196
// WriteMapStringToI64 writes a map[string]int64 to buffer.
8297
func (sn *SimpleNotation) WriteMapStringToI64(m map[string]int64, escape bool) {
8398
key := make([]string, 0, len(m))

common/serialize_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ func TestWriteBytesSlice(t *testing.T) {
5454
assert.Equal(t, []byte{'`', '^', 'a', 'a', '^', 'b', 'b', '`', '^', '\\', '^', '\\', '`'}, sn.Bytes())
5555
}
5656

57+
func TestWriteStringSlice(t *testing.T) {
58+
sn := NewSimpleNotation()
59+
sn.WriteStringSlice([]string{"aa", "bb"}, true)
60+
assert.Equal(t, []byte{'`', '^', 'a', 'a', '^', 'b', 'b'}, sn.Bytes())
61+
62+
sn.WriteBytesSlice([][]byte{[]byte("^`")}, true)
63+
assert.Equal(t, []byte{'`', '^', 'a', 'a', '^', 'b', 'b', '`', '^', '\\', '^', '\\', '`'}, sn.Bytes())
64+
}
65+
5766
func TestWriteMapStringToI64(t *testing.T) {
5867
sn := NewSimpleNotation()
5968
sn.WriteMapStringToI64(map[string]int64{"bb": 1024, "aa": 7}, true)

core/tx/tx.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,15 @@ func (t *Tx) ToBytes(l ToBytesLevel) []byte {
246246
sn.WriteInt64(t.GasPrice, true)
247247
sn.WriteInt64(t.GasLimit, true)
248248
sn.WriteInt64(t.Delay, true)
249-
for _, signer := range t.Signers {
250-
sn.WriteString(signer, true)
249+
250+
sn.WriteStringSlice(t.Signers, true)
251+
actionBytes := make([][]byte, 0, len(t.Actions))
252+
for _, a := range t.Actions {
253+
actionBytes = append(actionBytes, a.ToBytes())
251254
}
255+
sn.WriteBytesSlice(actionBytes, false)
252256

253257
if l > Base {
254-
actionBytes := make([][]byte, 0, len(t.Actions))
255-
for _, a := range t.Actions {
256-
actionBytes = append(actionBytes, a.ToBytes())
257-
}
258-
sn.WriteBytesSlice(actionBytes, false)
259-
260258
signBytes := make([][]byte, 0, len(t.Signs))
261259
for _, sig := range t.Signs {
262260
signBytes = append(signBytes, sig.ToBytes())

0 commit comments

Comments
 (0)