Skip to content

Commit

Permalink
add option in metadata url
Browse files Browse the repository at this point in the history
  • Loading branch information
supernovahs committed Jun 6, 2024
1 parent 7d6e616 commit 1d8adea
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
30 changes: 23 additions & 7 deletions crates/chainio/clients/elcontracts/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,29 @@ impl ELChainWriter {

let contract_delegation_manager = DelegationManager::new(self.delegation_manager, provider);

let contract_call =
contract_delegation_manager.registerAsOperator(op_details, operator.has_metadata_url());
match operator.has_metadata_url(){
Some(metadata) =>{
let contract_call =
contract_delegation_manager.registerAsOperator(op_details,metadata );

let tx = contract_call.send().await?;

info!(tx_hash = %tx.tx_hash(), "tx successfully included");
Ok(*tx.tx_hash())
},
None=>{
let contract_call =
contract_delegation_manager.registerAsOperator(op_details,"".to_string() );

let tx = contract_call.send().await?;

info!(tx_hash = %tx.tx_hash(), "tx successfully included");
Ok(*tx.tx_hash())
}

let tx = contract_call.send().await?;

info!(tx_hash = %tx.tx_hash(), "tx successfully included");
Ok(*tx.tx_hash())
}


}

pub async fn update_operator_details(
Expand Down Expand Up @@ -118,7 +134,7 @@ impl ELChainWriter {
info!(tx_hash = %tx.tx_hash(), operator = %operator.has_address(), "succesfully updated operator details");

let contract_call_update_metadata_uri =
contract_delegation_manager.updateOperatorMetadataURI(operator.has_metadata_url());
contract_delegation_manager.updateOperatorMetadataURI(operator.has_metadata_url().unwrap_or_default());

let metadata_tx = contract_call_update_metadata_uri.send().await?;

Expand Down
10 changes: 5 additions & 5 deletions crates/types/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct Operator {
earnings_receiver_address: Address,
delegation_approver_address: Address,
staker_opt_out_window_blocks: u32,
metadata_url: String,
metadata_url: Option<String>,
}

impl Operator {
Expand All @@ -57,7 +57,7 @@ impl Operator {
earnings_receiver_address,
delegation_approver_address,
staker_opt_out_window_blocks,
metadata_url: metadata_url.unwrap(),
metadata_url: metadata_url,
}
}

Expand All @@ -66,7 +66,7 @@ impl Operator {
}

pub fn metadata_url(&mut self, metadata: String) {
self.metadata_url = metadata;
self.metadata_url = Some(metadata);
}

pub fn earnings_receiver_address(&mut self, address: Address) {
Expand All @@ -85,8 +85,8 @@ impl Operator {
self.address
}

pub fn has_metadata_url(&self) -> String {
self.metadata_url.clone()
pub fn has_metadata_url(&self) -> Option<String> {
self.metadata_url.clone()
}

pub fn has_earnings_receiver_address(&self) -> Address {
Expand Down

0 comments on commit 1d8adea

Please sign in to comment.