Skip to content

Commit 0eee513

Browse files
author
Dev Kalra
authored
[fortuna] bind provider and contract address (#1218)
* bind provider and contract address * pre commit
1 parent 43bc28d commit 0eee513

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

fortuna/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fortuna/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fortuna"
3-
version = "3.1.0"
3+
version = "3.2.0"
44
edition = "2021"
55

66
[dependencies]

fortuna/src/command/register_provider.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ use {
88
state::PebbleHashChain,
99
},
1010
anyhow::Result,
11+
ethers::{
12+
signers::{
13+
LocalWallet,
14+
Signer,
15+
},
16+
types::Address,
17+
},
1118
std::sync::Arc,
1219
};
1320

@@ -20,22 +27,24 @@ pub struct CommitmentMetadata {
2027
/// Register as a randomness provider. This method will generate and commit to a new random
2128
/// hash chain from the configured secret & a newly generated random value.
2229
pub async fn register_provider(opts: &RegisterProviderOptions) -> Result<()> {
23-
// Initialize a Provider to interface with the EVM contract.
24-
let contract = Arc::new(
25-
SignablePythContract::from_config(
26-
&Config::load(&opts.config.config)?.get_chain_config(&opts.chain_id)?,
27-
&opts.private_key,
28-
)
29-
.await?,
30-
);
30+
let chain_config = Config::load(&opts.config.config)?.get_chain_config(&opts.chain_id)?;
3131

32+
// Initialize a Provider to interface with the EVM contract.
33+
let contract =
34+
Arc::new(SignablePythContract::from_config(&chain_config, &opts.private_key).await?);
3235
// Create a new random hash chain.
3336
let random = rand::random::<[u8; 32]>();
3437
let secret = opts.randomness.load_secret()?;
3538

3639
let commitment_length = opts.randomness.chain_length;
37-
let mut chain =
38-
PebbleHashChain::from_config(&secret, &opts.chain_id, &random, commitment_length)?;
40+
let mut chain = PebbleHashChain::from_config(
41+
&secret,
42+
&opts.chain_id,
43+
&opts.private_key.clone().parse::<LocalWallet>()?.address(),
44+
&chain_config.contract_addr,
45+
&random,
46+
commitment_length,
47+
)?;
3948

4049
// Arguments to the contract to register our new provider.
4150
let fee_in_wei = opts.fee;

fortuna/src/command/run.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ pub async fn run(opts: &RunOptions) -> Result<()> {
6868
let hash_chain = PebbleHashChain::from_config(
6969
&secret,
7070
&chain_id,
71+
&opts.provider,
72+
&chain_config.contract_addr,
7173
&metadata.seed,
7274
metadata.chain_length,
7375
)?;

fortuna/src/state.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use {
44
ensure,
55
Result,
66
},
7+
ethers::types::Address,
78
sha3::{
89
Digest,
910
Keccak256,
@@ -35,12 +36,16 @@ impl PebbleHashChain {
3536
pub fn from_config(
3637
secret: &str,
3738
chain_id: &ChainId,
39+
provider_address: &Address,
40+
contract_address: &Address,
3841
random: &[u8; 32],
3942
chain_length: u64,
4043
) -> Result<Self> {
4144
let mut input: Vec<u8> = vec![];
4245
input.extend_from_slice(&hex::decode(secret)?);
4346
input.extend_from_slice(&chain_id.as_bytes());
47+
input.extend_from_slice(&provider_address.as_bytes());
48+
input.extend_from_slice(&contract_address.as_bytes());
4449
input.extend_from_slice(random);
4550

4651
let secret: [u8; 32] = Keccak256::digest(input).into();

0 commit comments

Comments
 (0)