From b5e15aa5e1538dce9abf4b1f2295678d61aa0eca Mon Sep 17 00:00:00 2001 From: Daniel Akhterov Date: Wed, 30 Oct 2019 16:36:23 -0700 Subject: [PATCH] Add CreateFileExample --- Examples/CreateFile/main.swift | 18 ++++++++++++++++++ Package.swift | 5 +++++ .../Hedera/file/FileCreateTransaction.swift | 4 ++-- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 Examples/CreateFile/main.swift diff --git a/Examples/CreateFile/main.swift b/Examples/CreateFile/main.swift new file mode 100644 index 00000000..9f3d05be --- /dev/null +++ b/Examples/CreateFile/main.swift @@ -0,0 +1,18 @@ +import Hedera + +let privateKey = Ed25519PrivateKey("yourprivatekeyhere")! +let op = Operator(id: AccountId(2), privateKey: privateKey) + +let client = Client(node: AccountId("0.0.3")!, address: "0.testnet.hedera.com:50211") + .setMaxTransactionFee(100_000_000) + .setOperator(op) + +let fileCreateTransactionId = try! FileCreateTransaction(client: client) + .addKey(privateKey.publicKey) + .setContents("This is a test") + .setMemo("File Create Example - Swift SDK") + .setTransactionFee(1_000_000_000) + .build() + .execute() + +print("File Create Example succeeded with transaction id \(fileCreateTransactionId)") diff --git a/Package.swift b/Package.swift index 32da28fa..9ef458d6 100644 --- a/Package.swift +++ b/Package.swift @@ -15,6 +15,7 @@ let package = Package( targets: ["Hedera"]), .executable(name: "CreateAccountExample", targets: ["CreateAccountExample"]), .executable(name: "GetFileInfoExample", targets: ["GetFileInfoExample"]), + .executable(name: "CreateFileExample", targets: ["CreateFileExample"]), ], dependencies: [ .package(url: "https://github.com/jedisct1/swift-sodium", .exact("0.8.0")), @@ -38,5 +39,9 @@ let package = Package( name: "GetFileInfoExample", dependencies: ["Hedera"], path: "Examples/GetFileInfo"), + .target( + name: "CreateFileExample", + dependencies: ["Hedera"], + path: "Examples/CreateFile"), ] ) diff --git a/Sources/Hedera/file/FileCreateTransaction.swift b/Sources/Hedera/file/FileCreateTransaction.swift index 8a92f054..163c70c8 100644 --- a/Sources/Hedera/file/FileCreateTransaction.swift +++ b/Sources/Hedera/file/FileCreateTransaction.swift @@ -8,9 +8,9 @@ public class FileCreateTransaction: TransactionBuilder { body.fileCreate = Proto_FileCreateTransactionBody() - // For files and contracts expiration time needs be set to now + 7898 seconds + // For files and contracts expiration time needs be set to now + 7,890,000 seconds // otherwise file/contract creation fails - setExpirationTime(Date(timeIntervalSinceNow: 7898)) + setExpirationTime(Date(timeIntervalSinceNow: 7890000)) } /// Set the expiration time of the file