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 WalletCard struct {
Flags bin .Fields
Stickers []WalletCardSticker
BgNftItem WalletNftItem
Address string
Balance int64
}
const WalletCardTypeID = 0x8ed043b1
var (
_ bin .Encoder = &WalletCard {}
_ bin .Decoder = &WalletCard {}
_ bin .BareEncoder = &WalletCard {}
_ bin .BareDecoder = &WalletCard {}
)
func (c *WalletCard ) Zero () bool {
if c == nil {
return true
}
if !(c .Flags .Zero ()) {
return false
}
if !(c .Stickers == nil ) {
return false
}
if !(c .BgNftItem .Zero ()) {
return false
}
if !(c .Address == "" ) {
return false
}
if !(c .Balance == 0 ) {
return false
}
return true
}
func (c *WalletCard ) String () string {
if c == nil {
return "WalletCard(nil)"
}
type Alias WalletCard
return fmt .Sprintf ("WalletCard%+v" , Alias (*c ))
}
func (c *WalletCard ) FillFrom (from interface {
GetStickers () (value []WalletCardSticker , ok bool )
GetBgNftItem () (value WalletNftItem , ok bool )
GetAddress () (value string )
GetBalance () (value int64 )
}) {
if val , ok := from .GetStickers (); ok {
c .Stickers = val
}
if val , ok := from .GetBgNftItem (); ok {
c .BgNftItem = val
}
c .Address = from .GetAddress ()
c .Balance = from .GetBalance ()
}
func (*WalletCard ) TypeID () uint32 {
return WalletCardTypeID
}
func (*WalletCard ) TypeName () string {
return "wallet.card"
}
func (c *WalletCard ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "wallet.card" ,
ID : WalletCardTypeID ,
}
if c == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Stickers" ,
SchemaName : "stickers" ,
Null : !c .Flags .Has (0 ),
},
{
Name : "BgNftItem" ,
SchemaName : "bg_nft_item" ,
Null : !c .Flags .Has (1 ),
},
{
Name : "Address" ,
SchemaName : "address" ,
},
{
Name : "Balance" ,
SchemaName : "balance" ,
},
}
return typ
}
func (c *WalletCard ) SetFlags () {
if !(c .Stickers == nil ) {
c .Flags .Set (0 )
}
if !(c .BgNftItem .Zero ()) {
c .Flags .Set (1 )
}
}
func (c *WalletCard ) Encode (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't encode wallet.card#8ed043b1 as nil" )
}
b .PutID (WalletCardTypeID )
return c .EncodeBare (b )
}
func (c *WalletCard ) EncodeBare (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't encode wallet.card#8ed043b1 as nil" )
}
c .SetFlags ()
if err := c .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode wallet.card#8ed043b1: field flags: %w" , err )
}
if c .Flags .Has (0 ) {
b .PutVectorHeader (len (c .Stickers ))
for idx , v := range c .Stickers {
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode wallet.card#8ed043b1: field stickers element with index %d: %w" , idx , err )
}
}
}
if c .Flags .Has (1 ) {
if err := c .BgNftItem .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode wallet.card#8ed043b1: field bg_nft_item: %w" , err )
}
}
b .PutString (c .Address )
b .PutLong (c .Balance )
return nil
}
func (c *WalletCard ) Decode (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't decode wallet.card#8ed043b1 to nil" )
}
if err := b .ConsumeID (WalletCardTypeID ); err != nil {
return fmt .Errorf ("unable to decode wallet.card#8ed043b1: %w" , err )
}
return c .DecodeBare (b )
}
func (c *WalletCard ) DecodeBare (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't decode wallet.card#8ed043b1 to nil" )
}
{
if err := c .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode wallet.card#8ed043b1: field flags: %w" , err )
}
}
if c .Flags .Has (0 ) {
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode wallet.card#8ed043b1: field stickers: %w" , err )
}
if headerLen > 0 {
c .Stickers = make ([]WalletCardSticker , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
var value WalletCardSticker
if err := value .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode wallet.card#8ed043b1: field stickers: %w" , err )
}
c .Stickers = append (c .Stickers , value )
}
}
if c .Flags .Has (1 ) {
if err := c .BgNftItem .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode wallet.card#8ed043b1: field bg_nft_item: %w" , err )
}
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode wallet.card#8ed043b1: field address: %w" , err )
}
c .Address = value
}
{
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode wallet.card#8ed043b1: field balance: %w" , err )
}
c .Balance = value
}
return nil
}
func (c *WalletCard ) SetStickers (value []WalletCardSticker ) {
c .Flags .Set (0 )
c .Stickers = value
}
func (c *WalletCard ) GetStickers () (value []WalletCardSticker , ok bool ) {
if c == nil {
return
}
if !c .Flags .Has (0 ) {
return value , false
}
return c .Stickers , true
}
func (c *WalletCard ) SetBgNftItem (value WalletNftItem ) {
c .Flags .Set (1 )
c .BgNftItem = value
}
func (c *WalletCard ) GetBgNftItem () (value WalletNftItem , ok bool ) {
if c == nil {
return
}
if !c .Flags .Has (1 ) {
return value , false
}
return c .BgNftItem , true
}
func (c *WalletCard ) GetAddress () (value string ) {
if c == nil {
return
}
return c .Address
}
func (c *WalletCard ) GetBalance () (value int64 ) {
if c == nil {
return
}
return c .Balance
}
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 .