Skip to content

Commit

Permalink
Merge pull request #288 from tonkeeper/set_root_dns
Browse files Browse the repository at this point in the history
specifying root DNS in the SetDefaultExecutor
  • Loading branch information
mr-tron authored Aug 15, 2024
2 parents ed80923 + 7a4a126 commit 6f2d68c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion abi/generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ func TestWhalesNominators(t *testing.T) {
if len(members.List.Keys()) == 0 {
t.Fatal(len(members.List.Keys()))
}
memberAddress := ton.NewAccountID(0, members.List.Keys()[4])
memberAddress := ton.NewAccountID(0, members.List.Keys()[0])
_, v, err = GetMember(context.Background(), client, address, memberAddress.ToMsgAddress())
if err != nil {
t.Fatal(err)
Expand Down
24 changes: 22 additions & 2 deletions account.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,32 @@ func DefaultAddressParser() *addressParser {
return defaultParser
}

type ParserOptions struct {
RootDNS AccountID
Executor abi.Executor
}

type ParserOption func(options *ParserOptions)

func WithRootDNS(root AccountID) ParserOption {
return func(options *ParserOptions) {
options.RootDNS = root
}
}

// SetDefaultExecutor sets the default executor for the default address parser.
// The executor is used to resolve DNS records.
func SetDefaultExecutor(executor abi.Executor) {
func SetDefaultExecutor(executor abi.Executor, opts ...ParserOption) {
options := &ParserOptions{
RootDNS: MustParseAccountID(DefaultRoot),
Executor: executor,
}
for _, f := range opts {
f(options)
}
mu.Lock()
defer mu.Unlock()
resolver := dns.NewDNS(MustParseAccountID(DefaultRoot), executor)
resolver := dns.NewDNS(options.RootDNS, options.Executor)
defaultParser = NewAccountAddressParser(resolver)
}

Expand Down
4 changes: 2 additions & 2 deletions address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func TestParseAddress(t *testing.T) {
{
name: "Parse dns to raw address",
typeParse: parseDnsToRawAddress,
request: "subbotin.ton",
response: "0:2cf3b5b8c891e517c9addbda1c0386a09ccacbb0e3faf630b51cfc8152325acb",
request: "wallet-ton.ton",
response: "0:b9fa6045aee35c428b4f7fa9f0e6dfd2e51253a6e7c661b76d6803796ebf80c5",
},
{
name: "url-unsafe",
Expand Down

0 comments on commit 6f2d68c

Please sign in to comment.