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
add evm example pending astar response
  • Loading branch information
ltfschoen committed Jun 22, 2023
commit 768361f7f9041bf6a1fa9aedb5e29fd0b1dba7dc
55 changes: 55 additions & 0 deletions dapps/basic_contract_caller/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod basic_contract_caller {
ExecutionInput,
Selector,
},
Call,
DefaultEnvironment,
};

Expand Down Expand Up @@ -65,6 +66,60 @@ mod basic_contract_caller {
}
}

/// Reference: https://github.com/hyperledger/solang/blob/main/integration/substrate/ink/caller/lib.rs#L33-L38
/// Do a proxy call to `callee` and return its result.
#[ink(message)]
pub fn u32_proxy(
&self,
callee: AccountId, // contract address
selector: [u8; 4], // method
// arg: u32, // args
max_gas: Option<u64>,
transfer_value: Option<u128>,
) -> bool {
let res = build_call::<DefaultEnvironment>()
.call_type(Call::new(callee).gas_limit(max_gas.unwrap_or_default()))
// .transferred_value(transfer_value.unwrap_or_default())
.transferred_value(0)
.exec_input(ExecutionInput::new(
Selector::new(selector))
// .push_arg(arg)
)
.returns::<bool>() // FIXME: This should be Result<bool, u8> to respect LanguageError
.try_invoke()
.expect("Error calling get.");

ink::env::debug_println!("res {:?}", res);

match res {
// Contract Success
EnvResult::Ok(MessageResult::Ok(ContractResult::Ok(tuple))) => {
ink::env::debug_println!("contract success tuple {:?}", tuple);
return Ok(tuple);
},
// Contract Error
EnvResult::Ok(MessageResult::Ok(ContractResult::Err(e))) => {
ink::env::debug_println!("contract error {:?}", e);
return Err(Error::ResponseError);
},
// Lang Error
EnvResult::Ok(MessageResult::Err(ink::LangError::CouldNotReadInput)) => {
ink::env::debug_println!("LangError::CouldNotReadInput");
return Err(Error::ResponseError);
},
// Environment Error
EnvResult::Err(e) => {
ink::env::debug_println!("environment error occurred {:?}", e);
return Err(Error::ResponseError);
},
// Unimplemented Error
_ => {
ink::env::debug_println!("unimplemented error in u32_proxy");
return unimplemented!();
},
};
}

#[ink(message)]
pub fn get(&mut self) -> Result<bool> {
match &self.other_contract_address {
Expand Down
1 change: 0 additions & 1 deletion dapps/evm/flipper
Submodule flipper deleted from 4147b3
2 changes: 2 additions & 0 deletions dapps/evm2/flipper/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://faucet.moonbeam.network/
MOONBASE_PRIVATE_KEY='0x'
5 changes: 5 additions & 0 deletions dapps/evm2/flipper/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build
node_modules
package-lock.json
release-version.json
.env
22 changes: 22 additions & 0 deletions dapps/evm2/flipper/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2018 Truffle

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

108 changes: 108 additions & 0 deletions dapps/evm2/flipper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Flipper

Note: The following was based upon Moonbeam Truffle Box https://docs.moonbeam.network/builders/build/eth-api/dev-env/truffle/

## Getting started

* Install Node.js v18.x (i.e. v18.16.0) since has LTS https://nodejs.org/en/download/releases
* Use an LTS version of NPM to avoid error `This version of µWS is not compatible with your Node.js build` https://stackoverflow.com/questions/71081725/this-version-of-%C2%B5ws-is-not-compatible-with-your-node-js-build-error-node-loade

```bash
apt-get remove -y nodejs
rm -rf /usr/lib/node_modules/
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
apt-get install -y nodejs
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | tee /etc/apt/sources.list.d/yarn.list
apt-get update && apt-get install yarn
npm config rm proxy
npm config rm https-proxy
```
* Install Truffle dependency:
```bash
npm install -g truffle
```
* Check if works
```bash
truffle --version
```
* Fix permissions error since /usr/bin/truffle symlinks to below but below didn't have execute permissions for any users
```bash
chmod 755 /usr/lib/node_modules/truffle/build/cli.bundled.js
```
* Setup Moonbeam Truffle Box template that this has been based upon
```bash
mkdir -p /app/dapps/evm/flipper
DAPP_PATH=/app/dapps/evm/flipper
git clone https://github.com/PureStake/moonbeam-truffle-box $DAPP_PATH
cd $DAPP_PATH
```bash
* Replace template contracts with just https://github.com/hyperledger/solang/blob/main/examples/substrate/flipper.sol and add `pragma solidity ^0.8.0;`

* Update all dependencies in package.json to new major version
```bash
npm outdated
npm install -g npm-check-updates
ncu -u
npm update
```
* Install dependencies
```bash
npm install
```

* Install Docker in Docker container
```bash
apt-get remove docker docker-engine docker.io containerd runc
apt-get update && apt-get upgrade -y
apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update
apt-get install docker-ce docker-ce-cli containerd.io -y
adduser user
usermod -aG docker user
systemctl restart docker
systemctl enable docker
apt-get install -y docker-compose-plugin
apt-get install docker-compose
```

Note: It is necessary to run Docker within a Docker container https://devopscube.com/run-docker-in-docker/ in order to use `truffle run moonbeam ...` commands from https://trufflesuite.com/boxes/moonbeam-truffle-box/, which use the Moonbeam Truffle Box plugin https://github.com/PureStake/moonbeam-truffle-plugin, which uses images from Docker hub https://hub.docker.com/r/purestake/moonbeam/tags, or setup manually by following https://docs.moonbeam.network/node-operators/networks/run-a-node/flags/, as follows:

To run a local node run similar to the following:
```bash
mkdir /opt/moonbeam
git clone https://github.com/PureStake/moonbeam /opt/moonbeam
cd /opt/moonbeam
git checkout tags/$(git describe --tags)
cargo build
./target/debug/moonbeam --help
```

Then configure Truffle to connect to it Moonbeam Development `node_modules/.bin/truffle migrate --network dev`. Note that use of Ganache does not include pre-compiles https://docs.moonbeam.network/builders/build/eth-api/dev-env/truffle/.

Preferably use Moonbase Alpha TestNet `node_modules/.bin/truffle migrate --network moonbase` that requires testnet tokens from the faucet https://faucet.moonbeam.network/.

Run tests
```
truffle test
```

* Generate account with Moonkey https://docs.moonbeam.network/node-operators/networks/collators/requirements/#generating-an-account-with-moonkey
```
cd /opt
wget https://github.com/PureStake/moonbeam/releases/download/v0.8.0/moonkey /opt
shasum -a 256 moonkey
```
* Verify output is `019c3de832ded3fccffae950835bb455482fca92714448cc0086a7c5f3d48d3e`
* Generate account `./moonkey --w12`
* Obtain Moonbase Alpha tokens from faucet
* https://faucet.moonbeam.network/

* Compile contracts on network of choice (i.e. "moonbase") defined in truffle.js
* Compile full `truffle compile --compile-all`
* Migrate
* Migrate full `truffle migrate --reset --compile-all --network moonbase`
* TODO - use for cross-contract calls
24 changes: 24 additions & 0 deletions dapps/evm2/flipper/contracts/Flipper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

contract Flipper {
bool private value;

/// Constructor that initializes the `bool` value to the given `init_value`.
constructor(bool initvalue) {
value = initvalue;
}

/// A message that can be called on instantiated contracts.
/// This one flips the value of the stored `bool` from `true`
/// to `false` and vice versa.
function flip() public {
value = !value;
}

/// Simply returns the current value of our `bool`.
function get() public view returns (bool) {
return value;
}
}
19 changes: 19 additions & 0 deletions dapps/evm2/flipper/contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Migrations {
address public owner;
uint public last_completed_migration;

constructor() {
owner = msg.sender;
}

modifier restricted() {
if (msg.sender == owner) _;
}

function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}
}
5 changes: 5 additions & 0 deletions dapps/evm2/flipper/migrations/1_initial_migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const Migrations = artifacts.require("Migrations");

module.exports = deployer => {
deployer.deploy(Migrations);
};
5 changes: 5 additions & 0 deletions dapps/evm2/flipper/migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var Flipper = artifacts.require("Flipper");

module.exports = function (deployer) {
deployer.deploy(Flipper, false);
};
11 changes: 11 additions & 0 deletions dapps/evm2/flipper/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "flipper",
"version": "1.0.0",
"dependencies": {
"@truffle/hdwallet-provider": "^2.1.12",
"dotenv": "^16.3.1",
"moonbeam-truffle-plugin": "github:PureStake/moonbeam-truffle-plugin",
"truffle": "^5.10.0",
"truffle-plugin-verify": "^0.6.3"
}
}
24 changes: 24 additions & 0 deletions dapps/evm2/flipper/test/test_Flipper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Uses Mocha and Ganache
const Flipper = artifacts.require("Flipper");

contract('Flipper', accounts => {
let flipper;
const initValue = false;
beforeEach(async () => {
// Deploy token contract
flipper = await Flipper.new(initValue, { from: accounts[0] });
});
// Check stored value
it("checks stored value", async () => {
const value = await flipper.get.call();
assert.equal(value, initValue, 'value stored does not match initial value');
});

// Set flipped value of existing value
it("should flip the value", async () => {
const previousValue = await flipper.get.call();
await flipper.flip.call({ from: accounts[0] });
const newValue = await flipper.flip.call();
assert.notEqual(previousValue, newValue, 'newValue is not opposite of previousValue');
})
});
21 changes: 21 additions & 0 deletions dapps/evm2/flipper/truffle-box.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"ignore": [
"README.md",
".gitignore"
],
"commands": {
"Compile contracts": "truffle compile",
"Migrate contracts": "truffle migrate",
"Test contracts": "truffle test",
"Pull docker image development node": "truffle run moonbeam install",
"Start development node": "truffle run moonbeam start",
"Stop docker image development node": "truffle run moonbeam stop",
"Pause development node": "truffle run moonbeam pause",
"Unpause docker image development node": "truffle run moonbeam unpause",
"Get development node status": "truffle run moonbeam status",
"Remove docker image development node": "truffle run moonbeam remove"
},
"hooks": {
"post-unpack": ""
}
}
Loading