Skip to content

Commit 5abade9

Browse files
authored
Merge pull request #298 from xssnick/dev-v1-11
v1.11
2 parents 0b9e7e9 + 42d3b96 commit 5abade9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+3420
-6182
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[![Based on TON][ton-svg]][ton]
66
[![Telegram Channel][tgc-svg]][tg-channel]
7-
![Coverage](https://img.shields.io/badge/Coverage-73.6%25-brightgreen)
7+
![Coverage](https://img.shields.io/badge/Coverage-72.6%25-brightgreen)
88

99
Golang library for interacting with TON blockchain.
1010

address/addr.go

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ func (a *Address) BitsLen() uint {
8787

8888
var crcTable = crc16.MakeTable(crc16.CRC16_XMODEM)
8989

90+
func (a *Address) StringRaw() string {
91+
switch a.addrType {
92+
case NoneAddress:
93+
return "NONE"
94+
case StdAddress:
95+
return strconv.Itoa(int(a.workchain)) + ":" + hex.EncodeToString(a.data)
96+
default:
97+
return "NOT_SUPPORTED"
98+
}
99+
}
100+
90101
func (a *Address) String() string {
91102
switch a.addrType {
92103
case NoneAddress:
@@ -118,28 +129,6 @@ func (a *Address) String() string {
118129
}
119130
}
120131

121-
func (a *Address) StringToBytes(dst []byte, addr []byte) {
122-
switch a.addrType {
123-
case NoneAddress:
124-
copy(dst, []byte("NONE"))
125-
return
126-
case StdAddress:
127-
copy(addr[0:34], a.prepareChecksumData())
128-
binary.BigEndian.PutUint16(addr[34:], crc16.Checksum(addr[:34], crcTable))
129-
base64.RawURLEncoding.Encode(dst, addr[:])
130-
return
131-
case ExtAddress:
132-
copy(dst, []byte("EXT_ADDRESS"))
133-
return
134-
case VarAddress:
135-
copy(dst, []byte("VAR_ADDRESS"))
136-
return
137-
default:
138-
copy(dst, []byte("NOT_SUPPORTED"))
139-
return
140-
}
141-
}
142-
143132
func (a *Address) MarshalJSON() ([]byte, error) {
144133
return []byte(fmt.Sprintf("%q", a.String())), nil
145134
}

address/addr_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,3 +708,26 @@ func TestAddress_UnmarshalJSON(t *testing.T) {
708708
})
709709
}
710710
}
711+
712+
func TestAddress_ToRaw(t *testing.T) {
713+
a := MustParseAddr("EQC6KV4zs8TJtSZapOrRFmqSkxzpq-oSCoxekQRKElf4nC1I")
714+
if v := a.StringRaw(); v != "0:ba295e33b3c4c9b5265aa4ead1166a92931ce9abea120a8c5e91044a1257f89c" {
715+
t.Fatal("address incorrect:", v)
716+
}
717+
}
718+
719+
func TestAddress_Flags(t *testing.T) {
720+
a := MustParseAddr("EQC6KV4zs8TJtSZapOrRFmqSkxzpq-oSCoxekQRKElf4nC1I").Testnet(true).Bounce(false)
721+
if v := a.String(); v != "0QC6KV4zs8TJtSZapOrRFmqSkxzpq-oSCoxekQRKElf4nMsH" {
722+
t.Fatal("address incorrect:", v)
723+
}
724+
}
725+
726+
func TestAddress_Eq(t *testing.T) {
727+
a := MustParseAddr("EQC6KV4zs8TJtSZapOrRFmqSkxzpq-oSCoxekQRKElf4nC1I")
728+
b := MustParseAddr("EQC6KV4zs8TJtSZapOrRFmqSkxzpq-oSCoxekQRKElf4nC1I").Bounce(false)
729+
730+
if !a.Equals(b) {
731+
t.Fatal("not eq")
732+
}
733+
}

0 commit comments

Comments
 (0)