-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from uphold/feature/add-reserve
Add reserve model
- Loading branch information
Showing
16 changed files
with
674 additions
and
67 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
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,59 @@ | ||
import Foundation | ||
import PromiseKit | ||
|
||
/// Reserve model. | ||
public class Reserve: BaseModel { | ||
|
||
/** | ||
Gets the ledger. | ||
|
||
- parameter start: The start position for the range. | ||
- parameter end: The end position for the range. | ||
|
||
- returns: A promise with the array of deposits. | ||
*/ | ||
public func getLedger(start: Int, end: Int) -> Promise<[Deposit]> { | ||
let request = self.adapter.buildRequest(ReserveService.getLedger(Header.buildRangeHeader(start, end: end))) | ||
|
||
return self.adapter.buildResponse(request) | ||
} | ||
|
||
/** | ||
Gets the reserve summary of all the obligations and assets within it. | ||
|
||
- returns: A promise with the reserve summary of all the obligations and assets within it. | ||
*/ | ||
public func getStatistics() -> Promise<[ReserveStatistics]> { | ||
let request = self.adapter.buildRequest(ReserveService.getStatistics()) | ||
|
||
return self.adapter.buildResponse(request) | ||
} | ||
|
||
/** | ||
Gets the information of any transaction. | ||
|
||
- parameter transactionId: The id of the transaction. | ||
|
||
- returns: A promise with the transaction. | ||
*/ | ||
public func getTransactionById(transactionId: String) -> Promise<Transaction> { | ||
let request = self.adapter.buildRequest(ReserveService.getReserveTransactionById(transactionId)) | ||
|
||
return self.adapter.buildResponse(request) | ||
} | ||
|
||
/** | ||
Gets information of all the transactions from the beginning of time. | ||
|
||
- parameter start: The start position for the range. | ||
- parameter end: The end position for the range. | ||
|
||
- returns: A promise with the array of transactions. | ||
*/ | ||
public func getTransactions(start: Int, end: Int) -> Promise<[Transaction]> { | ||
let request = self.adapter.buildRequest(ReserveService.getReserveTransactions(Header.buildRangeHeader(start, end: end))) | ||
|
||
return self.adapter.buildResponse(request) | ||
} | ||
|
||
} |
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,60 @@ | ||
import Foundation | ||
import ObjectMapper | ||
|
||
/// Deposit model. | ||
public class Deposit: Mappable { | ||
|
||
/// The date when the transaction was created. | ||
public private(set) var createdAt: String? | ||
|
||
/// The deposit in movement. | ||
public private(set) var input: DepositMovement? | ||
|
||
/// The deposit out movement. | ||
public private(set) var output: DepositMovement? | ||
|
||
/// The id of the transaction. | ||
public private(set) var transactionId: String? | ||
|
||
/// The type of the deposit. | ||
public private(set) var type: String? | ||
|
||
/** | ||
Constructor. | ||
|
||
- parameter createdAt: The date when the transaction was created. | ||
- parameter input: The deposit in movement. | ||
- parameter output: The deposit out movement. | ||
- parameter transactionId: The id of the transaction. | ||
- parameter type: The type of the deposit. | ||
*/ | ||
public init(createdAt: String, input: DepositMovement, output: DepositMovement, transactionId: String, type: String) { | ||
self.createdAt = createdAt | ||
self.input = input | ||
self.output = output | ||
self.transactionId = transactionId | ||
self.type = type | ||
} | ||
|
||
// MARK: Required by the ObjectMapper. | ||
|
||
/** | ||
Constructor. | ||
*/ | ||
required public init?(_ map: Map) { | ||
} | ||
|
||
/** | ||
Maps the JSON to the Object. | ||
|
||
- parameter map: The object to map. | ||
*/ | ||
public func mapping(map: Map) { | ||
self.createdAt <- map["createdAt"] | ||
self.input <- map["in"] | ||
self.output <- map["out"] | ||
self.transactionId <- map["TransactionId"] | ||
self.type <- map["type"] | ||
} | ||
|
||
} |
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,42 @@ | ||
import Foundation | ||
import ObjectMapper | ||
|
||
/// DepositMovement model. | ||
public class DepositMovement: Mappable { | ||
|
||
/// The amount of the deposit movement. | ||
public private(set) var amount: String? | ||
|
||
/// The currency of the deposit movement. | ||
public private(set) var currency: String? | ||
|
||
/** | ||
Constructor. | ||
|
||
- parameter amount: The amount of the deposit movement. | ||
- parameter currency: The currency of the deposit movement. | ||
*/ | ||
public init(amount: String, currency: String) { | ||
self.amount = amount | ||
self.currency = currency | ||
} | ||
|
||
// MARK: Required by the ObjectMapper. | ||
|
||
/** | ||
Constructor. | ||
*/ | ||
required public init?(_ map: Map) { | ||
} | ||
|
||
/** | ||
Maps the JSON to the Object. | ||
|
||
- parameter map: The object to map. | ||
*/ | ||
public func mapping(map: Map) { | ||
self.amount <- map["amount"] | ||
self.currency <- map["currency"] | ||
} | ||
|
||
} |
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,48 @@ | ||
import Foundation | ||
import ObjectMapper | ||
|
||
/// ReserveStatistics model. | ||
public class ReserveStatistics: Mappable { | ||
|
||
/// The currency from the reserve. | ||
public private(set) var currency: String? | ||
|
||
/// The commissions, transaction volume, assets and liabilities. | ||
public private(set) var totals: Total? | ||
|
||
/// The value of held in the associated currency in all supported forms. | ||
public private(set) var values: [Value]? | ||
|
||
/** | ||
Constructor. | ||
|
||
- parameter currency: The currency from the reserve. | ||
- parameter totals: The commissions, transaction volume, assets and liabilities. | ||
- parameter values: The value of held in the associated currency in all supported forms. | ||
*/ | ||
public init(currency: String, totals: Total, values: [Value]) { | ||
self.currency = currency | ||
self.totals = totals | ||
self.values = values | ||
} | ||
|
||
// MARK: Required by the ObjectMapper. | ||
|
||
/** | ||
Constructor. | ||
*/ | ||
required public init?(_ map: Map) { | ||
} | ||
|
||
/** | ||
Maps the JSON to the Object. | ||
|
||
- parameter map: The object to map. | ||
*/ | ||
public func mapping(map: Map) { | ||
self.currency <- map["currency"] | ||
self.totals <- map["totals"] | ||
self.values <- map["values"] | ||
} | ||
|
||
} |
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,54 @@ | ||
import Foundation | ||
import ObjectMapper | ||
|
||
/// Total model. | ||
public class Total: Mappable { | ||
|
||
/// The assets from the corresponding holding. | ||
public private(set) var assets: String? | ||
|
||
/// The commission from the corresponding holding. | ||
public private(set) var commissions: String? | ||
|
||
/// The liabilities from the corresponding holding. | ||
public private(set) var liabilities: String? | ||
|
||
/// The transactions from the corresponding holding. | ||
public private(set) var transactions: String? | ||
|
||
/** | ||
Constructor. | ||
|
||
- parameter assets: The assets from the corresponding holding. | ||
- parameter commissions: The commission from the corresponding holding. | ||
- parameter liabilities: The liabilities from the corresponding holding. | ||
- parameter transactions: The transactions from the corresponding holding. | ||
*/ | ||
public init(assets: String, commissions: String, liabilities: String, transactions: String) { | ||
self.assets = assets | ||
self.commissions = commissions | ||
self.liabilities = liabilities | ||
self.transactions = transactions | ||
} | ||
|
||
// MARK: Required by the ObjectMapper. | ||
|
||
/** | ||
Constructor. | ||
*/ | ||
required public init?(_ map: Map) { | ||
} | ||
|
||
/** | ||
Maps the JSON to the Object. | ||
|
||
- parameter map: The object to map. | ||
*/ | ||
public func mapping(map: Map) { | ||
self.assets <- map["assets"] | ||
self.commissions <- map["commissions"] | ||
self.liabilities <- map["liabilities"] | ||
self.transactions <- map["transactions"] | ||
} | ||
|
||
} |
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,54 @@ | ||
import Foundation | ||
import ObjectMapper | ||
|
||
/// Value model. | ||
public class Value: Mappable { | ||
|
||
/// The quantity of assets held for the corresponding holding, but converted to a different currency. | ||
public private(set) var assets: String? | ||
|
||
/// The currency we are computing the current holding in. | ||
public private(set) var currency: String? | ||
|
||
/// The quantity of liabilities for the corresponding holding, but converted to a different currency. | ||
public private(set) var liabilities: String? | ||
|
||
/// The rate we used when computing the holding to the corresponding currency. | ||
public private(set) var rate: String? | ||
|
||
/** | ||
Constructor. | ||
|
||
- parameter assets: The quantity of assets held for the corresponding holding, but converted to a different currency. | ||
- parameter currency: The currency we are computing the current holding in. | ||
- parameter liabilities: The quantity of liabilities for the corresponding holding, but converted to a different currency. | ||
- parameter rate: The rate we used when computing the holding to the corresponding currency. | ||
*/ | ||
public init(assets: String, currency: String, liabilities: String, rate: String) { | ||
self.assets = assets | ||
self.currency = currency | ||
self.liabilities = liabilities | ||
self.rate = rate | ||
} | ||
|
||
// MARK: Required by the ObjectMapper. | ||
|
||
/** | ||
Constructor. | ||
*/ | ||
required public init?(_ map: Map) { | ||
} | ||
|
||
/** | ||
Maps the JSON to the Object. | ||
|
||
- parameter map: The object to map. | ||
*/ | ||
public func mapping(map: Map) { | ||
self.assets <- map["assets"] | ||
self.currency <- map["currency"] | ||
self.liabilities <- map["liabilities"] | ||
self.rate <- map["rate"] | ||
} | ||
|
||
} |
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
Oops, something went wrong.