Skip to content

Commit

Permalink
Fixed TestTransactionLen and TestTxBodyLen random failures
Browse files Browse the repository at this point in the history
  • Loading branch information
david-julien committed Jul 13, 2017
1 parent f853ddc commit d942014
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions blockchain/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,23 @@ type Address struct {
// Marshal converts an Address to a byte slice.
func (a Address) Marshal() []byte {
buf := make([]byte, 0, AddrLen)
buf = append(buf, a.X.Bytes()...)
buf = append(buf, a.Y.Bytes()...)
xBytes := a.X.Bytes()
yBytes := a.Y.Bytes()

if len(xBytes) < CoordLen {
for i := len(xBytes); i < CoordLen; i++ {
xBytes = append(xBytes, 0)
}
}

if len(yBytes) < CoordLen {
for i := len(yBytes); i < CoordLen; i++ {
yBytes = append(yBytes, 0)
}
}

buf = append(buf, xBytes...)
buf = append(buf, yBytes...)
return buf
}

Expand Down Expand Up @@ -84,8 +99,23 @@ type Signature struct {
// Marshal converts a signature to a byte slice. Should be 64 bytes long.
func (s *Signature) Marshal() []byte {
buf := make([]byte, 0, SigLen)
buf = append(buf, s.R.Bytes()...)
buf = append(buf, s.S.Bytes()...)
rBytes := s.R.Bytes()
sBytes := s.S.Bytes()

if len(rBytes) < CoordLen {
for i := len(rBytes); i < CoordLen; i++ {
rBytes = append(rBytes, 0)
}
}

if len(sBytes) < CoordLen {
for i := len(sBytes); i < CoordLen; i++ {
rBytes = append(sBytes, 0)
}
}

buf = append(buf, rBytes...)
buf = append(buf, sBytes...)
return buf
}

Expand Down

0 comments on commit d942014

Please sign in to comment.