Skip to content

Commit

Permalink
feat(swift): add TokenBurnTransaction, TokenFreezeTransaction, TokenU…
Browse files Browse the repository at this point in the history
…nfreezeTransaction, TokenPauseTransaction, and TokenUnpauseTransaction
  • Loading branch information
mehcode committed Jun 17, 2022
1 parent d6e1876 commit 16f518f
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 0 deletions.
62 changes: 62 additions & 0 deletions sdk/swift/Sources/Hedera/TokenBurnTransaction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/// Burns tokens from the token's treasury account.
public class TokenBurnTransaction: Transaction {
/// Create a new `TokenBurnTransaction`.
public init(
tokenId: TokenId? = nil,
amount: UInt64 = 0,
serialNumbers: [UInt64] = []
) {
self.tokenId = tokenId
self.amount = amount
self.serialNumbers = serialNumbers
}

/// The token for which to burn tokens.
public var tokenId: TokenId?

/// Sets the token for which to burn tokens.
@discardableResult
public func tokenId(_ tokenId: TokenId) -> Self {
self.tokenId = tokenId

return self
}

/// The amount of a fungible token to burn from the treasury account.
public var amount: UInt64

//// Sets the amount of a fungible token to burn from the treasury account.
@discardableResult
public func amount(_ amount: UInt64) -> Self {
self.amount = amount

return self
}

/// The serial numbers of a non-fungible token to burn from the treasury account.
public var serialNumbers: [UInt64]

/// Sets the serial numbers of a non-fungible token to burn from the treasury account.
@discardableResult
public func serialNumbers(_ serialNumbers: [UInt64]) -> Self {
self.serialNumbers = serialNumbers

return self
}

private enum CodingKeys: String, CodingKey {
case tokenId
case amount
case serialNumbers
}

public override func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

try container.encode(tokenId, forKey: .tokenId)
try container.encode(amount, forKey: .amount)
try container.encode(serialNumbers, forKey: .serialNumbers)

try super.encode(to: encoder)
}
}
47 changes: 47 additions & 0 deletions sdk/swift/Sources/Hedera/TokenFreezeTransaction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/// Freezes transfers of the specified token for the account.
public class TokenFreezeTransaction: Transaction {
/// Create a new `TokenFreezeTransaction`.
public init(
accountId: AccountAddress? = nil,
tokenId: TokenId? = nil
) {
self.accountId = accountId
self.tokenId = tokenId
}

/// The account to be frozen.
public var accountId: AccountAddress?

/// Sets the account to be frozen.
@discardableResult
public func accountId(_ accountId: AccountAddress?) -> Self {
self.accountId = accountId

return self
}

/// The token for which this account will be frozen.
public var tokenId: TokenId?

/// Sets the token for which this account will be frozen.
@discardableResult
public func tokenId(_ tokenId: TokenId) -> Self {
self.tokenId = tokenId

return self
}

private enum CodingKeys: String, CodingKey {
case accountId
case tokenId
}

public override func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

try container.encode(accountId, forKey: .accountId)
try container.encode(tokenId, forKey: .tokenId)

try super.encode(to: encoder)
}
}
32 changes: 32 additions & 0 deletions sdk/swift/Sources/Hedera/TokenPauseTransaction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// Pauses the token from being involved in any kind of transaction until it is unpaused.
public class TokenPauseTransaction: Transaction {
/// Create a new `TokenPauseTransaction`.
public init(
tokenId: TokenId? = nil
) {
self.tokenId = tokenId
}

/// The token to be paused.
public var tokenId: TokenId?

/// Sets the token to be paused.
@discardableResult
public func tokenId(_ tokenId: TokenId?) -> Self {
self.tokenId = tokenId

return self
}

private enum CodingKeys: String, CodingKey {
case tokenId
}

public override func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

try container.encode(tokenId, forKey: .tokenId)

try super.encode(to: encoder)
}
}
47 changes: 47 additions & 0 deletions sdk/swift/Sources/Hedera/TokenUnfreezeTransaction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/// Unfreezes transfers of the specified token for the account.
public class TokenUnfreezeTransaction: Transaction {
/// Create a new `TokenUnfreezeTransaction`.
public init(
accountId: AccountAddress? = nil,
tokenId: TokenId? = nil
) {
self.accountId = accountId
self.tokenId = tokenId
}

/// The account to be unfrozen.
public var accountId: AccountAddress?

/// Sets the account to be unfrozen.
@discardableResult
public func accountId(_ accountId: AccountAddress?) -> Self {
self.accountId = accountId

return self
}

/// The token for which this account will be unfrozen.
public var tokenId: TokenId?

/// Sets the token for which this account will be unfrozen.
@discardableResult
public func tokenId(_ tokenId: TokenId) -> Self {
self.tokenId = tokenId

return self
}

private enum CodingKeys: String, CodingKey {
case accountId
case tokenId
}

public override func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

try container.encode(accountId, forKey: .accountId)
try container.encode(tokenId, forKey: .tokenId)

try super.encode(to: encoder)
}
}
32 changes: 32 additions & 0 deletions sdk/swift/Sources/Hedera/TokenUnpauseTransaction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// Unpauses a previously paused token.
public class TokenUnpauseTransaction: Transaction {
/// Create a new `TokenUnpauseTransaction`.
public init(
tokenId: TokenId? = nil
) {
self.tokenId = tokenId
}

/// The token to be paused.
public var tokenId: TokenId?

/// Sets the token to be paused.
@discardableResult
public func tokenId(_ tokenId: TokenId?) -> Self {
self.tokenId = tokenId

return self
}

private enum CodingKeys: String, CodingKey {
case tokenId
}

public override func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

try container.encode(tokenId, forKey: .tokenId)

try super.encode(to: encoder)
}
}

0 comments on commit 16f518f

Please sign in to comment.