1

I'm writing a script with subxt. How can I wrap a set_code tx in a sudo_unchecked_weight tx?

Current code:

    let sudo_set_code: Payload<SetCode>  = nodetemplate::tx().system().set_code(code);
    let weight = Weight {
        ref_time: 0,
        proof_size: 0,
    };
    let sudo_tx = nodetemplate::tx().sudo().sudo_unchecked_weight(sudo_set_code, weight);

Traceback:

error[E0308]: mismatched types
  --> src/main.rs:29:67
   |
29 |     let sudo_tx = nodetemplate::tx().sudo().sudo_unchecked_weight(sudo_set_code, weight);
   |                                             --------------------- ^^^^^^^^^^^^^ expected `RuntimeCall`, found `Payload<SetCode>`
   |                                             |
   |                                             arguments to this method are incorrect
   |
   = note: expected enum `RuntimeCall`
            found struct `subxt::tx::Payload<SetCode>`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `test_sudo_subxt` (bin "test_sudo_subxt") due to previous error


1
  • We'd like to support your "current code" eventually somehow, but it's tricky, so alas at the moment you indeed need to use the generated types manually to construct any "inner" extrinsics. We'll get there eventually I hope!
    – jsdw
    Aug 2 at 14:39

1 Answer 1

3

Solved it:

  let call = nodetemplate::runtime_types::node_template_runtime::RuntimeCall::System(
        SystemCall::set_code {
            code: wasm_binary.expect("could not decode wasm binary").into(),
        },
 let sudo_tx = nodetemplate::tx()
        .sudo()
        .sudo_unchecked_weight(call, weight);

Full code can be found here:
https://github.com/uptest-sc/submit-runtime-upgrade/blob/main/src/main.rs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.