From 87dd134eace065301a1e9ff6e242709a0135b133 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Thu, 16 Sep 2021 23:30:29 +0200 Subject: [PATCH] fix: network serialization (#28) --- .../statusgo_backend/accounts/constants.nim | 80 +++++++++---------- status/wallet2.nim | 2 +- status/wallet2/network.nim | 9 +-- 3 files changed, 43 insertions(+), 48 deletions(-) diff --git a/status/statusgo_backend/accounts/constants.nim b/status/statusgo_backend/accounts/constants.nim index f01b8b8..20afdf4 100644 --- a/status/statusgo_backend/accounts/constants.nim +++ b/status/statusgo_backend/accounts/constants.nim @@ -174,66 +174,66 @@ var NODE_CONFIG* = %* { }, "Networks": [ { - "chain_id": 1, - "chain_name": "Ethereum Mainnet", - "rpc_url": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED, - "block_explorer_url": "https://etherscan.io/", - "icon_url": "", - "native_currency_name": "Ether", - "native_currency_symbol": "ETH", - "native_currency_decimals": 18, + "chainId": 1, + "chainName": "Ethereum Mainnet", + "rpcUrl": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED, + "blockExplorerUrl": "https://etherscan.io/", + "iconUrl": "", + "nativeCurrencyName": "Ether", + "nativeCurrencySymbol": "ETH", + "nativeCurrencyDecimals": 18, "isTest": false, "layer": 1, "enabled": true, }, { - "chain_id": 3, - "chain_name": "Ropsten", - "rpc_url": "https://ropsten.infura.io/v3/" & INFURA_TOKEN_RESOLVED, - "block_explorer_url": "https://ropsten.etherscan.io/", - "icon_url": "", - "native_currency_name": "Ether", - "native_currency_symbol": "ETH", - "native_currency_decimals": 18, + "chainId": 3, + "chainName": "Ropsten", + "rpcUrl": "https://ropsten.infura.io/v3/" & INFURA_TOKEN_RESOLVED, + "blockExplorerUrl": "https://ropsten.etherscan.io/", + "iconUrl": "", + "nativeCurrencyName": "Ether", + "nativeCurrencySymbol": "ETH", + "nativeCurrencyDecimals": 18, "isTest": true, "layer": 1, "enabled": false, }, { - "chain_id": 4, - "chain_name": "Rinkeby", - "rpc_url": "https://rinkeby.infura.io/v3/" & INFURA_TOKEN_RESOLVED, - "block_explorer_url": "https://rinkeby.etherscan.io/", - "icon_url": "", - "native_currency_name": "Ether", - "native_currency_symbol": "ETH", - "native_currency_decimals": 18, + "chainId": 4, + "chainName": "Rinkeby", + "rpcUrl": "https://rinkeby.infura.io/v3/" & INFURA_TOKEN_RESOLVED, + "blockExplorerUrl": "https://rinkeby.etherscan.io/", + "iconUrl": "", + "nativeCurrencyName": "Ether", + "nativeCurrencySymbol": "ETH", + "nativeCurrencyDecimals": 18, "isTest": true, "layer": 1, "enabled": false, }, { - "chain_id": 5, - "chain_name": "Goerli", - "rpc_url": "http://goerli.blockscout.com/", - "block_explorer_url": "https://goerli.etherscan.io/", - "icon_url": "", - "native_currency_name": "Ether", - "native_currency_symbol": "ETH", - "native_currency_decimals": 18, + "chainId": 5, + "chainName": "Goerli", + "rpcUrl": "http://goerli.blockscout.com/", + "blockExplorerUrl": "https://goerli.etherscan.io/", + "iconUrl": "", + "nativeCurrencyName": "Ether", + "nativeCurrencySymbol": "ETH", + "nativeCurrencyDecimals": 18, "isTest": true, "layer": 1, "enabled": false, }, { - "chain_id": 10, - "chain_name": "Optimistic Ethereum", - "rpc_url": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED, - "block_explorer_url": "https://optimistic.etherscan.io", - "icon_url": "", - "native_currency_name": "Ether", - "native_currency_symbol": "ETH", - "native_currency_decimals": 18, + "chainId": 10, + "chainName": "Optimistic Ethereum", + "rpcUrl": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED, + "blockExplorerUrl": "https://optimistic.etherscan.io", + "iconUrl": "", + "nativeCurrencyName": "Ether", + "nativeCurrencySymbol": "ETH", + "nativeCurrencyDecimals": 18, "isTest": false, "layer": 2, "enabled": true, diff --git a/status/wallet2.nim b/status/wallet2.nim index a1f9e98..afe769d 100644 --- a/status/wallet2.nim +++ b/status/wallet2.nim @@ -27,7 +27,7 @@ type StatusWalletController* = ref object events: EventEmitter accounts: seq[WalletAccount] - networks: seq[Network] + networks*: seq[Network] tokens: seq[Erc20Contract] totalBalance*: float diff --git a/status/wallet2/network.nim b/status/wallet2/network.nim index ad2e24f..4258fd0 100644 --- a/status/wallet2/network.nim +++ b/status/wallet2/network.nim @@ -1,4 +1,4 @@ -from json import JsonNode, `%*` +from json import JsonNode, `%*`, parseJson from strformat import fmt import json_serialization @@ -19,9 +19,4 @@ proc `$`*(self: Network): string = return fmt"Network(chainID:{self.chainID}, name:{self.chainName}, rpcURL:{self.rpcURL}, isTest:{self.isTest}, enabled:{self.enabled})" proc toPayload*(self: Network): JsonNode = - return %* [{ - "chain_id": self.chainID, "native_currency_decimals": self.nativeCurrencyDecimals, "layer": self.layer, - "chain_name": self.chainName, "rpc_url": self.rpcURL, "block_explorer_url": self.blockExplorerURL, - "icon_url": self.iconURL, "native_currency_name": self.nativeCurrencyName, - "native_currency_symbol": self.nativeCurrencySymbol, "is_test": self.isTest, "enabled": self.enabled - }] \ No newline at end of file + return %* [Json.encode(self).parseJson] \ No newline at end of file