Skip to content

Commit

Permalink
Add ContractGetRecordsQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachery Gyurkovitz committed Nov 8, 2019
1 parent 4a4fe88 commit 40bc68e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Sources/Hedera/contract/ContractGetRecordsQuery.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Foundation

public class ContractGetRecordsQuery: QueryBuilder<[TransactionRecord]> {
public override init(client: Client) {
super.init(client: client)

body.contractGetRecords = Proto_ContractGetRecordsQuery()
}

/// Set the contract id to get the records of.
@discardableResult
public func setContract(_ id: ContractId) -> Self {
body.contractGetRecords.contractID = id.toProto()

return self
}

override func mapResponse(_ response: Proto_Response) throws -> [TransactionRecord] {
guard case .contractGetRecordsResponse(let response) = response.response else {
throw HederaError(message: "query response was not of type 'contractGetRecords'")
}

return response.records.map(TransactionRecord.init)
}
}

0 comments on commit 40bc68e

Please sign in to comment.