Skip to content
Snippets Groups Projects
Commit b9d2dfde authored by hianant2's avatar hianant2
Browse files

initial setups and ibc contract init

parent 08954a57
No related branches found
No related tags found
No related merge requests found
......@@ -28,4 +28,7 @@ Temporary Items
# project
data/
simplestorage/target/
\ No newline at end of file
simplestorage/target/
artifacts/
target/
out.log
\ No newline at end of file
......@@ -43,6 +43,9 @@ wasmd tx wasm instantiate 1 "{}" --node $NODE_0 --from $USER --chain-id ibc-0 --
CONTRACT=$(wasmd query wasm list-contract-by-code 1 --node $NODE_0 --output json | jq -r '.contracts[-1]')
wasmd query wasm list-contract-by-code 13 --node $NODE_0 --output json | jq -r '.contracts[-1]'
wasmd query wasm contract $CONTRACT --node $NODE_0
......
......@@ -3,9 +3,13 @@
NODE_0=http://127.0.0.1:26557
NODE_1=http://127.0.0.1:26657
NODE_2=http://127.0.0.1:26757
KEYRING_0='--keyring-backend test --keyring-dir data/ibc-0'
KEYRING_1='--keyring-backend test --keyring-dir data/ibc-1'
KEYRING_2='--keyring-backend test --keyring-dir data/ibc-2'
KEYRING_0='--keyring-backend test --keyring-dir ./data/ibc-0'
KEYRING_1='--keyring-backend test --keyring-dir ./data/ibc-1'
KEYRING_2='--keyring-backend test --keyring-dir ./data/ibc-2'
GAS_FLAG='--gas-prices 0.025stake --gas auto --gas-adjustment 1.5'
USER="user"
INIT_JSON='{"count": 1}'
INIT_JSON_2='{ "reflect_code_id": 1}'
target=$2
......@@ -13,7 +17,7 @@ param1=$3
node=$(expr 5 + $2)
node="http://127.0.0.1:26$node"
node+="57"
keyring="--keyring-backend test --keyring-dir data/ibc-$target"
keyring="--keyring-backend test --keyring-dir ./data/ibc-$target"
listKeys()
{
......@@ -28,6 +32,121 @@ balance()
wasmd query bank balances $param1 --node $node --chain-id ibc-$target
}
deployAll()
{
echo "killing all relayers..."
set -x
kilall rly
cd ./simplestorage/
cargo wasm
cd ..
file="simplestorage/target/wasm32-unknown-unknown/release/simplestorage.wasm"
#wasmd's MaxWasmSize change to higher https://github.com/CosmWasm/wasmd/blob/bfb4d31fcafa9acf148e7a9b07b3baed5938c38a/x/wasm/types/validation.go#L12 to skip optimization
# docker run --rm -v "$(pwd)":/code \
# --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
# --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
# cosmwasm/rust-optimizer-arm64:0.12.5 ./simplestorage/
# deploy smart contract to all chains...
wasmd tx wasm store $file --node $NODE_0 --from $USER --chain-id ibc-0 $GAS_FLAG --broadcast-mode block -y $KEYRING_0
wasmd tx wasm store $file --node $NODE_1 --from $USER --chain-id ibc-1 $GAS_FLAG --broadcast-mode block -y $KEYRING_1
wasmd tx wasm store $file --node $NODE_2 --from $USER --chain-id ibc-2 $GAS_FLAG --broadcast-mode block -y $KEYRING_2
#get code ids at each chain
code_id_0=$(wasmd query wasm list-code --node $NODE_0 --output json | jq -r ".code_infos[-1] | .code_id")
code_id_1=$(wasmd query wasm list-code --node $NODE_1 --output json | jq -r ".code_infos[-1] | .code_id")
code_id_2=$(wasmd query wasm list-code --node $NODE_2 --output json | jq -r ".code_infos[-1] | .code_id")
#instantiate contracts at all chains
wasmd tx wasm instantiate $code_id_0 "$INIT_JSON" --node $NODE_0 --from $USER --chain-id ibc-0 $GAS_FLAG -y --label "simplestorage" --no-admin $KEYRING_0
wasmd tx wasm instantiate $code_id_1 "$INIT_JSON" --node $NODE_1 --from $USER --chain-id ibc-1 $GAS_FLAG -y --label "simplestorage" --no-admin $KEYRING_1
wasmd tx wasm instantiate $code_id_2 "$INIT_JSON" --node $NODE_2 --from $USER --chain-id ibc-2 $GAS_FLAG -y --label "simplestorage" --no-admin $KEYRING_2
sleep 2
contract_address_0=$(wasmd query wasm list-contract-by-code $code_id_0 --node $NODE_0 --output json | jq -r '.contracts[-1]')
contract_address_1=$(wasmd query wasm list-contract-by-code $code_id_1 --node $NODE_1 --output json | jq -r '.contracts[-1]')
contract_address_2=$(wasmd query wasm list-contract-by-code $code_id_2 --node $NODE_2 --output json | jq -r '.contracts[-1]')
if [ -z $contract_address_0 ] || [ -z $contract_address_1 ] || [ -z $contract_address_2 ]; then
echo "!!!!!!!!!!!!!!!!!!!! retrying getting contract address !!!!!!!!!!!!!!"
sleep 2
contract_address_0=$(wasmd query wasm list-contract-by-code $code_id_0 --node $NODE_0 --output json | jq -r '.contracts[-1]')
contract_address_1=$(wasmd query wasm list-contract-by-code $code_id_1 --node $NODE_1 --output json | jq -r '.contracts[-1]')
contract_address_2=$(wasmd query wasm list-contract-by-code $code_id_2 --node $NODE_2 --output json | jq -r '.contracts[-1]')
fi
ibc_port_0=$(wasmd query wasm contract $contract_address_0 --node $NODE_0 --output --json | jq -r '.contract_info | .ibc_port_id')
ibc_port_1=$(wasmd query wasm contract $contract_address_1 --node $NODE_1 --output --json | jq -r '.contract_info | .ibc_port_id')
ibc_port_2=$(wasmd query wasm contract $contract_address_2 --node $NODE_2 --output --json | jq -r '.contract_info | .ibc_port_id')
set +x
echo "------------------------------------------Addreses-------------------------------------------------------"
echo "Deployed with code id $code_id_0 on chain 0 Contract Address = $contract_address_0 ibc_port = $ibc_port_0"
echo "Deployed with code id $code_id_1 on chain 1 Contract Address = $contract_address_1 ibc_port = $ibc_port_1"
echo "Deployed with code id $code_id_2 on chain 2 Contract Address = $contract_address_2 ibc_port = $ibc_port_2"
echo "-----------------------------------------Link Setup-----------------------------------------------"
set -x
rly tx link path01 --src-port $ibc_port_0 --dst-port $ibc_port_1 --order ordered --version trustboost-test
rly tx link path02 --src-port $ibc_port_0 --dst-port $ibc_port_2 --order ordered --version trustboost-test
set +x
sleep 2
echo "-----------------------------------------Channels-----------------------------------------------"
set -x
chan1=$(wasmd query ibc channel channels --node $NODE_0 --output --json | jq -r '.channels[-2] | .channel_id')
chan2=$(wasmd query ibc channel channels --node $NODE_0 --output --json | jq -r '.channels[-1] | .channel_id')
set +x
echo "Channel Id for 01: $chan1"
echo "Channel Id for 02: $chan2"
rly start path01 &
rly start path02 &
out="contract address: $contract_address_0 \n"
out+="Channel id 01: $chan1 \n"
out+="Channel id 02: $chan2 \n"
echo -e $out > out.log
}
deployOne()
{
node=$NODE_0
user=$USER
keyring=$KEYRING_0
init='{"count": 1}'
chain='ibc-0'
set -x
cd ./simplestorage/
cargo wasm
cd ..
file="simplestorage/target/wasm32-unknown-unknown/release/simplestorage.wasm"
wasmd tx wasm store $file --node $node --from $user --chain-id $chain --gas-prices "0.025stake" --gas auto --gas-adjustment 1.5 --broadcast-mode block -y $keyring
# get code id of deployed contract and
# instantiate contract and get address of the instantiated contract
code_id=$(wasmd query wasm list-code --node $node --output json | jq -r ".code_infos[-1] | .code_id")
wasmd tx wasm instantiate $code_id "$init" --node $node --from $user --chain-id $chain $GAS_FLAG -y --label "simplestorage" --no-admin $keyring
# wait 2 secs for the contract to be deployed properly
sleep 2
contract_address=$(wasmd query wasm list-contract-by-code $code_id --node $node --output json | jq -r '.contracts[-1]')
if [ -z $contract_address ]; then
echo "retrying getting contract address...."
sleep 2
contract_address=$(wasmd query wasm list-contract-by-code $code_id --node $node --output json | jq -r '.contracts[-1]')
fi
ibc_port=$(wasmd query wasm contract $contract_address --node $node --output --json | jq -r '.contract_info | .ibc_port_id')
set +x
echo "Deployed with code id $code_id on Node 0 Contract Address = $contract_address ibc_port = $ibc_port"
}
listChannels()
{
set -x
wasmd query ibc channel channels --node $node
}
if [ -z $1 ]; then
......@@ -35,6 +154,16 @@ if [ -z $1 ]; then
exit 1
fi
if [ $1 = "deployAll" ]; then
deployAll
exit 0
elif [ $1 = "deployOne" ]; then
deployOne
exit 0
fi
if [ -z $2 ]; then
echo "Need target chain 0/1/2"
exit 1
......@@ -49,6 +178,8 @@ elif [ $1 = "balance" ]; then
exit 1
fi
balance
elif [ $1 = "listChannels" ]; then
listChannels
else
echo "unknown method"
fi
......@@ -40,7 +40,7 @@ optimize = """docker run --rm -v "$(pwd)":/code \
"""
[dependencies]
cosmwasm-std = "1.0.0"
cosmwasm-std = { version = "1.0.0", features = ["stargate"] }
cosmwasm-storage = "1.0.0"
cw-storage-plus = "0.13.2"
cw2 = "0.13.2"
......
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};
use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, SubMsgResult, WasmMsg, StdResult, SubMsg};
//IBC imports
use cosmwasm_std::{
IbcBasicResponse, IbcChannelCloseMsg,
IbcChannelConnectMsg, IbcChannelOpenMsg, IbcMsg, IbcOrder, IbcPacketAckMsg,
IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse
};
use cw2::set_contract_version;
use crate::error::ContractError;
......@@ -76,6 +83,67 @@ fn query_count(deps: Deps) -> StdResult<CountResponse> {
Ok(CountResponse { count: state.count })
}
// ------------------------------------------------------- TODO move to ibc.rs ------------------------------------------------------
#[entry_point]
/// enforces ordering and versioning constraints
pub fn ibc_channel_open(deps: DepsMut, env: Env, msg: IbcChannelOpenMsg) -> StdResult<()> {
Ok(())
}
#[entry_point]
/// once it's established, we send a WhoAmI message
pub fn ibc_channel_connect(deps: DepsMut, env: Env, msg: IbcChannelConnectMsg) -> StdResult<IbcBasicResponse> {
Ok((IbcBasicResponse::new()))
}
#[entry_point]
/// On closed channel, simply delete the account from our local store
pub fn ibc_channel_close(
deps: DepsMut,
env: Env,
msg: IbcChannelCloseMsg,
) -> StdResult<IbcBasicResponse> {
Ok((IbcBasicResponse::new()))
}
#[entry_point]
/// never should be called as the other side never sends packets
pub fn ibc_packet_receive(
_deps: DepsMut,
_env: Env,
_packet: IbcPacketReceiveMsg,
) -> StdResult<IbcReceiveResponse> {
Ok(IbcReceiveResponse::new()
.set_ack(b"{}")
.add_attribute("action", "ibc_packet_ack"))
}
#[entry_point]
pub fn ibc_packet_ack(
deps: DepsMut,
env: Env,
msg: IbcPacketAckMsg,
) -> StdResult<IbcBasicResponse> {
Ok(IbcBasicResponse::new().add_attribute("action", "acknowledge_dispatch"))
}
#[entry_point]
/// never should be called as we do not send packets
pub fn ibc_packet_timeout(
deps: DepsMut,
env: Env,
msg: IbcPacketTimeoutMsg,
) -> StdResult<IbcBasicResponse> {
Ok(IbcBasicResponse::new())
}
// ------------------------------------------------------- TODO move to ibc.rs ------------------------------------------------------
#[cfg(test)]
mod tests {
use super::*;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment