Update and migrate POA network URLs.

Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
Igor Mandrigin 2019-02-05 10:59:57 +01:00
parent ce28f6df66
commit 27d6816cca
No known key found for this signature in database
GPG Key ID: 4A0EDDE26E66BC8B
3 changed files with 42 additions and 8 deletions

View File

@ -62,7 +62,7 @@
:config {:NetworkId (ethereum/chain-keyword->chain-id :poa)
:DataDir "/ethereum/poa_rpc"
:UpstreamConfig {:Enabled true
:URL "https://poa.infura.io"}}}})
:URL "https://core.poa.network"}}}})
(def testnet-networks
{"testnet" {:id "testnet",

View File

@ -91,6 +91,8 @@
extension/v12
account/v19])
(def v24 v23)
;; put schemas ordered by version
(def schemas [{:schema v1
:schemaVersion 1
@ -160,4 +162,7 @@
:migration (constantly nil)}
{:schema v23
:schemaVersion 23
:migration (constantly nil)}])
:migration (constantly nil)}
{:schema v24
:schemaVersion 24
:migration migrations/v24}])

View File

@ -140,7 +140,12 @@
(get-in constants/testnet-networks ["rinkeby_rpc" :config :UpstreamConfig :URL])
rpc-url))
(defn- update-infura-project-id! [network-js]
(defn transition-poa-rpc-url [rpc-url]
(if (= "https://poa.infura.io" rpc-url)
(get-in constants/sidechain-networks ["poa_rpc" :config :UpstreamConfig :URL])
rpc-url))
(defn- update-rpc-url [network-js transition-func]
(let [old-config (js->clj
(.parse js/JSON
(aget network-js "config")))]
@ -149,24 +154,44 @@
(let [new-config (update-in
old-config
["UpstreamConfig" "URL"]
transition-rpc-url)]
transition-func)]
(aset network-js
"config"
(.stringify js/JSON (clj->js new-config)))))))
(defn- update-infura-project-ids! [networks-js]
(defn- update-rpc-urls! [networks-js update-func]
(dotimes [i (.-length networks-js)]
(let [network-js (aget networks-js i)]
(update-infura-project-id! network-js))))
(update-func network-js))))
(defn- migrate-infura-project-ids! [realm-js]
(defn- migrate-rpc-urls! [realm-js migrate-func]
(let [accounts (.objects realm-js "account")]
(dotimes [i (.-length accounts)]
(let [account (aget accounts i)
networks (aget account "networks")]
(update-infura-project-ids! networks)
(migrate-func networks)
(aset account "networks" networks)))))
;; infura project id update
(defn- update-infura-project-id! [network-js]
(update-rpc-url network-js transition-rpc-url))
(defn- update-infura-project-ids! [networks-js]
(update-rpc-urls! networks-js update-infura-project-id!))
(defn- migrate-infura-project-ids! [realm-js]
(migrate-rpc-urls! realm-js update-infura-project-ids!))
;; poa network url update
(defn- update-poa-network-url! [network-js]
(update-rpc-url network-js transition-poa-rpc-url))
(defn- update-poa-network-urls! [networks-js]
(update-rpc-urls! networks-js update-poa-network-url!))
(defn- migrate-poa-network-urls! [realm-js]
(migrate-rpc-urls! realm-js update-poa-network-urls!))
(defn v18 [old-realm new-realm]
(log/debug "migrating accounts database v18: " old-realm new-realm)
(migrate-infura-project-ids! new-realm))
@ -199,3 +224,7 @@
(defn v21 [old-realm new-realm]
(log/debug "migrating base database v21: " old-realm new-realm))
(defn v24 [old-realm new-realm]
(log/debug "migrating base database v24: " old-realm new-realm)
(migrate-poa-network-urls! new-realm))