wallet

package
v0.11.4 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: MIT Imports: 14 Imported by: 0

README

Tools to simplify the deployment and interaction with the wallet smart contract

This library supports:

  1. Address generation from public or private keys for V1-V4 wallets
  2. Message generation for deploying new wallets
  3. Message generation for TON transfer (long comment supported) and custom payload (for V1-V4 supports up to 4 payload messages)

Wallets smart contracts description:

Usage

Example

Documentation

Index

Constants

View Source
const (
	DefaultSubWalletIdV3V4 = 698983191
	DefaultMessageLifetime = time.Minute * 3
	DefaultMessageMode     = 3
)

Variables

View Source
var WORDLIST = []string{}/* 2048 elements not displayed */

Functions

func GenerateWalletAddress

func GenerateWalletAddress(
	key ed25519.PublicKey,
	ver Version,
	workchain int,
	subWalletId *int,
) (tongo.AccountID, error)

GenerateWalletAddress Generate wallet address from known workchain, public key and version. subWalletId is only used in V3 and V4 wallets. Use nil for default value. The version number is associated with a specific implementation of the wallet code (https://github.com/toncenter/tonweb/blob/master/src/contract/wallet/WalletSources.md)

func GetCodeByVer

func GetCodeByVer(ver Version) *boc.Cell

func GetCodeHashByVer

func GetCodeHashByVer(ver Version) tongo.Hash

func SeedToPrivateKey

func SeedToPrivateKey(seed string) (ed25519.PrivateKey, error)

Types

type DataV1V2

type DataV1V2 struct {
	Seqno     uint32
	PublicKey tongo.Hash
}

type DataV3

type DataV3 struct {
	Seqno       uint32
	SubWalletId uint32
	PublicKey   tongo.Hash
}

type DataV4

type DataV4 struct {
	Seqno       uint32
	SubWalletId uint32
	PublicKey   tongo.Hash
	PluginDict  tlb.HashmapE[tlb.Any] // TODO: find type and size
}

type Message

type Message struct {
	Amount     int64
	Address    tongo.AccountID
	Comment    *string
	Body       *boc.Cell
	Code       *boc.Cell
	Data       *boc.Cell
	Bounceable *bool
	Mode       *byte
}

type MessageV3

type MessageV3 struct {
	SubWalletId uint32
	ValidUntil  uint32
	Seqno       uint32
	Payload     PayloadV1toV4
}

type MessageV4

type MessageV4 struct {
	// Op: 0 - simple send, 1 - deploy and install plugin, 2 - install plugin, 3 - remove plugin
	SubWalletId uint32
	ValidUntil  uint32
	Seqno       uint32
	Op          int32 `tlb:"8bits"`
	Payload     PayloadV1toV4
}

type PayloadV1toV4

type PayloadV1toV4 []RawMessage

func (PayloadV1toV4) MarshalTLB

func (p PayloadV1toV4) MarshalTLB(c *boc.Cell, tag string) error

func (*PayloadV1toV4) UnmarshalTLB

func (p *PayloadV1toV4) UnmarshalTLB(c *boc.Cell, tag string) error

type RawMessage

type RawMessage struct {
	Message *boc.Cell
	Mode    byte
}

type SimpleMockBlockchain

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

SimpleMockBlockchain Very simple mock. It does not provide blockchain logic for calculating state and seqno for different addresses. Only for internal tests and demonstration purposes.

func NewMockBlockchain

func NewMockBlockchain(seqno uint32, state tongo.AccountInfo) (*SimpleMockBlockchain, chan []byte)

func (*SimpleMockBlockchain) GetAccountState

func (b *SimpleMockBlockchain) GetAccountState(ctx context.Context, accountId tongo.AccountID) (tongo.AccountInfo, error)

func (*SimpleMockBlockchain) GetSeqno

func (b *SimpleMockBlockchain) GetSeqno(ctx context.Context, account tongo.AccountID) (uint32, error)

func (*SimpleMockBlockchain) SendRawMessage

func (b *SimpleMockBlockchain) SendRawMessage(ctx context.Context, payload []byte) error

type TextComment

type TextComment string

func (TextComment) MarshalTLB

func (t TextComment) MarshalTLB(c *boc.Cell, tag string) error

func (*TextComment) UnmarshalTLB

func (t *TextComment) UnmarshalTLB(c *boc.Cell, tag string) error

type TonTransfer

type TonTransfer struct {
	Recipient tongo.AccountID
	Amount    tongo.Grams
	Comment   string
	Bounce    bool
	Mode      byte
}

type Version

type Version int
const (
	V1R1 Version = iota
	V1R2
	V1R3
	V2R1
	V2R2
	V3R1
	V3R2
	V4R1
	V4R2
	HighLoadV2
)

func GetVerByCodeHash

func GetVerByCodeHash(hash tongo.Hash) Version

func (Version) ToString

func (v Version) ToString() string

type Wallet

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

func DefaultWalletFromSeed

func DefaultWalletFromSeed(seed string, version Version, blockchain blockchain) (Wallet, error)

func NewWallet

func NewWallet(key ed25519.PrivateKey, ver Version, workchain int, subWalletId *int, blockchain blockchain) (Wallet, error)

NewWallet Fill new Wallet struct from known workchain, public key and version. subWalletId is only used in V3 and V4 wallets. Use nil for default value. The version number is associated with a specific implementation of the wallet code (https://github.com/toncenter/tonweb/blob/master/src/contract/wallet/WalletSources.md)

func (*Wallet) GetAddress

func (w *Wallet) GetAddress() tongo.AccountID

func (*Wallet) GetBalance

func (w *Wallet) GetBalance(ctx context.Context) (uint64, error)

GetBalance Gets actual TON balance for wallet

func (*Wallet) RawSend

func (w *Wallet) RawSend(
	ctx context.Context,
	seqno uint32,
	validUntil time.Time,
	internalMessages []RawMessage,
	init *tongo.StateInit,
) error

RawSend Generates a signed external message for wallet with custom internal messages, seqno, TTL and init The payload is serialized into bytes and sent by the method SendRawMessage

func (*Wallet) SendJetton

func (w *Wallet) SendJetton(ctx context.Context, messages []jetton.TransferMessage) error

SendJetton Sends Jettons to recipient address

func (*Wallet) SimpleSend

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

SimpleSend Generates a signed external message for wallet with custom internal messages and default TTL Gets actual seqno and attach init for wallet if it needed The payload is serialized into bytes and sent by the method SendRawMessage

Jump to

Keyboard shortcuts

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