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
call via main but no Builder not support tuple return Decode(Error)
  • Loading branch information
ltfschoen committed Jun 18, 2023
commit 5686da39b1a109258c7bf7c68917a84e83ff2e19
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

146 changes: 125 additions & 21 deletions dapps/xcm/unnamed/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

#[ink::contract]
mod unnamed {
use ink::env::{
call::{
build_create,
build_call,
ExecutionInput,
Selector,
},
DefaultEnvironment,
};

use oracle_contract::OracleContractRef;

use ink::prelude::string::String;
Expand All @@ -10,6 +20,13 @@ mod unnamed {
// refactor into types file
pub type OracleOwner = AccountId;

#[derive(Clone, Debug, scale::Encode, scale::Decode)]
#[cfg_attr(
feature = "std",
derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout)
)]
pub struct EntropyData(BlockNumber, String, i16, i16);

/// Defines the storage of your contract.
/// Add new fields to the below struct in order
/// to add new static storage fields to your contract.
Expand All @@ -18,6 +35,7 @@ mod unnamed {
pub struct Unnamed {
/// Store a reference to the `OracleContract`.
oracle_contract: Option<OracleContractRef>,
oracle_contract_address: Option<AccountId>,
owner: Option<OracleOwner>,
}

Expand All @@ -27,6 +45,7 @@ mod unnamed {
pub enum Error {
/// Returned if not oracle contract address exists.
NoOracleContractAddress,
ResponseError,
}

/// Type alias for the contract's result type.
Expand All @@ -37,26 +56,32 @@ mod unnamed {
#[ink(constructor)]
pub fn new(
oracle_contract_code_hash: Hash,
oracle_contract_address: AccountId,
id_market: String,
block_number_guessed: BlockNumber,
block_number_entropy: BlockNumber,
block_number_end: BlockNumber,
) -> Self {
let instance = Self::default();
let caller = instance.env().caller();
let oracle_contract = OracleContractRef::new(
id_market,
block_number_guessed,
block_number_entropy,
block_number_end,
)
let oracle_contract = build_create::<OracleContractRef>()
.code_hash(oracle_contract_code_hash)
.gas_limit(100000000000)
.endowment(0)
.exec_input(
ExecutionInput::new(Selector::new(ink::selector_bytes!("new")))
.push_arg(id_market)
.push_arg(block_number_guessed)
.push_arg(block_number_entropy)
.push_arg(block_number_end)
)
.salt_bytes([0xDE, 0xAD, 0xBE, 0xEF])
.returns::<OracleContractRef>()
.instantiate();

Self {
oracle_contract: Some(oracle_contract),
oracle_contract_address: Some(oracle_contract_address),
owner: Some(caller),
}
}
Expand All @@ -69,14 +94,23 @@ mod unnamed {
block_number_entropy: BlockNumber, // always require this even though it may not have changed
block_hash_entropy: String, // Hash
) -> Result<()> {
ink::env::debug_println!("&self.oracle_contract {:?}", &self.oracle_contract);
match &self.oracle_contract {
ink::env::debug_println!("&self.oracle_contract_address {:?}", &self.oracle_contract_address);
match &self.oracle_contract_address {
Some(c) => {
let res = c.clone().set_block_for_entropy_for_market_id(
id_market,
block_number_entropy,
block_hash_entropy.clone(),
);
// using CallBuilder
// https://use.ink/basics/cross-contract-calling#callbuilder
build_call::<DefaultEnvironment>()
.call(c.clone())
.gas_limit(100000000000)
.transferred_value(0)
.exec_input(
ExecutionInput::new(Selector::new(ink::selector_bytes!("set_block_for_entropy_for_market_id")))
.push_arg(id_market)
.push_arg(block_number_entropy)
.push_arg(block_hash_entropy.clone())
)
.returns::<()>()
.invoke();
Ok(())
},
None => return Err(Error::NoOracleContractAddress),
Expand All @@ -85,14 +119,65 @@ 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 {
pub fn set_entropy_for_market_id(
&mut self,
id_market: String,
block_number_entropy: BlockNumber, // always require this even though it may not have changed
block_hash_entropy: String, // Hash
c1_entropy: i16,
c2_entropy: i16,
) -> Result<()> {
ink::env::debug_println!("&self.oracle_contract_address {:?}", &self.oracle_contract_address);
match &self.oracle_contract_address {
Some(c) => {
let res = match c.clone().get_entropy_for_market_id(id_market) {
Ok(r) => r,
Err(_e) => panic!("arr {:?}", _e),
// using CallBuilder
// https://use.ink/basics/cross-contract-calling#callbuilder
build_call::<DefaultEnvironment>()
.call(c.clone())
.gas_limit(100000000000)
.transferred_value(0)
.exec_input(
ExecutionInput::new(Selector::new(ink::selector_bytes!("set_entropy_for_market_id")))
.push_arg(id_market)
.push_arg(block_number_entropy)
.push_arg(block_hash_entropy.clone())
.push_arg(c1_entropy)
.push_arg(c2_entropy)
)
.returns::<()>()
.invoke();
Ok(())
},
None => return Err(Error::NoOracleContractAddress),
}
}

/// 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<EntropyData> {
match &self.oracle_contract_address {
Some(c) => {
let res =
build_call::<DefaultEnvironment>()
.call(c.clone())
.gas_limit(100000000000)
.exec_input(
ExecutionInput::new(Selector::new(ink::selector_bytes!("get_entropy_for_market_id")))
.push_arg(id_market)
)
.returns::<EntropyData>()
.try_invoke()
.expect("Error calling get_entropy_for_market_id.");
match res {
Ok(tuple) => {
ink::env::debug_println!("tuple {:?}", tuple);
return Ok(tuple);
},
Err(e) => {
ink::env::debug_println!("error {:?}", e);
return Err(Error::ResponseError);
},
};
Ok(res)
},
None => return Err(Error::NoOracleContractAddress),
}
Expand All @@ -101,9 +186,28 @@ mod unnamed {
/// 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 {
match &self.oracle_contract_address {
Some(c) => {
Ok(c.clone().get_oracle_contract_address())
let res =
build_call::<DefaultEnvironment>()
.call(c.clone())
.gas_limit(100000000000)
.exec_input(
ExecutionInput::new(Selector::new(ink::selector_bytes!("get_oracle_contract_address")))
)
.returns::<AccountId>()
.try_invoke()
.expect("Error calling get_oracle_contract_address.");
match res {
Ok(contract_address) => {
ink::env::debug_println!("contract_address {:?}", contract_address);
return Ok(contract_address);
},
Err(e) => {
ink::env::debug_println!("error {:?}", e);
return Err(Error::ResponseError);
},
};
},
None => return Err(Error::NoOracleContractAddress),
}
Expand Down
26 changes: 21 additions & 5 deletions dapps/xcm/unnamed/oracle_contract/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ mod oracle_contract {
pub type MarketGuessId = Vec<u8>;
pub type OracleOwner = AccountId;

#[derive(Clone, Debug, scale::Encode, scale::Decode)]
#[cfg_attr(
feature = "std",
derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout)
)]
pub struct EntropyData(BlockNumber, String, i16, i16);

/// Emitted when create new market guess for market id.
#[ink(event)]
pub struct NewOracleMarketGuessForMarketId {
Expand Down Expand Up @@ -216,17 +223,23 @@ mod oracle_contract {
// waiting sufficient blocks after previous so guarantee of waiting until \
// validators change after a certain amount of epochs"
// );
ink::env::debug_println!("111");
let block_hash_entropy_no_prefix = block_hash_entropy.replace("0x", "");
ink::env::debug_println!("222");
assert!(block_hash_entropy_no_prefix.len() == 64, "block hash should be a 256 bit block hash");

ink::env::debug_println!("333 {:?}, {:?}", market_guess.oracle_owner, caller);
// FIXME - if called from the main contract then the caller won't be the oracle_owner,
// instead it'll be the main contract's address
if market_guess.oracle_owner != Some(caller) {
return Err(Error::CallerIsNotOracleOwner)
return Err(Error::CallerIsNotOracleOwner);
}
ink::env::debug_println!("444");
let new_market_guess = MarketGuess {
block_number_entropy,
block_hash_entropy: Some(block_hash_entropy_no_prefix.clone()),
..market_guess
};
ink::env::debug_println!("new_market_guess: {:?}\n", new_market_guess);
self.market_data.insert(id_market.clone().into_bytes(), &new_market_guess);
self.env().emit_event(SetBlockHashEntropyForMarketId {
id_market: id_market.clone().into_bytes(),
Expand All @@ -246,13 +259,14 @@ mod oracle_contract {
c1_entropy: i16,
c2_entropy: i16,
) -> Result<()> {
ink::env::debug_println!("set_entropy_for_market_id");
let caller: AccountId = self.env().caller();
let market_guess = match self.market_data.get(id_market.clone().into_bytes()) {
Some(data) => data,
None => return Err(Error::NoDataForMarketGuessId),
};
if market_guess.oracle_owner != Some(caller) {
return Err(Error::CallerIsNotOracleOwner)
return Err(Error::CallerIsNotOracleOwner);
}
let block_hash_entropy_no_prefix = block_hash_entropy.replace("0x", "");
assert!(block_hash_entropy_no_prefix.len() == 64, "block hash should be a 256 bit block hash");
Expand All @@ -271,6 +285,7 @@ mod oracle_contract {
c2_entropy: Some(c2_entropy),
..market_guess
};
ink::env::debug_println!("new_market_guess: {:?}\n", new_market_guess);
self.market_data.insert(id_market.clone().into_bytes(), &new_market_guess);
self.env().emit_event(SetEntropyForMarketId {
id_market: id_market.into_bytes(),
Expand All @@ -290,7 +305,7 @@ mod oracle_contract {
}

#[ink(message)]
pub fn get_entropy_for_market_id(&self, id_market: String) -> Result<(BlockNumber, String, i16, i16)> {
pub fn get_entropy_for_market_id(&self, id_market: String) -> Result<EntropyData> {
let caller: AccountId = self.env().caller();
let market_guess = match self.market_data.get(id_market.clone().into_bytes()) {
Some(data) => data,
Expand Down Expand Up @@ -349,7 +364,8 @@ mod oracle_contract {
c2_entropy: c2_rem,
});

Ok((block_number_entropy, block_hash_entropy.clone(), c1_rem, c2_rem))
let entropy_data = EntropyData(block_number_entropy, block_hash_entropy.clone(), c1_rem, c2_rem);
Ok(entropy_data)
}

// get symbols 61-64 for coin1 and 57-60 for coin2 fro the block hash
Expand Down
Loading