From 5bb4d8f3fd37c974c3ce2d6e6dca11fd7ac86560 Mon Sep 17 00:00:00 2001 From: George Lima Date: Wed, 5 Dec 2018 11:42:46 -0300 Subject: [PATCH 1/5] feature: install got --- app/components/{Layout.js => layout.js} | 0 app/components/{Sidebar.js => sidebar.js} | 0 package.json | 1 + yarn.lock | 117 +++++++++++++++++++++- 4 files changed, 114 insertions(+), 4 deletions(-) rename app/components/{Layout.js => layout.js} (100%) rename app/components/{Sidebar.js => sidebar.js} (100%) diff --git a/app/components/Layout.js b/app/components/layout.js similarity index 100% rename from app/components/Layout.js rename to app/components/layout.js diff --git a/app/components/Sidebar.js b/app/components/sidebar.js similarity index 100% rename from app/components/Sidebar.js rename to app/components/sidebar.js diff --git a/package.json b/package.json index aaac900..6a34517 100644 --- a/package.json +++ b/package.json @@ -86,6 +86,7 @@ "@babel/register": "^7.0.0", "autoprefixer": "^9.3.1", "connected-react-router": "^5.0.1", + "got": "^9.3.2", "history": "^4.7.2", "react": "^16.6.0", "react-dom": "^16.6.0", diff --git a/yarn.lock b/yarn.lock index 697a075..42b8d3c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1074,6 +1074,13 @@ "@shellscape/koa-send" "^4.1.0" debug "^2.6.8" +"@sindresorhus/is@^0.12.0": + version "0.12.0" + resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.12.0.tgz#55c37409c809e802efea25911a579731adfc6e07" + integrity sha512-9ve22cGrAKlSRvi8Vb2JIjzcaaQg79531yQHnF+hi/kOpsSj3Om8AyR1wcHrgl0u7U3vYQ7gmF5erZzOp4+51Q== + dependencies: + symbol-observable "^1.2.0" + "@sindresorhus/is@^0.7.0": version "0.7.0" resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.7.0.tgz#9a06f4f137ee84d7df0460c1fdb1135ffa6c50fd" @@ -1200,6 +1207,13 @@ "@svgr/plugin-svgo" "^4.0.3" loader-utils "^1.1.0" +"@szmarczak/http-timer@^1.1.0": + version "1.1.1" + resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-1.1.1.tgz#6402258dfe467532b26649ef076b4d11f74fb612" + integrity sha512-WljfOGkmSJe8SUkl+4TPvN2ec0dpUGVyfTBQLoXJUiILs+wBSc4Kvp2N3aAWE4VwwDSLGdmD3/bufS5BgZpVSQ== + dependencies: + defer-to-connect "^1.0.1" + "@types/node@^8.0.24": version "8.10.38" resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.38.tgz#e05c201a668492e534b48102aca0294898f449f6" @@ -2741,6 +2755,19 @@ cache-loader@^1.2.2, cache-loader@^1.2.5: neo-async "^2.5.0" schema-utils "^0.4.2" +cacheable-request@^5.1.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/cacheable-request/-/cacheable-request-5.2.0.tgz#00c87097835af4caf92a97390660ecadce51187d" + integrity sha512-h1n0vjpFaByTvU6PiyTKk2kx4OnuV1aVUynCUd/FiKl4icpPSceowk3rHczwFEBuZvz+E1EU4KExR0MCPeQfaQ== + dependencies: + clone-response "^1.0.2" + get-stream "^4.0.0" + http-cache-semantics "^4.0.0" + keyv "^3.0.0" + lowercase-keys "^1.0.1" + normalize-url "^3.1.0" + responselike "^1.0.2" + call-me-maybe@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/call-me-maybe/-/call-me-maybe-1.0.1.tgz#26d208ea89e37b5cbde60250a15f031c16a4d66b" @@ -3130,6 +3157,13 @@ clone-deep@^2.0.1: kind-of "^6.0.0" shallow-clone "^1.0.0" +clone-response@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/clone-response/-/clone-response-1.0.2.tgz#d1dc973920314df67fbeb94223b4ee350239e96b" + integrity sha1-0dyXOSAxTfZ/vrlCI7TuNQI56Ws= + dependencies: + mimic-response "^1.0.0" + clone@^2.1.1, clone@^2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f" @@ -4078,7 +4112,7 @@ decode-uri-component@^0.2.0: resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545" integrity sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU= -decompress-response@^3.2.0: +decompress-response@^3.2.0, decompress-response@^3.3.0: version "3.3.0" resolved "https://registry.yarnpkg.com/decompress-response/-/decompress-response-3.3.0.tgz#80a4dd323748384bfa248083622aedec982adff3" integrity sha1-gKTdMjdIOEv6JICDYirt7Jgq3/M= @@ -4142,6 +4176,11 @@ default-require-extensions@^1.0.0: dependencies: strip-bom "^2.0.0" +defer-to-connect@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/defer-to-connect/-/defer-to-connect-1.0.1.tgz#41ec1dd670dc4c6dcbe7e54c9e44d784d025fe63" + integrity sha512-2e0FJesseUqQj671gvZWfUyxpnFx/5n4xleamlpCD3U6Fm5dh5qzmmLNxNhtmHF06+SYVHH8QU6FACffYTnj0Q== + define-properties@^1.1.2: version "1.1.3" resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.3.tgz#cf88da6cbee26fe6db7094f61d870cbd84cee9f1" @@ -6171,6 +6210,13 @@ get-stream@^3.0.0: resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14" integrity sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ= +get-stream@^4.0.0, get-stream@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-4.1.0.tgz#c1b255575f3dc21d59bfc79cd3d2b46b1c3a54b5" + integrity sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w== + dependencies: + pump "^3.0.0" + get-value@^2.0.3, get-value@^2.0.6: version "2.0.6" resolved "https://registry.yarnpkg.com/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28" @@ -6433,6 +6479,23 @@ got@^7.1.0: url-parse-lax "^1.0.0" url-to-options "^1.0.1" +got@^9.3.2: + version "9.3.2" + resolved "https://registry.yarnpkg.com/got/-/got-9.3.2.tgz#f6e3bd063aa8f461ccd924afa2ba2b61deab3989" + integrity sha512-OyKOUg71IKvwb8Uj0KP6EN3+qVVvXmYsFznU1fnwUnKtDbZnwSlAi7muNlu4HhBfN9dImtlgg9e7H0g5qVdaeQ== + dependencies: + "@sindresorhus/is" "^0.12.0" + "@szmarczak/http-timer" "^1.1.0" + cacheable-request "^5.1.0" + decompress-response "^3.3.0" + duplexer3 "^0.1.4" + get-stream "^4.1.0" + lowercase-keys "^1.0.1" + mimic-response "^1.0.1" + p-cancelable "^1.0.0" + to-readable-stream "^1.0.0" + url-parse-lax "^3.0.0" + graceful-fs@^4.1.0, graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9: version "4.1.15" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00" @@ -6822,6 +6885,11 @@ http-assert@^1.3.0: deep-equal "~1.0.1" http-errors "~1.7.1" +http-cache-semantics@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz#6c2ef57e22090b177828708a52eaeae9d1d63e1b" + integrity sha512-OO/9K7uFN30qwAKvslzmCTbimZ/uRjtdN5S50vvWLwUKqFuZj0n96XyCzF5tHRHEO/Q4JYC01hv41gkX06gmHA== + http-deceiver@^1.2.7: version "1.2.7" resolved "https://registry.yarnpkg.com/http-deceiver/-/http-deceiver-1.2.7.tgz#fa7168944ab9a519d337cb0bec7284dc3e723d87" @@ -8203,6 +8271,11 @@ jsesc@~0.5.0: resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d" integrity sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0= +json-buffer@3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/json-buffer/-/json-buffer-3.0.0.tgz#5b1f397afc75d677bde8bcfc0e47e1f9a3d9a898" + integrity sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg= + json-parse-better-errors@^1.0.1, json-parse-better-errors@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9" @@ -8291,6 +8364,13 @@ keygrip@~1.0.3: resolved "https://registry.yarnpkg.com/keygrip/-/keygrip-1.0.3.tgz#399d709f0aed2bab0a059e0cdd3a5023a053e1dc" integrity sha512-/PpesirAIfaklxUzp4Yb7xBper9MwP6hNRA6BGGUFCgbJ+BM5CKBtsoxinNXkLHAr+GXS1/lSlF2rP7cv5Fl+g== +keyv@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/keyv/-/keyv-3.1.0.tgz#ecc228486f69991e49e9476485a5be1e8fc5c4d9" + integrity sha512-9ykJ/46SN/9KPM/sichzQ7OvXyGDYKGTaDlKMGCAlg2UK8KRy4jb0d8sFc+0Tt0YYnThq8X2RZgCg74RPxgcVA== + dependencies: + json-buffer "3.0.0" + killable@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/killable/-/killable-1.0.1.tgz#4c8ce441187a061c7474fb87ca08e2a638194892" @@ -8834,7 +8914,7 @@ lower-case@^1.1.0, lower-case@^1.1.1, lower-case@^1.1.2: resolved "https://registry.yarnpkg.com/lower-case/-/lower-case-1.1.4.tgz#9a2cabd1b9e8e0ae993a4bf7d5875c39c42e8eac" integrity sha1-miyr0bno4K6ZOkv31YdcOcQujqw= -lowercase-keys@^1.0.0: +lowercase-keys@^1.0.0, lowercase-keys@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-1.0.1.tgz#6f9e30b47084d971a7c820ff15a6c5167b74c26f" integrity sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA== @@ -9231,7 +9311,7 @@ mimic-fn@^1.0.0: resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022" integrity sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ== -mimic-response@^1.0.0: +mimic-response@^1.0.0, mimic-response@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-1.0.1.tgz#4923538878eef42063cb8a3e3b0798781487ab1b" integrity sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ== @@ -9721,7 +9801,7 @@ normalize-range@^0.1.2: resolved "https://registry.yarnpkg.com/normalize-range/-/normalize-range-0.1.2.tgz#2d10c06bdfd312ea9777695a4d28439456b75942" integrity sha1-LRDAa9/TEuqXd2laTShDlFa3WUI= -normalize-url@^3.0.0: +normalize-url@^3.0.0, normalize-url@^3.1.0: version "3.3.0" resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-3.3.0.tgz#b2e1c4dc4f7c6d57743df733a4f5978d18650559" integrity sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg== @@ -10050,6 +10130,11 @@ p-cancelable@^0.3.0: resolved "https://registry.yarnpkg.com/p-cancelable/-/p-cancelable-0.3.0.tgz#b9e123800bcebb7ac13a479be195b507b98d30fa" integrity sha512-RVbZPLso8+jFeq1MfNvgXtCRED2raz/dKpacfTNxsx6pLEpEomM7gah6VeHSYV3+vo0OAi4MkArtQcWWXuQoyw== +p-cancelable@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/p-cancelable/-/p-cancelable-1.0.0.tgz#07e9c6d22c31f9c6784cb4f1e1454a79b6d9e2d6" + integrity sha512-USgPoaC6tkTGlS831CxsVdmZmyb8tR1D+hStI84MyckLOzfJlYQUweomrwE3D8T7u5u5GVuW064LT501wHTYYA== + p-defer@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/p-defer/-/p-defer-1.0.0.tgz#9f6eb182f6c9aa8cd743004a7d4f96b196b0fb0c" @@ -10899,6 +10984,11 @@ prepend-http@^1.0.1: resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc" integrity sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw= +prepend-http@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897" + integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc= + preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" @@ -12227,6 +12317,13 @@ resolve@^1.3.2, resolve@^1.5.0, resolve@^1.6.0, resolve@^1.7.1, resolve@^1.8.1: dependencies: path-parse "^1.0.5" +responselike@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/responselike/-/responselike-1.0.2.tgz#918720ef3b631c5642be068f15ade5a46f4ba1e7" + integrity sha1-kYcg7ztjHFZCvgaPFa3lpG9Loec= + dependencies: + lowercase-keys "^1.0.0" + restore-cursor@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-2.0.0.tgz#9f7ee287f82fd326d4fd162923d62129eee0dfaf" @@ -13631,6 +13728,11 @@ to-object-path@^0.3.0: dependencies: kind-of "^3.0.2" +to-readable-stream@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/to-readable-stream/-/to-readable-stream-1.0.0.tgz#ce0aa0c2f3df6adf852efb404a783e77c0475771" + integrity sha512-Iq25XBt6zD5npPhlLVXGFN3/gyR2/qODcKNNyTMd4vbm39HUaOiAM4PMq0eMVC/Tkxz+Zjdsc55g9yyz+Yq00Q== + to-regex-range@^2.1.0: version "2.1.1" resolved "https://registry.yarnpkg.com/to-regex-range/-/to-regex-range-2.1.1.tgz#7c80c17b9dfebe599e27367e0d4dd5590141db38" @@ -14191,6 +14293,13 @@ url-parse-lax@^1.0.0: dependencies: prepend-http "^1.0.1" +url-parse-lax@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/url-parse-lax/-/url-parse-lax-3.0.0.tgz#16b5cafc07dbe3676c1b1999177823d6503acb0c" + integrity sha1-FrXK/Afb42dsGxmZF3gj1lA6yww= + dependencies: + prepend-http "^2.0.0" + url-parse@^1.1.8, url-parse@^1.4.3: version "1.4.4" resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.4.4.tgz#cac1556e95faa0303691fec5cf9d5a1bc34648f8" From 53171990b7d1ba85ae816306500cd9efc1fbe6da Mon Sep 17 00:00:00 2001 From: George Lima Date: Wed, 5 Dec 2018 11:43:34 -0300 Subject: [PATCH 2/5] feature: add RPC api --- services/api.js | 38 +++ services/utils.js | 827 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 865 insertions(+) create mode 100644 services/api.js create mode 100644 services/utils.js diff --git a/services/api.js b/services/api.js new file mode 100644 index 0000000..0468184 --- /dev/null +++ b/services/api.js @@ -0,0 +1,38 @@ +// @flow +import got from 'got'; + +import { METHODS, type APIMethods } from './utils'; + +// TODO: Fix RPC connect params +const RPC = { + host: 'localhost', + port: 8232, + user: 'george', + password: '123456', +}; + +const client = got.extend({ + method: 'POST', + json: true, + auth: `${RPC.user}:${RPC.password}`, +}); + +// $FlowFixMe +const api: APIMethods = METHODS.reduce( + (obj, method) => ({ + ...obj, + [method]: (...args) => client + .post(`http://${RPC.host}:${RPC.port}`, { + body: { + method, + jsonrpc: '2.0', + id: Date.now(), + params: args, + }, + }) + .then(data => Promise.resolve(data.body && data.body.result)), + }), + {}, +); + +export default api; diff --git a/services/utils.js b/services/utils.js new file mode 100644 index 0000000..356a15b --- /dev/null +++ b/services/utils.js @@ -0,0 +1,827 @@ +// @flow + +export const METHODS = [ + 'getbestblockhash', + 'getblock', + 'getblockchaininfo', + 'getblockcount', + 'getblockhash', + 'getblockheader', + 'getchaintips', + 'getdifficulty', + 'getmempoolinfo', + 'getrawmempool', + 'gettxout', + 'gettxoutproof', + 'gettxoutsetinfo', + 'verifychain', + 'verifytxoutproof', + 'getinfo', + 'help', + 'stop', + 'z_getpaymentdisclosure', + 'z_validatepaymentdisclosure', + 'generate', + 'getgenerate', + 'setgenerate', + 'getblocksubsidy', + 'getblocktemplate', + 'getlocalsolps', + 'getmininginfo', + 'getnetworkhashps', + 'getnetworksolps', + 'prioritisetransaction', + 'submitblock', + 'addnode', + 'clearbanned', + 'disconnectnode', + 'getaddednodeinfo', + 'getconnectioncount', + 'getdeprecationinfo', + 'getnettotals', + 'getnetworkinfo', + 'getpeerinfo', + 'listbanned', + 'ping', + 'setban', + 'createrawtransaction', + 'decoderawtransaction', + 'decodescript', + 'fundrawtransaction', + 'getrawtransaction', + 'sendrawtransaction', + 'signrawtransaction', + 'createmultisig', + 'estimatefee', + 'estimatepriority', + 'validateaddress', + 'verifymessage', + 'z_validateaddress', + 'addmultisigaddress', + 'backupwallet', + 'dumpprivkey', + 'dumpwallet', + 'encryptwallet', + 'getaccount', + 'getaccountaddress', + 'getaddressesbyaccount', + 'getbalance', + 'getnewaddress', + 'getrawchangeaddress', + 'getreceivedbyaccount', + 'getreceivedbyaddress', + 'gettransaction', + 'getunconfirmedbalance', + 'getwalletinfo', + 'importaddress', + 'importprivkey', + 'importwallet', + 'keypoolrefill', + 'listaccounts', + 'listaddressgroupings', + 'listlockunspent', + 'listreceivedbyaccount', + 'listreceivedbyaddress', + 'listsinceblock', + 'listtransactions', + 'listunspent', + 'lockunspent', + 'move', + 'sendfrom', + 'sendmany', + 'sendtoaddress', + 'setaccount', + 'settxfee', + 'signmessage', + 'z_exportkey', + 'z_exportviewingkey', + 'z_exportwallet', + 'z_getbalance', + 'z_getnewaddress', + 'z_getoperationresult', + 'z_getoperationstatus', + 'z_gettotalbalance', + 'z_importkey', + 'z_importviewingkey', + 'z_importwallet', + 'z_listaddresses', + 'z_listoperationids', + 'z_listreceivedbyaddress', + 'z_listunspent', + 'z_mergetoaddress', + 'z_sendmany', + 'z_shieldcoinbase', +]; + +export type APIMethods = { + getbestblockhash: () => Promise, + getblock: ( + hash: string, + ) => Promise<{ + hash: string, + confirmations: number, + size: number, + height: number, + version: number, + merkleroot: string, + finalsaplingroot: string, + tx: string[], + time: number, + nonce: string, + solution: string, + bits: string, + difficulty: number, + chainwork: string, + anchor: string, + valuePools: { + id: string, + monitored: boolean, + chainValue: number, + chainValueZat: number, + valueDelta: number, + valueDeltaZat: number, + }[], + previousblockhash: string, + nextblockhash: string, + }>, + getblockchaininfo: () => Promise<{ + chain: string, + blocks: number, + headers: number, + bestblockhash: string, + difficulty: number, + verificationprogress: number, + chainwork: string, + pruned: boolean, + commitments: number, + valuePools: { + id: string, + monitored: boolean, + chainValue: number, + chainValueZat: number, + }[], + softforks: { + id: string, + version: number, + enforce: { + status: boolean, + found: number, + required: number, + window: number, + }, + reject: { + status: boolean, + found: number, + required: number, + window: number, + }, + }[], + upgrades: { [x: string]: Object }, + consensus: { + chaintip: string, + nextblock: string, + }, + }>, + getblockcount: () => Promise, + getblockhash: (idx: number) => Promise, + getblockheader: ( + hash: string, + ) => Promise<{ + hash: string, + confirmations: number, + height: number, + version: number, + merkleroot: string, + finalsaplingroot: string, + time: number, + nonce: string, + solution: string, + bits: string, + difficulty: number, + chainwork: string, + previousblockhash: string, + nextblockhash: string, + }>, + /* eslint-disable-next-line flowtype/generic-spacing */ + getchaintips: () => Promise< + Array<{ + height: number, + hash: string, + branchlen: number, + status: string, + }>, + >, + getdifficulty: () => Promise, + getmempoolinfo: () => Promise<{ + size: string, + bytes: string, + usage: string, + }>, + getrawmempool: () => Promise, + gettxout: ( + txid: string, + n: number, + includemempool: boolean, + ) => Promise<{ + bestblock: string, + confirmations: number, + value: number, + scriptPubKey: { + asm: string, + hex: string, + reqSigs: number, + type: string, + addresses: string[], + }, + version: number, + coinbase: number, + }>, + gettxoutproof: (txid: string, n: number, includemempool: boolean) => Promise, + gettxoutsetinfo: () => Promise<{ + height: number, + bestblock: string, + transactions: number, + txouts: number, + bytes_serialized: number, + hash_serialized: string, + total_amount: number, + }>, + verifychain: (checklevel: number, numblocks: number) => Promise, + verifytxoutproof: (proof: string) => Promise, + getinfo: () => Promise<{ + version: number, + protocolversion: number, + walletversion: number, + balance: number, + blocks: number, + timeoffset: number, + connections: number, + proxy: string, + difficulty: number, + testnet: boolean, + keypoololdest: number, + keypoolsize: number, + paytxfee: number, + relayfee: number, + errors: string, + }>, + help: () => Promise, + stop: () => Promise, + z_getpaymentdisclosure: (txid: string, js_index: string, output_index: string, message: string) => Promise, + z_validatepaymentdisclosure: (paymentdisclosure: string) => Promise, + generate: (numblocks: number) => Promise, + getgenerate: () => Promise, + setgenerate: (generate: boolean, genproclimit?: number) => Promise, + getblocksubsidy: (height?: number) => Promise<{ miner: number, founders: number }>, + getblocktemplate: ( + jsonrequestobject: string, + ) => Promise<{ + capabilities: string[], + version: number, + previousblockhash: string, + finalsaplingroothash: string, + transactions: { + data: string, + hash: string, + depends: any[], + fee: number, + sigops: number, + }[], + coinbasetxn: { + data: string, + hash: string, + depends: any[], + fee: number, + sigops: number, + foundersreward: number, + required: boolean, + }, + longpollid: string, + target: string, + mintime: number, + mutable: string[], + noncerange: string, + sigoplimit: number, + sizelimit: number, + curtime: number, + bits: string, + height: number, + }>, + getlocalsolps: () => Promise, + getmininginfo: () => Promise<{ + blocks: number, + currentblocksize: number, + currentblocktx: number, + difficulty: number, + errors: string, + genproclimit: number, + localsolps: number, + networksolps: number, + networkhashps: number, + pooledtx: number, + testnet: boolean, + chain: string, + generate: boolean, + }>, + getnetworkhashps: (blocks?: number, height?: number) => Promise, + getnetworksolps: (blocks?: number, height?: number) => Promise, + prioritisetransaction: (txid: string, priorityDelta: number, feeDelta: number) => Promise, + submitblock: ( + hexdata: string, + jsonparametersobject?: string, + ) => Promise<'duplicate' | 'duplicate-invalid' | 'duplicate-inconclusive' | 'inconclusive' | 'rejected'>, + addnode: (node: string, command: string) => Promise, + clearbanned: () => Promise, + disconnectnode: (node: string) => Promise, + getaddednodeinfo: ( + dns?: boolean, + node?: string, + ) => Promise<{ + addednode: string, + connected: number, + addresses: { + address: string, + connected: string, + }[], + }>, + getconnectioncount: () => Promise, + getdeprecationinfo: () => Promise<{ + version: string, + subversion: string, + deprecationheight: number, + }>, + getnettotals: () => Promise<{ + totalbytesrecv: number, + totalbytessent: number, + timemillis: number, + }>, + getnetworkinfo: () => Promise<{ + version: number, + subversion: string, + protocolversion: number, + localservices: string, + timeoffset: number, + connections: number, + networks: { + name: string, + limited: boolean, + reachable: boolean, + proxy: string, + proxy_randomize_credentials: boolean, + }[], + relayfee: number, + localaddresses: { + name: string, + limited: boolean, + reachable: boolean, + proxy: string, + proxy_randomize_credentials: boolean, + }[], + warnings: string, + }>, + getpeerinfo: () => Promise<{ + id: number, + addr: string, + addrlocal: string, + services: string, + lastsend: number, + lastrecv: number, + bytessent: number, + bytesrecv: number, + conntime: number, + timeoffset: number, + pingtime: number, + version: number, + subver: string, + inbound: boolean, + startingheight: number, + banscore: number, + synced_headers: number, + synced_blocks: number, + inflight: any[], + whitelisted: boolean, + }>, + listbanned: () => Promise, + ping: () => Promise, + setban: (ip: string, command: string, bantime?: number, absolute?: number) => Promise, + createrawtransaction: ( + transactions: { txid: string, vout: number, sequence?: number }[], + addresses: { address: number }[], + locktime?: number, + expiryheight?: number, + ) => Promise, + decoderawtransaction: ( + hex: string, + ) => Promise<{ + txid: string, + overwintered: boolean, + version: number, + versiongroupid: string, + locktime: number, + expiryheight: number, + vin: { + txid: string, + vout: number, + scriptSig: { + value: number, + n: number, + scriptPubKey: { + asm: string, + hex: string, + reqSigs: number, + type: string, + addresses: string[], + }, + }, + sequence: number, + }[], + vout: { + value: number, + n: number, + scriptPubKey: { + asm: string, + hex: string, + reqSigs: number, + type: string, + addresses: string[], + }, + }[], + vjoinsplit: { + value: number, + n: number, + scriptPubKey: { + asm: string, + hex: string, + reqSigs: number, + type: string, + addresses: string[], + }, + }[], + }>, + decodescript: ( + hex: string, + ) => Promise<{ + asm: string, + hex: string, + type: string, + reqSigs: string, + addresses: string[], + p2sh: string, + address: string, + }>, + fundrawtransaction: ( + hex: string, + ) => Promise<{ + hex: string, + fee: number, + changepos: string, + }>, + getrawtransaction: ( + txid: string, + ) => Promise<{ + hex: string, + txid: string, + version: number, + locktime: number, + expiryheight: number, + vin: { + txid: string, + vout: number, + scriptSig: { + asm: string, + hex: string, + }, + sequence: number, + }[], + vout: { + value: number, + n: number, + scriptPubKey: { + asm: string, + hex: string, + reqSigs: number, + type: string, + addresses: string[], + }, + }[], + vjoinsplit: { + vpub_old: number, + vpub_new: number, + anchor: string, + nullifiers: string[], + commitments: string[], + onetimePubKey: string, + randomSeed: string, + macs: string[], + proof: string, + ciphertexts: string[], + }[], + blockhash: string, + confirmations: number, + time: number, + blocktime: number, + }>, + sendrawtransaction: (hex: string, allowHighFees?: boolean) => Promise, + signrawtransaction: ( + hex: string, + prevtxs?: Array<{ txid: string, vout: number, scriptPubKey: string, redeemScript: string, amount: number }>, + privatekeys?: string[], + sighashtype?: 'ALL' | 'NONE' | 'SINGLE' | 'ALL|ANYONECANPAY' | 'NONE|ANYONECANPAY' | 'SINGLE|ANYONECANPAY', + branchid?: string, + ) => Promise<{ + hex: string, + complete: boolean, + errors: { txid: string, vout: number, scriptSig: string, sequence: number, error?: string }[], + }>, + createmultisig: (nrequired: number, keys: string[]) => Promise<{ address: string, redeemScript: string }>, + estimatefee: (nblocks: number) => Promise, + estimatepriority: (nblocks: number) => Promise, + validateaddress: ( + zcashaddress: string, + ) => Promise<{ + isvalid: boolean, + address: string, + scriptPubKey: string, + ismine: boolean, + isscript: boolean, + pubkey: string, + iscompressed: boolean, + account: string, + }>, + verifymessage: (zcashaddress: string, signature: string, message: string) => Promise, + z_validateaddress: ( + zaddr: string, + ) => Promise<{ + isvalid: boolean, + address: string, + type: string, + ismine: boolean, + payingkey: string, + transmissionkey: string, + diversifier: string, + diversifiedtransmissionkey: string, + }>, + addmultisigaddress: (nrequired: string, keysobject: { address: string }[], account: string) => Promise, + backupwallet: (destination: string) => Promise, + dumpprivkey: (tAddr: string) => Promise, + dumpwallet: (filename: string) => Promise, + encryptwallet: (passphrase: string) => Promise, + getaccount: (zcashaddress: string) => Promise, + getaccountaddress: (account: string) => Promise, + getaddressesbyaccount: (account: string) => Promise, + getbalance: (account?: string, minconf?: number, includeWatchonly?: boolean) => Promise, + getnewaddress: (account: string) => Promise, + getrawchangeaddress: (address: string) => Promise, + getreceivedbyaccount: (account: string, minconf?: number) => Promise, + getreceivedbyaddress: (zcashaddress: string, minconf?: number) => Promise, + gettransaction: ( + txid: string, + includeWatchonly?: boolean, + ) => Promise<{ + amount: number, + confirmations: number, + blockhash: string, + blockindex: number, + blocktime: number, + txid: string, + time: number, + timereceived: number, + details: { + account: string, + address: string, + category: string, + amount: number, + vout: number, + }[], + vjoinsplit: { + anchor: string, + nullifiers: string[], + commitments: string[], + macs: string[], + vpub_old: number, + vpub_new: number, + }[], + hex: string, + }>, + getunconfirmedbalance: (account: string) => Promise, + getwalletinfo: () => Promise<{ + walletversion: number, + balance: number, + unconfirmed_balance: number, + immature_balance: number, + txcount: number, + keypoololdest: number, + keypoolsize: number, + paytxfee: number, + seedfp: string, + }>, + importaddress: (address: string, label?: string, rescan?: boolean) => Promise, + importprivkey: (zcashprivkey: string, label?: string, rescan?: boolean) => Promise, + importwallet: (filename: string) => Promise, + keypoolrefill: (newsize?: number) => Promise, + listaccounts: (minconf?: number, includeWatchonly?: boolean) => Promise<{ [account: string]: number }>, + listaddressgroupings: () => Promise, + listlockunspent: () => Promise<{ txid: string, vout: number }[]>, + /* eslint-disable flowtype/generic-spacing */ + listreceivedbyaccount: ( + minconf?: number, + includeempty?: boolean, + includeWatchonly?: boolean, + ) => Promise< + { + involvesWatchonly: boolean, + account: string, + amount: number, + confirmations: number, + }[], + >, + listreceivedbyaddress: ( + minconf?: number, + includeempty?: boolean, + includeWatchonly?: boolean, + ) => Promise< + { involvesWatchonly: boolean, account: string, amount: number, confirmations: number, account: string }[], + >, + listsinceblock: ( + blockhash: string, + targetConfirmations?: number, + includeWatchonly?: boolean, + ) => Promise<{ + transactions: { + account: string, + address: string, + category: string, + amount: number, + vout: number, + fee: number, + confirmations: number, + blockhash: string, + blockindex: number, + blocktime: number, + txid: string, + time: number, + timereceived: number, + comment: string, + to: string, + }[], + lastblock: string, + }>, + listtransactions: ( + account?: string, + count?: number, + from?: number, + includeWatchonly?: boolean, + ) => Promise< + { + account: string, + address: string, + amount: number, + vout: number, + fee: number, + confirmations: number, + blockhash: string, + blockindex: number, + txid: string, + time: number, + timereceived: number, + comment: string, + otheraccount: string, + size: number, + }[], + >, + listunspent: ( + minconf?: number, + maxconf?: number, + addresses: string[], + ) => Promise< + { + txid: string, + vout: number, + generated: boolean, + address: string, + account: string, + scriptPubKey: string, + amount: number, + confirmations: number, + redeemScript: number, + spendable: number, + }[], + >, + lockunspent: (unlock: boolean, transactions: { txid: string, vout: string }[]) => Promise, + move: ( + fromaccount: string, + toaccount: string, + amount: number, + minconf?: number, + comment?: string, + ) => Promise, + sendfrom: ( + fromaccount: string, + tozcashaddress: string, + amount: number, + minconf?: number, + comment?: string, + commentTo: string, + ) => Promise, + sendmany: ( + fromaccount: string, + amounts: { [address: string]: number }[], + minconf?: number, + comment?: string, + subtractfeefromamount?: string[], + ) => Promise, + sendtoaddress: ( + zcashaddress: string, + amount: number, + comment?: string, + commentTo?: string, + subtractfeefromamount?: boolean, + ) => Promise, + setaccount: (zcashaddress: string, account: string) => Promise, + settxfee: (amount: number) => Promise, + signmessage: (tAddr: string, message: string) => Promise, + z_exportkey: (zaddr: string) => Promise, + z_exportviewingkey: (zaddr: string) => Promise, + z_exportwallet: (filename: string) => Promise, + z_getbalance: (address: string, minconf?: number) => Promise, + z_getnewaddress: (type: string) => Promise, + z_getoperationresult: (operationid: string) => Promise, + z_getoperationstatus: (operationid: string) => Promise, + z_gettotalbalance: ( + minconf?: number, + includeWatchonly?: boolean, + ) => Promise<{ + transparent: number, + private: number, + total: number, + }>, + z_importkey: (zkey: string, rescan?: 'yes' | 'no' | 'whenkeyisnew', startHeight?: number) => Promise, + z_importviewingkey: (vkey: string, rescan?: 'yes' | 'no' | 'whenkeyisnew', startHeight?: number) => Promise, + z_importwallet: (filename: string) => Promise, + z_listaddresses: (includeWatchonly?: boolean) => Promise, + z_listoperationids: (status?: string) => Promise, + z_listreceivedbyaddress: ( + address: string, + minconf?: number, + ) => Promise<{ + txid: string, + amount: number, + memo: number, + change: boolean, + }>, + z_listunspent: ( + minconf?: number, + maxconf?: number, + includeWatchonly?: boolean, + addresses: string[], + ) => Promise< + { + txid: string, + jsindex: number, + jsoutindex: number, + outindex: number, + confirmations: number, + spendable: boolean, + address: string, + amount: number, + memo: number, + change: boolean, + }[], + >, + z_mergetoaddress: ( + fromaddresses: string[], + toaddress: string, + fee?: number, + transparent_limit?: number, + shielded_limit?: number, + memo?: string, + ) => Promise<{ + remainingUTXOs: number, + remainingTransparentValue: number, + remainingNotes: number, + remainingShieldedValue: number, + mergingUTXOs: number, + mergingTransparentValue: number, + mergingNotes: number, + mergingShieldedValue: number, + opid: number, + }>, + z_sendmany: ( + fromaddress: string, + amounts: { address: string, amount: number, memo?: string }[], + minconf?: number, + fee?: number, + ) => Promise, + z_shieldcoinbase: ( + fromaddress: string, + toaddress: string, + fee?: number, + limit?: number, + ) => Promise<{ + remainingUTXOs: number, + remainingValue: number, + shieldingUTXOs: number, + shieldingValue: number, + opid: number, + }>, +}; From 6941bda31265548fe0afc728d7e665e4b31ebd26 Mon Sep 17 00:00:00 2001 From: George Lima Date: Fri, 7 Dec 2018 10:43:36 -0300 Subject: [PATCH 3/5] hotfix: add -addnode=testnet.z.cash in dev daemon --- config/daemon/zcashd-child-process.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/daemon/zcashd-child-process.js b/config/daemon/zcashd-child-process.js index c889a3d..af09d67 100644 --- a/config/daemon/zcashd-child-process.js +++ b/config/daemon/zcashd-child-process.js @@ -35,7 +35,7 @@ const getDaemonOptions = ({ username, password }) => { `-rpcuser=${username}`, `-rpcpassword=${password}`, ]; - return isDev ? defaultOptions.concat('-testnet') : defaultOptions; + return isDev ? defaultOptions.concat(['-testnet', '-addnode=testnet.z.cash']) : defaultOptions; }; let resolved = false; From fa5540ee1ed885fefcb59369e133a21e50b72109 Mon Sep 17 00:00:00 2001 From: George Lima Date: Fri, 7 Dec 2018 10:45:20 -0300 Subject: [PATCH 4/5] type: fix input types --- app/components/input.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/components/input.js b/app/components/input.js index 459ae30..68ce8fb 100644 --- a/app/components/input.js +++ b/app/components/input.js @@ -9,7 +9,10 @@ const defaultStyles = ` padding: 10px; width: 100%; outline: none; - font-family: ${props => props.theme.fontFamily} + font-family: ${ + // $FlowFixMe + props => props.theme.fontFamily +} `; const Input = styled.input.attrs({ @@ -39,10 +42,10 @@ export const InputComponent = ({ inputType, onChange, ...props }: Props) => { }; if (!Object.keys(inputTypes).find(key => key === inputType)) { - throw new Error(`Invalid input type: ${inputType}`); + throw new Error(`Invalid input type: ${String(inputType)}`); } - return inputTypes[inputType](); + return inputTypes[inputType || 'input'](); }; InputComponent.defaultProps = { From 3863b800eb06cc3871c10589a36f56fb5ef6b857 Mon Sep 17 00:00:00 2001 From: George Lima Date: Fri, 7 Dec 2018 10:46:03 -0300 Subject: [PATCH 5/5] feature: load rpc credentials from store --- services/api.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/services/api.js b/services/api.js index 0468184..259f337 100644 --- a/services/api.js +++ b/services/api.js @@ -1,14 +1,16 @@ // @flow import got from 'got'; +/* eslint-disable-next-line */ +import isDev from 'electron-is-dev'; import { METHODS, type APIMethods } from './utils'; +import store from '../config/electron-store'; -// TODO: Fix RPC connect params const RPC = { - host: 'localhost', - port: 8232, - user: 'george', - password: '123456', + host: '127.0.0.1', + port: isDev ? 18232 : 8232, + user: store.get('rpcuser'), + password: store.get('rpcpassword'), }; const client = got.extend({