Skip to content

Commit 563f130

Browse files
committed
Expose prepareChecksumData as Bytes
It's useful to expose a raw representation, and most other chain SDKs provide a way to get a byte slice.
1 parent 89cc955 commit 563f130

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

address/addr.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ func ParseAddr(addr string) (*Address, error) {
230230
if err != nil {
231231
return nil, err
232232
}
233-
233+
return ParseBytes(data)
234+
}
235+
func ParseAddr(data []byte) (*Address, error) {
234236
if len(data) != 36 {
235237
return nil, errors.New("incorrect address data")
236238
}
@@ -267,10 +269,10 @@ func ParseRawAddr(addr string) (*Address, error) {
267269
}
268270

269271
func (a *Address) Checksum() uint16 {
270-
return crc16.Checksum(a.prepareChecksumData(), crc16.MakeTable(crc16.CRC16_XMODEM))
272+
return crc16.Checksum(a.Bytes(), crc16.MakeTable(crc16.CRC16_XMODEM))
271273
}
272274

273-
func (a *Address) prepareChecksumData() []byte {
275+
func (a *Address) Bytes() []byte {
274276
var data [34]byte
275277
data[0] = a.FlagsToByte()
276278
data[1] = byte(a.workchain)

address/addr_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ func TestAddress_Workchain(t *testing.T) {
334334
}
335335
}
336336

337-
func TestAddress_prepareChecksumData(t *testing.T) {
337+
func TestAddress_Bytes(t *testing.T) {
338338
type fields struct {
339339
flags flags
340340
workchain int32
@@ -357,8 +357,8 @@ func TestAddress_prepareChecksumData(t *testing.T) {
357357
workchain: tt.fields.workchain,
358358
data: tt.fields.data,
359359
}
360-
if got := a.prepareChecksumData(); !reflect.DeepEqual(got, tt.want) {
361-
t.Errorf("prepareChecksumData() = %v, want %v", got, tt.want)
360+
if got := a.Bytes(); !reflect.DeepEqual(got, tt.want) {
361+
t.Errorf("Bytes() = %v, want %v", got, tt.want)
362362
}
363363
})
364364
}

0 commit comments

Comments
 (0)