Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions abi/generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2439,6 +2439,40 @@ func TestMessageDecoder(t *testing.T) {
},
},
},
{
name: "new_bounce_flag_1",
boc: "b5ee9c720101030100a3000213fffffffe00ffffffff40010200ff000000007364676c6b647368676a736168676b6a61736468676a6b647368676b6a7368616a6b676864736b6a6768736b6a6468676b6a736468676a6b647368676b6a736864676a68736468736a6b68676b6a736468677368646b6a67686473676a6b6873646b6a676873646b6a68676b6a736867646a6b7364686b6a676873650021405f5e10000001225ea9938c134733ab6c",
wantOpName: BounceV2MsgOp,
wantValue: BounceV2MsgBody{
OriginalBody: tlb.Any(mustHexToCell("b5ee9c720101010100820000ff000000007364676c6b647368676a736168676b6a61736468676a6b647368676b6a7368616a6b676864736b6a6768736b6a6468676b6a736468676a6b647368676b6a736864676a68736468736a6b68676b6a736468677368646b6a67686473676a6b6873646b6a676873646b6a68676b6a736867646a6b7364686b6a67687365")),
OriginalInfo: NewBounceOriginalInfo{
Value: tlb.CurrencyCollection{
Grams: tlb.Grams(100000000),
},
CreatedLt: 39908118000002,
CreatedAt: 1759933805,
},
BouncedByPhase: 0,
ExitCode: -1,
},
},
{
name: "new_bounce_flag_3",
boc: "b5ee9c72010103010054000213fffffffe00ffffffff40010200620000000068692120686f70652069742077696c6c20626520656e6f75676820666f7220627579696e6720612079616368740021405f5e10000001225d27569813473370b4",
wantOpName: BounceV2MsgOp,
wantValue: BounceV2MsgBody{
OriginalBody: tlb.Any(mustHexToCell("b5ee9c720101010100330000620000000068692120686f70652069742077696c6c20626520656e6f75676820666f7220627579696e672061207961636874")),
OriginalInfo: NewBounceOriginalInfo{
Value: tlb.CurrencyCollection{
Grams: tlb.Grams(100000000),
},
CreatedLt: 39907308000002,
CreatedAt: 1759931926,
},
BouncedByPhase: 0,
ExitCode: -1,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions abi/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ The list below contains the supported message operations, their names and opcode
| BidaskSwapV2| 0x87d36990 |
| BidaskSwapV2| 0x87d36990 |
| Bounce| 0xffffffff |
| BounceV2| 0xfffffffe |
| ChallengeQuarantinedChannelState| 0x088eaa32 |
| ChangeDnsRecord| 0x4eb1f0f9 |
| ChannelClosed| 0xdddc88ba |
Expand Down
16 changes: 16 additions & 0 deletions abi/messages_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ var (
decodeFuncElectorRecoverStakeResponseMsgBody = decodeMsg(tlb.Tag{Val: 0xf96f7324, Len: 32}, ElectorRecoverStakeResponseMsgOp, ElectorRecoverStakeResponseMsgBody{})
// 0xfb88e119
decodeFuncJettonClaimAdminMsgBody = decodeMsg(tlb.Tag{Val: 0xfb88e119, Len: 32}, JettonClaimAdminMsgOp, JettonClaimAdminMsgBody{})
// 0xfffffffe
decodeFuncBounceV2MsgBody = decodeMsg(tlb.Tag{Val: 0xfffffffe, Len: 32}, BounceV2MsgOp, BounceV2MsgBody{})
// 0xffffffff
decodeFuncBounceMsgBody = decodeMsg(tlb.Tag{Val: 0xffffffff, Len: 32}, BounceMsgOp, BounceMsgBody{})
)
Expand Down Expand Up @@ -1383,6 +1385,9 @@ var opcodedMsgInDecodeFunctions = map[uint32]msgDecoderFunc{
// 0xfb88e119
JettonClaimAdminMsgOpCode: decodeFuncJettonClaimAdminMsgBody,

// 0xfffffffe
BounceV2MsgOpCode: decodeFuncBounceV2MsgBody,

// 0xffffffff
BounceMsgOpCode: decodeFuncBounceMsgBody,
}
Expand Down Expand Up @@ -1661,6 +1666,7 @@ const (
CoffeeStakingDepositMsgOp MsgOpName = "CoffeeStakingDeposit"
ElectorRecoverStakeResponseMsgOp MsgOpName = "ElectorRecoverStakeResponse"
JettonClaimAdminMsgOp MsgOpName = "JettonClaimAdmin"
BounceV2MsgOp MsgOpName = "BounceV2"
BounceMsgOp MsgOpName = "Bounce"
)

Expand Down Expand Up @@ -1938,6 +1944,7 @@ const (
CoffeeStakingDepositMsgOpCode MsgOpCode = 0xf9471134
ElectorRecoverStakeResponseMsgOpCode MsgOpCode = 0xf96f7324
JettonClaimAdminMsgOpCode MsgOpCode = 0xfb88e119
BounceV2MsgOpCode MsgOpCode = 0xfffffffe
BounceMsgOpCode MsgOpCode = 0xffffffff
)

Expand Down Expand Up @@ -3793,6 +3800,14 @@ type JettonClaimAdminMsgBody struct {
QueryId uint64
}

type BounceV2MsgBody struct {
OriginalBody tlb.Any `tlb:"^"`
OriginalInfo NewBounceOriginalInfo `tlb:"^"`
BouncedByPhase uint8
ExitCode int32
ComputePhase *NewBounceComputePhaseInfo `tlb:"maybe"`
}

type BounceMsgBody struct {
Payload tlb.Any
}
Expand Down Expand Up @@ -4071,6 +4086,7 @@ var KnownMsgInTypes = map[string]any{
CoffeeStakingDepositMsgOp: CoffeeStakingDepositMsgBody{},
ElectorRecoverStakeResponseMsgOp: ElectorRecoverStakeResponseMsgBody{},
JettonClaimAdminMsgOp: JettonClaimAdminMsgBody{},
BounceV2MsgOp: BounceV2MsgBody{},
BounceMsgOp: BounceMsgBody{},
}

Expand Down
8 changes: 8 additions & 0 deletions abi/schemas/known.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
<abi>
<types>
_ value:CurrencyCollection created_lt:uint64 created_at:uint32 = NewBounceOriginalInfo;
_ gas_used:uint32 vm_steps:uint32 = NewBounceComputePhaseInfo;
</types>

<!-- Internal messages -->
<internal name="bounce">
bounce_message#ffffffff payload:Cell = InternalMsgBody;
</internal>

<internal name="bounce_v2">
new_bounce_body#fffffffe original_body:^Cell original_info:^NewBounceOriginalInfo bounced_by_phase:uint8 exit_code:int32 compute_phase:(Maybe NewBounceComputePhaseInfo) = InternalMsgBody;
</internal>

<!-- Text -->
<internal name="text_comment">
text_comment#00000000 text:Text = InternalMsgBody;
Expand Down
11 changes: 11 additions & 0 deletions abi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ func (t *JettonForceAction) MarshalJSON() ([]byte, error) {
}
}

type NewBounceComputePhaseInfo struct {
GasUsed uint32
VmSteps uint32
}

type NewBounceOriginalInfo struct {
Value tlb.CurrencyCollection
CreatedLt uint64
CreatedAt uint32
}

type TonstakersControllerData struct {
ControllerId uint32
Validator tlb.MsgAddress
Expand Down
84 changes: 72 additions & 12 deletions tlb/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package tlb

import (
"encoding/hex"
"encoding/json"
"fmt"
"math"
"math/big"
"strconv"
"strings"

Expand Down Expand Up @@ -97,18 +99,28 @@ func (m Message) MarshalTLB(c *boc.Cell, encoder *Encoder) error {
// created_lt:uint64 created_at:uint32 = CommonMsgInfo;
type CommonMsgInfo struct {
SumType
IntMsgInfo *struct {
IhrDisabled bool
Bounce bool
Bounced bool
Src MsgAddress
Dest MsgAddress
Value CurrencyCollection
IhrFee Grams
FwdFee Grams
CreatedLt uint64
CreatedAt uint32
} `tlbSumType:"int_msg_info$0"`
IntMsgInfoIhr *struct {
Bounce bool
Bounced bool
Src MsgAddress
Dest MsgAddress
Value CurrencyCollection
IhrFee Grams
FwdFee Grams
CreatedLt uint64
CreatedAt uint32
} `tlbSumType:"int_msg_info_ihr$00"`
IntMsgInfoNoIhr *struct {
Bounce bool
Bounced bool
Src MsgAddress
Dest MsgAddress
Value CurrencyCollection
ExtraFlags InMsgExtraFlags
FwdFee Grams
CreatedLt uint64
CreatedAt uint32
} `tlbSumType:"int_msg_info_no_ihr$01"`
ExtInMsgInfo *struct {
Src MsgAddress
Dest MsgAddress
Expand All @@ -122,6 +134,54 @@ type CommonMsgInfo struct {
} `tlbSumType:"ext_out_msg_info$11"`
}

type BouncedMessageFormat string

const (
OldFormat BouncedMessageFormat = "old"
BodyRoot BouncedMessageFormat = "body_root"
WholeBody BouncedMessageFormat = "whole_body"
)

type InMsgExtraFlags VarUInteger16

func (f InMsgExtraFlags) BouncedMessageFormat() BouncedMessageFormat {
flags := big.Int(f)
if flags.Bit(0) == 0 { // ...0
return OldFormat
}
if flags.Bit(1) == 0 { // ...01 = 1
return BodyRoot
} else { // ...11 = 3
return WholeBody
}
}

func (f BouncedMessageFormat) ToFlags() InMsgExtraFlags {
switch f {
case BodyRoot:
return InMsgExtraFlags(*big.NewInt(1))
case WholeBody:
return InMsgExtraFlags(*big.NewInt(3))
}
return InMsgExtraFlags(*big.NewInt(0))
}

func (f *InMsgExtraFlags) UnmarshalTLB(c *boc.Cell, decoder *Decoder) error {
return decoder.Unmarshal(c, (*VarUInteger16)(f))
}

func (f InMsgExtraFlags) MarshalTLB(c *boc.Cell, encoder *Encoder) error {
return encoder.Marshal(c, VarUInteger16(f))
}

func (f InMsgExtraFlags) MarshalJSON() ([]byte, error) {
return json.Marshal(VarUInteger16(f))
}

func (f *InMsgExtraFlags) UnmarshalJSON(p []byte) error {
return json.Unmarshal(p, (*VarUInteger16)(f))
}

// StateInit
// _ split_depth:(Maybe (## 5)) special:(Maybe TickTock)
// code:(Maybe ^Cell) data:(Maybe ^Cell)
Expand Down
75 changes: 74 additions & 1 deletion tlb/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,41 @@ func TestMessage_Marshal_and_Unmarshal(t *testing.T) {
wantHash: "23ff6f150d573f64d5599a57813f991882b7b4d5ae0550ebd08ea658431e62f6",
},
{
name: "IntMsg with body",
name: "IntMsg with body without ihr fee",
boc: "te6ccgEBAgEAjAABsUgALXKEDiSWLCdVuhCWy/hYz3hnzF93uwd93pYymUX+v88AGzNMlqFjDeWk/rivKqxwpBoMaThCmw7tE7othW8odIgQBycOAAYdyRAAAEQo20NHEsixYeDAAQBbBRONkQAAAAAAAAAAgBZQOG7qXmeA/2Tw1pLX2IkcQ5h5fxWzzcBskMJbVVRsKA==",
filename: "testdata/message-2",
wantHash: "b55e0995ab2428b7ccffa4d417ff78caca62dc4d33bc0e33b2d9bcf0c396f08c",
},
{
name: "IntMsg with ihr fee",
boc: "te6ccgEBAgEAkgABtSgAF/xeC0+Z4JVGTZZ1wRhXb7LlO72P+AlL86AgD7OMvz8AKKsn8cUm4Sk3Ql20owK7xh4S3Go43Wl1UJu/tiH0UrBOgN6AYbd0Bgw1CAAAP6tjTcqE0GZh/sABAGQjsFZBaQj/SM/sMMAfore0NaplC/1LWkSitkf0UwRrPbvG7oLtN8TM6hReXwAAaDMw9A==",
filename: "testdata/message-3",
wantHash: "d0ac48e7bd45ab1e2612b9b34dd61d819caa93519fd78343fe2671f4669651e1",
},
{
name: "IntMsg with extra flags: flag 3",
boc: "te6ccgEBAwEAtAABs2gBYqR801amEcWPEqykRMeNbQq1nQkyHZStEyBBnWaWQKU/1VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVQ6MY8ACBneJb+AABIh5nK9YjRynviwAEBY25DU2wAAAAAAAAAAP///ACAEzaGxPYq5VZDsyPobYQJ9FdB3Ks7FbJX8SODYzN6WKBQAgBAIP1FYVtaLm1bwsfi0pEzUpDxKI/Sjw36lANz1WAnOLg=",
filename: "testdata/message-4",
wantHash: "6282b35168e81b57184e1cd095599be4659b47e7f06c2d1c393c0da1604aea75",
},
{
name: "IntMsg with extra flags: flag 1",
boc: "te6ccgEBAwEAtAABs2gBYqR801amEcWPEqykRMeNbQq1nQkyHZStEyBBnWaWQKU/1VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVQ6MY8ACAneJb+AABIh5nK9YjRynviwAEBY25DU2wAAAAAAAAAAP///ACAEzaGxPYq5VZDsyPobYQJ9FdB3Ks7FbJX8SODYzN6WKBQAgBAIP1FYVtaLm1bwsfi0pEzUpDxKI/Sjw36lANz1WAnOLg=",
filename: "testdata/message-5",
wantHash: "0388917b66f8685eb1851a302ec3495e46cfa4ca805708c5f221299835069df2",
},
{
name: "IntMsg with extra flags: flag 2",
boc: "te6ccgEBAwEAtAABs2gBYqR801amEcWPEqykRMeNbQq1nQkyHZStEyBBnWaWQKU/1VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVQ6MY8ACBHeJb+AABIh5nK9YjRynviwAEBY25DU2wAAAAAAAAAAP///ACAEzaGxPYq5VZDsyPobYQJ9FdB3Ks7FbJX8SODYzN6WKBQAgBAIP1FYVtaLm1bwsfi0pEzUpDxKI/Sjw36lANz1WAnOLg=",
filename: "testdata/message-6",
wantHash: "1d9c0b411914c309eafc5b804e4bb786574f07729fbc51c5d77572e9d212fabe",
},
{
name: "IntMsg with extra flags: flag random",
boc: "te6ccgEBAwEAtQABtWgBYqR801amEcWPEqykRMeNbQq1nQkyHZStEyBBnWaWQKU/1VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVQ6MY8AEYHJ3iW/gAASIeZyvWI0cp74sABAWNuQ1NsAAAAAAAAAAD///wAgBM2hsT2KuVWQ7Mj6G2ECfRXQdyrOxWyV/Ejg2MzeligUAIAQCD9RWFbWi5tW8LH4tKRM1KQ8SiP0o8N+pQDc9VgJzi4",
filename: "testdata/message-7",
wantHash: "3399d38ccd1099d98bc5fab725c29b63815ae4041c9ba756d2d619bae9035b49",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -351,3 +381,46 @@ func TestMessage_Marshal_and_Unmarshal(t *testing.T) {
})
}
}

func TestInMsgExtraFlags_BouncedMessageFormat(t *testing.T) {
tests := []struct {
name string
flags int64
wantFormat BouncedMessageFormat
}{
{
name: "old",
flags: 0,
wantFormat: OldFormat,
},
{
name: "root",
flags: 1,
wantFormat: BodyRoot,
},
{
name: "old",
flags: 2,
wantFormat: OldFormat,
},
{
name: "full",
flags: 3,
wantFormat: WholeBody,
},
{
name: "random",
flags: 12145624761,
wantFormat: BodyRoot,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
x := InMsgExtraFlags(*big.NewInt(tt.flags))
res := x.BouncedMessageFormat()
if res != tt.wantFormat {
t.Fatalf("want format: %v, got: %v", tt.wantFormat, res)
}
})
}
}
3 changes: 2 additions & 1 deletion tlb/testdata/message-1.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"Info": {
"SumType": "ExtInMsgInfo",
"IntMsgInfo": null,
"IntMsgInfoIhr": null,
"IntMsgInfoNoIhr": null,
"ExtInMsgInfo": {
"Src": "",
"Dest": "0:6ccd325a858c379693fae2bcaab1c2906831a4e10a6c3bb44ee8b615bca1d220",
Expand Down
8 changes: 4 additions & 4 deletions tlb/testdata/message-2.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"Info": {
"SumType": "IntMsgInfo",
"IntMsgInfo": {
"IhrDisabled": true,
"SumType": "IntMsgInfoNoIhr",
"IntMsgInfoIhr": null,
"IntMsgInfoNoIhr": {
"Bounce": false,
"Bounced": false,
"Src": "0:16b94207124b1613aadd084b65fc2c67bc33e62fbbdd83beef4b194ca2ff5fe7",
Expand All @@ -11,7 +11,7 @@
"Grams": "30000000",
"Other": {}
},
"IhrFee": "0",
"ExtraFlags": "0",
"FwdFee": "976008",
"CreatedLt": 37471134000009,
"CreatedAt": 1683534064
Expand Down
Loading
Loading