Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 7 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.<br />
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br />
You will also see any lint errors in the console.

### `yarn test`

Launches the test runner in the interactive watch mode.<br />
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.<br />
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.<br />
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 し続ける方法を模索中です。。。
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "3"

services:
nginx:
build: ./nginx/
ports:
- "8008:80"
volumes:
- "./build:/var/www/html"
3 changes: 3 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM nginx

COPY ./conf.d/ /etc/nginx/conf.d/
19 changes: 19 additions & 0 deletions nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
server{
charset utf-8;

location / {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CORS回避

add_header Cache-Control no-cache;
index index.html;
root /var/www/html;
}

location /staking {
proxy_pass https://cosmos-mainnet-s-001.k80s.net;
}
location /txs {
proxy_pass https://cosmos-mainnet-s-001.k80s.net;
}
location /auth {
proxy_pass https://cosmos-mainnet-s-001.k80s.net;
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.8",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1",
Expand Down
139 changes: 121 additions & 18 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,127 @@
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";
import { StdTx, BroadcastReq, auth, BaseAccount } from "cosmos-client/x/auth";
import { sign } from "./sign";
// import Ledger from "@lunie/cosmos-ledger";

const sdk = new CosmosSDK("http://localhost:8008", "cosmoshub-3");
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,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base_req""でいいっぽい

account_number: account.result.account_number,
sequence: seq,
fees: [],
gas: "",
gas_adjustment: "",
gas_prices: [],
simulate: false
},
delegator_address: AccAddress.fromBech32(DELEGATOR_ADDRESS),
validator_address: ValAddress.fromBech32(
"cosmosvaloper1qdxmyqkvt8jsxpn5pp45a38ngs36mn2604cqk9"
),
amount: {
denom: "uatom",
amount: "1"
}
};

console.log(account);

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);

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"
};

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(resp);
};
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
<div>
hello
<button onClick={handleDelegation}>テスト</button>
</div>
);
}
Expand Down
22 changes: 22 additions & 0 deletions src/sign.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Ledger from "@lunie/cosmos-ledger";
import { createSignMessage } from "../node_modules/@lunie/cosmos-js/src/signature";

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: seq,
accountNumber: anum
});

const publicKey = await ledger.getPubKey();
const signature = await ledger.sign(msg);

return {
signatures: signature.toString(`base64`),
publicKey: publicKey.toString(`base64`)
};
};
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"isolatedModules": true,
"noEmit": true,
"jsx": "react",
"noImplicitAny": true
"noImplicitAny": false,
"strictPropertyInitialization": false
},
"include": ["src"]
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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.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"
Expand Down