MCPcopy Index your code
hub / github.com/BitVM/BitVM / process_peg_in_as_operator

Method process_peg_in_as_operator

bridge/src/client/client.rs:770–817  ·  view source on GitHub ↗

TODO: refactor, see note on self.process_peg_in_as_verifier

(&mut self, peg_in_graph_id: &GraphId)

Source from the content-addressed store, hash-verified

768
769 // TODO: refactor, see note on self.process_peg_in_as_verifier
770 pub async fn process_peg_in_as_operator(&mut self, peg_in_graph_id: &GraphId) {
771 if let Some(ref context) = self.operator_context {
772 if let Ok(peg_in_graph) = self.get_peg_in_graph(peg_in_graph_id) {
773 let peg_out_graph_id =
774 peg_out_generate_id(peg_in_graph, &context.operator_public_key);
775 if !peg_in_graph
776 .peg_out_graphs
777 .iter()
778 .any(|x| x == &peg_out_graph_id)
779 {
780 let deposit_amount =
781 peg_in_graph.peg_in_deposit_transaction.tx().output[0].value;
782 let reward_amount = deposit_amount * REWARD_MULTIPLIER / REWARD_PRECISION;
783 let expected_peg_out_confirm_amount = reward_amount.to_sat() + PEG_OUT_FEE;
784 let input = {
785 // todo: don't use a random address
786 let address = generate_pay_to_pubkey_script_address(
787 context.network,
788 &context.operator_public_key,
789 );
790 let utxos = self
791 .esplora
792 .get_address_utxo(address.clone())
793 .await
794 .unwrap();
795 let utxo = utxos
796 .into_iter()
797 .find(|x| x.value.to_sat() >= expected_peg_out_confirm_amount)
798 .unwrap_or_else(|| {
799 panic!("No utxo found with at least {expected_peg_out_confirm_amount} sats for address {address}")
800 });
801 Input {
802 amount: utxo.value,
803 outpoint: OutPoint {
804 txid: utxo.txid,
805 vout: utxo.vout,
806 },
807 }
808 };
809 self.create_peg_out_graph(
810 peg_in_graph_id,
811 input,
812 CommitmentMessageId::generate_commitment_secrets(),
813 );
814 }
815 }
816 }
817 }
818
819 pub async fn process_peg_ins(&mut self) {
820 for peg_in_graph in self.data.peg_in_graphs.clone() {

Callers 2

process_peg_insMethod · 0.80

Calls 5

get_peg_in_graphMethod · 0.80
cloneMethod · 0.80
create_peg_out_graphMethod · 0.80
txMethod · 0.45

Tested by 1