Skip to content

Commit

Permalink
Merge pull request #200 from af913337456/master
Browse files Browse the repository at this point in the history
Identify the Mode parameter in the on chain request using a constant, making it easier for developers to read and understand.
  • Loading branch information
xssnick authored Jun 10, 2024
2 parents 9b2eadd + 1ca4b5d commit 5a8cdc8
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 @@ -124,7 +124,7 @@ func (s *SpecHighloadV3) packActions(queryId uint64, messages []*Message) (_ *Me
}

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 @@ -44,6 +44,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 @@ -367,7 +375,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 @@ -393,7 +401,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 @@ -734,7 +742,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 @@ -765,7 +773,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 @@ -793,7 +801,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 @@ -807,7 +815,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 5a8cdc8

Please sign in to comment.