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

[miner] Update miner to retrieve and write sBTC ops to the .sbtc contract #3960

Open
jferrant opened this issue Sep 20, 2023 · 0 comments
Open
Labels
feature Brand new functionality. New pages, workflows, endpoints, etc.

Comments

@jferrant
Copy link
Collaborator

The miner should be updating the contract with sBTC ops similar to the below code snippet:

for stack_stx_op in operations.into_iter() {
   let StackStxOp {
       sender,
       reward_addr,
       stacked_ustx,
       num_cycles,
       block_height,
       txid,
       burn_header_hash,
       ..
   } = &stack_stx_op;
   let result = clarity_tx.connection().as_transaction(|tx| {
       tx.run_contract_call(
           &sender.clone().into(),
           None,
           &boot_code_id(active_pox_contract, mainnet),
           "stack-stx",
           &[
               Value::UInt(*stacked_ustx),
               // this .expect() should be unreachable since we coerce the hash mode when
               // we parse the StackStxOp from a burnchain transaction
               reward_addr
                   .as_clarity_tuple()
                   .expect("FATAL: stack-stx operation has no hash mode")
                   .into(),
               Value::UInt(u128::from(*block_height)),
               Value::UInt(u128::from(*num_cycles)),
           ],
           |_, _| false,
       )
   });
   match result {
       Ok((value, _, events)) => {
           if let Value::Response(ref resp) = value {
               if !resp.committed {
                   debug!("StackStx burn op rejected by PoX contract.";
                          "txid" => %txid,
                          "burn_block" => %burn_header_hash,
                          "contract_call_ecode" => %resp.data);
               } else {
                   debug!("Processed StackStx burnchain op"; "amount_ustx" => stacked_ustx, "num_cycles" => num_cycles, "burn_block_height" => block_height, "sender" => %sender, "reward_addr" => %reward_addr, "txid" => %txid);
               }
               let mut execution_cost = clarity_tx.cost_so_far();
               execution_cost
                   .sub(&cost_so_far)
                   .expect("BUG: cost declined between executions");

Depends on #3958

@jferrant jferrant added the feature Brand new functionality. New pages, workflows, endpoints, etc. label Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Brand new functionality. New pages, workflows, endpoints, etc.
Projects
Status: Status: 🆕 New
Development

No branches or pull requests

1 participant