Skip to content

Commit

Permalink
encrpted messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-tron committed Jul 20, 2023
1 parent 59cf5f5 commit d192228
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/sourcegraph/conc v0.3.0
github.com/stretchr/testify v1.8.1
github.com/tonkeeper/scam_backoffice_rules v0.0.0-20230413094040-a66ab71fb269
github.com/tonkeeper/tongo v1.1.3-0.20230710082735-cf74127e1fb6
github.com/tonkeeper/tongo v1.2.0
go.opentelemetry.io/otel v1.11.1
go.opentelemetry.io/otel/metric v0.33.0
go.opentelemetry.io/otel/trace v1.11.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ github.com/tonkeeper/scam_backoffice_rules v0.0.0-20230413094040-a66ab71fb269 h1
github.com/tonkeeper/scam_backoffice_rules v0.0.0-20230413094040-a66ab71fb269/go.mod h1:VGp8QednbWkKHcpQVlWyO0XSqAA0cR6d9wEdrDmHbbA=
github.com/tonkeeper/tongo v1.1.3-0.20230710082735-cf74127e1fb6 h1:81bPcaL70eL6yRMFPWP2pfMuoXOeeVi05YZB98Ji2Vk=
github.com/tonkeeper/tongo v1.1.3-0.20230710082735-cf74127e1fb6/go.mod h1:LdOBjpUz6vLp1EdX3E0XLNks9YI5XMSqaQahfOMrBEY=
github.com/tonkeeper/tongo v1.2.0 h1:AJ9hlJKKSN/dboKd4ras24vhqCnakdiAYwAATWnW5WY=
github.com/tonkeeper/tongo v1.2.0/go.mod h1:LdOBjpUz6vLp1EdX3E0XLNks9YI5XMSqaQahfOMrBEY=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
Expand Down
27 changes: 20 additions & 7 deletions pkg/api/event_converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"context"
"encoding/hex"
"fmt"
"math/big"
"sort"
Expand Down Expand Up @@ -153,10 +154,11 @@ func (h Handler) convertAction(ctx context.Context, viewer tongo.AccountID, a ba
}
}
action.TonTransfer.SetTo(oas.TonTransferAction{
Amount: a.TonTransfer.Amount,
Comment: g.Opt(a.TonTransfer.Comment),
Recipient: convertAccountAddress(a.TonTransfer.Recipient, h.addressBook),
Sender: convertAccountAddress(a.TonTransfer.Sender, h.addressBook),
Amount: a.TonTransfer.Amount,
Comment: g.Opt(a.TonTransfer.Comment),
Recipient: convertAccountAddress(a.TonTransfer.Recipient, h.addressBook),
Sender: convertAccountAddress(a.TonTransfer.Sender, h.addressBook),
EncryptedComment: convertEncryptedComment(a.TonTransfer.EncryptedComment),
})
if a.TonTransfer.Refund != nil {
action.TonTransfer.Value.Refund.SetTo(oas.Refund{
Expand All @@ -178,9 +180,11 @@ func (h Handler) convertAction(ctx context.Context, viewer tongo.AccountID, a ba
}
case bath.NftItemTransfer:
action.NftItemTransfer.SetTo(oas.NftItemTransferAction{
Nft: a.NftItemTransfer.Nft.ToRaw(),
Recipient: convertOptAccountAddress(a.NftItemTransfer.Recipient, h.addressBook),
Sender: convertOptAccountAddress(a.NftItemTransfer.Sender, h.addressBook),
Nft: a.NftItemTransfer.Nft.ToRaw(),
Recipient: convertOptAccountAddress(a.NftItemTransfer.Recipient, h.addressBook),
Sender: convertOptAccountAddress(a.NftItemTransfer.Sender, h.addressBook),
Comment: g.Opt(a.NftItemTransfer.Comment),
EncryptedComment: convertEncryptedComment(a.NftItemTransfer.EncryptedComment),
})
action.SimplePreview = oas.ActionSimplePreview{
Name: "NFT Transfer",
Expand All @@ -201,6 +205,7 @@ func (h Handler) convertAction(ctx context.Context, viewer tongo.AccountID, a ba
RecipientsWallet: a.JettonTransfer.RecipientsWallet.ToRaw(),
SendersWallet: a.JettonTransfer.SendersWallet.ToRaw(),
Comment: g.Opt(a.JettonTransfer.Comment),
EncryptedComment: convertEncryptedComment(a.JettonTransfer.EncryptedComment),
})
if len(preview.Image) > 0 {
action.SimplePreview.ValueImage = oas.NewOptString(preview.Image)
Expand Down Expand Up @@ -500,3 +505,11 @@ func (h Handler) toAccountEvent(ctx context.Context, account tongo.AccountID, tr
}
return e, nil
}

func convertEncryptedComment(comment *bath.EncryptedComment) oas.OptEncryptedComment {
c := oas.OptEncryptedComment{}
if comment != nil {
c.SetTo(oas.EncryptedComment{EncryptionType: comment.EncryptionType, CipherText: hex.EncodeToString(comment.CipherText)})
}
return c
}
27 changes: 17 additions & 10 deletions pkg/bath/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ type (
Type RefundType
Origin string
}
EncryptedComment struct {
EncryptionType string
CipherText []byte
}

Action struct {
TonTransfer *TonTransferAction `json:",omitempty"`
Expand All @@ -68,11 +72,12 @@ type (
Type ActionType
}
TonTransferAction struct {
Amount int64
Comment *string
Recipient tongo.AccountID
Sender tongo.AccountID
Refund *Refund
Amount int64
Comment *string
EncryptedComment *EncryptedComment
Recipient tongo.AccountID
Sender tongo.AccountID
Refund *Refund
}
SmartContractAction struct {
TonAttached int64
Expand All @@ -83,11 +88,12 @@ type (
}

NftTransferAction struct {
Comment *string
Recipient *tongo.AccountID
Sender *tongo.AccountID
Nft tongo.AccountID
Refund *Refund
Comment *string
EncryptedComment *EncryptedComment
Recipient *tongo.AccountID
Sender *tongo.AccountID
Nft tongo.AccountID
Refund *Refund
}

NftPurchaseAction struct {
Expand All @@ -112,6 +118,7 @@ type (

JettonTransferAction struct {
Comment *string
EncryptedComment *EncryptedComment
Jetton tongo.AccountID
Recipient *tongo.AccountID
Sender *tongo.AccountID
Expand Down
8 changes: 5 additions & 3 deletions pkg/bath/bubble_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (b BubbleTx) ToAction() *Action {
}
return nil
}
if b.opCode != nil && *b.opCode != 0 && b.accountWasActiveAtComputingTime && !b.account.Is(abi.Wallet) {
if b.opCode != nil && (*b.opCode == 0 || b.operation(abi.EncryptedTextCommentMsgOp)) && b.accountWasActiveAtComputingTime && !b.account.Is(abi.Wallet) {
operation := fmt.Sprintf("0x%08x", *b.opCode)
payload := ""
if b.decodedBody != nil {
Expand Down Expand Up @@ -81,10 +81,12 @@ func (b BubbleTx) ToAction() *Action {
Type: TonTransfer,
}
if b.decodedBody != nil {
s, ok := b.decodedBody.Value.(abi.TextCommentMsgBody)
if ok {
switch s := b.decodedBody.Value.(type) {
case abi.TextCommentMsgBody:
converted := string(s.Text)
a.TonTransfer.Comment = &converted
case abi.EncryptedTextCommentMsgBody:
a.TonTransfer.EncryptedComment = &EncryptedComment{EncryptionType: "simple", CipherText: s.CipherText}
}
}
return a
Expand Down
18 changes: 15 additions & 3 deletions pkg/bath/straws.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ func (b BubbleNftTransfer) ToAction() (action *Action) {
Success: b.success,
Type: NftItemTransfer,
}
if c, ok := b.payload.(string); ok {
switch c := b.payload.(type) {
case string:
a.NftItemTransfer.Comment = &c
case EncryptedComment:
a.NftItemTransfer.EncryptedComment = &c
}
return &a
}
Expand All @@ -116,6 +119,12 @@ func cellToTextComment(payloadCell boc.Cell) any {
}
payloadCell.ResetCounters()
op, err := payloadCell.ReadUint(32)
if uint32(op) == abi.EncryptedTextCommentMsgOpCode {
var b tlb.Bytes
if tlb.Unmarshal(&payloadCell, &b) == nil {
return EncryptedComment{CipherText: b, EncryptionType: "simple"}
}
}
if err == nil {
return fmt.Sprintf("Call: 0x%x", op)
}
Expand Down Expand Up @@ -252,8 +261,11 @@ func (b BubbleJettonTransfer) ToAction() (action *Action) {
Success: b.success,
Type: JettonTransfer,
}
if c, ok := b.payload.(string); ok {
a.JettonTransfer.Comment = &c
switch c := b.payload.(type) {
case string:
a.NftItemTransfer.Comment = &c
case EncryptedComment:
a.NftItemTransfer.EncryptedComment = &c
}
return &a
}

0 comments on commit d192228

Please sign in to comment.