Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
bb6a407
add unnamed using flipper template
ltfschoen Jun 10, 2023
231d7ae
wip
ltfschoen Jun 11, 2023
8fdf3bb
wip
ltfschoen Jun 11, 2023
3faf53e
resolve some errors
ltfschoen Jun 11, 2023
e5e7720
fix all errors
ltfschoen Jun 12, 2023
14b04a5
use raw bytes instead of hash type so can access length of block hash
ltfschoen Jun 12, 2023
7d035fe
save and emit entropy of coin1 and coin2
ltfschoen Jun 12, 2023
f1b5c55
wip stuck stubbing blocknumber from ink environment
ltfschoen Jun 13, 2023
56aaa29
use set_block_number from pr to upstream working
ltfschoen Jun 13, 2023
10a08f8
fix contracts using String but already uploaded error
ltfschoen Jun 15, 2023
88782c0
working. allow toggle --skip-dry-run with bulk comment
ltfschoen Jun 15, 2023
aeb12bc
add basic_contract_caller from ink-examples
ltfschoen Jun 15, 2023
ed4290e
add basic_contract_caller all working
ltfschoen Jun 16, 2023
931fe20
remove get message from main contract and do not call it generates error
ltfschoen Jun 16, 2023
4217f6b
restore get method in main contract
ltfschoen Jun 16, 2023
455c222
convert to CreateBuilder and CallBuilder but with error when call via…
ltfschoen Jun 16, 2023
e5f449a
fix basic-contract-caller
ltfschoen Jun 17, 2023
5686da3
call via main but no Builder not support tuple return Decode(Error)
ltfschoen Jun 18, 2023
bf4e6f2
fix Decode(Error) caused by assertion failing since call from contrac…
ltfschoen Jun 18, 2023
3433a89
demo handling errors
ltfschoen Jun 19, 2023
75f5370
fix LangError
ltfschoen Jun 19, 2023
4ae3e63
setup moonbeam MyToken template
ltfschoen Jun 20, 2023
39fcd92
ipsp22
ltfschoen Jun 20, 2023
73750e6
update readme and add ipsp22 script
ltfschoen Jun 21, 2023
768361f
add evm example pending astar response
ltfschoen Jun 22, 2023
e98be60
Merge pull request #17 from ltfschoen/moonbeam
ltfschoen Jun 22, 2023
8887442
update precompile but DeploymentError RandonNumber hit a require or r…
ltfschoen Jun 23, 2023
fd5624c
incorporate feedback from moonbuilders
ltfschoen Jun 23, 2023
d68f6d5
fix so only use randomness after instantiated Randomness
ltfschoen Jun 24, 2023
4962720
try use console log
ltfschoen Jun 24, 2023
2f66366
wip errors due to https://github.com/trufflesuite/truffle/issues/3468…
ltfschoen Jun 24, 2023
4df48da
stuck on error ProviderError 32603 calling requestRandomness
ltfschoen Jun 25, 2023
30db35e
StatusError in tx for requestRandomness
ltfschoen Jun 25, 2023
df8ac88
try change to Websocket endpoint but error Web3WSProviderError: Reque…
ltfschoen Jun 26, 2023
84a6508
MethodNotImplementedError: The method you're trying to call is not im…
ltfschoen Jun 26, 2023
49f7632
timeouts
ltfschoen Jun 26, 2023
2efa2e6
works up to getting requestId but still often get error PollingBlockT…
ltfschoen Jun 26, 2023
6d85e28
tests working enough to generate random number
ltfschoen Jun 27, 2023
5b96de4
update readme
ltfschoen Jun 27, 2023
3b01dd0
add vrf template contracts
ltfschoen Jun 27, 2023
fb3d91f
wip Chainlink VRF Sepolia
ltfschoen Jun 27, 2023
2a2cd51
Uncaught Error: invalid 1st argument: block_number value was not vali…
ltfschoen Jun 27, 2023
dd0d6ab
success deploying chainlink VRF to Sepolia
ltfschoen Jun 27, 2023
f1d3067
Merge pull request #20 from ltfschoen/chainlink
ltfschoen Jun 27, 2023
039630f
trying to interact with vrf to play game
ltfschoen Jun 28, 2023
e8992e4
able to get instance of vrf contract
ltfschoen Jun 28, 2023
3a8541b
fix use of correct alchemy key
ltfschoen Jun 28, 2023
5d3b2c3
fix migration, requires min deposit of 1 eth to not error
ltfschoen Jun 29, 2023
34e8cf5
fix use of alchemy but error when creating chainlink subscription to …
ltfschoen Jul 2, 2023
a7a7971
wait a few blocks before get rolled value for player
ltfschoen Jul 2, 2023
79af150
show current error
ltfschoen Jul 2, 2023
991b0cd
wip
ltfschoen Jul 2, 2023
4da18cf
insufficient funds for gas * price + value
ltfschoen Jul 3, 2023
78c4c52
crashes on requestRandomness. fixes error insufficient funds for intr…
ltfschoen Jul 3, 2023
74eca77
wip
ltfschoen Jul 3, 2023
4e136dc
fix vrf
ltfschoen Jul 5, 2023
5dde11b
wip
ltfschoen Jul 6, 2023
0d6b01a
split flipper from moonbase vrf example
ltfschoen Jul 6, 2023
5f827f9
update readme
ltfschoen Jul 6, 2023
b724f57
rename flipper folder to randomness
ltfschoen Jul 6, 2023
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
Prev Previous commit
Next Next commit
working. allow toggle --skip-dry-run with bulk comment
  • Loading branch information
ltfschoen committed Jun 15, 2023
commit 88782c0d0447802626c8e89c9fb16ffae5395eda
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,9 @@ docker buildx rm --all-inactive
* Contracts pallet allows deployment and execution of WebAssembly-based smart contracts
* What trait do smart contract accounts used in the Contracts pallet of Substrate extend?
* `Currency` trait
* How to resolve `ERROR: This contract has already been uploaded with code hash`
* It may be because you ran a Substrate contract node on your host machine and then tried running another one in your Docker container. So it may be necessary to run `kill -9 $(lsof -ti:30333)` on
both the host machine and inside the Docker container. Or just restart Docker.


* Link
Expand Down
19 changes: 18 additions & 1 deletion dapps/xcm/unnamed/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,28 @@ mod unnamed {
}
}

/// Using the `OracleContractRef` we can call all the messages of the `OracleContract`
#[ink(message)]
pub fn get_entropy_for_market_id(&self, id_market: String) -> Result<(BlockNumber, String, i16, i16)> {
match &self.oracle_contract {
Some(c) => {
let res = match c.clone().get_entropy_for_market_id(id_market) {
Ok(r) => r,
Err(_e) => panic!("arr {:?}", _e),
};
Ok(res)
},
None => return Err(Error::NoOracleContractAddress),
}
}

/// Using the `OracleContractRef` we can call all the messages of the `OracleContract`
#[ink(message)]
pub fn get_oracle_contract_address(&self) -> Result<AccountId> {
match &self.oracle_contract {
Some(c) => Ok(c.get_oracle_contract_address()),
Some(c) => {
Ok(c.clone().get_oracle_contract_address())
},
None => return Err(Error::NoOracleContractAddress),
}
}
Expand Down
1 change: 1 addition & 0 deletions dapps/xcm/unnamed/oracle_contract/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ mod oracle_contract {

#[ink(message)]
pub fn get_oracle_contract_address(&self) -> AccountId {
ink::env::debug_println!("oracle contract address {:?}", self.env().account_id());
self.env().account_id()
}

Expand Down
219 changes: 140 additions & 79 deletions docker/quickstart-unnamed.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/bin/bash

# compatibility cargo-contract v3.0.1
#
# start a fresh substrate-contracts-node and upload the "unnamed" ink!
# smart contracts to it and then instantiate and call a method
#
# if you want to sky dry run then find/replace `--skip-dry-run` with `#--skip-dry-run`
# to comment those lines out

trap "echo; exit" INT
trap "echo; exit" HUP
Expand All @@ -18,7 +23,6 @@ echo "Removing previous database..."
# delete the blockchain database so we don't get this error when we redeploy the
# smart contract `ERROR: This contract has already been uploaded with code hash:`
rm -rf /tmp/ink
sleep 5

echo "Running new Substrate contracts node..."
cd ${PARENT_DIR}/docker/
Expand All @@ -40,29 +44,52 @@ cargo contract build \
cd $PROJECT_ROOT
echo "Uploading sub-contract..."
# upload sub-contract
OUTPUT_CODE_HASH=$(
cargo contract upload --suri //Alice \
--execute \
--skip-confirm \
$PARENT_DIR/target/ink/oracle_contract/oracle_contract.wasm | tail -1
#
# note: provide args variable so able to comment out all `--skip-dry-run` options in bulk
# since it breaks command if comment out a multiline command option `#--skip-dry-run \`
# see https://stackoverflow.com/a/9522766/3208553
args=(
--suri //Alice
--execute
--skip-dry-run
--skip-confirm
$PARENT_DIR/target/ink/oracle_contract/oracle_contract.wasm
)
echo "Uploading contract..."
OUTPUT_CODE_HASH_SUB=$(
cargo contract upload "${args[@]}" | tail -1
)
echo "Finished uploading contract..."
# example: ' Code hash "0x..."'
echo $OUTPUT_CODE_HASH_SUB
# remove text 'Code hash' and the outer double quotes of the code hash
OUTPUT_CODE_HASH_SUB_REMOVED_LABEL=$(echo "$OUTPUT_CODE_HASH_SUB" | sed 's/Code hash//;s/$//' | tr -d '"')
# trim whitespace
CODE_HASH_SUB=$(echo $OUTPUT_CODE_HASH_SUB_REMOVED_LABEL)
echo $CODE_HASH_SUB

echo "Uploading main-contract..."
# upload main-contract
#
args=(
--suri //Alice
--execute
# --skip-dry-run
--skip-confirm
$PARENT_DIR/target/ink/unnamed/unnamed.wasm
)
OUTPUT_CODE_HASH_MAIN=$(
cargo contract upload --suri //Alice \
--execute \
--skip-dry-run \
--skip-confirm \
$PARENT_DIR/target/ink/unnamed/unnamed.wasm | tail -1
cargo contract upload "${args[@]}" | tail -1
)
echo "Finished uploading contracts..."
echo "Finished uploading contract..."
# example: ' Code hash "0x..."'
echo $OUTPUT_CODE_HASH
echo $OUTPUT_CODE_HASH_MAIN
# remove text 'Code hash' and the outer double quotes of the code hash
OUTPUT_CODE_HASH_REMOVED_LABEL=$(echo "$OUTPUT_CODE_HASH" | sed 's/Code hash//;s/$//' | tr -d '"')
OUTPUT_CODE_HASH_MAIN_REMOVED_LABEL=$(echo "$OUTPUT_CODE_HASH_MAIN" | sed 's/Code hash//;s/$//' | tr -d '"')
# trim whitespace
CODE_HASH=$(echo $OUTPUT_CODE_HASH_REMOVED_LABEL)
echo $CODE_HASH
CODE_HASH_MAIN=$(echo $OUTPUT_CODE_HASH_MAIN_REMOVED_LABEL)
echo $CODE_HASH_MAIN

ARG_ID_MARKET="\"my_id\""

# Note: The id_market is stored as Vec<u8> format instead of String.
# Paste the following at https://play.rust-lang.org/?version=stable&mode=debug&edition=2021
Expand All @@ -78,71 +105,105 @@ echo $CODE_HASH
# ```

# instantiate "main" contract, providing the code hash generated from uploading the "sub" contract
echo "Instantiating main-contract..."

echo "Instantiating contract..."
OUTPUT_CONTRACT_ADDR=$(
cargo contract instantiate \
--manifest-path $PARENT_DIR/dapps/xcm/unnamed/Cargo.toml \
--suri //Alice \
--constructor new \
--args "$CODE_HASH" "my_id" "100" "228" "500" \
--execute \
--skip-dry-run \
--gas 100000000000 \
--proof-size 100000000000 \
--skip-confirm \
| tail -1
args=(
--manifest-path $PARENT_DIR/dapps/xcm/unnamed/Cargo.toml
--suri //Alice
--constructor new
--args $CODE_HASH_SUB $ARG_ID_MARKET "100" "228" "500"
--execute
--gas 100000000000
--proof-size 100000000000
# --skip-dry-run
--skip-confirm
)
OUTPUT_CONTRACT_ADDR_MAIN=$(
cargo contract instantiate "${args[@]}" | tail -1
)

sleep 5
# example: ' Contract 5...'
echo $OUTPUT_CONTRACT_ADDR_MAIN
# remove text 'Contract'
OUTPUT_CONTRACT_ADDR_MAIN_REMOVED_LABEL=$(echo "$OUTPUT_CONTRACT_ADDR_MAIN" | sed 's/Contract//;s/$//')
# trim whitespace using `echo ...`
CONTRACT_ADDR_MAIN=$(echo $OUTPUT_CONTRACT_ADDR_MAIN_REMOVED_LABEL)
echo $CONTRACT_ADDR_MAIN

echo "Instantiating sub-contract..."
args=(
--manifest-path $PARENT_DIR/dapps/xcm/unnamed/oracle_contract/Cargo.toml
--suri //Alice
--constructor new
--args $ARG_ID_MARKET "100" "228" "500"
--execute
--gas 100000000000
--proof-size 100000000000
# --skip-dry-run
--skip-confirm
)
OUTPUT_CONTRACT_ADDR_SUB=$(
cargo contract instantiate "${args[@]}" | tail -1
)

# example: ' Contract 5...'
echo $OUTPUT_CONTRACT_ADDR
echo $OUTPUT_CONTRACT_ADDR_SUB
# remove text 'Contract'
OUTPUT_CONTRACT_ADDR_REMOVED_LABEL=$(echo "$OUTPUT_CONTRACT_ADDR" | sed 's/Contract//;s/$//')
# trim whitespace
CONTRACT_ADDR=$(echo $OUTPUT_CONTRACT_ADDR_REMOVED_LABEL)
echo $CONTRACT_ADDR
# echo "Calling contract method..."
# note: an example hash value has been used
# TODO - should the hash be '0x' prefixed?
# cargo contract call \
# --suri //Alice \
# --contract $CONTRACT_ADDR \
# --message set_block_for_entropy_for_market_id \
# --args "my_id" "228" "aef6eca62ae61934a7ab5ad3814f6e319abd3e4e4aa1a3386466ad197d1c4dea" \
# --execute \
# --skip-dry-run \
# --gas 100000000000 \
# --proof-size 100000000000 \
# --skip-confirm \
# | grep --color=always -z 'data'

# cargo contract call \
# --suri //Alice \
# --contract $CONTRACT_ADDR \
# --message get_entropy_for_market_id \
# --args "my_id" \
# --execute \
# --skip-confirm \
# | grep --color=always -z 'data'

# # TODO - why is this method even necessary in the code? was it to override results incase of missed blocks?
# #
# # cargo contract call \
# # --suri //Alice \
# # --contract $CONTRACT_ADDR \
# # --message set_entropy_for_market_id \
# # --args "my_id" "228" "aef6eca62ae61934a7ab5ad3814f6e319abd3e4e4aa1a3386466ad197d1c4dea" "0" "0" \
# # --execute \
# # --skip-confirm \
# # | grep --color=always -z 'data'

# # highlight the `data` line in output containing the value of the emitted `Retrieve` event
# cargo contract call \
# --suri //Alice \
# --contract $CONTRACT_ADDR \
# --message get_oracle_contract_address \
# --execute \
# --skip-confirm \
# | grep --color=always -z 'data'
OUTPUT_CONTRACT_ADDR_SUB_REMOVED_LABEL=$(echo "$OUTPUT_CONTRACT_ADDR_SUB" | sed 's/Contract//;s/$//')
# trim whitespace using `echo ...`
CONTRACT_ADDR_SUB=$(echo $OUTPUT_CONTRACT_ADDR_SUB_REMOVED_LABEL)
echo $CONTRACT_ADDR_SUB

ARG_BLOCK_HASH_ENTROPY="\"aef6eca62ae61934a7ab5ad3814f6e319abd3e4e4aa1a3386466ad197d1c4dea\""

echo "Calling contract method set_block_for_entropy_for_market_id..."
args=(
--suri //Alice
--contract $CONTRACT_ADDR_MAIN
--message set_block_for_entropy_for_market_id
--args $ARG_ID_MARKET "228" $ARG_BLOCK_HASH_ENTROPY
--execute
--gas 100000000000
--proof-size 100000000000
# --skip-dry-run
--skip-confirm
)
cargo contract call "${args[@]}" | grep --color=always -z 'data'

echo "Calling contract method get_entropy_for_market_id ..."
args=(
--suri //Alice
--contract $CONTRACT_ADDR_MAIN
--message get_entropy_for_market_id
--args $ARG_ID_MARKET
--execute
# --skip-dry-run
--skip-confirm
)
cargo contract call "${args[@]}" | grep --color=always -z 'data'

# TODO - consider removing. maybe use to override results incase of missed blocks?
#
# args=(
# --suri //Alice
# --contract $CONTRACT_ADDR_MAIN
# --message set_entropy_for_market_id
# --args $ARG_ID_MARKET "228" $ARG_BLOCK_HASH_ENTROPY "0" "0"
# --execute
# # --skip-dry-run
# --skip-confirm
# )
# cargo contract call "${args[@]}" | grep --color=always -z 'data'

# highlight the `data` line in output containing the value of the emitted `Retrieve` event
echo "Calling contract method get_oracle_contract_address ..."
args=(
--suri //Alice
--contract $CONTRACT_ADDR_MAIN
--message get_oracle_contract_address
--execute
# --skip-dry-run
--skip-confirm
)
# FIXME - why doesn't this return anything?
cargo contract call "${args[@]}" | grep --color=always -z 'data'