From a52bb9d7d1b3f7f8d78ec3008980a1917fc80a3f Mon Sep 17 00:00:00 2001 From: Dragon-taro Date: Mon, 23 Mar 2020 17:07:10 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=E3=83=88=E3=83=A9=E3=83=B3=E3=82=B6?= =?UTF-8?q?=E3=82=AF=E3=82=B7=E3=83=A7=E3=83=B3=E4=BD=9C=E6=88=90=E3=81=AB?= =?UTF-8?q?=E6=8C=91=E6=88=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 61 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index a53698a..23c59af 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,24 +1,49 @@ -import React from 'react'; -import logo from './logo.svg'; -import './App.css'; +import React from "react"; +import { CosmosSDK, AccAddress, ValAddress } from "cosmos-client"; +import { staking, DelegateRequest } from "cosmos-client/x/staking"; + +const sdk = new CosmosSDK( + "https://cosmos-mainnet-s-001.k80s.net/", + "cosmoshub-3" +); +const DELEGATOR_ADDRESS = "cosmos1z52hq26g5n3la3m8sucrpessx33dgedw3cgvn0"; function App() { + const handleDelegation = async () => { + const delegationReq: DelegateRequest = { + base_req: { + from: DELEGATOR_ADDRESS, + memo: "", + chain_id: sdk.chainID, + account_number: "0", + sequence: "1", + fees: [], + gas: "", + gas_adjustment: "", + gas_prices: [], + simulate: false + }, + delegator_address: AccAddress.fromBech32(DELEGATOR_ADDRESS), + validator_address: ValAddress.fromBech32( + "cosmosvaloper1qdxmyqkvt8jsxpn5pp45a38ngs36mn2604cqk9" + ), + amount: { + denom: "uatom", + amount: "0.0001" + } + }; + const unsinedTxs = await staking.postDelegation( + sdk, + AccAddress.fromBech32(DELEGATOR_ADDRESS), + delegationReq + ); + + console.log(unsinedTxs); + }; return ( -
-
- logo -

- Edit src/App.tsx and save to reload. -

- - Learn React - -
+
+ hello +
); } From 7762d825664fb0f4820688649a5fa517d9d73af6 Mon Sep 17 00:00:00 2001 From: Dragon-taro Date: Mon, 23 Mar 2020 23:05:58 +0900 Subject: [PATCH 2/6] =?UTF-8?q?cosmos-client=E3=81=AEupdate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 0c19d9b..24b6880 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "@types/node": "^12.0.0", "@types/react": "^16.9.0", "@types/react-dom": "^16.9.0", - "cosmos-client": "^0.4.1", + "cosmos-client": "^0.4.2", "react": "^16.13.1", "react-dom": "^16.13.1", "react-scripts": "3.4.1", diff --git a/yarn.lock b/yarn.lock index 83ba216..8a3e9a6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3234,10 +3234,10 @@ cosmiconfig@^6.0.0: path-type "^4.0.0" yaml "^1.7.2" -cosmos-client@^0.4.1: - version "0.4.1" - resolved "https://registry.yarnpkg.com/cosmos-client/-/cosmos-client-0.4.1.tgz#195b428dd627ceaab1306ff83caba89150793081" - integrity sha512-cef09ZUQCeoFbQkiF7ukAY0dvPo1Tnj9mLO8YZSI8JKdgLSl5Q7YzFZUJTqXRF0fBqTgCknIA5DOU6sttuzdQg== +cosmos-client@^0.4.2: + version "0.4.2" + resolved "https://registry.yarnpkg.com/cosmos-client/-/cosmos-client-0.4.2.tgz#0def8bc09f65bbffaa4a73b369f16a6f6c5d3e8d" + integrity sha512-dxtN9dXhuOhNh4D2ZKwIABiErfgA0KW04geCWDgjeAgRuBUOYo91mOgeMFWcIliXV1ZObzRZlfvvMvF8rzb8fQ== dependencies: "@types/node-fetch" "^2.5.4" bech32 "^1.1.3" From 91ed3af1d83d954451dfa15f01ced61f776e0200 Mon Sep 17 00:00:00 2001 From: Dragon-taro Date: Tue, 7 Apr 2020 22:57:32 +0900 Subject: [PATCH 3/6] =?UTF-8?q?tx=E3=81=AE=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 48 ++++++--------------------------------- docker-compose.yml | 9 ++++++++ nginx/Dockerfile | 3 +++ nginx/conf.d/default.conf | 13 +++++++++++ src/App.tsx | 22 ++++++++++-------- 5 files changed, 44 insertions(+), 51 deletions(-) create mode 100644 docker-compose.yml create mode 100644 nginx/Dockerfile create mode 100644 nginx/conf.d/default.conf diff --git a/README.md b/README.md index 64e343e..5cd6fc0 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,10 @@ -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). +# 起動方法 -## Available Scripts +Cosmos のサーバーが CORS で怒られるのでなんちゃってプロキシを挟んでいます。 -In the project directory, you can run: +``` +$ yarn build +$ docker-compose up -d +``` -### `yarn start` - -Runs the app in the development mode.
-Open [http://localhost:3000](http://localhost:3000) to view it in the browser. - -The page will reload if you make edits.
-You will also see any lint errors in the console. - -### `yarn test` - -Launches the test runner in the interactive watch mode.
-See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. - -### `yarn build` - -Builds the app for production to the `build` folder.
-It correctly bundles React in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.
-Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -### `yarn eject` - -**Note: this is a one-way operation. Once you `eject`, you can’t go back!** - -If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. - -Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. - -You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. - -## Learn More - -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). - -To learn React, check out the [React documentation](https://reactjs.org/). +フロントをいい感じに build し続ける方法を模索中です。。。 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b6833cd --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +version: "3" + +services: + nginx: + build: ./nginx/ + ports: + - "8008:80" + volumes: + - "./build:/var/www/html" diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 0000000..82af9c7 --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,3 @@ +FROM nginx + +COPY ./conf.d/ /etc/nginx/conf.d/ \ No newline at end of file diff --git a/nginx/conf.d/default.conf b/nginx/conf.d/default.conf new file mode 100644 index 0000000..a106200 --- /dev/null +++ b/nginx/conf.d/default.conf @@ -0,0 +1,13 @@ +server{ + charset utf-8; + + location / { + add_header Cache-Control no-cache; + index index.html; + root /var/www/html; + } + + location /staking { + proxy_pass https://cosmos-mainnet-s-001.k80s.net; + } +} \ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index 23c59af..bd47f6c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,10 +2,7 @@ import React from "react"; import { CosmosSDK, AccAddress, ValAddress } from "cosmos-client"; import { staking, DelegateRequest } from "cosmos-client/x/staking"; -const sdk = new CosmosSDK( - "https://cosmos-mainnet-s-001.k80s.net/", - "cosmoshub-3" -); +const sdk = new CosmosSDK("http://localhost:8008", "cosmoshub-3"); const DELEGATOR_ADDRESS = "cosmos1z52hq26g5n3la3m8sucrpessx33dgedw3cgvn0"; function App() { @@ -29,14 +26,19 @@ function App() { ), amount: { denom: "uatom", - amount: "0.0001" + amount: "1" } }; - const unsinedTxs = await staking.postDelegation( - sdk, - AccAddress.fromBech32(DELEGATOR_ADDRESS), - delegationReq - ); + + const unsinedTxs = await fetch( + sdk.url + `/staking/delegators/${DELEGATOR_ADDRESS}/delegations`, + { + method: "POST", + body: JSON.stringify(delegationReq), + headers: { "Content-Type": "application/json" }, + mode: "cors" + } + ).then(resp => resp.json()); console.log(unsinedTxs); }; From e3f72b744f2b066361c10daa55e5d980b9ea49e3 Mon Sep 17 00:00:00 2001 From: Dragon-taro Date: Mon, 13 Apr 2020 21:19:30 +0900 Subject: [PATCH 4/6] =?UTF-8?q?delegation=E3=81=AETxs=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 28 +++++++++++++++++++--------- tsconfig.json | 3 ++- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index bd47f6c..23b5f98 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,7 @@ import React from "react"; import { CosmosSDK, AccAddress, ValAddress } from "cosmos-client"; import { staking, DelegateRequest } from "cosmos-client/x/staking"; +// import Ledger from "@lunie/cosmos-ledger"; const sdk = new CosmosSDK("http://localhost:8008", "cosmoshub-3"); const DELEGATOR_ADDRESS = "cosmos1z52hq26g5n3la3m8sucrpessx33dgedw3cgvn0"; @@ -30,15 +31,24 @@ function App() { } }; - const unsinedTxs = await fetch( - sdk.url + `/staking/delegators/${DELEGATOR_ADDRESS}/delegations`, - { - method: "POST", - body: JSON.stringify(delegationReq), - headers: { "Content-Type": "application/json" }, - mode: "cors" - } - ).then(resp => resp.json()); + // const unsinedTxs = await fetch( + // sdk.url + `/staking/delegators/${DELEGATOR_ADDRESS}/delegations`, + // { + // method: "POST", + // body: JSON.stringify(delegationReq), + // headers: { "Content-Type": "application/json" }, + // mode: "cors" + // } + // ).then(resp => resp.json()); + + const unsinedTxs = await staking.postDelegation( + sdk, + AccAddress.fromBech32(DELEGATOR_ADDRESS), + delegationReq + ); + + // const ledger = await new Ledger().connect(); + // const signature = await ledger.sign(unsinedTxs); console.log(unsinedTxs); }; diff --git a/tsconfig.json b/tsconfig.json index d1c80df..f31ed4a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,7 +14,8 @@ "isolatedModules": true, "noEmit": true, "jsx": "react", - "noImplicitAny": true + "noImplicitAny": false, + "strictPropertyInitialization": false }, "include": ["src"] } From 1fa62ddc282884b23119e6a086e54338dd371015 Mon Sep 17 00:00:00 2001 From: Dragon-taro Date: Mon, 13 Apr 2020 23:05:38 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=E7=BD=B2=E5=90=8D=E3=81=BE=E3=81=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nginx/conf.d/default.conf | 3 +++ src/App.tsx | 51 +++++++++++++++++++++++++++------------ src/sign.js | 20 +++++++++++++++ 3 files changed, 58 insertions(+), 16 deletions(-) create mode 100644 src/sign.js diff --git a/nginx/conf.d/default.conf b/nginx/conf.d/default.conf index a106200..0b04860 100644 --- a/nginx/conf.d/default.conf +++ b/nginx/conf.d/default.conf @@ -10,4 +10,7 @@ server{ location /staking { proxy_pass https://cosmos-mainnet-s-001.k80s.net; } + location /txs { + proxy_pass https://cosmos-mainnet-s-001.k80s.net; + } } \ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index 23b5f98..9981565 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,8 @@ import React from "react"; import { CosmosSDK, AccAddress, ValAddress } from "cosmos-client"; import { staking, DelegateRequest } from "cosmos-client/x/staking"; +import { StdTx } from "cosmos-client/x/auth"; +import { sign } from "./sign"; // import Ledger from "@lunie/cosmos-ledger"; const sdk = new CosmosSDK("http://localhost:8008", "cosmoshub-3"); @@ -31,26 +33,43 @@ function App() { } }; - // const unsinedTxs = await fetch( - // sdk.url + `/staking/delegators/${DELEGATOR_ADDRESS}/delegations`, - // { - // method: "POST", - // body: JSON.stringify(delegationReq), - // headers: { "Content-Type": "application/json" }, - // mode: "cors" - // } - // ).then(resp => resp.json()); - - const unsinedTxs = await staking.postDelegation( - sdk, - AccAddress.fromBech32(DELEGATOR_ADDRESS), - delegationReq - ); + const unsinedTxs = await fetch( + sdk.url + `/staking/delegators/${DELEGATOR_ADDRESS}/delegations`, + { + method: "POST", + body: JSON.stringify(delegationReq), + headers: { "Content-Type": "application/json" }, + mode: "cors" + } + ).then(resp => resp.json()); + + // const unsinedTxs = await staking.postDelegation( + // sdk, + // AccAddress.fromBech32(DELEGATOR_ADDRESS), + // delegationReq + // ); // const ledger = await new Ledger().connect(); // const signature = await ledger.sign(unsinedTxs); - console.log(unsinedTxs); + const { signatures, publicKey } = await sign(unsinedTxs.value); + const signedTxs = { + tx: { + ...unsinedTxs.value, + signatures, + pub_key: { type: `tendermint/PubKeySecp256k1`, value: publicKey } + }, + mode: "block" + }; + + const result = await fetch(sdk.url + `/txs`, { + method: "POST", + body: JSON.stringify(signedTxs), + headers: { "Content-Type": "application/json" }, + mode: "cors" + }).then(resp => resp.json()); + + console.log(result); }; return (
diff --git a/src/sign.js b/src/sign.js new file mode 100644 index 0000000..9c5ec79 --- /dev/null +++ b/src/sign.js @@ -0,0 +1,20 @@ +import Ledger from "@lunie/cosmos-ledger"; +import { createSignMessage } from "../node_modules/@lunie/cosmos-js/src/signature"; + +export const sign = async tx => { + const ledger = await new Ledger({ testModeAllowed: true }).connect(); + + const msg = createSignMessage(tx, { + chainId: "cosmoshub-3", + sequence: 1, + accountNumber: 1 + }); + + const publicKey = await ledger.getPubKey(); + const signature = await ledger.sign(msg); + + return { + signatures: signature.toString(`base64`), + publicKey: publicKey.toString(`base64`) + }; +}; From 935bf3b000b3a3a66fa17cc0bddb5145cb982087 Mon Sep 17 00:00:00 2001 From: Dragon-taro Date: Tue, 5 May 2020 15:04:25 +0900 Subject: [PATCH 6/6] WIP --- nginx/conf.d/default.conf | 3 ++ package.json | 2 +- src/App.tsx | 79 +++++++++++++++++++++++++++++++-------- src/sign.js | 8 ++-- yarn.lock | 8 ++-- 5 files changed, 76 insertions(+), 24 deletions(-) diff --git a/nginx/conf.d/default.conf b/nginx/conf.d/default.conf index 0b04860..3cd8179 100644 --- a/nginx/conf.d/default.conf +++ b/nginx/conf.d/default.conf @@ -13,4 +13,7 @@ server{ location /txs { proxy_pass https://cosmos-mainnet-s-001.k80s.net; } + location /auth { + proxy_pass https://cosmos-mainnet-s-001.k80s.net; + } } \ No newline at end of file diff --git a/package.json b/package.json index 24b6880..b7d0976 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "@types/node": "^12.0.0", "@types/react": "^16.9.0", "@types/react-dom": "^16.9.0", - "cosmos-client": "^0.4.2", + "cosmos-client": "^0.4.8", "react": "^16.13.1", "react-dom": "^16.13.1", "react-scripts": "3.4.1", diff --git a/src/App.tsx b/src/App.tsx index 9981565..8266ef9 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,7 +1,7 @@ import React from "react"; import { CosmosSDK, AccAddress, ValAddress } from "cosmos-client"; import { staking, DelegateRequest } from "cosmos-client/x/staking"; -import { StdTx } from "cosmos-client/x/auth"; +import { StdTx, BroadcastReq, auth, BaseAccount } from "cosmos-client/x/auth"; import { sign } from "./sign"; // import Ledger from "@lunie/cosmos-ledger"; @@ -10,13 +10,20 @@ const DELEGATOR_ADDRESS = "cosmos1z52hq26g5n3la3m8sucrpessx33dgedw3cgvn0"; function App() { const handleDelegation = async () => { + const account = (await auth.queryAccount( + sdk, + AccAddress.fromBech32(DELEGATOR_ADDRESS) + )) as any; + + const seq = `${Number(account.result.sequence) + 1}`; + const delegationReq: DelegateRequest = { base_req: { from: DELEGATOR_ADDRESS, memo: "", chain_id: sdk.chainID, - account_number: "0", - sequence: "1", + account_number: account.result.account_number, + sequence: seq, fees: [], gas: "", gas_adjustment: "", @@ -33,6 +40,8 @@ function App() { } }; + console.log(account); + const unsinedTxs = await fetch( sdk.url + `/staking/delegators/${DELEGATOR_ADDRESS}/delegations`, { @@ -52,24 +61,62 @@ function App() { // const ledger = await new Ledger().connect(); // const signature = await ledger.sign(unsinedTxs); - const { signatures, publicKey } = await sign(unsinedTxs.value); - const signedTxs = { - tx: { - ...unsinedTxs.value, - signatures, - pub_key: { type: `tendermint/PubKeySecp256k1`, value: publicKey } + const { signatures: s, publicKey } = await sign( + unsinedTxs.value, + account.result.account_number, + seq + ); + console.log(s); + + const signatures: any = [ + { + signature: s, + account_number: account.result.account_number, + sequence: seq, + pub_key: { + type: "tendermint/PubKeySecp256k1", + value: publicKey + } + } + ]; + // const signedTxs = new StdTx( + // unsinedTxs.value.msg, + // { + // ...unsinedTxs.value.fee, + // amount: [{ amount: "48000", denom: "uatom" }] + // }, + // signatures, + // "" + // ); + const signedTxs: any = { + msg: unsinedTxs.value.msg, + signatures, + fee: { + ...unsinedTxs.value.fee, + amount: [{ amount: "48000", denom: "uatom" }] }, + memo: "", + account_number: account.result.account_number, + sequence: seq, + chain_id: sdk.chainID + }; + + const broadcastReq: BroadcastReq = { + tx: signedTxs, mode: "block" }; - const result = await fetch(sdk.url + `/txs`, { - method: "POST", - body: JSON.stringify(signedTxs), - headers: { "Content-Type": "application/json" }, - mode: "cors" - }).then(resp => resp.json()); + console.log(broadcastReq); + + const resp = await auth.broadcast(sdk, broadcastReq); + // const result = await fetch(sdk.url + `/txs`, { + // method: "POST", + // body: JSON.stringify(broadcastReq), + // headers: { "Content-Type": "application/json" }, + // mode: "cors" + // }).then(resp => resp.json()); - console.log(result); + console.log(resp); }; return (
diff --git a/src/sign.js b/src/sign.js index 9c5ec79..69f1117 100644 --- a/src/sign.js +++ b/src/sign.js @@ -1,13 +1,15 @@ import Ledger from "@lunie/cosmos-ledger"; import { createSignMessage } from "../node_modules/@lunie/cosmos-js/src/signature"; -export const sign = async tx => { +export const sign = async (tx, anum, seq) => { const ledger = await new Ledger({ testModeAllowed: true }).connect(); + console.log(anum); + const msg = createSignMessage(tx, { chainId: "cosmoshub-3", - sequence: 1, - accountNumber: 1 + sequence: seq, + accountNumber: anum }); const publicKey = await ledger.getPubKey(); diff --git a/yarn.lock b/yarn.lock index 8a3e9a6..2be939d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3234,10 +3234,10 @@ cosmiconfig@^6.0.0: path-type "^4.0.0" yaml "^1.7.2" -cosmos-client@^0.4.2: - version "0.4.2" - resolved "https://registry.yarnpkg.com/cosmos-client/-/cosmos-client-0.4.2.tgz#0def8bc09f65bbffaa4a73b369f16a6f6c5d3e8d" - integrity sha512-dxtN9dXhuOhNh4D2ZKwIABiErfgA0KW04geCWDgjeAgRuBUOYo91mOgeMFWcIliXV1ZObzRZlfvvMvF8rzb8fQ== +cosmos-client@^0.4.8: + version "0.4.8" + resolved "https://registry.yarnpkg.com/cosmos-client/-/cosmos-client-0.4.8.tgz#e8378d537f46637a5380c82d8f0eb2f1e6a63bf9" + integrity sha512-KW3GfQArYfQ1Em5cRCBWSgmeS4wac/ySNew1OysyAzQSUt+M96rNG1n0b01PmG3c085GYZdFBfxhUVLrCzJ91w== dependencies: "@types/node-fetch" "^2.5.4" bech32 "^1.1.3"