From d0f981e49164df889e6cbc9c4cecbbf699874a7f Mon Sep 17 00:00:00 2001 From: Victoria Erokhina Date: Tue, 24 Sep 2024 19:08:33 +0000 Subject: [PATCH] Add conditions to parse AddrVar --- tlb/messages.go | 5 ++++- tlb/messages_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/tlb/messages.go b/tlb/messages.go index 28995444..d68f8fe9 100644 --- a/tlb/messages.go +++ b/tlb/messages.go @@ -3,6 +3,7 @@ package tlb import ( "encoding/hex" "fmt" + "math" "strconv" "strings" @@ -330,7 +331,9 @@ func (a *MsgAddress) UnmarshalJSON(b []byte) error { } } // try AddrStd first - if len(parts[1]) == 64 { + num, err := strconv.ParseInt(parts[0], 10, 32) + isWorkchainInt8 := err == nil && num >= int64(math.MinInt8) && num <= int64(math.MaxInt8) + if len(parts[1]) == 64 && isWorkchainInt8 && !strings.HasSuffix(parts[1], "_") { var dst [32]byte _, err := hex.Decode(dst[:], []byte(parts[1])) if err != nil { diff --git a/tlb/messages_test.go b/tlb/messages_test.go index 91514cc2..4eb1270f 100644 --- a/tlb/messages_test.go +++ b/tlb/messages_test.go @@ -194,6 +194,30 @@ func TestMsgAddress_UnmarshalJSON(t *testing.T) { }, }, }, + { + name: "AddrVar - all good", + addressStr: "-43464703:B36192BFD8DB3EABFCC47AE5EF2E7F4ED6AEFB1C2E8F0A3549A66FFC45051CD3:Anycast(30,927184944)", + wantAddr: &MsgAddress{ + SumType: "AddrVar", + AddrVar: &struct { + Anycast Maybe[Anycast] + AddrLen Uint9 + WorkchainId int32 + Address boc.BitString + }{ + Anycast: Maybe[Anycast]{ + Exists: true, + Value: Anycast{ + Depth: 30, + RewritePfx: 927184944, + }, + }, + AddrLen: 256, + WorkchainId: -43464703, + Address: mustFromFiftHex("B36192BFD8DB3EABFCC47AE5EF2E7F4ED6AEFB1C2E8F0A3549A66FFC45051CD3"), + }, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {