Proton

public class Proton : ObservableObject

The Proton class is the heart of the ProtonSwift SDK.

  • The proton config object which is a required param for initialisation of Proton

    See more

    Declaration

    Swift

    public struct Config
  • Proton typealias of the EOSIO.Name

    Declaration

    Swift

    public typealias Name = EOSIO.Name
  • Proton typealias of the EOSIO.PrivateKey

    Declaration

    Swift

    public typealias PrivateKey = EOSIO.PrivateKey
  • Proton typealias of the EOSIO.Asset

    Declaration

    Swift

    public typealias Asset = EOSIO.Asset
  • Proton typealias of the EOSIO.Asset.Symbol

    Declaration

    Swift

    public typealias Symbol = EOSIO.Asset.Symbol
  • Proton typealias of the of WebOperations WebError

    Declaration

    Swift

    public typealias ProtonError = WebError
  • The proton config which gets set during initialisation

    Declaration

    Swift

    public static var config: Config?
  • Use this function as your starting point to initialize the singleton class Proton

    Declaration

    Swift

    @discardableResult
    public static func initialize(_ config: Config) -> Proton

    Parameters

    config

    The configuration object that includes urls for chainProviders

    Return Value

    Initialized Proton singleton

  • The shared instance of the Proton class. Use this for accessing functionality after initialisation of Proton

    Declaration

    Swift

    public static let shared: Proton
  • Checks if user has authentication enabled. At least passcode set is required

    Declaration

    Swift

    public func authenticationEnabled() -> Bool

    Return Value

    Bool

Data Containers

  • Live updated chainProvider.

    Declaration

    Swift

    @Published
    public var chainProvider: ChainProvider? { get set }
  • Live updated array of tokenContracts

    Declaration

    Swift

    @Published
    public var tokenContracts: [TokenContract] { get set }
  • Live updated array of tokenBalances.

    Declaration

    Swift

    @Published
    public var tokenBalances: [TokenBalance] { get set }
  • Live updated array of tokenTransferActions.

    Declaration

    Swift

    @Published
    public var tokenTransferActions: [String : [TokenTransferAction]] { get set }
  • Live updated array of contacts.

    Declaration

    Swift

    @Published
    public var contacts: [Contact] { get set }
  • Live updated array of producers.

    Declaration

    Swift

    @Published
    public var producers: [Producer] { get set }
  • Live updated array of protonESRSessions.

    Declaration

    Swift

    @Published
    public var protonESRSessions: [ProtonESRSession] { get set }
  • Live updated protonESR.

    Declaration

    Swift

    @Published
    public var protonESR: ProtonESR? { get set }
  • Live updated protonESR.

    Declaration

    Swift

    @Published
    public var protonESRAvailable: Bool { get set }
  • Live updated account.

    Declaration

    Swift

    @Published
    public var account: Account? { get set }
  • Live updated GlobalsXPR.

    Declaration

    Swift

    @Published
    public var globalsXPR: GlobalsXPR? { get set }

Data Functions

  • Loads all data objects from disk into memory

    Declaration

    Swift

    public func loadAll()
  • Saves all current data objects that are in memory to disk

    Declaration

    Swift

    public func saveAll()
  • Connects/Reconnects websocket connections needed for ESR requests

    Declaration

    Swift

    public func enableProtonESRWebSocketConnections()
  • Use this to force storing the key into the keychain.

    Declaration

    Swift

    public func store(privateKey: PrivateKey, synchronizable: Bool = false,
                      completion: @escaping ((Result<Bool, Error>) -> Void))

    Parameters

    privateKey

    PrivateKey

    chainId

    chainId for the account

    completion

    Closure returning Result

  • Fetches the account from the chain, the stores private key and sets account active

    Declaration

    Swift

    public func setAccount(withName accountName: String, andPrivateKey privateKey: PrivateKey,
                           completion: @escaping ((Result<Account, Error>) -> Void))

    Parameters

    withName

    Proton account name not including @

    andPrivateKey

    PrivateKey

    chainId

    chainId for the account

    completion

    Closure returning Result

  • Sets the active account, fetchs and updates. This includes, account names, avatars, balances, etc Use this for switching accounts when you know the private key has already been stored.

    Declaration

    Swift

    public func setAccount(withName accountName: String, chainId: String, synchronizable: Bool = false,
                           completion: @escaping ((Result<Account, Error>) -> Void))

    Parameters

    withName

    Proton account name not including @

    chainId

    chainId for the account

    completion

    Closure returning Result

  • Use this function to store the private key and set the account after finding the account you want to save via findAccounts

    Declaration

    Swift

    public func setAccount(_ account: Account, withPrivateKeyString privateKey: String, synchronizable: Bool = false,
                           completion: @escaping ((Result<Account, Error>) -> Void))

    Parameters

    account

    Account object, normally retrieved via findAccounts

    withPrivateKeyString

    Wif formated private key

    completion

    Closure returning Result

  • Fetchs all required data objects from external data sources. This should be done at startup

    Declaration

    Swift

    public func clearAccount(removingPrivateKey: Bool = false)

    Parameters

    removingPrivateKey

    NOT WORKING YET

  • Fetchs all required data objects from external data sources. This should be done at startup

    Declaration

    Swift

    public func updateDataRequirements(completion: @escaping ((Result<Bool, Error>) -> Void))

    Parameters

    completion

    Closure returning Result

  • Updates the GlobalsXPR object. This has information like min required bp votes, staking period, etc.

    Declaration

    Swift

    public func updateGlobalsXPR(completion: @escaping ((Result<Bool, Error>) -> Void))

    Parameters

    completion

    Closure returning Result

  • Updates all TokenContract data objects with latest exchange rates from external data sources.

    Declaration

    Swift

    public func updateExchangeRates(completion: @escaping ((Result<Bool, Error>) -> Void))

    Parameters

    completion

    Closure returning Result

  • Fetchs and updates the active account. This includes, account names, avatars, balances, etc

    Declaration

    Swift

    public func updateAccount(completion: @escaping ((Result<Account, Error>) -> Void))

    Parameters

    completion

    Closure returning Result

  • Changes the account’s userdefined name on chain

    Declaration

    Swift

    public func changeAccountUserDefinedName(withUserDefinedName userDefinedName: String, andPrivateKey privateKey: PrivateKey, completion: @escaping ((Result<Account, Error>) -> Void))

    Parameters

    userDefinedName

    New user defined name

    andPrivateKey

    PrivateKey, FYI, this is used to sign on the device. Private key is never sent.

    completion

    Closure returning Result

  • Changes the account’s avatar on chain

    Declaration

    Swift

    public func changeAccountAvatar(withImage image: AvatarImage, andPrivateKey privateKey: PrivateKey, completion: @escaping ((Result<Account, Error>) -> Void))

    Parameters

    withImage

    AvatarImage which is platform dependent alias. UIImage for iOS, NSImage for macOS

    andPrivateKey

    PrivateKey, FYI, this is used to sign on the device. Private key is never sent.

    completion

    Closure returning Result

  • Changes the account’s userdefined name and avatar on chain

    Declaration

    Swift

    public func changeAccountUserDefinedNameAndAvatar(withUserDefinedName userDefinedName: String, image: AvatarImage, andPrivateKey privateKey: PrivateKey, completion: @escaping ((Result<Account, Error>) -> Void))

    Parameters

    withUserDefinedName

    New user defined name

    image

    AvatarImage

    andPrivateKey

    PrivateKey, FYI, this is used to sign on the device. Private key is never sent.

    completion

    Closure returning Result

  • Use this function to obtain a list of Accounts which match a given private key. These accounts are not stored. If you want to store the Account and private key, you should then call storePrivateKey function

    Declaration

    Swift

    public func findAccounts(forPrivateKeyString privateKey: String, completion: @escaping ((Result<Set<Account>, Error>) -> Void))

    Parameters

    forPrivateKeyString

    Wif formated private key

    completion

    Closure returning Result

  • Checks the chain for presence of account by name

    Declaration

    Swift

    public func chain(hasAccountWithName accountName: String, completion: @escaping ((Result<Bool, Error>) -> Void))

    Parameters

    hasAccountWithName

    String account name

    completion

    Closure returning Result

  • Creates a transfer, signs and pushes that transfer to the chain

    Declaration

    Swift

    public func transfer(withPrivateKey privateKey: PrivateKey, to: Name, quantity: Double, tokenContract: TokenContract, memo: String = "", completion: @escaping ((Result<TokenTransferAction, Error>) -> Void))

    Parameters

    withPrivateKey

    PrivateKey, FYI, this is used to sign on the device. Private key is never sent.

    to

    The account to be transfered to

    quantity

    The amount to be transfered

    tokenContract

    The TokenContract that’s being transfered

    memo

    The memo for the transfer

    completion

    Closure returning Result

  • Stakes XPR

    Declaration

    Swift

    public func stake(withPrivateKey privateKey: PrivateKey, quantity: Double, completion: @escaping ((Result<Any?, Error>) -> Void))

    Parameters

    withPrivateKey

    PrivateKey, FYI, this is used to sign on the device. Private key is never sent.

    quantity

    Amount to added or removed from stake. Postive for adding stake, Negative for removing stake. Cannot be zero

    completion

    Closure returning Result

  • Claims XPR staking rewards

    Declaration

    Swift

    public func claimRewards(withPrivateKey privateKey: PrivateKey, completion: @escaping ((Result<Any?, Error>) -> Void))

    Parameters

    withPrivateKey

    PrivateKey, FYI, this is used to sign on the device. Private key is never sent.

    completion

    Closure returning Result

  • Refunds unstaking amount if the deferred action did not complete

    Declaration

    Swift

    public func refund(withPrivateKey privateKey: PrivateKey, completion: @escaping ((Result<Any?, Error>) -> Void))

    Parameters

    withPrivateKey

    PrivateKey, FYI, this is used to sign on the device. Private key is never sent.

    completion

    Closure returning Result

  • Votes for block producers

    Declaration

    Swift

    public func vote(forProducers producerNames: [Name], withPrivateKey privateKey: PrivateKey, completion: @escaping ((Result<Any?, Error>) -> Void))

    Parameters

    forProducers

    Array of producer Names

    withPrivateKey

    PrivateKey, FYI, this is used to sign on the device. Private key is never sent.

    completion

    Closure returning Result

  • Use this function generate a k1 PrivateKey object. See PrivateKey inside of EOSIO for more details

    Declaration

    Swift

    public func generatePrivateKey() -> PrivateKey?
  • Creates signature by signing arbitrary string

    Declaration

    Swift

    public func signArbitrary(string: String, withPrivateKey privateKey: PrivateKey, completion: @escaping ((Result<Signature, Error>) -> Void))

    Parameters

    withPrivateKey

    PrivateKey, FYI, this is used to sign on the device. Private key is never sent.

    completion

    Closure returning Result

  • Signs and pushes transaction

    Declaration

    Swift

    public func signAndPushTransaction(withActions actions: [Action], andPrivateKey privateKey: PrivateKey, completion: @escaping ((Result<API.V1.Chain.PushTransaction.Response, Error>) -> Void))

    Parameters

    withActions

    [Actions]

    andPrivateKey

    PrivateKey, FYI, this is used to sign on the device. Private key is never sent.

    completion

    Closure returning Result

  • Fetches a single contact’s info without saving to contacts

    Declaration

    Swift

    public func fetchContact(withAccountName accountName: String, completion: @escaping ((Result<Contact?, Error>) -> Void))

    Parameters

    withAccountName

    String

    completion

    Closure returning Result

ESR Functions 🚧 UNDER CONSTRUCTION. DO NOT USE YET