Skip to content

Commit

Permalink
Fix QueryBuilder
Browse files Browse the repository at this point in the history
    - Implement FileInfoQuery
    - Implement FileInfoQueryExample
    - Implement Transaction from bytes
    - Update FileId to new spec
  • Loading branch information
janaakhterov authored and qtbeee committed Nov 6, 2019
1 parent 1f85647 commit 5664aa2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
22 changes: 13 additions & 9 deletions Sources/Hedera/QueryBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class QueryBuilder<Response> {
let client: Client
var header = Proto_QueryHeader()
var node: Node
var needsPayment = true

init(client: Client) {
self.client = client
Expand All @@ -32,6 +33,7 @@ public class QueryBuilder<Response> {
@discardableResult
public func setPayment(_ transaction: Transaction) -> Self {
header.payment = transaction.toProto()
needsPayment = false

return self
}
Expand Down Expand Up @@ -90,16 +92,18 @@ public class QueryBuilder<Response> {
}

public func execute() throws -> Response {
// if let maxQueryPayment = client.maxQueryPayment, header.hasPayment {
if needsPayment {
let cost = try requestCost()
print("supposedly this query will cost \(cost) tinybar")
// if cost > maxQueryPayment {
// throw HederaError(message: "Query payment exceeds maxQueryPayment")
// }

setPayment(1_000_000_000)
// }


if let maxQueryPayment = client.maxQueryPayment {
if cost > maxQueryPayment {
throw HederaError(message: "Query payment exceeds maxQueryPayment")
}
}

setPayment(cost)
}

let response = try executeClosure(client.grpcClient(for: node))

var resHeader: Proto_ResponseHeader
Expand Down
7 changes: 2 additions & 5 deletions Sources/Hedera/file/FileInfoQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ public class FileInfoQuery: QueryBuilder<FileInfo> {
_ grpc: HederaGRPCClient
) throws -> Proto_Response {
body.fileGetInfo.header = header

// print("the whole query \n\(Transaction(client, bytes: try! body.fileGetInfo.serializedData()))")

return try grpc.fileService.getFileInfo(body)
}

Expand All @@ -39,11 +36,11 @@ public class FileInfoQuery: QueryBuilder<FileInfo> {
let fileId = fileInfo.fileID

return FileInfo(
fileId: EntityId(
fileId: FileId(EntityId(
shard: UInt64(fileId.shardNum),
realm: UInt64(fileId.realmNum),
num: UInt64(fileId.fileNum)
),
)),
size: UInt64(fileInfo.size),
expirationTime: Date(fileInfo.expirationTime),
deleted: fileInfo.deleted
Expand Down

0 comments on commit 5664aa2

Please sign in to comment.