Allow to connect to any node for dev mode [#4817]

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
Andrey Shovkoplyas 2018-07-15 17:04:00 +03:00
parent d3b28ddbe8
commit e4e6c71600
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
15 changed files with 113 additions and 86 deletions

View File

@ -84,7 +84,7 @@
(into {} (filter network-enabled?
(merge testnet-networks mainnet-networks))))
(def default-wnodes
(def default-wnodes-without-custom
{:testnet {"mailserver-a" {:id "mailserver-a" ;mail-01.do-ams3.eth.beta
:name "Status mailserver A"
:password inbox-password
@ -142,6 +142,9 @@
:password inbox-password
:address "enode://70a2004e78399075f566033c42e9a0b1d43c683d4742755bb5457d03191be66a1b48c2b4fb259696839f28646a5828a1958b900860e27897f984ad0fc8482404@206.189.56.154:30504"}}})
(def default-wnodes
(assoc default-wnodes-without-custom :custom (:testnet default-wnodes-without-custom)))
(defn default-account-settings []
{:wallet {:visible-tokens {:testnet #{:STT :ATT}
:mainnet #{:SNT}}}})

View File

@ -35,9 +35,10 @@
(map :error)
(not-any? identity)))
(defn- new-network [{:keys [random-id] :as cofx} network-name upstream-url type]
(defn- new-network [{:keys [random-id]} network-name upstream-url type network-id]
(let [data-dir (str "/ethereum/" (name type) "_rpc")
config {:NetworkId (ethereum/chain-keyword->chain-id type)
config {:NetworkId (or (when network-id (int network-id))
(ethereum/chain-keyword->chain-id type))
:DataDir data-dir
:UpstreamConfig {:Enabled true
:URL upstream-url}}]
@ -56,8 +57,8 @@
(defn save [{{:networks/keys [manage] :account/keys [account] :as db} :db :as cofx}]
(when (valid-manage? manage)
(let [{:keys [name url chain]} manage
network (new-network cofx (:value name) (:value url) (:value chain))
(let [{:keys [name url chain network-id]} manage
network (new-network cofx (:value name) (:value url) (:value chain) (:value network-id))
new-networks (merge {(:id network) network} (:networks account))]
(handlers-macro/merge-fx cofx
{:db (dissoc db :networks/manage)

View File

@ -40,9 +40,10 @@
(defn- assert-correct-network
[{:keys [db]}]
;; Assure that node was started correctly
(let [{:keys [network web3]} db]
(when-let [network-id (str (get-in db [:account/account :networks network :config :NetworkId]))]
(when web3 ; necessary because of the unit tests
(let [{:keys [web3]} db]
(let [network (get-in db [:account/account :network])
network-id (str (get-in db [:account/account :networks network :config :NetworkId]))]
(when (and network-id web3) ; necessary because of the unit tests
(.getNetwork (.-version web3)
(fn [error fetched-network-id]
(when (and (not error) ; error most probably means we are offline

View File

@ -30,6 +30,7 @@
:on "On"
:off "Off"
:mailserver-connection-error "Could not connect to mailserver"
:custom "Custom"
:camera-access-error "To grant the required camera permission, please go to your system settings and make sure that Status > Camera is selected."
:photos-access-error "To grant the required photos permission, please go to your system settings and make sure that Status > Photos is selected."
@ -671,6 +672,8 @@
:mainnet-network "Main network"
:ropsten-network "Ropsten test network"
:rinkeby-network "Rinkeby test network"
:network-id "Network ID"
:specify-network-id "Specify network id"
;; invalid-key

View File

@ -55,20 +55,14 @@
(defn add-account
"Takes db and new account, creates map of effects describing adding account to database and realm"
[{:keys [network] :networks/keys [networks] :as db} {:keys [address] :as account}]
[{:networks/keys [networks] :as db} {:keys [address] :as account}]
(let [enriched-account (assoc account
:network network
:network config/default-network
:networks networks
:address address)]
{:db (assoc-in db [:accounts/accounts address] enriched-account)
:data-store/base-tx [(accounts-store/save-account-tx enriched-account)]}))
;; TODO(janherich) we have this handler here only because of the tests, refactor/improve tests ASAP
(handlers/register-handler-fx
:add-account
(fn [{:keys [db]} [_ new-account]]
(add-account db new-account)))
(handlers/register-handler-fx
::account-created
[re-frame/trim-v (re-frame/inject-cofx ::get-signing-phrase) (re-frame/inject-cofx ::get-status)]

View File

@ -384,12 +384,10 @@
(handlers/register-handler-fx
:initialize-geth
(fn [{db :db} _]
(let [default-networks (:networks/networks db)
default-network (:network db)
{:keys [network networks]} (:account/account db)
network-config (or (get-in networks [network :config])
(get-in default-networks [default-network :config]))]
{:initialize-geth-fx network-config})))
(when-not (:status-node-started? db)
(let [default-networks (:networks/networks db)
default-network (:network db)]
{:initialize-geth-fx (get-in default-networks [default-network :config])}))))
(handlers/register-handler-fx
:fetch-web3-node-version-callback

View File

@ -11,13 +11,14 @@
[status-im.ui.components.list.views :as list]
[status-im.ui.components.text-input.view :as text-input]
[status-im.ui.screens.network-settings.edit-network.styles :as styles]
[status-im.ui.components.checkbox.view :as checkbox]))
[clojure.string :as string]))
(defn- render-network-type [manage-network type]
(let [name (case type
:mainnet (i18n/label :t/mainnet-network)
:testnet (i18n/label :t/ropsten-network)
:rinkeby (i18n/label :t/rinkeby-network))]
:rinkeby (i18n/label :t/rinkeby-network)
:custom (i18n/label :t/custom))]
[list/list-item-with-checkbox
{:checked? (= (get-in manage-network [:chain :value]) type)
:on-value-change #(re-frame/dispatch [:network-set-input :chain type])
@ -28,35 +29,42 @@
(views/defview edit-network []
(views/letsubs [manage-network [:get-manage-network]
is-valid? [:manage-network-valid?]]
[react/view components.styles/flex
[status-bar/status-bar]
[react/keyboard-avoiding-view components.styles/flex
[toolbar/simple-toolbar (i18n/label :t/add-network)]
[react/scroll-view
[react/view styles/edit-network-view
[text-input/text-input-with-label
{:label (i18n/label :t/name)
:placeholder (i18n/label :t/specify-name)
:container styles/input-container
:default-value (get-in manage-network [:name :value])
:on-change-text #(re-frame/dispatch [:network-set-input :name %])
:auto-focus true}]
[text-input/text-input-with-label
{:label (i18n/label :t/rpc-url)
:placeholder (i18n/label :t/specify-rpc-url)
:container styles/input-container
:default-value (get-in manage-network [:url :value])
:on-change-text #(re-frame/dispatch [:network-set-input :url %])}]
[react/i18n-text {:key :network-chain}]
[react/view styles/network-type
[list/flat-list {:data [:mainnet :testnet :rinkeby]
:key-fn (fn [_ i] (str i))
:separator list/base-separator
:render-fn #(render-network-type manage-network %)}]]]]
[react/view styles/bottom-container
[react/view components.styles/flex]
[components.common/bottom-button
{:forward? true
:label (i18n/label :t/save)
:disabled? (not is-valid?)
:on-press #(re-frame/dispatch [:save-new-network])}]]]]))
(let [custom? (= (get-in manage-network [:chain :value]) :custom)]
[react/view components.styles/flex
[status-bar/status-bar]
[react/keyboard-avoiding-view components.styles/flex
[toolbar/simple-toolbar (i18n/label :t/add-network)]
[react/scroll-view
[react/view styles/edit-network-view
[text-input/text-input-with-label
{:label (i18n/label :t/name)
:placeholder (i18n/label :t/specify-name)
:container styles/input-container
:default-value (get-in manage-network [:name :value])
:on-change-text #(re-frame/dispatch [:network-set-input :name %])
:auto-focus true}]
[text-input/text-input-with-label
{:label (i18n/label :t/rpc-url)
:placeholder (i18n/label :t/specify-rpc-url)
:container styles/input-container
:default-value (get-in manage-network [:url :value])
:on-change-text #(re-frame/dispatch [:network-set-input :url (string/lower-case %)])}]
[react/i18n-text {:key :network-chain}]
[react/view styles/network-type
[list/flat-list {:data [:mainnet :testnet :rinkeby :custom]
:key-fn (fn [_ i] (str i))
:separator list/base-separator
:render-fn #(render-network-type manage-network %)}]]
(when custom?
[text-input/text-input-with-label
{:label (i18n/label :t/network-id)
:container styles/input-container
:placeholder (i18n/label :t/specify-network-id)
:on-change-text #(re-frame/dispatch [:network-set-input :network-id %])}])]]
[react/view styles/bottom-container
[react/view components.styles/flex]
[components.common/bottom-button
{:forward? true
:label (i18n/label :t/save)
:disabled? (not is-valid?)
:on-press #(re-frame/dispatch [:save-new-network])}]]]])))

View File

@ -105,7 +105,8 @@
(let [address? (and (not (nil? address)) (not= address ""))]
[react/view styles/recipient-container
[react/view styles/recipient-icon
[photos/photo (:photo-path contact) {:size list.styles/image-size}]]
(when contact
[photos/photo (:photo-path contact) {:size list.styles/image-size}])]
[react/view {:style styles/recipient-name}
[react/text {:style (styles/participant true)
:accessibility-label (if request? :contact-name-text :recipient-name-text)

View File

@ -142,20 +142,21 @@
(handlers/register-handler-fx
:update-transactions
(fn [{{:keys [network network-status web3] :as db} :db} _]
(when (not= network-status :offline)
(when-not (= network-status :offline)
(let [network (get-in db [:account/account :networks network])
chain (ethereum/network->chain-keyword network)
all-tokens (tokens/tokens-for chain)
token-addresses (map :address all-tokens)]
{:get-transactions {:account-id (get-in db [:account/account :address])
:token-addresses token-addresses
:chain chain
:web3 web3
:success-event :update-transactions-success
:error-event :update-transactions-fail}
:db (-> db
(clear-error-message :transactions-update)
(assoc-in [:wallet :transactions-loading?] true))}))))
chain (ethereum/network->chain-keyword network)]
(when-not (= :custom chain)
(let [all-tokens (tokens/tokens-for chain)
token-addresses (map :address all-tokens)]
{:get-transactions {:account-id (get-in db [:account/account :address])
:token-addresses token-addresses
:chain chain
:web3 web3
:success-event :update-transactions-success
:error-event :update-transactions-fail}
:db (-> db
(clear-error-message :transactions-update)
(assoc-in [:wallet :transactions-loading?] true))}))))))
(defn combine-entries [transaction token-transfer]
(merge transaction (select-keys token-transfer [:symbol :from :to :value :type :token :transfer])))

View File

@ -13,7 +13,8 @@
:rinkeby {:id 4 :name "Rinkeby"}})
(defn chain-id->chain-keyword [i]
(some #(when (= i (:id (val %))) (key %)) chains))
(or (some #(when (= i (:id (val %))) (key %)) chains)
:custom))
(defn chain-keyword->chain-id [k]
(get-in chains [k :id]))

View File

@ -104,7 +104,7 @@
(defn generate-erc20-uri
"Generate a EIP 681 URI encapsulating ERC20 token transfer"
[address {:keys [symbol value chain-id] :as m}]
(when-let [token (tokens/symbol->token (or (ethereum/chain-id->chain-keyword chain-id) :mainnet) symbol)]
(when-let [token (tokens/symbol->token (if chain-id (ethereum/chain-id->chain-keyword chain-id) :mainnet) symbol)]
(generate-uri (:address token)
(merge (dissoc m :value :symbol)
{:function-name "transfer"

View File

@ -424,7 +424,8 @@
{:name "Modest Test Token"
:symbol :MDS
:decimals 18
:address "0x57cc9b83730e6d22b224e9dc3e370967b44a2de0"}])})
:address "0x57cc9b83730e6d22b224e9dc3e370967b44a2de0"}])
:custom []})
(defn tokens-for [chain]
(get all chain))

View File

@ -70,12 +70,4 @@
(rf/dispatch [:load-accounts])
(is (= {(:address account-from-realm) account-from-realm} @accounts)))
(testing ":add-account event"
(let [new-account' (assoc new-account :network constants/default-network)]
(rf/dispatch [:add-account new-account])
(is (= {(:address account-from-realm) account-from-realm
(:address new-account) new-account'} @accounts)))))))
(is (= {(:address account-from-realm) account-from-realm} @accounts))))))

View File

@ -13,6 +13,8 @@
(is (not (model/valid-rpc-url? "http://something with space"))))
(testing "a url without a hostname"
(is (not (model/valid-rpc-url? "https://"))))
(testing "an uppercase HTTP url"
(is (not (model/valid-rpc-url? "HTTP://valid.com"))))
(testing "an http url"
(is (model/valid-rpc-url? "http://valid.com")))
(testing "an https url"
@ -32,7 +34,8 @@
(let [actual (model/new-network {:random-id "random-id"}
"network-name"
"upstream-url"
:mainnet)]
:mainnet
nil)]
(is (= {:id "randomid"
:name "network-name"
:config {:NetworkId 1
@ -41,6 +44,20 @@
:URL "upstream-url"}}}
actual))))
(deftest new-network-id-test
(let [actual (model/new-network {:random-id "random-id"}
"network-name"
"upstream-url"
:mainnet
"5777")]
(is (= {:id "randomid"
:name "network-name"
:config {:NetworkId 5777
:DataDir "/ethereum/mainnet_rpc"
:UpstreamConfig {:Enabled true
:URL "upstream-url"}}}
actual))))
(deftest valid-manage-test
(testing "a valid manage"
(is (model/valid-manage? {:url {:value "http://valid.com"}
@ -83,4 +100,4 @@
:db {:networks/manage {:url {:value "wrong"}
:chain {:value "1"}
:name {:value "empty"}}
:account/account {}}})))))
:account/account {}}})))))

View File

@ -5,9 +5,9 @@
(deftest call-params
(testing "ERC20 balance-of params"
(let [contract "0x29b5f6efad2ad701952dfde9f29c960b5d6199c5"
address "0xa7cfd581060ec66414790691681732db249502bd"]
address "0xa7cfd581060ec66414790691681732db249502bd"]
(is (= (ethereum/call-params contract "balanceOf(address)" address)
{:to "0x29b5f6efad2ad701952dfde9f29c960b5d6199c5"
{:to "0x29b5f6efad2ad701952dfde9f29c960b5d6199c5"
:data "0x70a08231000000000000000000000000a7cfd581060ec66414790691681732db249502bd"})))))
(deftest valid-words?
@ -20,3 +20,9 @@
(ethereum/passphrase->words "one two three for five six seven height nine ten eleven twelve"))
(= ["one" "two" "three" "for" "five" "six" "seven" "height" "nine" "ten" "eleven" "twelve"]
(ethereum/passphrase->words " one two three for five six seven height nine ten eleven twelve "))))
(deftest chain-id->chain-keyword
(is (= (ethereum/chain-id->chain-keyword 1) :mainnet))
(is (= (ethereum/chain-id->chain-keyword 3) :testnet))
(is (= (ethereum/chain-id->chain-keyword 4) :rinkeby))
(is (= (ethereum/chain-id->chain-keyword 5777) :custom)))