Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MsgType and Hash fields to Message #263

Merged
merged 1 commit into from
Dec 4, 2023
Merged
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
15 changes: 15 additions & 0 deletions api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3532,6 +3532,10 @@
"format": "int64",
"type": "integer"
},
"hash": {
"example": "97264395BD65A255A429B11326C84128B7D70FFED7949ABAE3036D506BA38621",
"type": "string"
},
"ihr_disabled": {
"example": true,
"type": "boolean"
Expand All @@ -3549,6 +3553,15 @@
"init": {
"$ref": "#/components/schemas/StateInit"
},
"msg_type": {
"enum": [
"int_msg",
"ext_in_msg",
"ext_out_msg"
],
"example": "int_msg",
"type": "string"
},
"op_code": {
"example": "0xdeadbeaf",
"type": "string"
Expand All @@ -3568,6 +3581,8 @@
}
},
"required": [
"msg_type",
"hash",
"created_lt",
"ihr_disabled",
"bounce",
Expand Down
12 changes: 12 additions & 0 deletions api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2923,6 +2923,8 @@ components:
Message:
type: object
required:
- msg_type
- hash
- created_lt
- ihr_disabled
- bounce
Expand All @@ -2933,6 +2935,16 @@ components:
- import_fee
- created_at
properties:
msg_type:
type: string
example: int_msg
enum:
- int_msg
- ext_in_msg
- ext_out_msg
hash:
type: string
example: 97264395BD65A255A429B11326C84128B7D70FFED7949ABAE3036D506BA38621
created_lt:
type: integer
format: int64
Expand Down
40 changes: 29 additions & 11 deletions pkg/api/blockchain_converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,37 @@ func convertTransaction(t core.Transaction, book addressBook) oas.Transaction {
return tx
}

func convertMsgType(msgType core.MsgType) oas.MessageMsgType {
switch msgType {
case core.ExtInMsg:
return oas.MessageMsgTypeExtInMsg
case core.ExtOutMsg:
return oas.MessageMsgTypeExtOutMsg
default:
return oas.MessageMsgTypeIntMsg
}
}

func convertMessage(m core.Message, book addressBook) oas.Message {
msg := oas.Message{
CreatedLt: int64(m.CreatedLt),
IhrDisabled: m.IhrDisabled,
Bounce: m.Bounce,
Bounced: m.Bounced,
Value: m.Value,
FwdFee: m.FwdFee,
IhrFee: m.IhrFee,
Destination: convertOptAccountAddress(m.Destination, book),
Source: convertOptAccountAddress(m.Source, book),
ImportFee: m.ImportFee,
CreatedAt: int64(m.CreatedAt),
MsgType: convertMsgType(m.MsgType),
Hash: m.Hash.Hex(),
CreatedLt: int64(m.CreatedLt),
IhrDisabled: m.IhrDisabled,
Bounce: m.Bounce,
Bounced: m.Bounced,
Value: m.Value,
FwdFee: m.FwdFee,
IhrFee: m.IhrFee,
Destination: convertOptAccountAddress(m.Destination, book),
Source: convertOptAccountAddress(m.Source, book),
ImportFee: m.ImportFee,
CreatedAt: int64(m.CreatedAt),
OpCode: oas.OptString{},
Init: oas.OptStateInit{},
RawBody: oas.OptString{},
DecodedOpName: oas.OptString{},
DecodedBody: nil,
}
if len(m.Body) != 0 {
msg.RawBody.SetTo(hex.EncodeToString(m.Body))
Expand Down
6 changes: 6 additions & 0 deletions pkg/core/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ func ConvertMessage(message tlb.Message, txLT uint64) (Message, error) {
Source: source,
Destination: dest,
},
MsgType: IntMsg,
Hash: tongo.Bits256(message.Hash()),
IhrDisabled: info.IhrDisabled,
Bounce: info.Bounce,
Bounced: info.Bounced,
Expand All @@ -327,6 +329,8 @@ func ConvertMessage(message tlb.Message, txLT uint64) (Message, error) {
CreatedLt: txLT,
Destination: dest,
},
MsgType: ExtInMsg,
Hash: tongo.Bits256(message.Hash()),
SourceExtern: externalAddressFromTlb(info.Src),
ImportFee: int64(info.ImportFee),
Body: body,
Expand All @@ -345,6 +349,8 @@ func ConvertMessage(message tlb.Message, txLT uint64) (Message, error) {
CreatedLt: info.CreatedLt,
Source: source,
},
MsgType: ExtOutMsg,
Hash: tongo.Bits256(message.Hash()),
DestinationExtern: externalAddressFromTlb(info.Dest),
Body: body,
DecodedBody: decodedBody,
Expand Down
4 changes: 4 additions & 0 deletions pkg/core/testdata/convert-tx-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"CreatedLt": 37362820000002,
"Source": "0:6ccd325a858c379693fae2bcaab1c2906831a4e10a6c3bb44ee8b615bca1d220",
"Destination": "0:6dcb8357c6bef52b43f0f681d976f5a46068ae195cb95f7a959d25c71b0cac6c",
"MsgType": "IntMsg",
"Hash": "ec658106d3196e2ae0a2471ff8a36f9ee304c3b035862f184791f3f1097de72d",
"SourceExtern": null,
"DestinationExtern": null,
"IhrDisabled": true,
Expand All @@ -30,6 +32,8 @@
"CreatedLt": 37362820000004,
"Source": "0:6dcb8357c6bef52b43f0f681d976f5a46068ae195cb95f7a959d25c71b0cac6c",
"Destination": "0:e185f22dd230150f2a9d6e9d2bf833b5c03d6215bdfd031d2691f8b835dd99de",
"MsgType": "IntMsg",
"Hash": "81a3c7682efc9187b59f210432169d34e4f088fa70994b0c6a5f893f6a90d896",
"SourceExtern": null,
"DestinationExtern": null,
"IhrDisabled": true,
Expand Down
13 changes: 12 additions & 1 deletion pkg/core/transactions.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package core

import (
"github.com/tonkeeper/tongo/boc"
"math/big"

"github.com/tonkeeper/tongo/boc"

"github.com/tonkeeper/tongo/abi"
"github.com/tonkeeper/tongo/tlb"

Expand Down Expand Up @@ -122,8 +123,18 @@ func (m Message) IsEmission() bool {
return m.Source != nil && m.Source.IsZero() && m.Source.Workchain == -1 && m.Bounced == false
}

type MsgType string

const (
IntMsg MsgType = "IntMsg"
ExtInMsg MsgType = "ExtInMsg"
ExtOutMsg MsgType = "ExtOutMsg"
)

type Message struct {
MessageID
MsgType MsgType
Hash tongo.Bits256
SourceExtern *ExternalAddress
DestinationExtern *ExternalAddress
IhrDisabled bool
Expand Down
Loading
Loading