Skip to content

Commit

Permalink
SetCustomQueryIDFetcherWithContext
Browse files Browse the repository at this point in the history
Signed-off-by: s.klimov <[email protected]>
  • Loading branch information
klimov-ankr committed Jul 26, 2024
1 parent 2ec0b5d commit e3e497c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ton/wallet/highloadv2r2.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type SpecHighloadV2R2 struct {
SpecQuery
}

func (s *SpecHighloadV2R2) BuildMessage(_ context.Context, messages []*Message) (*cell.Cell, error) {
func (s *SpecHighloadV2R2) BuildMessage(ctx context.Context, messages []*Message) (*cell.Cell, error) {
if len(messages) > 254 {
return nil, errors.New("for this type of wallet max 254 messages can be sent in the same time")
}
Expand All @@ -47,7 +47,7 @@ func (s *SpecHighloadV2R2) BuildMessage(_ context.Context, messages []*Message)

var ttl, queryID uint32
if s.customQueryIDFetcher != nil {
ttl, queryID = s.customQueryIDFetcher()
ttl, queryID = s.customQueryIDFetcher(ctx)
} else {
queryID = randUint32()
ttl = uint32(timeNow().Add(time.Duration(s.messagesTTL) * time.Second).UTC().Unix())
Expand Down
8 changes: 7 additions & 1 deletion ton/wallet/regular.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,15 @@ type SpecQuery struct {
// Do not set ttl to high if you are sending many messages,
// unexpired executed messages will be cached in contract,
// and it may become too expensive to make transactions.
customQueryIDFetcher func() (ttl uint32, randPart uint32)
customQueryIDFetcher func(context.Context) (ttl uint32, randPart uint32)
}

func (s *SpecQuery) SetCustomQueryIDFetcher(fetcher func() (ttl uint32, randPart uint32)) {
s.SetCustomQueryIDFetcherWithContext(func(ctx context.Context) (ttl uint32, randPart uint32) {
return fetcher()
})
}

func (s *SpecQuery) SetCustomQueryIDFetcherWithContext(fetcher func(ctx context.Context) (ttl uint32, randPart uint32)) {
s.customQueryIDFetcher = fetcher
}

0 comments on commit e3e497c

Please sign in to comment.