SPB Git

spb/os-vault Public

Self-custody, multi-chain crypto wallet for macOS. One recovery phrase, six chain families, zero API keys — nothing leaves your Mac.

Swift 96% Shell 3.4% Makefile 0.6%
1.8 KB · 58 lines swift
Raw Blame History
1import WalletCoreC2import Foundation3// Copyright © 2017-2018 Trust.4//5// This file is part of Trust. The full Trust copyright notice, including6// terms governing use, modification, and redistribution, is contained in the7// file LICENSE at the root of the source code distribution tree.89import Foundation1011/// An account watch.12public struct Watch: Codable, Equatable {13    /// Coin type.14    public var coin: CoinType1516    /// Account name17    public var name: String1819    /// Account address.20    public var address: String2122    /// Account xpub.23    public var xpub: String?2425    public init(coin: CoinType, name: String, address: String, xpub: String?) {26        self.coin = coin27        self.name = name28        self.address = address29        self.xpub = xpub30    }3132    enum CodingKeys: CodingKey {33        case coin34        case name35        case address36        case xpub37    }3839    public init(from decoder: Decoder) throws {40        let container = try decoder.container(keyedBy: CodingKeys.self)41        guard let coin = CoinType(rawValue: try container.decode(CoinType.RawValue.self, forKey: .coin)) else {42            throw DecodingError.dataCorruptedError(forKey: CodingKeys.coin, in: container, debugDescription: "Invalid coin type")43        }44        self.coin = coin45        name = try container.decodeIfPresent(String.self, forKey: .name) ?? ""46        address = try container.decode(String.self, forKey: .address)47        xpub = try container.decodeIfPresent(String.self, forKey: .xpub)48    }4950    public func encode(to encoder: Encoder) throws {51        var container = encoder.container(keyedBy: CodingKeys.self)52        try container.encode(coin.rawValue, forKey: .coin)53        try container.encode(name, forKey: .name)54        try container.encode(address, forKey: .address)55        try container.encodeIfPresent(xpub, forKey: .xpub)56    }57}58