Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VRF Logic #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
112 changes: 112 additions & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ k256 = "0.13.2"
subxt-signer = "0.32.1"
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
log = "0.4.14"
structopt = { version = "0.3" }
structopt = { version = "0.3" }
vrf = "0.2.4"
hex = "0.4.3"
46 changes: 45 additions & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::evmclient::EvmClient;
use crate::substrateclient::SubstrateClient;
use crate::traits::VerificationMode;
use ethers::abi::{ethabi, Contract};
use std::path::PathBuf;

Expand All @@ -17,6 +18,8 @@ pub struct Builder<Url, ContractFile, SeedString, ContractAddress> {
contract: ContractFile,
seed: SeedString,
contract_address: ContractAddress,
vrf_seed: String,
mode: VerificationMode,
}

impl Default for Builder<NoDestinationChain, NoContract, NoSeed, NoTheaContractAddress> {
Expand All @@ -26,6 +29,8 @@ impl Default for Builder<NoDestinationChain, NoContract, NoSeed, NoTheaContractA
contract: NoContract,
seed: NoSeed,
contract_address: NoTheaContractAddress,
vrf_seed: "".to_string(),
mode: VerificationMode::Relayer,
}
}
}
Expand All @@ -42,6 +47,8 @@ impl<Url, ContractFile, SeedString, ContractAddress>
contract: self.contract,
seed: self.seed,
contract_address: self.contract_address,
vrf_seed: self.vrf_seed,
mode: self.mode,
}
}

Expand All @@ -56,6 +63,8 @@ impl<Url, ContractFile, SeedString, ContractAddress>
contract: EVMContract(log_contract),
seed: self.seed,
contract_address: self.contract_address,
vrf_seed: self.vrf_seed,
mode: self.mode,
}
}

Expand All @@ -65,6 +74,8 @@ impl<Url, ContractFile, SeedString, ContractAddress>
contract: self.contract,
seed: Seed(seed),
contract_address: self.contract_address,
vrf_seed: self.vrf_seed,
mode: self.mode,
}
}

Expand All @@ -77,6 +88,36 @@ impl<Url, ContractFile, SeedString, ContractAddress>
contract: self.contract,
seed: self.seed,
contract_address: TheaContractAddress(contract_address),
vrf_seed: self.vrf_seed,
mode: self.mode,
}
}

pub fn vrf_seed(
self,
vrf_seed: String,
) -> Builder<Url, ContractFile, SeedString, ContractAddress> {
Builder {
chain_url: self.chain_url,
contract: self.contract,
seed: self.seed,
contract_address: self.contract_address,
vrf_seed,
mode: self.mode,
}
}

pub fn mode(
self,
mode: VerificationMode,
) -> Builder<Url, ContractFile, SeedString, ContractAddress> {
Builder {
chain_url: self.chain_url,
contract: self.contract,
seed: self.seed,
contract_address: self.contract_address,
vrf_seed: self.vrf_seed,
mode,
}
}
}
Expand All @@ -88,12 +129,15 @@ impl Builder<DestinationChain, EVMContract, Seed, TheaContractAddress> {
self.contract.0,
self.seed.0,
self.contract_address.0,
self.mode,
self.vrf_seed,
)
.await
}
}

impl Builder<DestinationChain, NoContract, NoSeed, NoTheaContractAddress> { //FIXME: Take seed while building
impl Builder<DestinationChain, NoContract, NoSeed, NoTheaContractAddress> {
//FIXME: Take seed while building
pub async fn build(self) -> SubstrateClient {
SubstrateClient::initialize(self.chain_url.0).await.unwrap()
}
Expand Down
30 changes: 10 additions & 20 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
use crate::traits::VerificationMode;
use std::path::PathBuf;
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
pub struct Cli {
#[structopt(parse(from_os_str))]
pub thea_contract: PathBuf,
#[structopt(
short = "e",
long = "eth-url",
default_value = "https://ropsten.infura.io/v3/3d30527c65a144f082effabeaa0c778d"
)]
#[structopt(short = "e", long = "eth-url")]
pub eth_url: String,
#[structopt(
short = "e",
long = "sub-url",
default_value = "localhost:9944"
)]
#[structopt(short = "e", long = "sub-url", default_value = "localhost:9944")]
pub sub_url: String,
#[structopt(
short = "t",
long = "thea-contract-address",
default_value = "0x69F593B0F96EE94041422bF60208Ec6d007D909F"
)]
#[structopt(short = "t", long = "thea-contract-address")]
pub thea_contract_address: String,
#[structopt(
short = "s",
long = "seed",
default_value = "380eb0f3d505f087e438eca80bc4df9a7faa24f868e69fc0440261a0fc0567da"
)]
#[structopt(short = "s", long = "seed")]
pub seed: String,
#[structopt(short = "vs", long = "vrf-seed")]
pub vrf_seed: String,

#[structopt(short = "m", long = "mode")]
pub verification_mode: VerificationMode,
}
Loading