package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
var (
_ = bin .Buffer {}
_ = context .Background ()
_ = fmt .Stringer (nil )
_ = strings .Builder {}
_ = errors .Is
_ = multierr .AppendInto
_ = sort .Ints
_ = tdp .Format
_ = tgerr .Error {}
_ = tdjson .Encoder {}
)
type WalletStateEmpty struct {
Flags bin .Fields
Creating bool
}
const WalletStateEmptyTypeID = 0x9cb9b2ec
func (w WalletStateEmpty ) construct () WalletStateClass { return &w }
var (
_ bin .Encoder = &WalletStateEmpty {}
_ bin .Decoder = &WalletStateEmpty {}
_ bin .BareEncoder = &WalletStateEmpty {}
_ bin .BareDecoder = &WalletStateEmpty {}
_ WalletStateClass = &WalletStateEmpty {}
)
func (w *WalletStateEmpty ) Zero () bool {
if w == nil {
return true
}
if !(w .Flags .Zero ()) {
return false
}
if !(w .Creating == false ) {
return false
}
return true
}
func (w *WalletStateEmpty ) String () string {
if w == nil {
return "WalletStateEmpty(nil)"
}
type Alias WalletStateEmpty
return fmt .Sprintf ("WalletStateEmpty%+v" , Alias (*w ))
}
func (w *WalletStateEmpty ) FillFrom (from interface {
GetCreating () (value bool )
}) {
w .Creating = from .GetCreating ()
}
func (*WalletStateEmpty ) TypeID () uint32 {
return WalletStateEmptyTypeID
}
func (*WalletStateEmpty ) TypeName () string {
return "walletStateEmpty"
}
func (w *WalletStateEmpty ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "walletStateEmpty" ,
ID : WalletStateEmptyTypeID ,
}
if w == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Creating" ,
SchemaName : "creating" ,
Null : !w .Flags .Has (0 ),
},
}
return typ
}
func (w *WalletStateEmpty ) SetFlags () {
if !(w .Creating == false ) {
w .Flags .Set (0 )
}
}
func (w *WalletStateEmpty ) Encode (b *bin .Buffer ) error {
if w == nil {
return fmt .Errorf ("can't encode walletStateEmpty#9cb9b2ec as nil" )
}
b .PutID (WalletStateEmptyTypeID )
return w .EncodeBare (b )
}
func (w *WalletStateEmpty ) EncodeBare (b *bin .Buffer ) error {
if w == nil {
return fmt .Errorf ("can't encode walletStateEmpty#9cb9b2ec as nil" )
}
w .SetFlags ()
if err := w .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode walletStateEmpty#9cb9b2ec: field flags: %w" , err )
}
return nil
}
func (w *WalletStateEmpty ) Decode (b *bin .Buffer ) error {
if w == nil {
return fmt .Errorf ("can't decode walletStateEmpty#9cb9b2ec to nil" )
}
if err := b .ConsumeID (WalletStateEmptyTypeID ); err != nil {
return fmt .Errorf ("unable to decode walletStateEmpty#9cb9b2ec: %w" , err )
}
return w .DecodeBare (b )
}
func (w *WalletStateEmpty ) DecodeBare (b *bin .Buffer ) error {
if w == nil {
return fmt .Errorf ("can't decode walletStateEmpty#9cb9b2ec to nil" )
}
{
if err := w .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode walletStateEmpty#9cb9b2ec: field flags: %w" , err )
}
}
w .Creating = w .Flags .Has (0 )
return nil
}
func (w *WalletStateEmpty ) SetCreating (value bool ) {
if value {
w .Flags .Set (0 )
w .Creating = true
} else {
w .Flags .Unset (0 )
w .Creating = false
}
}
func (w *WalletStateEmpty ) GetCreating () (value bool ) {
if w == nil {
return
}
return w .Flags .Has (0 )
}
type WalletState struct {
Flags bin .Fields
BackupEnabled bool
CanExportPhrase bool
CanEnableBackup bool
Address string
PublicKey []byte
Balance int64
}
const WalletStateTypeID = 0x95c5346b
func (w WalletState ) construct () WalletStateClass { return &w }
var (
_ bin .Encoder = &WalletState {}
_ bin .Decoder = &WalletState {}
_ bin .BareEncoder = &WalletState {}
_ bin .BareDecoder = &WalletState {}
_ WalletStateClass = &WalletState {}
)
func (w *WalletState ) Zero () bool {
if w == nil {
return true
}
if !(w .Flags .Zero ()) {
return false
}
if !(w .BackupEnabled == false ) {
return false
}
if !(w .CanExportPhrase == false ) {
return false
}
if !(w .CanEnableBackup == false ) {
return false
}
if !(w .Address == "" ) {
return false
}
if !(w .PublicKey == nil ) {
return false
}
if !(w .Balance == 0 ) {
return false
}
return true
}
func (w *WalletState ) String () string {
if w == nil {
return "WalletState(nil)"
}
type Alias WalletState
return fmt .Sprintf ("WalletState%+v" , Alias (*w ))
}
func (w *WalletState ) FillFrom (from interface {
GetBackupEnabled () (value bool )
GetCanExportPhrase () (value bool )
GetCanEnableBackup () (value bool )
GetAddress () (value string )
GetPublicKey () (value []byte )
GetBalance () (value int64 )
}) {
w .BackupEnabled = from .GetBackupEnabled ()
w .CanExportPhrase = from .GetCanExportPhrase ()
w .CanEnableBackup = from .GetCanEnableBackup ()
w .Address = from .GetAddress ()
w .PublicKey = from .GetPublicKey ()
w .Balance = from .GetBalance ()
}
func (*WalletState ) TypeID () uint32 {
return WalletStateTypeID
}
func (*WalletState ) TypeName () string {
return "walletState"
}
func (w *WalletState ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "walletState" ,
ID : WalletStateTypeID ,
}
if w == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "BackupEnabled" ,
SchemaName : "backup_enabled" ,
Null : !w .Flags .Has (0 ),
},
{
Name : "CanExportPhrase" ,
SchemaName : "can_export_phrase" ,
Null : !w .Flags .Has (1 ),
},
{
Name : "CanEnableBackup" ,
SchemaName : "can_enable_backup" ,
Null : !w .Flags .Has (2 ),
},
{
Name : "Address" ,
SchemaName : "address" ,
},
{
Name : "PublicKey" ,
SchemaName : "public_key" ,
},
{
Name : "Balance" ,
SchemaName : "balance" ,
},
}
return typ
}
func (w *WalletState ) SetFlags () {
if !(w .BackupEnabled == false ) {
w .Flags .Set (0 )
}
if !(w .CanExportPhrase == false ) {
w .Flags .Set (1 )
}
if !(w .CanEnableBackup == false ) {
w .Flags .Set (2 )
}
}
func (w *WalletState ) Encode (b *bin .Buffer ) error {
if w == nil {
return fmt .Errorf ("can't encode walletState#95c5346b as nil" )
}
b .PutID (WalletStateTypeID )
return w .EncodeBare (b )
}
func (w *WalletState ) EncodeBare (b *bin .Buffer ) error {
if w == nil {
return fmt .Errorf ("can't encode walletState#95c5346b as nil" )
}
w .SetFlags ()
if err := w .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode walletState#95c5346b: field flags: %w" , err )
}
b .PutString (w .Address )
b .PutBytes (w .PublicKey )
b .PutLong (w .Balance )
return nil
}
func (w *WalletState ) Decode (b *bin .Buffer ) error {
if w == nil {
return fmt .Errorf ("can't decode walletState#95c5346b to nil" )
}
if err := b .ConsumeID (WalletStateTypeID ); err != nil {
return fmt .Errorf ("unable to decode walletState#95c5346b: %w" , err )
}
return w .DecodeBare (b )
}
func (w *WalletState ) DecodeBare (b *bin .Buffer ) error {
if w == nil {
return fmt .Errorf ("can't decode walletState#95c5346b to nil" )
}
{
if err := w .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode walletState#95c5346b: field flags: %w" , err )
}
}
w .BackupEnabled = w .Flags .Has (0 )
w .CanExportPhrase = w .Flags .Has (1 )
w .CanEnableBackup = w .Flags .Has (2 )
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode walletState#95c5346b: field address: %w" , err )
}
w .Address = value
}
{
value , err := b .Bytes ()
if err != nil {
return fmt .Errorf ("unable to decode walletState#95c5346b: field public_key: %w" , err )
}
w .PublicKey = value
}
{
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode walletState#95c5346b: field balance: %w" , err )
}
w .Balance = value
}
return nil
}
func (w *WalletState ) SetBackupEnabled (value bool ) {
if value {
w .Flags .Set (0 )
w .BackupEnabled = true
} else {
w .Flags .Unset (0 )
w .BackupEnabled = false
}
}
func (w *WalletState ) GetBackupEnabled () (value bool ) {
if w == nil {
return
}
return w .Flags .Has (0 )
}
func (w *WalletState ) SetCanExportPhrase (value bool ) {
if value {
w .Flags .Set (1 )
w .CanExportPhrase = true
} else {
w .Flags .Unset (1 )
w .CanExportPhrase = false
}
}
func (w *WalletState ) GetCanExportPhrase () (value bool ) {
if w == nil {
return
}
return w .Flags .Has (1 )
}
func (w *WalletState ) SetCanEnableBackup (value bool ) {
if value {
w .Flags .Set (2 )
w .CanEnableBackup = true
} else {
w .Flags .Unset (2 )
w .CanEnableBackup = false
}
}
func (w *WalletState ) GetCanEnableBackup () (value bool ) {
if w == nil {
return
}
return w .Flags .Has (2 )
}
func (w *WalletState ) GetAddress () (value string ) {
if w == nil {
return
}
return w .Address
}
func (w *WalletState ) GetPublicKey () (value []byte ) {
if w == nil {
return
}
return w .PublicKey
}
func (w *WalletState ) GetBalance () (value int64 ) {
if w == nil {
return
}
return w .Balance
}
const WalletStateClassName = "WalletState"
type WalletStateClass interface {
bin .Encoder
bin .Decoder
bin .BareEncoder
bin .BareDecoder
construct () WalletStateClass
TypeID () uint32
TypeName () string
String () string
Zero () bool
AsNotEmpty () (*WalletState , bool )
}
func (w *WalletStateEmpty ) AsNotEmpty () (*WalletState , bool ) {
return nil , false
}
func (w *WalletState ) AsNotEmpty () (*WalletState , bool ) {
return w , true
}
func DecodeWalletState (buf *bin .Buffer ) (WalletStateClass , error ) {
id , err := buf .PeekID ()
if err != nil {
return nil , err
}
switch id {
case WalletStateEmptyTypeID :
v := WalletStateEmpty {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode WalletStateClass: %w" , err )
}
return &v , nil
case WalletStateTypeID :
v := WalletState {}
if err := v .Decode (buf ); err != nil {
return nil , fmt .Errorf ("unable to decode WalletStateClass: %w" , err )
}
return &v , nil
default :
return nil , fmt .Errorf ("unable to decode WalletStateClass: %w" , bin .NewUnexpectedID (id ))
}
}
type WalletStateBox struct {
WalletState WalletStateClass
}
func (b *WalletStateBox ) Decode (buf *bin .Buffer ) error {
if b == nil {
return fmt .Errorf ("unable to decode WalletStateBox to nil" )
}
v , err := DecodeWalletState (buf )
if err != nil {
return fmt .Errorf ("unable to decode boxed value: %w" , err )
}
b .WalletState = v
return nil
}
func (b *WalletStateBox ) Encode (buf *bin .Buffer ) error {
if b == nil || b .WalletState == nil {
return fmt .Errorf ("unable to encode WalletStateClass as nil" )
}
return b .WalletState .Encode (buf )
}
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .