-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Claim to AccountInfo & add CryptoGetClaimQuery
- Loading branch information
Zachery Gyurkovitz
committed
Nov 9, 2019
1 parent
33997b8
commit a0b7365
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |