Skip to content
This repository has been archived by the owner on Jan 7, 2021. It is now read-only.

name app using enigmadev #22

Closed
wants to merge 2 commits into from
Closed
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
63 changes: 23 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

To run this locally against a demo blockchain, you need to set up a few things:

## Set up local servers....

To run this locally against a demo blockchain, you need to set up a few things:
Start enigmadev:

```sh
docker-compose up
```

CI server:
Start the rest-server

```sh
git clone https://github.com/CosmWasm/cosmwasm-js.git
cd cosmwasm-js
./scripts/wasmd/start.sh
./scripts/start_rest_server.sh
```

Fund the faucet

```sh
./scripts/start_rest_server.sh
```

Deploy the contract

```sh
./scripts/deploy_name_service.sh
```

A faucet to provide initial tokens ([see README](https://github.com/CosmWasm/cosmwasm-js/tree/master/packages/faucet)):
NB [WIP for Enigma faucet](https://github.com/levackt/cosmwasm-js/pull/1)

```sh
cd cosmwasm-js
Expand All @@ -24,41 +41,7 @@ yarn dev-start

In the project directory, you can run:

### `yarn start`
### `yarn start:local`

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/).
59 changes: 59 additions & 0 deletions config/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
user nginx;

events {
worker_connections 100;
}
http {
server {
listen 1317;
location / {
if ($request_method = 'OPTIONS') {

add_header 'Access-Control-Allow-Origin' '*';

#
# Om nom nom cookies
#

add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';

#
# Custom headers and headers various browsers *should* be OK with but aren't
#

add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

#
# Tell client that this pre-flight info is valid for 20 days
#

add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;

return 204;
}

if ($request_method = 'POST') {

add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

}

if ($request_method = 'GET') {

add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

}
proxy_pass http://enigmadev:1317;
}
}

}
Binary file added contract.wasm
Binary file not shown.
33 changes: 33 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3'

services:
enigmadev:
# Built from https://github.com/levackt/enigmachain
image: taariq/enigmadev:latest
stdin_open: true
tty: true
networks:
- net
hostname: enigmadev
volumes:
- ".:/root/code"
- "~/.enigmad:/root/.enigmad"
- "~/.enigmacli:/root/.enigmacli"

nginx:
image: nginx:latest
hostname: nginx
volumes:
- "./config/nginx.conf:/etc/nginx/nginx.conf:ro"
depends_on:
- enigmadev
ports:
- "1317:1317"
networks:
- net

networks:
net:

volumes:
shared:
5 changes: 5 additions & 0 deletions scripts/deploy_name_service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
INIT="{\"purchase_price\": {\"denom\": \"uscrt\",\"amount\": \"2000000\"},\"transfer_price\": {\"denom\": \"uscrt\",\"amount\": \"1000000\"}}"
docker-compose exec enigmadev \
enigmacli tx compute instantiate 1 "$INIT" --from a --keyring-backend test --label "my name service" -y \
--keyring-backend test
4 changes: 4 additions & 0 deletions scripts/fund_faucet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
docker-compose exec enigmadev \
enigmacli tx send b enigma1pkptre7fdkl6gfrzlesjjvhxhlc3r4gm277l4c 10000000000uscrt -y \
--keyring-backend test
6 changes: 6 additions & 0 deletions scripts/start_rest_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
docker-compose exec enigmadev \
enigmacli rest-server \
--node tcp://localhost:26657 \
--trust-node \
--laddr tcp://0.0.0.0:1317
2 changes: 1 addition & 1 deletion src/components/ContractLogic/TransferForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const TransferForm: React.FC<TransferFormProps> = ({ handleTransfer, load
{({ handleSubmit }) => (
<Form onSubmit={handleSubmit} className={classes.form}>
<div className={classes.input}>
<FormTextField placeholder="cosmos1234567..." name={ADDRESS_FIELD} type="text" />
<FormTextField placeholder="enigma1234567..." name={ADDRESS_FIELD} type="text" />
</div>
<div>
<Button type="submit" disabled={loading}>
Expand Down
8 changes: 4 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export interface AppConfig {
const local: AppConfig = {
httpUrl: "http://localhost:1317",
faucetUrl: "http://localhost:8000/credit",
codeId: 2,
codeId: 1,
};

const demo: AppConfig = {
httpUrl: "https://lcd.demo-07.cosmwasm.com",
faucetUrl: "https://faucet.demo-07.cosmwasm.com/credit",
codeId: 2,
httpUrl: "http://cors-container.herokuapp.com/http://bootstrap.testnet.enigma.co",
faucetUrl: "https://faucet.testnet.enigma.co/claim",
codeId: 1,
};

// REACT_APP_LOCAL is set via `yarn start:local`
Expand Down
23 changes: 21 additions & 2 deletions src/service/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
SigningCallback,
SigningCosmWasmClient,
} from "@cosmwasm/sdk";
import {FeeTable} from "@cosmwasm/sdk/types/signingcosmwasmclient";
import { StdSignature } from "@cosmwasm/sdk/types/types";
import { Bip39, Random } from "@iov/crypto";

Expand Down Expand Up @@ -40,14 +41,32 @@ export async function burnerWallet(): Promise<Wallet> {
const mnemonic = loadOrCreateMnemonic();
const pen = await Secp256k1Pen.fromMnemonic(mnemonic);
const pubkey = encodeSecp256k1Pubkey(pen.pubkey);
const address = pubkeyToAddress(pubkey, "cosmos");
const address = pubkeyToAddress(pubkey, "enigma");
const signer = (signBytes: Uint8Array): Promise<StdSignature> => pen.sign(signBytes);
return { address, signer };
}

const buildFeeTable = (feeToken: string, gasPrice: number): FeeTable => {
const stdFee = (gas: number, denom: string, price: number) => {
const amount = Math.floor(gas * price);
return {
amount: [{ amount: amount.toString(), denom: denom }],
gas: gas.toString(),
}
};

return {
upload: stdFee(1000000, feeToken, gasPrice),
init: stdFee(500000, feeToken, gasPrice),
exec: stdFee(200000, feeToken, gasPrice),
send: stdFee(80000, feeToken, gasPrice),
}
};

// this creates a new connection to a server at URL,
// using a signing keyring generated from the given mnemonic
export async function connect(httpUrl: string, { address, signer }: Wallet): Promise<ConnectResult> {
const client = new SigningCosmWasmClient(httpUrl, address, signer);
const client = new SigningCosmWasmClient(httpUrl, address, signer,
buildFeeTable("uscrt", 1));
return { address, client };
}
2 changes: 1 addition & 1 deletion src/service/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function SdkProvider(props: SdkProviderProps): JSX.Element {
if (config.faucetUrl) {
const acct = await client.getAccount();
if (!acct?.balance?.length) {
await ky.post(config.faucetUrl, { json: { ticker: "COSM", address } });
await ky.post(config.faucetUrl, { json: { ticker: "SCRT", address } });
}
}

Expand Down