78 lines
2.4 KiB
Swift
78 lines
2.4 KiB
Swift
//
|
|
// NetworkModelAccount.swift
|
|
// Wallet
|
|
//
|
|
// Created by Igor on 05.11.2020.
|
|
// Copyright © 2020 List. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import EosioSwift
|
|
|
|
extension Network.Model {
|
|
struct Account: Codable {
|
|
let netLimit: Limit
|
|
let cpuLimit: Limit
|
|
let ramUsage: Int
|
|
let ramQuota: Int
|
|
let total: Total
|
|
let delegated: Delegated?
|
|
let refund: Refund?
|
|
}
|
|
}
|
|
|
|
extension Network.Model.Account {
|
|
init(response: EosioRpcAccountResponse) {
|
|
self.init(
|
|
netLimit: .init(
|
|
used: (response.netLimit["used"] as? Int) ?? 0,
|
|
available: (response.netLimit["available"] as? Int) ?? 0,
|
|
max: (response.netLimit["max"] as? Int) ?? 0
|
|
), cpuLimit: .init(
|
|
used: (response.cpuLimit["used"] as? Int) ?? 0,
|
|
available: (response.cpuLimit["available"] as? Int) ?? 0,
|
|
max: (response.cpuLimit["max"] as? Int) ?? 0
|
|
), ramUsage: Int(response.ramUsage.value),
|
|
ramQuota: Int(response.ramQuota.value),
|
|
total: .init(
|
|
netWeight: (response.totalResources?["net_weight"] as? String) ?? "",
|
|
cpuWeight: (response.totalResources?["cpu_weight"] as? String) ?? "",
|
|
ramBytes: (response.totalResources?["ram_bytes"] as? Int) ?? 0
|
|
),
|
|
delegated: condition(response.selfDelegatedBandwidth) {
|
|
.init(netWeight: ($0["net_weight"] as? String) ?? "", cpuWeight: ($0["cpu_weight"] as? String) ?? "")
|
|
},
|
|
refund: condition(response.refundRequest) {
|
|
.init(
|
|
netAmount: ($0["net_amount"] as? String) ?? "",
|
|
cpuAmount: ($0["cpu_amount"] as? String) ?? "",
|
|
requestTime: ($0["request_time"] as? String) ?? ""
|
|
)
|
|
}
|
|
)
|
|
}
|
|
}
|
|
|
|
extension Network.Model.Account {
|
|
struct Limit: Codable {
|
|
let used: Int
|
|
let available: Int
|
|
let max: Int
|
|
}
|
|
struct Refund: Codable {
|
|
let netAmount: String
|
|
let cpuAmount: String
|
|
let requestTime: String
|
|
var date: Date? { requestTime.serverDate() }
|
|
}
|
|
struct Total: Codable {
|
|
let netWeight: String
|
|
let cpuWeight: String
|
|
let ramBytes: Int
|
|
}
|
|
struct Delegated: Codable {
|
|
let netWeight: String
|
|
let cpuWeight: String
|
|
}
|
|
}
|