Skip to content

Commit

Permalink
Add maxMessages constant for WalletContract
Browse files Browse the repository at this point in the history
  • Loading branch information
voloshinskii committed Dec 17, 2024
1 parent b4cd884 commit 6fa4db2
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Source/TonSwift/Wallets/WalletContract.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Foundation
/// All wallets implement a compatible interface for sending messages
public protocol WalletContract: Contract {
func createTransfer(args: WalletTransferData, messageType: MessageType) throws -> WalletTransfer

var maxMessages: Int { get }
}

/// Message type (external | internal) to sign. Is using in v5 wallet contract
Expand Down
2 changes: 2 additions & 0 deletions Source/TonSwift/Wallets/WalletV1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public final class WalletV1: WalletContract {
public let stateInit: StateInit
public let publicKey: Data
public let revision: WalletContractV1Revision

public let maxMessages: Int = 4

public init(workchain: Int8, publicKey: Data, revision: WalletContractV1Revision) throws {
self.workchain = workchain
Expand Down
6 changes: 4 additions & 2 deletions Source/TonSwift/Wallets/WalletV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public final class WalletV2: WalletContract {
public let publicKey: Data
public let revision: WalletContractV2Revision

public let maxMessages: Int = 4

public init(workchain: Int8, publicKey: Data, revision: WalletContractV2Revision) throws {
self.workchain = workchain
self.publicKey = publicKey
Expand All @@ -34,8 +36,8 @@ public final class WalletV2: WalletContract {
}

public func createTransfer(args: WalletTransferData, messageType: MessageType = .ext) throws -> WalletTransfer {
guard args.messages.count <= 4 else {
throw TonError.custom("Maximum number of messages in a single transfer is 4")
guard args.messages.count <= maxMessages else {
throw TonError.custom("Maximum number of messages in a single transfer is \(maxMessages)")
}

let signingMessage = try Builder().store(uint: args.seqno, bits: 32)
Expand Down
6 changes: 4 additions & 2 deletions Source/TonSwift/Wallets/WalletV3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public final class WalletV3: WalletContract {
public let publicKey: Data
public let walletId: UInt64
public let revision: WalletContractV3Revision

public var maxMessages: Int = 4

public init(workchain: Int8, publicKey: Data, walletId: UInt64? = nil, revision: WalletContractV3Revision) throws {
self.workchain = workchain
Expand Down Expand Up @@ -43,8 +45,8 @@ public final class WalletV3: WalletContract {
}

public func createTransfer(args: WalletTransferData, messageType: MessageType = .ext) throws -> WalletTransfer {
guard args.messages.count <= 4 else {
throw TonError.custom("Maximum number of messages in a single transfer is 4")
guard args.messages.count <= maxMessages else {
throw TonError.custom("Maximum number of messages in a single transfer is \(maxMessages)")
}

let signingMessage = try Builder().store(uint: walletId, bits: 32)
Expand Down
6 changes: 4 additions & 2 deletions Source/TonSwift/Wallets/WalletV4.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class WalletV4: WalletContract {
public let walletId: UInt32
public let plugins: Set<Address>
public let code: Cell

public let maxMessages: Int = 4

fileprivate init(code: Cell,
seqno: Int64 = 0,
Expand Down Expand Up @@ -71,8 +73,8 @@ public class WalletV4: WalletContract {
}

public func createTransfer(args: WalletTransferData, messageType: MessageType = .ext) throws -> WalletTransfer {
guard args.messages.count <= 4 else {
throw TonError.custom("Maximum number of messages in a single transfer is 4")
guard args.messages.count <= maxMessages else {
throw TonError.custom("Maximum number of messages in a single transfer is \(maxMessages)")
}

let signingMessage = try Builder().store(uint: walletId, bits: 32)
Expand Down
6 changes: 4 additions & 2 deletions Source/TonSwift/Wallets/WalletV5.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class WalletV5: WalletContract {
public let walletId: WalletId
public let plugins: Set<Address>
public let code: Cell

public let maxMessages: Int = 255

fileprivate init(code: Cell,
seqno: Int64 = 0,
Expand Down Expand Up @@ -113,8 +115,8 @@ public class WalletV5: WalletContract {
}

public func createTransfer(args: WalletTransferData, messageType: MessageType = .ext) throws -> WalletTransfer {
guard args.messages.count <= 255 else {
throw TonError.custom("Maximum number of messages in a single transfer is 255")
guard args.messages.count <= maxMessages else {
throw TonError.custom("Maximum number of messages in a single transfer is \(maxMessages)")
}

let signingMessage = try Builder()
Expand Down
6 changes: 4 additions & 2 deletions Source/TonSwift/Wallets/WalletV5Beta.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class WalletV5BetaContract: WalletContract {
public let walletId: WalletIdBeta
public let plugins: Set<Address>
public let code: Cell

public let maxMessages: Int = 255

fileprivate init(code: Cell,
seqno: Int64 = 0,
Expand Down Expand Up @@ -103,8 +105,8 @@ public class WalletV5BetaContract: WalletContract {
}

public func createTransfer(args: WalletTransferData, messageType: MessageType = .ext) throws -> WalletTransfer {
guard args.messages.count <= 255 else {
throw TonError.custom("Maximum number of messages in a single transfer is 255")
guard args.messages.count <= maxMessages else {
throw TonError.custom("Maximum number of messages in a single transfer is \(maxMessages)")
}

let signingMessage = try Builder()
Expand Down

0 comments on commit 6fa4db2

Please sign in to comment.