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 UserWallet struct {
Flags bin .Fields
Address string
Balance int64
PublicKey []byte
StateInit []byte
}
const UserWalletTypeID = 0x454d2737
var (
_ bin .Encoder = &UserWallet {}
_ bin .Decoder = &UserWallet {}
_ bin .BareEncoder = &UserWallet {}
_ bin .BareDecoder = &UserWallet {}
)
func (u *UserWallet ) Zero () bool {
if u == nil {
return true
}
if !(u .Flags .Zero ()) {
return false
}
if !(u .Address == "" ) {
return false
}
if !(u .Balance == 0 ) {
return false
}
if !(u .PublicKey == nil ) {
return false
}
if !(u .StateInit == nil ) {
return false
}
return true
}
func (u *UserWallet ) String () string {
if u == nil {
return "UserWallet(nil)"
}
type Alias UserWallet
return fmt .Sprintf ("UserWallet%+v" , Alias (*u ))
}
func (u *UserWallet ) FillFrom (from interface {
GetAddress () (value string )
GetBalance () (value int64 )
GetPublicKey () (value []byte , ok bool )
GetStateInit () (value []byte , ok bool )
}) {
u .Address = from .GetAddress ()
u .Balance = from .GetBalance ()
if val , ok := from .GetPublicKey (); ok {
u .PublicKey = val
}
if val , ok := from .GetStateInit (); ok {
u .StateInit = val
}
}
func (*UserWallet ) TypeID () uint32 {
return UserWalletTypeID
}
func (*UserWallet ) TypeName () string {
return "userWallet"
}
func (u *UserWallet ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "userWallet" ,
ID : UserWalletTypeID ,
}
if u == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Address" ,
SchemaName : "address" ,
},
{
Name : "Balance" ,
SchemaName : "balance" ,
},
{
Name : "PublicKey" ,
SchemaName : "public_key" ,
Null : !u .Flags .Has (0 ),
},
{
Name : "StateInit" ,
SchemaName : "state_init" ,
Null : !u .Flags .Has (0 ),
},
}
return typ
}
func (u *UserWallet ) SetFlags () {
if !(u .PublicKey == nil ) {
u .Flags .Set (0 )
}
if !(u .StateInit == nil ) {
u .Flags .Set (0 )
}
}
func (u *UserWallet ) Encode (b *bin .Buffer ) error {
if u == nil {
return fmt .Errorf ("can't encode userWallet#454d2737 as nil" )
}
b .PutID (UserWalletTypeID )
return u .EncodeBare (b )
}
func (u *UserWallet ) EncodeBare (b *bin .Buffer ) error {
if u == nil {
return fmt .Errorf ("can't encode userWallet#454d2737 as nil" )
}
u .SetFlags ()
if err := u .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode userWallet#454d2737: field flags: %w" , err )
}
b .PutString (u .Address )
b .PutLong (u .Balance )
if u .Flags .Has (0 ) {
b .PutBytes (u .PublicKey )
}
if u .Flags .Has (0 ) {
b .PutBytes (u .StateInit )
}
return nil
}
func (u *UserWallet ) Decode (b *bin .Buffer ) error {
if u == nil {
return fmt .Errorf ("can't decode userWallet#454d2737 to nil" )
}
if err := b .ConsumeID (UserWalletTypeID ); err != nil {
return fmt .Errorf ("unable to decode userWallet#454d2737: %w" , err )
}
return u .DecodeBare (b )
}
func (u *UserWallet ) DecodeBare (b *bin .Buffer ) error {
if u == nil {
return fmt .Errorf ("can't decode userWallet#454d2737 to nil" )
}
{
if err := u .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode userWallet#454d2737: field flags: %w" , err )
}
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode userWallet#454d2737: field address: %w" , err )
}
u .Address = value
}
{
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode userWallet#454d2737: field balance: %w" , err )
}
u .Balance = value
}
if u .Flags .Has (0 ) {
value , err := b .Bytes ()
if err != nil {
return fmt .Errorf ("unable to decode userWallet#454d2737: field public_key: %w" , err )
}
u .PublicKey = value
}
if u .Flags .Has (0 ) {
value , err := b .Bytes ()
if err != nil {
return fmt .Errorf ("unable to decode userWallet#454d2737: field state_init: %w" , err )
}
u .StateInit = value
}
return nil
}
func (u *UserWallet ) GetAddress () (value string ) {
if u == nil {
return
}
return u .Address
}
func (u *UserWallet ) GetBalance () (value int64 ) {
if u == nil {
return
}
return u .Balance
}
func (u *UserWallet ) SetPublicKey (value []byte ) {
u .Flags .Set (0 )
u .PublicKey = value
}
func (u *UserWallet ) GetPublicKey () (value []byte , ok bool ) {
if u == nil {
return
}
if !u .Flags .Has (0 ) {
return value , false
}
return u .PublicKey , true
}
func (u *UserWallet ) SetStateInit (value []byte ) {
u .Flags .Set (0 )
u .StateInit = value
}
func (u *UserWallet ) GetStateInit () (value []byte , ok bool ) {
if u == nil {
return
}
if !u .Flags .Has (0 ) {
return value , false
}
return u .StateInit , true
}
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 .