Skip to content

Commit

Permalink
custom jetton unmarshalling
Browse files Browse the repository at this point in the history
  • Loading branch information
akos-tk committed Oct 6, 2024
1 parent 996d9dc commit 81e8b72
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
101 changes: 101 additions & 0 deletions abi/jetton.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,104 @@ func (j *JettonPayload) UnmarshalTLB(cell *boc.Cell, decoder *tlb.Decoder) error

return nil
}

func (j *JettonNotifyMsgBody) UnmarshalTLB(cell *boc.Cell, decoder *tlb.Decoder) error {
var prefix struct {
QueryId uint64
Amount tlb.VarUInteger16
Sender tlb.MsgAddress
}
err := decoder.Unmarshal(cell, &prefix)
if err != nil {
return err
}
j.QueryId = prefix.QueryId
j.Amount = prefix.Amount
j.Sender = prefix.Sender
j.ForwardPayload = failsafeJettonPayloadEitherRef(cell, decoder)
return nil
}

func (j *JettonTransferMsgBody) UnmarshalTLB(cell *boc.Cell, decoder *tlb.Decoder) error {
var prefix struct {
QueryId uint64
Amount tlb.VarUInteger16
Destination tlb.MsgAddress
ResponseDestination tlb.MsgAddress
}
err := decoder.Unmarshal(cell, &prefix)
if err != nil {
return err
}
isCustomPayload, err := cell.PickUint(1)
if err != nil {
return err
}
var (
customPayload struct {
CustomPayload *tlb.Any `tlb:"maybe^"`
}
forwardTonAmount tlb.VarUInteger16
)
if isCustomPayload == 1 && cell.RefsAvailableForRead() > 0 {
err = decoder.Unmarshal(cell, &customPayload)
if err != nil {
return err
}
} else {
_ = cell.Skip(1)
}
err = decoder.Unmarshal(cell, &forwardTonAmount)
if err != nil {
return err
}
j.QueryId = prefix.QueryId
j.Amount = prefix.Amount
j.Destination = prefix.Destination
j.ResponseDestination = prefix.ResponseDestination
j.CustomPayload = customPayload.CustomPayload
j.ForwardTonAmount = forwardTonAmount
j.ForwardPayload = failsafeJettonPayloadEitherRef(cell, decoder)
return nil
}

func (j *JettonInternalTransferMsgBody) UnmarshalTLB(cell *boc.Cell, decoder *tlb.Decoder) error {
var res struct {
QueryId uint64
Amount tlb.VarUInteger16
From tlb.MsgAddress
ResponseAddress tlb.MsgAddress
ForwardTonAmount tlb.VarUInteger16
}
err := decoder.Unmarshal(cell, &res)
if err != nil {
return err
}
j.QueryId = res.QueryId
j.Amount = res.Amount
j.From = res.From
j.ResponseAddress = res.ResponseAddress
j.ForwardPayload = failsafeJettonPayloadEitherRef(cell, decoder)
return nil
}

func failsafeJettonPayloadEitherRef(cell *boc.Cell, decoder *tlb.Decoder) tlb.EitherRef[JettonPayload] {
isRight, err := cell.PickUint(1)
switch {
case err != nil:
return tlb.EitherRef[JettonPayload]{} // empty either
case isRight == 1 && cell.RefsAvailableForRead() < 1: // invalid either
return tlb.EitherRef[JettonPayload]{
IsRight: true,
}
default:
var res tlb.EitherRef[JettonPayload]
err = decoder.Unmarshal(cell, &res)
if err != nil {
return tlb.EitherRef[JettonPayload]{
IsRight: isRight == 1,
}
}
return res
}
}
1 change: 1 addition & 0 deletions abi/messages_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,7 @@ type JettonInternalTransferMsgBody struct {
From tlb.MsgAddress
ResponseAddress tlb.MsgAddress
ForwardTonAmount tlb.VarUInteger16
ForwardPayload tlb.EitherRef[JettonPayload]
}

type WhalesNominatorsWithdrawUnownedResponseMsgBody struct {
Expand Down
2 changes: 1 addition & 1 deletion abi/schemas/jettons.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
internal_transfer#178d4519 query_id:uint64 amount:(VarUInteger 16) from:MsgAddress
response_address:MsgAddress
forward_ton_amount:(VarUInteger 16)
<!-- forward_payload:(Either Cell ^Cell)-->
forward_payload:(Either JettonPayload ^JettonPayload)
= InternalMsgBody;
</internal>
<internal name="jetton_burn" >
Expand Down

0 comments on commit 81e8b72

Please sign in to comment.