fix: network serialization (#28)

This commit is contained in:
Anthony Laibe 2021-09-16 23:30:29 +02:00 committed by GitHub
parent 12a8b59780
commit 87dd134eac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 48 deletions

View File

@ -174,66 +174,66 @@ var NODE_CONFIG* = %* {
}, },
"Networks": [ "Networks": [
{ {
"chain_id": 1, "chainId": 1,
"chain_name": "Ethereum Mainnet", "chainName": "Ethereum Mainnet",
"rpc_url": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED, "rpcUrl": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED,
"block_explorer_url": "https://etherscan.io/", "blockExplorerUrl": "https://etherscan.io/",
"icon_url": "", "iconUrl": "",
"native_currency_name": "Ether", "nativeCurrencyName": "Ether",
"native_currency_symbol": "ETH", "nativeCurrencySymbol": "ETH",
"native_currency_decimals": 18, "nativeCurrencyDecimals": 18,
"isTest": false, "isTest": false,
"layer": 1, "layer": 1,
"enabled": true, "enabled": true,
}, },
{ {
"chain_id": 3, "chainId": 3,
"chain_name": "Ropsten", "chainName": "Ropsten",
"rpc_url": "https://ropsten.infura.io/v3/" & INFURA_TOKEN_RESOLVED, "rpcUrl": "https://ropsten.infura.io/v3/" & INFURA_TOKEN_RESOLVED,
"block_explorer_url": "https://ropsten.etherscan.io/", "blockExplorerUrl": "https://ropsten.etherscan.io/",
"icon_url": "", "iconUrl": "",
"native_currency_name": "Ether", "nativeCurrencyName": "Ether",
"native_currency_symbol": "ETH", "nativeCurrencySymbol": "ETH",
"native_currency_decimals": 18, "nativeCurrencyDecimals": 18,
"isTest": true, "isTest": true,
"layer": 1, "layer": 1,
"enabled": false, "enabled": false,
}, },
{ {
"chain_id": 4, "chainId": 4,
"chain_name": "Rinkeby", "chainName": "Rinkeby",
"rpc_url": "https://rinkeby.infura.io/v3/" & INFURA_TOKEN_RESOLVED, "rpcUrl": "https://rinkeby.infura.io/v3/" & INFURA_TOKEN_RESOLVED,
"block_explorer_url": "https://rinkeby.etherscan.io/", "blockExplorerUrl": "https://rinkeby.etherscan.io/",
"icon_url": "", "iconUrl": "",
"native_currency_name": "Ether", "nativeCurrencyName": "Ether",
"native_currency_symbol": "ETH", "nativeCurrencySymbol": "ETH",
"native_currency_decimals": 18, "nativeCurrencyDecimals": 18,
"isTest": true, "isTest": true,
"layer": 1, "layer": 1,
"enabled": false, "enabled": false,
}, },
{ {
"chain_id": 5, "chainId": 5,
"chain_name": "Goerli", "chainName": "Goerli",
"rpc_url": "http://goerli.blockscout.com/", "rpcUrl": "http://goerli.blockscout.com/",
"block_explorer_url": "https://goerli.etherscan.io/", "blockExplorerUrl": "https://goerli.etherscan.io/",
"icon_url": "", "iconUrl": "",
"native_currency_name": "Ether", "nativeCurrencyName": "Ether",
"native_currency_symbol": "ETH", "nativeCurrencySymbol": "ETH",
"native_currency_decimals": 18, "nativeCurrencyDecimals": 18,
"isTest": true, "isTest": true,
"layer": 1, "layer": 1,
"enabled": false, "enabled": false,
}, },
{ {
"chain_id": 10, "chainId": 10,
"chain_name": "Optimistic Ethereum", "chainName": "Optimistic Ethereum",
"rpc_url": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED, "rpcUrl": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED,
"block_explorer_url": "https://optimistic.etherscan.io", "blockExplorerUrl": "https://optimistic.etherscan.io",
"icon_url": "", "iconUrl": "",
"native_currency_name": "Ether", "nativeCurrencyName": "Ether",
"native_currency_symbol": "ETH", "nativeCurrencySymbol": "ETH",
"native_currency_decimals": 18, "nativeCurrencyDecimals": 18,
"isTest": false, "isTest": false,
"layer": 2, "layer": 2,
"enabled": true, "enabled": true,

View File

@ -27,7 +27,7 @@ type
StatusWalletController* = ref object StatusWalletController* = ref object
events: EventEmitter events: EventEmitter
accounts: seq[WalletAccount] accounts: seq[WalletAccount]
networks: seq[Network] networks*: seq[Network]
tokens: seq[Erc20Contract] tokens: seq[Erc20Contract]
totalBalance*: float totalBalance*: float

View File

@ -1,4 +1,4 @@
from json import JsonNode, `%*` from json import JsonNode, `%*`, parseJson
from strformat import fmt from strformat import fmt
import json_serialization 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})" return fmt"Network(chainID:{self.chainID}, name:{self.chainName}, rpcURL:{self.rpcURL}, isTest:{self.isTest}, enabled:{self.enabled})"
proc toPayload*(self: Network): JsonNode = proc toPayload*(self: Network): JsonNode =
return %* [{ return %* [Json.encode(self).parseJson]
"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
}]