Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use env vars to specify chain or waku #468

Merged
merged 5 commits into from
Oct 10, 2023
Merged
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
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PUBLIC_BLOCKCHAIN=gnosis
PUBLIC_WAKU=production
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
vite.config.js.timestamp-*
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ pnpm build

You can preview the production build with `pnpm preview`.

## Config

Use env variables to specify:

```bash
# Which waku node to connect to
# Options:
# local single waku node running in docker
# production waku nodes used for production deployment
# Defaults to
PUBLIC_WAKU='production'

# Which blockchain to connect to
# Options:
# local local chain running in docker
# chiado chiado testnet
# gnosis gnosis mainnet
# Defaults to
PUBLIC_BLOCKCHAIN='gnosis'
```

## CLI

There is a built-in command line tool for making development easier.
Expand Down
38 changes: 16 additions & 22 deletions src/lib/adapters/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Contract,
} from 'ethers'
import abi from '$lib/abis/erc20.json'
import { PUBLIC_BLOCKCHAIN } from '$env/static/public'

interface BlockchainExplorer {
name: string
Expand All @@ -26,8 +27,7 @@ interface BlockchainNetwork {
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const testBlockchain: BlockchainNetwork = {
const localBlockchain: BlockchainNetwork = {
name: 'Local testnet',
provider: 'http://127.0.0.1:8545',
nativeToken: {
Expand All @@ -41,7 +41,6 @@ const testBlockchain: BlockchainNetwork = {
},
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const chiadoBlockchain: BlockchainNetwork = {
name: 'Chiado testnet',
provider: 'https://rpc.chiado.apyos.dev/',
Expand Down Expand Up @@ -69,7 +68,6 @@ const chiadoBlockchain: BlockchainNetwork = {
},
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const gnosisBlockchain: BlockchainNetwork = {
name: 'Gnosis',
provider: 'https://gnosis-erigon.apyos.dev/',
Expand Down Expand Up @@ -97,26 +95,22 @@ const gnosisBlockchain: BlockchainNetwork = {
},
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const sepoliaBlockchain: BlockchainNetwork = {
name: 'Sepolia testnet',
provider: 'https://rpc2.sepolia.org/ ',
explorer: {
name: 'Etherscan',
url: 'https://sepolia.etherscan.io/',
},
nativeToken: {
name: 'Sepolia ETH',
symbol: 'SEP',
decimals: 18,
image: 'https://s2.coinmarketcap.com/static/img/coins/64x64/1027.png',
},
objects: {
splitterFactory: '0x0',
},
function getBlockchainNetwork(): BlockchainNetwork {
switch (PUBLIC_BLOCKCHAIN) {
case 'local':
return localBlockchain

case 'chiado':
return chiadoBlockchain

// Defaults to production
case 'gnosis':
default:
return gnosisBlockchain
}
}

export const defaultBlockchainNetwork = gnosisBlockchain
export const defaultBlockchainNetwork = getBlockchainNetwork()

export function getProvider(): Provider {
const providerUrl = defaultBlockchainNetwork.provider
Expand Down
38 changes: 21 additions & 17 deletions src/lib/adapters/waku/waku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,28 @@ import {
type StoreQueryOptions,
type Unsubscribe,
} from '@waku/interfaces'
import { PUBLIC_WAKU } from '$env/static/public'

function getPeers(): string[] {
switch (PUBLIC_WAKU) {
// Local version in docker
case 'local':
return [
'/ip4/127.0.0.1/tcp/8000/ws/p2p/16Uiu2HAm53sojJN72rFbYg6GV2LpRRER9XeWkiEAhjKy3aL9cN5Z',
]

// Defaults to production
case 'production':
default:
return [
'/dns4/go-waku.gra.nomad.apyos.dev/tcp/443/wss/p2p/16Uiu2HAmMafTFmwN9xat1jw7eHnwZJruQiezttwfRaeSgY5hkwe5',
'/dns4/go-waku.de.nomad.apyos.dev/tcp/443/wss/p2p/16Uiu2HAmTwF1VMGkNLXJDj7jLNLMeFwZt8jP8qKS1uojQSCiHib6',
'/dns4/go-waku.bhs.nomad.apyos.dev/tcp/443/wss/p2p/16Uiu2HAm2RwLYewyx3UWZgKT7SQPjASF8AYE3WCyWiM9xupZNCmW',
]
}
}

const peers = [
// use this address for local testing
// '/ip4/127.0.0.1/tcp/8000/ws/p2p/16Uiu2HAm53sojJN72rFbYg6GV2LpRRER9XeWkiEAhjKy3aL9cN5Z',

// '/dns4/ws.waku.apyos.dev/tcp/443/wss/p2p/16Uiu2HAm5wH4dPAV6zDfrBHkWt9Wu9iiXT4ehHdUArDUbEevzmBY',
// '/dns4/ws.waku-1.apyos.dev/tcp/443/wss/p2p/16Uiu2HAm8gXHntr3SB5sde11pavjptaoiqyvwoX3GyEZWKMPiuBu',

// '/dns4/waku.gra.nomad.apyos.dev/tcp/443/wss/p2p/16Uiu2HAmDvywnsGaB32tFqwjTsg8sfC1ZV2EXo3xjxM4V2gvH6Up',
// '/dns4/waku.bhs.nomad.apyos.dev/tcp/443/wss/p2p/16Uiu2HAkvrRkEHRMfe26F8NCWUfzMuaCfyCzwoPSUYG7yminM5Bn',
// '/dns4/waku.de.nomad.apyos.dev/tcp/443/wss/p2p/16Uiu2HAmRgjA134DcoyK8r44pKWJQ69C7McLSWtRgxUVwkKAsbGx',

'/dns4/go-waku.gra.nomad.apyos.dev/tcp/443/wss/p2p/16Uiu2HAmMafTFmwN9xat1jw7eHnwZJruQiezttwfRaeSgY5hkwe5',
'/dns4/go-waku.de.nomad.apyos.dev/tcp/443/wss/p2p/16Uiu2HAmTwF1VMGkNLXJDj7jLNLMeFwZt8jP8qKS1uojQSCiHib6',
'/dns4/go-waku.bhs.nomad.apyos.dev/tcp/443/wss/p2p/16Uiu2HAm2RwLYewyx3UWZgKT7SQPjASF8AYE3WCyWiM9xupZNCmW',

// '/dns4/go-waku.srv02.apyos.dev/tcp/443/wss/p2p/16Uiu2HAmPwoBY7YzjGAkHDzd93wX1rXks7MRMCX7m1Jr2b8jSSwQ',
]
const peers = getPeers()

export type ContentTopic = 'private-message' | 'profile' | 'chats' | 'objects' | 'group-chats'

Expand Down