Skip to content

Commit

Permalink
Add Claim to AccountInfo & add CryptoGetClaimQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachery Gyurkovitz committed Nov 9, 2019
1 parent 33997b8 commit a0b7365
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Sources/Hedera/Claim.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Foundation
import Sodium

public final class Claim: ProtoConvertible {
let id: AccountId
let hash: Bytes
let keys: KeyList

init(_ proto: Proto_Claim) {
id = AccountId(proto.accountID)
hash = Bytes(proto.hash)
keys = KeyList(proto.keys)!
}

func toProto() -> Proto_Claim {
var proto = Proto_Claim()
proto.accountID = id.toProto()
proto.hash = Data(hash)
proto.keys = keys.toProto()
return proto
}
}
2 changes: 2 additions & 0 deletions Sources/Hedera/account/AccountInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public struct AccountInfo {
let receiverSigRequired: Bool
let expirationTime: Date
let autoRenewPeriod: TimeInterval
let claims: [Claim]

init(_ accountInfo: Proto_CryptoGetInfoResponse.AccountInfo) {
let proxyAccountId: AccountId?
Expand All @@ -34,5 +35,6 @@ public struct AccountInfo {
receiverSigRequired = accountInfo.receiverSigRequired
expirationTime = Date(accountInfo.expirationTime)
autoRenewPeriod = TimeInterval(accountInfo.autoRenewPeriod)!
claims = accountInfo.claims.map(Claim.init)
}
}
30 changes: 30 additions & 0 deletions Sources/Hedera/account/CryptoGetClaimQuery.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Foundation
import Sodium

public class CryptoGetClaimQuery: QueryBuilder<Claim> {
public override init(client: Client) {
super.init(client: client)

body.cryptoGetClaim = Proto_CryptoGetClaimQuery()
}

@discardableResult
public func setAccount(_ id: AccountId) -> Self {
body.cryptoGetClaim.accountID = id.toProto()
return self
}

@discardableResult
public func setHash(_ hash: Bytes) -> Self {
body.cryptoGetClaim.hash = Data(hash)
return self
}

override func mapResponse(_ response: Proto_Response) throws -> Claim {
guard case .cryptoGetClaim(let response) = response.response else {
throw HederaError(message: "Query response was not of `cryptoGetClaim`")
}

return Claim(response.claim)
}
}

0 comments on commit a0b7365

Please sign in to comment.