From 1ca4b5ddfcff0d1bdbcd2b85b90047cf2d0688e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=95=A6=E5=95=A6=E5=95=A6?= Date: Thu, 6 Jun 2024 21:08:07 +0800 Subject: [PATCH] Identify the Mode parameter in the on chain request using a constant, making it easier for developers to read and understand. --- example/highload-wallet/main.go | 2 +- example/send-to-contract/main.go | 2 +- ton/wallet/highloadv3.go | 2 +- ton/wallet/wallet.go | 20 ++++++++++++++------ ton/wallet/wallet_test.go | 2 +- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/example/highload-wallet/main.go b/example/highload-wallet/main.go index 3bb8f32e..883a9b82 100644 --- a/example/highload-wallet/main.go +++ b/example/highload-wallet/main.go @@ -84,7 +84,7 @@ func main() { for addrStr, amtStr := range receivers { addr := address.MustParseAddr(addrStr) messages = append(messages, &wallet.Message{ - Mode: 1 + 2, // pay fee separately, ignore action errors + Mode: wallet.PayGasSeparately + wallet.IgnoreErrors, // pay fee separately, ignore action errors InternalMessage: &tlb.InternalMessage{ IHRDisabled: true, // disable hyper routing (currently not works in ton) Bounce: addr.IsBounceable(), diff --git a/example/send-to-contract/main.go b/example/send-to-contract/main.go index 41163a44..5ea514ac 100644 --- a/example/send-to-contract/main.go +++ b/example/send-to-contract/main.go @@ -82,7 +82,7 @@ func main() { log.Println("sending transaction and waiting for confirmation...") tx, block, err := w.SendWaitTransaction(context.Background(), &wallet.Message{ - Mode: 1, // pay fees separately (from balance, not from amount) + Mode: wallet.PayGasSeparately, // pay fees separately (from balance, not from amount) InternalMessage: &tlb.InternalMessage{ Bounce: true, // return amount in case of processing error DstAddr: address.MustParseAddr("EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N"), diff --git a/ton/wallet/highloadv3.go b/ton/wallet/highloadv3.go index 592d5a36..722c3f15 100644 --- a/ton/wallet/highloadv3.go +++ b/ton/wallet/highloadv3.go @@ -122,7 +122,7 @@ func (s *SpecHighloadV3) packActions(queryId uint64, messages []*Message) (*Mess } return &Message{ - Mode: 1 + 2, + Mode: PayGasSeparately + IgnoreErrors, InternalMessage: &tlb.InternalMessage{ IHRDisabled: true, Bounce: false, diff --git a/ton/wallet/wallet.go b/ton/wallet/wallet.go index 62a6f384..cd92f0f6 100644 --- a/ton/wallet/wallet.go +++ b/ton/wallet/wallet.go @@ -43,6 +43,14 @@ const ( Unknown Version = 0 ) +const ( + CarryAllRemainingBalance = 128 + CarryAllRemainingIncomingValue = 64 + DestroyAccountIfZero = 32 + IgnoreErrors = 2 + PayGasSeparately = 1 +) + func (v Version) String() string { if v == Unknown { return "unknown" @@ -343,7 +351,7 @@ func (w *Wallet) BuildTransfer(to *address.Address, amount tlb.Coins, bounce boo } return &Message{ - Mode: 1 + 2, + Mode: PayGasSeparately + IgnoreErrors, InternalMessage: &tlb.InternalMessage{ IHRDisabled: true, Bounce: bounce, @@ -369,7 +377,7 @@ func (w *Wallet) BuildTransferEncrypted(ctx context.Context, to *address.Address } return &Message{ - Mode: 1 + 2, + Mode: PayGasSeparately + IgnoreErrors, InternalMessage: &tlb.InternalMessage{ IHRDisabled: true, Bounce: bounce, @@ -710,7 +718,7 @@ func (w *Wallet) DeployContractWaitTransaction(ctx context.Context, amount tlb.C addr := address.NewAddress(0, 0, stateCell.Hash()) tx, block, err := w.SendWaitTransaction(ctx, &Message{ - Mode: 1 + 2, + Mode: PayGasSeparately + IgnoreErrors, InternalMessage: &tlb.InternalMessage{ IHRDisabled: true, Bounce: false, @@ -741,7 +749,7 @@ func (w *Wallet) DeployContract(ctx context.Context, amount tlb.Coins, msgBody, addr := address.NewAddress(0, 0, stateCell.Hash()) if err = w.Send(ctx, &Message{ - Mode: 1 + 2, + Mode: PayGasSeparately + IgnoreErrors, InternalMessage: &tlb.InternalMessage{ IHRDisabled: true, Bounce: false, @@ -769,7 +777,7 @@ func (w *Wallet) FindTransactionByInMsgHash(ctx context.Context, msgHash []byte, func SimpleMessage(to *address.Address, amount tlb.Coins, payload *cell.Cell) *Message { return &Message{ - Mode: 1 + 2, + Mode: PayGasSeparately + IgnoreErrors, InternalMessage: &tlb.InternalMessage{ IHRDisabled: true, Bounce: true, @@ -783,7 +791,7 @@ func SimpleMessage(to *address.Address, amount tlb.Coins, payload *cell.Cell) *M // SimpleMessageAutoBounce - will determine bounce flag from address func SimpleMessageAutoBounce(to *address.Address, amount tlb.Coins, payload *cell.Cell) *Message { return &Message{ - Mode: 1 + 2, + Mode: PayGasSeparately + IgnoreErrors, InternalMessage: &tlb.InternalMessage{ IHRDisabled: true, Bounce: to.IsBounceable(), diff --git a/ton/wallet/wallet_test.go b/ton/wallet/wallet_test.go index 0d8fae55..47aca381 100644 --- a/ton/wallet/wallet_test.go +++ b/ton/wallet/wallet_test.go @@ -258,7 +258,7 @@ func TestWallet_Send(t *testing.T) { } msg := &Message{ - Mode: 128, + Mode: CarryAllRemainingBalance, InternalMessage: intMsg, }