Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conditions to parse AddrVar #302

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tlb/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tlb
import (
"encoding/hex"
"fmt"
"math"
"strconv"
"strings"

Expand Down Expand Up @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions tlb/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading