Skip to content

Commit

Permalink
Add documentation for File*Transaction methods
Browse files Browse the repository at this point in the history
  • Loading branch information
janaakhterov authored and qtbeee committed Nov 6, 2019
1 parent 0444b3b commit a60578d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Sources/Hedera/file/FileAppendTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,40 @@ import Foundation
import Sodium

public class FileAppendTransaction: TransactionBuilder {
/// Create a FileAppendTransaction
///
/// This transaction must be signed with all the required keys to successfully update the file.
public override init(client: Client) {
super.init(client: client)

body.fileAppend = Proto_FileAppendTransactionBody()
}

/// Set the content to be appened to the file
@discardableResult
public func setContents(_ data: Data) -> Self {
body.fileAppend.contents = data

return self
}

/// Set the content to be appened to the file
@discardableResult
public func setContents(_ bytes: Bytes) -> Self {
body.fileAppend.contents = Data(bytes)

return self
}

/// Set the content to be appened to the file
@discardableResult
public func setContents(_ string: String) -> Self {
body.fileAppend.contents = Data(Array(string.utf8))

return self
}

/// Set the file to be append the contents to
@discardableResult
public func setFile(_ id: FileId) -> Self {
body.fileAppend.fileID = id.toProto()
Expand Down
9 changes: 9 additions & 0 deletions Sources/Hedera/file/FileCreateTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,46 @@ public class FileCreateTransaction: TransactionBuilder {

body.fileCreate = Proto_FileCreateTransactionBody()

// For files and contracts expiration time needs be set to now + 7898 seconds
// otherwise file/contract creation fails
setExpirationTime(Date(timeIntervalSinceNow: 7898))
}

/// Set the expiration time of the file
@discardableResult
public func setExpirationTime(_ date: Date) -> Self {
body.fileCreate.expirationTime = date.toProto()

return self
}

/// Add a Ed25519PublicKey that will be required to create and update this file
///
/// At least one key must be provided
@discardableResult
public func addKey(_ key: Ed25519PublicKey) -> Self {
body.fileCreate.keys.keys.append(key.toProto())

return self
}

/// Set the initial contents of the to be created file
@discardableResult
public func setContents(_ data: Data) -> Self {
body.fileCreate.contents = data

return self
}

/// Set the initial contents of the to be created file
@discardableResult
public func setContents(_ bytes: Bytes) -> Self {
body.fileCreate.contents = Data(bytes)

return self
}

/// Set the initial contents of the to be created file
@discardableResult
public func setContents(_ string: String) -> Self {
body.fileCreate.contents = Data(Array(string.utf8))
Expand Down
4 changes: 4 additions & 0 deletions Sources/Hedera/file/FileDeleteTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import SwiftProtobuf
import Foundation

public class FileDeleteTransaction: TransactionBuilder {
/// Create a FileDeleteTransaction
///
/// This transaction must be signed with all the required keys to successfully update the file.
public override init(client: Client) {
super.init(client: client)

body.fileDelete = Proto_FileDeleteTransactionBody()
}

/// Set the file to delete
@discardableResult
public func setFile(_ id: FileId) -> Self {
body.fileDelete.fileID = id.toProto()
Expand Down
8 changes: 8 additions & 0 deletions Sources/Hedera/file/FileUpdateTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,48 @@ import Foundation
import Sodium

public class FileUpdateTransaction: TransactionBuilder {
/// Create a FileUpdateTransaction
///
/// This transaction must be signed with all the required keys to successfully update the file.
public override init(client: Client) {
super.init(client: client)

body.fileUpdate = Proto_FileUpdateTransactionBody()
}

/// Set a new expiration time of the file
@discardableResult
public func setExpirationTime(_ date: Date) -> Self {
body.fileUpdate.expirationTime = date.toProto()

return self
}

/// Set the new contents of the file
@discardableResult
public func setContents(_ data: Data) -> Self {
body.fileUpdate.contents = data

return self
}

/// Set the new contents of the file
@discardableResult
public func setContents(_ bytes: Bytes) -> Self {
body.fileUpdate.contents = Data(bytes)

return self
}

/// Set the new contents of the file
@discardableResult
public func setContents(_ string: String) -> Self {
body.fileUpdate.contents = Data(Array(string.utf8))

return self
}

/// Set the file to be updated
@discardableResult
public func setFile(_ id: FileId) -> Self {
body.fileUpdate.fileID = id.toProto()
Expand Down

0 comments on commit a60578d

Please sign in to comment.