wallet

package
v1.10.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2024 License: Apache-2.0 Imports: 21 Imported by: 51

Documentation

Index

Constants

View Source
const (
	CarryAllRemainingBalance       = 128
	CarryAllRemainingIncomingValue = 64
	DestroyAccountIfZero           = 32
	IgnoreErrors                   = 2
	PayGasSeparately               = 1
)
View Source
const DefaultSubwallet = 698983191
View Source
const EncryptedCommentOpcode = 0x2167da4b
View Source
const MainnetGlobalID = -239

Network IDs

View Source
const TestnetGlobalID = -3

Variables

View Source
var (
	ErrUnsupportedWalletVersion = errors.New("wallet version is not supported")
)

Functions

func AddressFromPubKey

func AddressFromPubKey(key ed25519.PublicKey, version VersionConfig, subwallet uint32) (*address.Address, error)

func CreateCommentCell added in v1.5.1

func CreateCommentCell(text string) (*cell.Cell, error)

func CreateEncryptedCommentCell added in v1.8.0

func CreateEncryptedCommentCell(text string, senderAddr *address.Address, ourKey ed25519.PrivateKey, theirKey ed25519.PublicKey) (*cell.Cell, error)

func DecryptCommentCell added in v1.8.0

func DecryptCommentCell(commentCell *cell.Cell, sender *address.Address, ourKey ed25519.PrivateKey, theirKey ed25519.PublicKey) ([]byte, error)

func GetPublicKey added in v1.8.0

func GetPublicKey(ctx context.Context, api TonAPI, addr *address.Address) (ed25519.PublicKey, error)

func GetStateInit

func GetStateInit(pubKey ed25519.PublicKey, version VersionConfig, subWallet uint32) (*tlb.StateInit, error)

func NewSeed

func NewSeed() []string

func NewSeedWithPassword

func NewSeedWithPassword(password string) []string

Types

type ConfigCustom added in v1.10.0

type ConfigCustom interface {
	GetStateInit(pubKey ed25519.PublicKey, subWallet uint32) (*tlb.StateInit, error)
	GetSpec(w *Wallet) MessageBuilder
}

type ConfigHighloadV3 added in v1.9.3

type ConfigHighloadV3 struct {
	// MessageTTL must be > 5 and less than 1<<22
	MessageTTL uint32

	// This function wil be used to get query id and creation time for the new message.
	// ID can be iterator from your database, max id is 1<<23, when it is higher, start from 0 and repeat
	// MessageBuilder should be defined if you want to send transactions
	MessageBuilder func(ctx context.Context, subWalletId uint32) (id uint32, createdAt int64, err error)
}

type ConfigV5R1Beta added in v1.9.9

type ConfigV5R1Beta struct {
	NetworkGlobalID int32
	Workchain       int8
}

func (ConfigV5R1Beta) String added in v1.9.9

func (c ConfigV5R1Beta) String() string

type ConfigV5R1Final added in v1.9.9

type ConfigV5R1Final struct {
	NetworkGlobalID int32
	Workchain       int8
}

func (ConfigV5R1Final) String added in v1.9.9

func (c ConfigV5R1Final) String() string

type Message added in v1.0.0

type Message struct {
	Mode            uint8
	InternalMessage *tlb.InternalMessage
}

func SimpleMessage added in v1.1.0

func SimpleMessage(to *address.Address, amount tlb.Coins, payload *cell.Cell) *Message

func SimpleMessageAutoBounce added in v1.9.3

func SimpleMessageAutoBounce(to *address.Address, amount tlb.Coins, payload *cell.Cell) *Message

SimpleMessageAutoBounce - will determine bounce flag from address

type MessageBuilder added in v1.10.0

type MessageBuilder interface {
	BuildMessage(ctx context.Context, messages []*Message) (*cell.Cell, error)
}

type RegularBuilder added in v1.0.0

type RegularBuilder interface {
	BuildMessage(ctx context.Context, isInitialized bool, _ *ton.BlockIDExt, messages []*Message) (*cell.Cell, error)
}

type SpecHighloadV2R2 added in v1.1.0

type SpecHighloadV2R2 struct {
	SpecRegular
	SpecQuery
}

func (*SpecHighloadV2R2) BuildMessage added in v1.1.0

func (s *SpecHighloadV2R2) BuildMessage(ctx context.Context, messages []*Message) (*cell.Cell, error)

type SpecHighloadV3 added in v1.9.3

type SpecHighloadV3 struct {
	// contains filtered or unexported fields
}

func (*SpecHighloadV3) BuildMessage added in v1.9.3

func (s *SpecHighloadV3) BuildMessage(ctx context.Context, messages []*Message) (_ *cell.Cell, err error)

type SpecQuery added in v1.8.0

type SpecQuery struct {
	// contains filtered or unexported fields
}

func (*SpecQuery) SetCustomQueryIDFetcher added in v1.8.0

func (s *SpecQuery) SetCustomQueryIDFetcher(fetcher func() (ttl uint32, randPart uint32))

func (*SpecQuery) SetCustomQueryIDFetcherWithContext added in v1.10.0

func (s *SpecQuery) SetCustomQueryIDFetcherWithContext(fetcher func(ctx context.Context, subWalletId uint32) (ttl uint32, randPart uint32, err error))

type SpecRegular added in v1.0.0

type SpecRegular struct {
	// contains filtered or unexported fields
}

func (*SpecRegular) SetMessagesTTL added in v1.0.0

func (s *SpecRegular) SetMessagesTTL(ttl uint32)

type SpecSeqno added in v1.8.0

type SpecSeqno struct {
	// contains filtered or unexported fields
}

func (*SpecSeqno) SetCustomSeqnoFetcher deprecated added in v1.8.0

func (s *SpecSeqno) SetCustomSeqnoFetcher(fetcher func() uint32)

Deprecated: Use SetSeqnoFetcher

func (*SpecSeqno) SetSeqnoFetcher added in v1.9.3

func (s *SpecSeqno) SetSeqnoFetcher(fetcher func(ctx context.Context, subWallet uint32) (uint32, error))

type SpecV3 added in v1.0.0

type SpecV3 struct {
	SpecRegular
	SpecSeqno
}

func (*SpecV3) BuildMessage added in v1.0.0

func (s *SpecV3) BuildMessage(ctx context.Context, _ bool, _ *ton.BlockIDExt, messages []*Message) (_ *cell.Cell, err error)

type SpecV4R2 added in v1.0.0

type SpecV4R2 struct {
	SpecRegular
	SpecSeqno
}

func (*SpecV4R2) BuildMessage added in v1.0.0

func (s *SpecV4R2) BuildMessage(ctx context.Context, _ bool, _ *ton.BlockIDExt, messages []*Message) (_ *cell.Cell, err error)

type SpecV5R1Beta added in v1.9.9

type SpecV5R1Beta struct {
	SpecRegular
	SpecSeqno
	// contains filtered or unexported fields
}

func (*SpecV5R1Beta) BuildMessage added in v1.9.9

func (s *SpecV5R1Beta) BuildMessage(ctx context.Context, _ bool, _ *ton.BlockIDExt, messages []*Message) (_ *cell.Cell, err error)

type SpecV5R1Final added in v1.9.9

type SpecV5R1Final struct {
	SpecRegular
	SpecSeqno
	// contains filtered or unexported fields
}

func (*SpecV5R1Final) BuildMessage added in v1.9.9

func (s *SpecV5R1Final) BuildMessage(ctx context.Context, _ bool, _ *ton.BlockIDExt, messages []*Message) (_ *cell.Cell, err error)

type TonAPI

type TonAPI interface {
	WaitForBlock(seqno uint32) ton.APIClientWrapped
	Client() ton.LiteClient
	CurrentMasterchainInfo(ctx context.Context) (*ton.BlockIDExt, error)
	GetAccount(ctx context.Context, block *ton.BlockIDExt, addr *address.Address) (*tlb.Account, error)
	SendExternalMessage(ctx context.Context, msg *tlb.ExternalMessage) error
	SendExternalMessageWaitTransaction(ctx context.Context, ext *tlb.ExternalMessage) (*tlb.Transaction, *ton.BlockIDExt, []byte, error)
	RunGetMethod(ctx context.Context, blockInfo *ton.BlockIDExt, addr *address.Address, method string, params ...interface{}) (*ton.ExecutionResult, error)
	ListTransactions(ctx context.Context, addr *address.Address, num uint32, lt uint64, txHash []byte) ([]*tlb.Transaction, error)
	FindLastTransactionByInMsgHash(ctx context.Context, addr *address.Address, msgHash []byte, maxTxNumToScan ...int) (*tlb.Transaction, error)
	FindLastTransactionByOutMsgHash(ctx context.Context, addr *address.Address, msgHash []byte, maxTxNumToScan ...int) (*tlb.Transaction, error)
}

type V5R1ID added in v1.9.9

type V5R1ID struct {
	NetworkGlobalID int32
	WorkChain       int8
	SubwalletNumber uint16
	WalletVersion   uint8
}

func (V5R1ID) Serialized added in v1.9.9

func (w V5R1ID) Serialized() uint32

type Version

type Version int
const (
	V1R1               Version = 11
	V1R2               Version = 12
	V1R3               Version = 13
	V2R1               Version = 21
	V2R2               Version = 22
	V3R1               Version = 31
	V3R2               Version = 32
	V3                         = V3R2
	V4R1               Version = 41
	V4R2               Version = 42
	V5R1Beta           Version = 51 // W5 Beta
	V5R1Final          Version = 52 // W5 Final
	HighloadV2R2       Version = 122
	HighloadV2Verified Version = 123
	HighloadV3         Version = 300
	Lockup             Version = 200
	Unknown            Version = 0
)

func GetWalletVersion added in v1.3.0

func GetWalletVersion(account *tlb.Account) Version

func (Version) String added in v1.4.0

func (v Version) String() string

type VersionConfig added in v1.9.3

type VersionConfig any

type Wallet

type Wallet struct {
	// contains filtered or unexported fields
}

func FromPrivateKey

func FromPrivateKey(api TonAPI, key ed25519.PrivateKey, version VersionConfig) (*Wallet, error)

func FromSeed

func FromSeed(api TonAPI, seed []string, version VersionConfig) (*Wallet, error)

func FromSeedWithPassword

func FromSeedWithPassword(api TonAPI, seed []string, password string, version VersionConfig) (*Wallet, error)

func (*Wallet) Address

func (w *Wallet) Address() *address.Address

Address - returns old (bounce) version of wallet address DEPRECATED: because of address reform, use WalletAddress, it will return UQ format

func (*Wallet) BuildExternalMessage added in v1.8.0

func (w *Wallet) BuildExternalMessage(ctx context.Context, message *Message) (*tlb.ExternalMessage, error)

func (*Wallet) BuildExternalMessageForMany added in v1.8.0

func (w *Wallet) BuildExternalMessageForMany(ctx context.Context, messages []*Message) (*tlb.ExternalMessage, error)

func (*Wallet) BuildMessageForMany deprecated added in v1.2.0

func (w *Wallet) BuildMessageForMany(ctx context.Context, messages []*Message) (*tlb.ExternalMessage, error)

Deprecated: use BuildExternalMessageForMany

func (*Wallet) BuildTransfer added in v1.8.0

func (w *Wallet) BuildTransfer(to *address.Address, amount tlb.Coins, bounce bool, comment string) (_ *Message, err error)

func (*Wallet) BuildTransferEncrypted added in v1.8.0

func (w *Wallet) BuildTransferEncrypted(ctx context.Context, to *address.Address, amount tlb.Coins, bounce bool, comment string) (_ *Message, err error)

func (*Wallet) DeployContract deprecated added in v0.7.0

func (w *Wallet) DeployContract(ctx context.Context, amount tlb.Coins, msgBody, contractCode, contractData *cell.Cell, waitConfirmation ...bool) (*address.Address, error)

Deprecated: use DeployContractWaitTransaction

func (*Wallet) DeployContractWaitTransaction added in v1.8.0

func (w *Wallet) DeployContractWaitTransaction(ctx context.Context, amount tlb.Coins, msgBody, contractCode, contractData *cell.Cell) (*address.Address, *tlb.Transaction, *ton.BlockIDExt, error)

func (*Wallet) GetBalance

func (w *Wallet) GetBalance(ctx context.Context, block *ton.BlockIDExt) (tlb.Coins, error)

func (*Wallet) GetSpec added in v1.0.0

func (w *Wallet) GetSpec() any

func (*Wallet) GetSubwallet added in v1.0.0

func (w *Wallet) GetSubwallet(subwallet uint32) (*Wallet, error)

func (*Wallet) GetSubwalletID added in v1.10.0

func (w *Wallet) GetSubwalletID() uint32

func (*Wallet) PrepareExternalMessageForMany added in v1.9.3

func (w *Wallet) PrepareExternalMessageForMany(ctx context.Context, withStateInit bool, messages []*Message) (_ *tlb.ExternalMessage, err error)

PrepareExternalMessageForMany - Prepares external message for wallet can be used directly for offline signing but custom fetchers should be defined in this case

func (*Wallet) PrivateKey added in v1.1.0

func (w *Wallet) PrivateKey() ed25519.PrivateKey

func (*Wallet) Send

func (w *Wallet) Send(ctx context.Context, message *Message, waitConfirmation ...bool) error

func (*Wallet) SendMany added in v1.0.0

func (w *Wallet) SendMany(ctx context.Context, messages []*Message, waitConfirmation ...bool) error

func (*Wallet) SendManyGetInMsgHash added in v1.2.0

func (w *Wallet) SendManyGetInMsgHash(ctx context.Context, messages []*Message, waitConfirmation ...bool) ([]byte, error)

SendManyGetInMsgHash returns hash of external incoming message payload.

func (*Wallet) SendManyWaitTransaction added in v1.7.0

func (w *Wallet) SendManyWaitTransaction(ctx context.Context, messages []*Message) (*tlb.Transaction, *ton.BlockIDExt, error)

SendManyWaitTransaction always waits for tx block confirmation and returns found tx.

func (*Wallet) SendManyWaitTxHash added in v1.2.0

func (w *Wallet) SendManyWaitTxHash(ctx context.Context, messages []*Message) ([]byte, error)

SendManyWaitTxHash always waits for tx block confirmation and returns found tx hash in block.

func (*Wallet) SendWaitTransaction added in v1.7.0

func (w *Wallet) SendWaitTransaction(ctx context.Context, message *Message) (*tlb.Transaction, *ton.BlockIDExt, error)

SendWaitTransaction always waits for tx block confirmation and returns found tx.

func (*Wallet) Transfer

func (w *Wallet) Transfer(ctx context.Context, to *address.Address, amount tlb.Coins, comment string, waitConfirmation ...bool) error

Transfer - safe transfer, in case of error on smart contract side, you will get coins back, cannot be used to transfer TON to not yet initialized contract/wallet

func (*Wallet) TransferNoBounce added in v1.0.0

func (w *Wallet) TransferNoBounce(ctx context.Context, to *address.Address, amount tlb.Coins, comment string, waitConfirmation ...bool) error

TransferNoBounce - can be used to transfer TON to not yet initialized contract/wallet

func (*Wallet) TransferWaitTransaction added in v1.10.0

func (w *Wallet) TransferWaitTransaction(ctx context.Context, to *address.Address, amount tlb.Coins, comment string) (*tlb.Transaction, *ton.BlockIDExt, error)

TransferWaitTransaction always waits for tx block confirmation and returns found tx.

func (*Wallet) TransferWithEncryptedComment added in v1.8.0

func (w *Wallet) TransferWithEncryptedComment(ctx context.Context, to *address.Address, amount tlb.Coins, comment string, waitConfirmation ...bool) error

TransferWithEncryptedComment - same as Transfer but encrypts comment, throws error if target contract (address) has no get_public_key method.

func (*Wallet) WalletAddress added in v1.8.4

func (w *Wallet) WalletAddress() *address.Address

WalletAddress - returns new standard non bounce address

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL