Skip to content

Commit

Permalink
Identify the Mode parameter in the on chain request using a constant,…
Browse files Browse the repository at this point in the history
… making it easier for developers to read and understand.
  • Loading branch information
啦啦啦 committed Jun 6, 2024
1 parent 97fe541 commit 1ca4b5d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion example/highload-wallet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion example/send-to-contract/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion ton/wallet/highloadv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 14 additions & 6 deletions ton/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion ton/wallet/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func TestWallet_Send(t *testing.T) {
}

msg := &Message{
Mode: 128,
Mode: CarryAllRemainingBalance,
InternalMessage: intMsg,
}

Expand Down

0 comments on commit 1ca4b5d

Please sign in to comment.