status-lib/status/status.nim

115 lines
4.4 KiB
Nim
Raw Normal View History

import statusgo_backend/accounts as statusgo_backend_accounts
import statusgo_backend/core as statusgo_backend_core
import statusgo_backend/settings as statusgo_backend_settings
import chat, accounts, wallet, wallet2, node, network, messages, contacts, profile, stickers, permissions, fleet, settings, mailservers, tokens, provider
2021-09-08 18:05:39 +00:00
import notifications/os_notifications
import ../eventemitter
import bitops, stew/byteutils, chronicles
import ./types/[setting]
Keycard initial integration (#63) * add nim-keycard-go to makefile * fix keycard-go build * add keycard.nim * remove test make task * remove debug line from makefile * fix import keycard_go * add keycard-go to .PHONY * add keycard start/stop/select methods * use https url for submodule * add KeycardApplication info and return it from select * update nim-keycard-go version * fix select return type * actually return the result * update nim-keycard-go * add keycard methods to backend * add base/mock keycard backends * imports * export keycard methods in backend * update start/stop keycard implementation * add KeycardStarted signal * fix keycard started signal * rename to KeycardConnected signal * fix keycard signal renamed * add keycardgo in makefile tasks * add back build/.gitignore * fix .gitignore * fix .gitignore * Makefile: export keycard vars * add keycard lib to nimble file * use spaces instead of tabs in non-recipe sections of Makefile * use install_name_tool on libkeycard on macOS * in GHA ubuntu environment install libpcsclite-dev with apt at start of workflow * add Keycard exceptions * remove useless test * remove useless return * move keycard types to /types * reraise exception from status/keycard.nim * remove unused import * add keycard commands: opensecure channel, pair, verify pin, export key * fix last keycard commands * add exportKey params * update nim-keycard-go Co-authored-by: Michele Balistreri <michele@bitgamma.com> Co-authored-by: Michael Bradley, Jr <michaelsbradleyjr@gmail.com>
2021-10-04 21:21:07 +00:00
import ./keycard
2021-09-08 18:05:39 +00:00
import ../backends/backend
2021-09-08 18:05:39 +00:00
export chat, accounts, node, messages, contacts, profile, network, permissions, fleet, eventemitter
Keycard initial integration (#63) * add nim-keycard-go to makefile * fix keycard-go build * add keycard.nim * remove test make task * remove debug line from makefile * fix import keycard_go * add keycard-go to .PHONY * add keycard start/stop/select methods * use https url for submodule * add KeycardApplication info and return it from select * update nim-keycard-go version * fix select return type * actually return the result * update nim-keycard-go * add keycard methods to backend * add base/mock keycard backends * imports * export keycard methods in backend * update start/stop keycard implementation * add KeycardStarted signal * fix keycard started signal * rename to KeycardConnected signal * fix keycard signal renamed * add keycardgo in makefile tasks * add back build/.gitignore * fix .gitignore * fix .gitignore * Makefile: export keycard vars * add keycard lib to nimble file * use spaces instead of tabs in non-recipe sections of Makefile * use install_name_tool on libkeycard on macOS * in GHA ubuntu environment install libpcsclite-dev with apt at start of workflow * add Keycard exceptions * remove useless test * remove useless return * move keycard types to /types * reraise exception from status/keycard.nim * remove unused import * add keycard commands: opensecure channel, pair, verify pin, export key * fix last keycard commands * add exportKey params * update nim-keycard-go Co-authored-by: Michele Balistreri <michele@bitgamma.com> Co-authored-by: Michael Bradley, Jr <michaelsbradleyjr@gmail.com>
2021-10-04 21:21:07 +00:00
type Status* = ref object
backend*: Backend
2021-09-08 18:05:39 +00:00
events*: EventEmitter
fleet*: FleetModel
chat*: ChatModel
messages*: MessagesModel
accounts*: AccountModel
wallet*: WalletModel
wallet2*: Wallet2Model
2021-09-08 18:05:39 +00:00
node*: NodeModel
profile*: ProfileModel
contacts*: ContactModel
network*: NetworkModel
stickers*: StickersModel
permissions*: PermissionsModel
settings*: SettingsModel
mailservers*: MailserversModel
tokens*: TokensModel
provider*: ProviderModel
osnotifications*: OsNotifications
Keycard initial integration (#63) * add nim-keycard-go to makefile * fix keycard-go build * add keycard.nim * remove test make task * remove debug line from makefile * fix import keycard_go * add keycard-go to .PHONY * add keycard start/stop/select methods * use https url for submodule * add KeycardApplication info and return it from select * update nim-keycard-go version * fix select return type * actually return the result * update nim-keycard-go * add keycard methods to backend * add base/mock keycard backends * imports * export keycard methods in backend * update start/stop keycard implementation * add KeycardStarted signal * fix keycard started signal * rename to KeycardConnected signal * fix keycard signal renamed * add keycardgo in makefile tasks * add back build/.gitignore * fix .gitignore * fix .gitignore * Makefile: export keycard vars * add keycard lib to nimble file * use spaces instead of tabs in non-recipe sections of Makefile * use install_name_tool on libkeycard on macOS * in GHA ubuntu environment install libpcsclite-dev with apt at start of workflow * add Keycard exceptions * remove useless test * remove useless return * move keycard types to /types * reraise exception from status/keycard.nim * remove unused import * add keycard commands: opensecure channel, pair, verify pin, export key * fix last keycard commands * add exportKey params * update nim-keycard-go Co-authored-by: Michele Balistreri <michele@bitgamma.com> Co-authored-by: Michael Bradley, Jr <michaelsbradleyjr@gmail.com>
2021-10-04 21:21:07 +00:00
keycard*: KeycardModel
2021-09-08 18:05:39 +00:00
proc newStatusInstance*(fleetConfig: string, backendName: string = "statusgo"): Status =
2021-09-08 18:05:39 +00:00
result = Status()
result.backend = newBackend(backendName)
2021-09-08 18:05:39 +00:00
result.events = createEventEmitter()
result.fleet = fleet.newFleetModel(fleetConfig)
result.chat = chat.newChatModel(result.events)
result.accounts = accounts.newAccountModel(result.events)
result.wallet = wallet.newWalletModel(result.events)
result.wallet.initEvents()
result.wallet2 = wallet2.newWallet2Model(result.events)
2021-09-08 18:05:39 +00:00
result.node = node.newNodeModel()
result.messages = messages.newMessagesModel(result.events)
result.profile = profile.newProfileModel()
result.contacts = contacts.newContactModel(result.events)
result.network = network.newNetworkModel(result.events)
result.stickers = stickers.newStickersModel(result.events)
result.permissions = permissions.newPermissionsModel(result.events)
result.settings = settings.newSettingsModel(result.events)
result.mailservers = mailservers.newMailserversModel(result.events)
result.tokens = tokens.newTokensModel(result.events)
2021-09-10 17:27:49 +00:00
result.provider = provider.newProviderModel(result.events, result.permissions, result.wallet)
2021-09-08 18:05:39 +00:00
result.osnotifications = newOsNotifications(result.events)
Keycard initial integration (#63) * add nim-keycard-go to makefile * fix keycard-go build * add keycard.nim * remove test make task * remove debug line from makefile * fix import keycard_go * add keycard-go to .PHONY * add keycard start/stop/select methods * use https url for submodule * add KeycardApplication info and return it from select * update nim-keycard-go version * fix select return type * actually return the result * update nim-keycard-go * add keycard methods to backend * add base/mock keycard backends * imports * export keycard methods in backend * update start/stop keycard implementation * add KeycardStarted signal * fix keycard started signal * rename to KeycardConnected signal * fix keycard signal renamed * add keycardgo in makefile tasks * add back build/.gitignore * fix .gitignore * fix .gitignore * Makefile: export keycard vars * add keycard lib to nimble file * use spaces instead of tabs in non-recipe sections of Makefile * use install_name_tool on libkeycard on macOS * in GHA ubuntu environment install libpcsclite-dev with apt at start of workflow * add Keycard exceptions * remove useless test * remove useless return * move keycard types to /types * reraise exception from status/keycard.nim * remove unused import * add keycard commands: opensecure channel, pair, verify pin, export key * fix last keycard commands * add exportKey params * update nim-keycard-go Co-authored-by: Michele Balistreri <michele@bitgamma.com> Co-authored-by: Michael Bradley, Jr <michaelsbradleyjr@gmail.com>
2021-10-04 21:21:07 +00:00
result.keycard = newKeycardModel(result.backend)
2021-09-08 18:05:39 +00:00
proc initNode*(self: Status, statusGoDir, keystoreDir: string) =
statusgo_backend_accounts.initNode(statusGoDir, keystoreDir)
2021-09-08 18:05:39 +00:00
proc startMessenger*(self: Status) {.exportc, dynlib.} =
statusgo_backend_core.startMessenger()
2021-09-08 18:05:39 +00:00
proc reset*(self: Status) {.exportc, dynlib.} =
2021-09-08 18:05:39 +00:00
# TODO: remove this once accounts are not tracked in the AccountsModel
self.accounts.reset()
# NOT NEEDED self.chat.reset()
# NOT NEEDED self.wallet.reset()
# NOT NEEDED self.node.reset()
# NOT NEEDED self.mailservers.reset()
# NOT NEEDED self.profile.reset()
# TODO: add all resets here
proc getNodeVersion*(self: Status): string {.exportc, dynlib.} =
statusgo_backend_settings.getWeb3ClientVersion()
2021-09-08 18:05:39 +00:00
# TODO: duplicated??
proc saveSetting*(self: Status, setting: Setting, value: string | bool) =
discard statusgo_backend_settings.saveSetting(setting, value)
2021-09-08 18:05:39 +00:00
proc getBloomFilter*(self: Status): string {.exportc, dynlib.} =
result = statusgo_backend_core.getBloomFilter()
2021-09-08 18:05:39 +00:00
proc getBloomFilterBitsSet*(self: Status): int {.exportc, dynlib.} =
let bloomFilter = statusgo_backend_core.getBloomFilter()
2021-09-08 18:05:39 +00:00
var bitCount = 0;
for b in hexToSeqByte(bloomFilter):
bitCount += countSetBits(b)
return bitCount
# C Helpers
# ==============================================================================
# This creates extra functions with a simpler API for C interop. This is to avoid
# having to manually create nim strings, (we can use cstring) instead, and also
# because functions that accept more than one type for the same parameter are not
# exported correctly
proc newStatusInstance*(fleetConfig: cstring): Status {.exportc, dynlib.} =
newStatusInstance($fleetConfig)
proc initNode*(self: Status, statusGoDir, keystoreDir: cstring) {.exportc, dynlib.} =
self.initNode($statusGoDir, $keystoreDir)
proc saveStringSetting*(self: Status, setting: Setting, value: cstring) {.exportc, dynlib.} =
self.saveSetting(setting, $value)
proc saveBoolSetting*(self: Status, setting: Setting, value: bool) {.exportc, dynlib.} =
Keycard initial integration (#63) * add nim-keycard-go to makefile * fix keycard-go build * add keycard.nim * remove test make task * remove debug line from makefile * fix import keycard_go * add keycard-go to .PHONY * add keycard start/stop/select methods * use https url for submodule * add KeycardApplication info and return it from select * update nim-keycard-go version * fix select return type * actually return the result * update nim-keycard-go * add keycard methods to backend * add base/mock keycard backends * imports * export keycard methods in backend * update start/stop keycard implementation * add KeycardStarted signal * fix keycard started signal * rename to KeycardConnected signal * fix keycard signal renamed * add keycardgo in makefile tasks * add back build/.gitignore * fix .gitignore * fix .gitignore * Makefile: export keycard vars * add keycard lib to nimble file * use spaces instead of tabs in non-recipe sections of Makefile * use install_name_tool on libkeycard on macOS * in GHA ubuntu environment install libpcsclite-dev with apt at start of workflow * add Keycard exceptions * remove useless test * remove useless return * move keycard types to /types * reraise exception from status/keycard.nim * remove unused import * add keycard commands: opensecure channel, pair, verify pin, export key * fix last keycard commands * add exportKey params * update nim-keycard-go Co-authored-by: Michele Balistreri <michele@bitgamma.com> Co-authored-by: Michael Bradley, Jr <michaelsbradleyjr@gmail.com>
2021-10-04 21:21:07 +00:00
self.saveSetting(setting, value)