Skip to content

Commit

Permalink
Add Amino support for CommunityPoolSpendProposal (#4811)
Browse files Browse the repository at this point in the history
* - upgrade cosmjs to 0.31.0, use createAltGovAminoConverters to register CommunitySpend in MsgSubmitProposal
- encodeCommunitySpend to utils, devnet tests for communitySpend
- DRY up tests and add amino tests for all
- null check for mindeposit.denom to fix intermittent bug

* Bootstrap mod (#4872)

fix dasel syntax
unstaked tokens visible in keplr
fix platform for docker
update wiki
new image ref for CI tests

* migration for more keplr-friendly chain names
  • Loading branch information
mhagel authored Aug 23, 2023
1 parent 557afaa commit d2e5e96
Show file tree
Hide file tree
Showing 33 changed files with 674 additions and 469 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ jobs:
ports:
- 3000:3000
cosmos_test_app:
image: irowan/heroku-csdk
image: mhagel1/csdk-v1
ports:
- 5050:5050
cosmos_beta_test_app:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"@capacitor/core": "^4.3.0",
"@capacitor/ios": "^4.3.0",
"@capacitor/splash-screen": "^4.1.0",
"@cosmjs/stargate": "^0.26.1",
"@cosmjs/tendermint-rpc": "^0.26.1",
"@cosmjs/stargate": "^0.31.0",
"@cosmjs/tendermint-rpc": "^0.31.0",
"@solana/web3.js": "^1.30.2",
"@types/moment": "^2.13.0",
"axios": "^1.3.4",
Expand Down
17 changes: 2 additions & 15 deletions packages/chain-events/cosmos-chain-testing/v1/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
# Simple usage with a mounted data directory:
# > docker build -t simapp .
#
# Server:
# > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simapp:/root/.simapp simapp simd init test-chain
# TODO: need to set validator in genesis so start runs
# > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simapp:/root/.simapp simapp simd start
#
# Client: (Note the simapp binary always looks at ~/.simapp we can bind to different local storage)
# > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simappcli:/root/.simapp simapp simd keys add foo
# > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simappcli:/root/.simapp simapp simd keys list
# TODO: demo connecting rest-server (or is this in server now?)

FROM golang:1.19-alpine AS build-env

FROM --platform=linux/amd64 golang:1.19-alpine AS build-env

# Install minimum necessary dependencies
ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3 py3-pip build-base dasel nginx
Expand All @@ -33,9 +23,6 @@ RUN make build \

WORKDIR /root

# ADD https://simd-binary.s3.amazonaws.com/simd /usr/bin/simd
# COPY simd /usr/bin/simd

EXPOSE ${PORT}
EXPOSE 5050
COPY nginx.conf /etc/nginx/nginx.conf
Expand Down
63 changes: 40 additions & 23 deletions packages/chain-events/cosmos-chain-testing/v1/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,70 @@ CONFIG_FOLDER=$CSDK_HOME/config
GENESIS=$CONFIG_FOLDER/genesis.json
# You can add this mnemonic to keplr to use the UI
COW_MNEMONIC="ignore medal pitch lesson catch stadium victory jewel first stairs humble excuse scrap clutch cup daughter bench length sell goose deliver critic favorite thought"
CSDK_CHAIN_ID="testnet"
CSDK_CHAIN_ID="csdkv1-1"

### start nginx
sed -i "s/listen\ 80;/listen\ ${PORT:=5050};/" /etc/nginx/nginx.conf
echo "starting nginx"
nginx

### intialize the chain
simd init csdk-local --chain-id $CSDK_CHAIN_ID
simd init csdk-v1 --chain-id $CSDK_CHAIN_ID
simd config keyring-backend test
simd config chain-id $CSDK_CHAIN_ID
simd config broadcast-mode block
simd config output json
echo $COW_MNEMONIC | simd keys add cow --recover --keyring-backend=test --home $CSDK_HOME
# make cow a validator:
simd add-genesis-account cow 1000000000000stake
simd gentx cow 7000000000stake --chain-id testnet
simd collect-gentxs
# Update gov module
simd config node http://localhost:26657

### Configure chain generated config files - genesis.json, app.toml, config.toml
dasel put string -r json -f $GENESIS -v '600s' '.app_state.gov.voting_params.voting_period'
dasel put string -r json -f $GENESIS -v '100000' '.app_state.gov.deposit_params.min_deposit.[0].amount'
# Update denom references
dasel put -t string -r json -f $GENESIS -v "ustake" '.app_state.staking.params.bond_denom'
dasel put -t string -r json -f $GENESIS -v "240s" '.app_state.staking.params.unbonding_time'

dasel put -t string -r json -f $GENESIS -v "ustake" '.app_state.txfees.basedenom'
dasel put -t string -r json -f $GENESIS -v "ustake" '.app_state.crisis.constant_fee.denom'
dasel put -t string -r json -f $GENESIS -v "ustake" '.app_state.mint.params.mint_denom'

# Update gov module
dasel put -t string -r json -f $GENESIS -v "90s" '.app_state.gov.voting_params.voting_period'
dasel put -t string -r json -f $GENESIS -v "2000000" '.app_state.gov.deposit_params.min_deposit.[0].amount'
dasel put -t string -r json -f $GENESIS -v "ustake" '.app_state.gov.deposit_params.min_deposit.[0].denom'

# decrease block-time so tests run faster
sed -i "s/timeout_commit = \"5s\"/timeout_commit = \"500ms\"/g" $CONFIG_FOLDER/config.toml
# bind on all interfaces, enabling ports to be exposed outside docker
sed -i "s/127\.0\.0\.1/0.0.0.0/g" $CONFIG_FOLDER/config.toml

# expose the LCD
dasel put bool -r toml -f $CONFIG_FOLDER/app.toml -v "true" '.api.enable'
dasel put -t bool -r toml -f $CONFIG_FOLDER/app.toml -v "true" '.api.enable'
dasel put -t string -r toml -f $CONFIG_FOLDER/app.toml -v "tcp://0.0.0.0:1317" '.api.address'

# Expose the rpc
dasel put string -r toml -f $CONFIG_FOLDER/config.toml -v "tcp://0.0.0.0:26657" '.rpc.laddr'
dasel put -t string -r toml -f $CONFIG_FOLDER/config.toml -v "tcp://0.0.0.0:26657" '.rpc.laddr'

# Enable cors on RPC
dasel put string -r toml -f $CONFIG_FOLDER/config.toml -v "*" '.rpc.cors_allowed_origins.[]'
dasel put string -r toml -f $CONFIG_FOLDER/config.toml -v "Accept-Encoding" '.rpc.cors_allowed_headers.[]'
dasel put string -r toml -f $CONFIG_FOLDER/config.toml -v "DELETE" '.rpc.cors_allowed_methods.[]'
dasel put string -r toml -f $CONFIG_FOLDER/config.toml -v "OPTIONS" '.rpc.cors_allowed_methods.[]'
dasel put string -r toml -f $CONFIG_FOLDER/config.toml -v "PATCH" '.rpc.cors_allowed_methods.[]'
dasel put string -r toml -f $CONFIG_FOLDER/config.toml -v "PUT" '.rpc.cors_allowed_methods.[]'
dasel put -t string -r toml -f $CONFIG_FOLDER/config.toml -v "*" '.rpc.cors_allowed_origins.[]'
dasel put -t string -r toml -f $CONFIG_FOLDER/config.toml -v "Accept-Encoding" '.rpc.cors_allowed_headers.[]'
dasel put -t string -r toml -f $CONFIG_FOLDER/config.toml -v "DELETE" '.rpc.cors_allowed_methods.[]'
dasel put -t string -r toml -f $CONFIG_FOLDER/config.toml -v "OPTIONS" '.rpc.cors_allowed_methods.[]'
dasel put -t string -r toml -f $CONFIG_FOLDER/config.toml -v "PATCH" '.rpc.cors_allowed_methods.[]'
dasel put -t string -r toml -f $CONFIG_FOLDER/config.toml -v "PUT" '.rpc.cors_allowed_methods.[]'

# Enable unsafe cors and swagger on the api
dasel put bool -r toml -f $CONFIG_FOLDER/app.toml -v "true" '.api.swagger'
dasel put bool -r toml -f $CONFIG_FOLDER/app.toml -v "true" '.api.enabled-unsafe-cors'
dasel put -t bool -r toml -f $CONFIG_FOLDER/app.toml -v "true" '.api.swagger'
dasel put -t bool -r toml -f $CONFIG_FOLDER/app.toml -v "true" '.api.enabled-unsafe-cors'

echo $COW_MNEMONIC | simd keys add cow --recover --keyring-backend=test --home $CSDK_HOME
# make cow a validator:
simd add-genesis-account cow 50000000000ustake
simd gentx cow 40000000000ustake --chain-id $CSDK_CHAIN_ID --ip 127.0.0.1
simd collect-gentxs

### Start chain
echo "Starting up csdk v1 node..."
simd start --api.enable true &
simd start &
CSDK_PID=$!
# Sleep for node to full boot up
sleep 3
# wait again on the node process so it can be terminated with ctrl+C
echo "CSDK V1 node started & state initialized!"
echo "CSDK v1 node started & state initialized!"
wait $CSDK_PID
2 changes: 1 addition & 1 deletion packages/chain-events/cosmos-chain-testing/v1/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SCRIPT_NAME=$(basename "$0")
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)

PORT=5050
IMAGE_NAME=heroku-csdk
IMAGE_NAME=csdk-v1

if [ "$1" = "--build" ]; then
cd $SCRIPT_DIR
Expand Down
2 changes: 1 addition & 1 deletion packages/chain-events/cosmos-chain-testing/v1/stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# This script is used to start a local cosmos chain for testing purposes.

set -x
IMAGE_NAME=heroku-csdk
IMAGE_NAME=csdk-v1
# docker force stop and remove the container but leave the image
docker stop ${IMAGE_NAME} && docker rm ${IMAGE_NAME} -f || true
63 changes: 39 additions & 24 deletions packages/chain-events/cosmos-chain-testing/v1beta1/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CONFIG_FOLDER=$CSDK_HOME/config
GENESIS=$CONFIG_FOLDER/genesis.json
# You can add this mnemonic to keplr to use the UI
COW_MNEMONIC="ignore medal pitch lesson catch stadium victory jewel first stairs humble excuse scrap clutch cup daughter bench length sell goose deliver critic favorite thought"
CSDK_CHAIN_ID="testnet"
CSDK_CHAIN_ID="csdkbeta-1"

### start nginx
sed -i "s/listen\ 80;/listen\ ${PORT:=5051};/" /etc/nginx/nginx.conf
Expand All @@ -21,42 +21,57 @@ simd config keyring-backend test
simd config chain-id $CSDK_CHAIN_ID
simd config broadcast-mode block
simd config output json
echo $COW_MNEMONIC | simd keys add cow --recover --keyring-backend=test --home $CSDK_HOME
# make cow a validator:
simd add-genesis-account cow 1000000000000stake
simd gentx cow 7000000000stake --chain-id testnet
simd collect-gentxs
simd config node http://localhost:26657

### Configure chain generated config files - genesis.json, app.toml, config.toml
# Update denom references
dasel put -t string -r json -f $GENESIS -v "ustake" '.app_state.staking.params.bond_denom'
dasel put -t string -r json -f $GENESIS -v "240s" '.app_state.staking.params.unbonding_time'

dasel put -t string -r json -f $GENESIS -v "ustake" '.app_state.txfees.basedenom'
dasel put -t string -r json -f $GENESIS -v "ustake" '.app_state.crisis.constant_fee.denom'
dasel put -t string -r json -f $GENESIS -v "ustake" '.app_state.mint.params.mint_denom'

# Update gov module
dasel put -t string -r json -f $GENESIS -v "90s" '.app_state.gov.voting_params.voting_period'
dasel put -t string -r json -f $GENESIS -v "2000000" '.app_state.gov.deposit_params.min_deposit.[0].amount'
dasel put -t string -r json -f $GENESIS -v "ustake" '.app_state.gov.deposit_params.min_deposit.[0].denom'

dasel put string -f $GENESIS '.app_state.gov.voting_params.voting_period' '600s'
dasel put string -f $GENESIS '.app_state.gov.deposit_params.min_deposit.[0].amount' '100000'
# decrease block-time so tests run faster
sed -i "s/timeout_commit = \"5s\"/timeout_commit = \"500ms\"/g" $CONFIG_FOLDER/config.toml
# bind on all interfaces, enabling ports to be exposed outside docker
sed -i "s/127\.0\.0\.1/0.0.0.0/g" $CONFIG_FOLDER/config.toml

# expose the LCD
dasel put bool -f $CONFIG_FOLDER/app.toml -v "true" '.api.enable'
dasel put -t bool -r toml -f $CONFIG_FOLDER/app.toml -v "true" '.api.enable'
dasel put -t string -r toml -f $CONFIG_FOLDER/app.toml -v "tcp://0.0.0.0:1317" '.api.address'

# Expose the rpc
dasel put string -f $CONFIG_FOLDER/config.toml -v "tcp://0.0.0.0:26657" '.rpc.laddr'
dasel put -t string -r toml -f $CONFIG_FOLDER/config.toml -v "tcp://0.0.0.0:26657" '.rpc.laddr'

# Enable cors on RPC
dasel put string -f $CONFIG_FOLDER/config.toml -v "*" '.rpc.cors_allowed_origins.[]'
dasel put string -f $CONFIG_FOLDER/config.toml -v "Accept-Encoding" '.rpc.cors_allowed_headers.[]'
dasel put string -f $CONFIG_FOLDER/config.toml -v "DELETE" '.rpc.cors_allowed_methods.[]'
dasel put string -f $CONFIG_FOLDER/config.toml -v "OPTIONS" '.rpc.cors_allowed_methods.[]'
dasel put string -f $CONFIG_FOLDER/config.toml -v "PATCH" '.rpc.cors_allowed_methods.[]'
dasel put string -f $CONFIG_FOLDER/config.toml -v "PUT" '.rpc.cors_allowed_methods.[]'
dasel put -t string -r toml -f $CONFIG_FOLDER/config.toml -v "*" '.rpc.cors_allowed_origins.[]'
dasel put -t string -r toml -f $CONFIG_FOLDER/config.toml -v "Accept-Encoding" '.rpc.cors_allowed_headers.[]'
dasel put -t string -r toml -f $CONFIG_FOLDER/config.toml -v "DELETE" '.rpc.cors_allowed_methods.[]'
dasel put -t string -r toml -f $CONFIG_FOLDER/config.toml -v "OPTIONS" '.rpc.cors_allowed_methods.[]'
dasel put -t string -r toml -f $CONFIG_FOLDER/config.toml -v "PATCH" '.rpc.cors_allowed_methods.[]'
dasel put -t string -r toml -f $CONFIG_FOLDER/config.toml -v "PUT" '.rpc.cors_allowed_methods.[]'

# Enable unsafe cors and swagger on the api
dasel put bool -f $CONFIG_FOLDER/app.toml -v "true" '.api.swagger'
dasel put bool -f $CONFIG_FOLDER/app.toml -v "true" '.api.enabled-unsafe-cors'
dasel put -t bool -r toml -f $CONFIG_FOLDER/app.toml -v "true" '.api.swagger'
dasel put -t bool -r toml -f $CONFIG_FOLDER/app.toml -v "true" '.api.enabled-unsafe-cors'

# Enable cors on gRPC Web
dasel put bool -f $CONFIG_FOLDER/app.toml -v "true" '.grpc-web.enable-unsafe-cors'
echo $COW_MNEMONIC | simd keys add cow --recover --keyring-backend=test --home $CSDK_HOME
# make cow a validator:
simd add-genesis-account cow 50000000000ustake
simd gentx cow 40000000000ustake --chain-id $CSDK_CHAIN_ID --ip 127.0.0.1
simd collect-gentxs

### Start chain
echo "Starting up csdk-v1beta1 node..."
simd start & CSDK_PID=$!
echo "Starting up csdk v1beta1 node..."
simd start &
CSDK_PID=$!
# Sleep for node to full boot up
sleep 3
# wait again on the node process so it can be terminated with ctrl+C
echo "CSDK-beta node started & state initialized!"
echo "CSDK beta node started & state initialized!"
wait $CSDK_PID
5 changes: 2 additions & 3 deletions packages/chain-events/cosmos-chain-testing/v1beta1/dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Simple usage with a mounted data directory:
# > docker build -t simapp .
#

FROM golang:1.19-alpine AS build-env
FROM --platform=linux/amd64 golang:1.19-alpine AS build-env

# Install minimum necessary dependencies
ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3 py3-pip build-base dasel nginx
Expand All @@ -27,7 +26,7 @@ WORKDIR /root
EXPOSE ${PORT}
EXPOSE 5051
COPY nginx.conf /etc/nginx/nginx.conf
COPY bootstrap.sh bootstrap.sh
COPY bootstrap.sh bootstrap.sh
RUN chmod +x bootstrap.sh && chmod +x /usr/bin/simd && mkdir -p /run/nginx

# Run simd by default, omit entrypoint to ease using container with simcli
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
build:
docker:
web: dockerfile
web: Dockerfile
12 changes: 4 additions & 8 deletions packages/chain-events/src/chains/cosmos/filters/enricher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ export async function Enrich(
);
});

const dateToUnix = (d?: Date): number | undefined => {
if (d) return Math.floor(d.getTime() / 1000);
return undefined;
};
if (!proposal) throw new Error('Proposal not found!');
return {
blockNumber,
Expand All @@ -46,10 +42,10 @@ export async function Enrich(
typeUrl: proposal.content.typeUrl,
value: Buffer.from(proposal.content.value).toString('hex'),
},
submitTime: dateToUnix(proposal.submitTime),
depositEndTime: dateToUnix(proposal.depositEndTime),
votingStartTime: dateToUnix(proposal.votingStartTime),
votingEndTime: dateToUnix(proposal.votingEndTime),
submitTime: proposal.submitTime.seconds.toNumber(),
depositEndTime: proposal.depositEndTime.seconds.toNumber(),
votingStartTime: proposal.votingStartTime.seconds.toNumber(),
votingEndTime: proposal.votingEndTime.seconds.toNumber(),
},
};
}
Expand Down
13 changes: 4 additions & 9 deletions packages/chain-events/src/chains/cosmos/storageFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import { addPrefix, factory } from '../../logging';
import type { IEventData, Api, ISubmitProposal } from './types';
import { EventKind, coinToCoins } from './types';

const dateToUnix = (d?: Date): number | undefined => {
if (d) return Math.floor(d.getTime() / 1000);
return undefined;
};

export class StorageFetcher extends IStorageFetcher<Api> {
private readonly log;

Expand Down Expand Up @@ -63,10 +58,10 @@ export class StorageFetcher extends IStorageFetcher<Api> {
typeUrl: proposal.content.typeUrl,
value: Buffer.from(proposal.content.value).toString('hex'),
},
submitTime: dateToUnix(proposal.submitTime),
depositEndTime: dateToUnix(proposal.depositEndTime),
votingStartTime: dateToUnix(proposal.votingStartTime),
votingEndTime: dateToUnix(proposal.votingEndTime),
submitTime: proposal.submitTime.seconds.toNumber(),
depositEndTime: proposal.depositEndTime.seconds.toNumber(),
votingStartTime: proposal.votingStartTime.seconds.toNumber(),
votingEndTime: proposal.votingEndTime.seconds.toNumber(),
// TODO: do we need to query the tally separately if it's complete?
finalTallyResult: proposal.finalTallyResult,
totalDeposit:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { AccountData, OfflineDirectSigner } from '@cosmjs/proto-signing';
import type {
AccountData,
OfflineDirectSigner,
OfflineSigner,
} from '@cosmjs/proto-signing';
import type { ChainInfo, Window as KeplrWindow } from '@keplr-wallet/types';
import type { SessionPayload } from '@canvas-js/interfaces';

Expand All @@ -19,7 +23,7 @@ class KeplrWebWalletController implements IWebWallet<AccountData> {
private _enabling = false;
private _chainId: string;
private _chain: string;
private _offlineSigner: OfflineDirectSigner;
private _offlineSigner: OfflineDirectSigner | OfflineSigner;

public readonly name = WalletId.Keplr;
public readonly label = 'Keplr';
Expand Down Expand Up @@ -159,7 +163,9 @@ class KeplrWebWalletController implements IWebWallet<AccountData> {
}
console.log(`Enabled web wallet for ${this._chainId}`);

this._offlineSigner = window.keplr.getOfflineSigner(this._chainId);
this._offlineSigner = await window.keplr.getOfflineSignerAuto(
this._chainId
);
this._accounts = await this._offlineSigner.getAccounts();
this._enabled = true;
this._enabling = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ class CosmosChain implements IChainModule<CosmosToken, CosmosAccount> {
DEFAULT_MEMO
);
console.log(result);
if (cosm.isBroadcastTxFailure(result)) {
if (cosm.isDeliverTxFailure(result)) {
throw new Error('TX execution failed.');
} else if (cosm.isBroadcastTxSuccess(result)) {
} else if (cosm.isDeliverTxSuccess(result)) {
const txHash = result.transactionHash;
const txResult = await this._tmClient.tx({
hash: Buffer.from(txHash, 'hex'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { Tendermint34Client } from '@cosmjs/tendermint-rpc';
import { OfflineSigner } from '@cosmjs/proto-signing';
import { SigningStargateClient } from '@cosmjs/stargate';
import {
AminoTypes,
SigningStargateClient,
createDefaultAminoConverters,
} from '@cosmjs/stargate';
import { CosmosApiType } from './chain';
import { LCD } from 'chain-events/src/chains/cosmos/types';
import { createAltGovAminoConverters } from './gov/aminomessages';

export const getTMClient = async (
rpcUrl: string
Expand Down Expand Up @@ -38,5 +43,12 @@ export const getSigningClient = async (
url: string,
signer: OfflineSigner
): Promise<SigningStargateClient> => {
return await SigningStargateClient.connectWithSigner(url, signer);
const aminoTypes = new AminoTypes({
...createDefaultAminoConverters(),
...createAltGovAminoConverters(),
});

return await SigningStargateClient.connectWithSigner(url, signer, {
aminoTypes,
});
};
Loading

0 comments on commit d2e5e96

Please sign in to comment.