-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
transfer.go
36 lines (28 loc) · 923 Bytes
/
transfer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package telegram
import (
"context"
"github.com/go-faster/errors"
"github.com/gotd/td/tg"
)
func (c *Client) exportAuth(ctx context.Context, dcID int) (*tg.AuthExportedAuthorization, error) {
export, err := c.tg.AuthExportAuthorization(ctx, dcID)
if err != nil {
return nil, errors.Wrapf(err, "export auth to %d", dcID)
}
return export, nil
}
// transfer exports current authorization and imports it to another DC.
// See https://core.telegram.org/api/datacenter#authorization-transfer.
func (c *Client) transfer(ctx context.Context, to *tg.Client, dc int) (tg.AuthAuthorizationClass, error) {
auth, err := c.exportAuth(ctx, dc)
if err != nil {
return nil, errors.Wrapf(err, "export to %d", dc)
}
req := &tg.AuthImportAuthorizationRequest{}
req.FillFrom(auth)
r, err := to.AuthImportAuthorization(ctx, req)
if err != nil {
return nil, errors.Wrapf(err, "import from %d", dc)
}
return r, nil
}