-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(swift): add TokenBurnTransaction, TokenFreezeTransaction, TokenU…
…nfreezeTransaction, TokenPauseTransaction, and TokenUnpauseTransaction
- Loading branch information
Showing
5 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |