ergoplatform / ergo-headless-dapp-framework

An easy to use framework for building Ergo headless dApps. Developed by EMURGO and Ergo Platform.
MIT License
25 stars 5 forks source link

Issues - (Math Bounty Headless dApp - Getting Started Writing Your First Action) #6

Open dbuchacher opened 2 years ago

dbuchacher commented 2 years ago

Under: Preparing Your Project

the current text doesn't work

ergo-headless-dapp-framework      = "0.1.0"
ergo-lib                          = "0.4.0"

update to?

ergo-headless-dapp-framework      = "0.1.0"
ergo-lib                          = "0.15.0"
bounded-vec                       = "0.5.0"

Under: This is the final code from everything we've accomplished in this tutorial:

the current lines not working

Line 59: UnsignedTransaction::new(tx_inputs, vec![], output_candidates)
Line 108: UnsignedTransaction::new(tx_inputs, vec![], output_candidates)

update to?

Line 59: UnsignedTransaction::new(tx_inputs, vec![], output_candidates).unwrap()
Line 108: UnsignedTransaction::new(tx_inputs, vec![], output_candidates).unwrap()

then there are now some issues with needing to use bounded-vec but I gave up at this point and now I'm writing this.

console log

PS D:\code\rust\ergo-test> cargo build
   Compiling ergo-test v0.1.0 (D:\code\rust\ergo-test)
error[E0308]: mismatched types
  --> src\lib.rs:59:34
   |
59 |         UnsignedTransaction::new(tx_inputs, vec![], output_candidates).unwrap()
   |                                  ^^^^^^^^^ expected struct `bounded_vec::bounded_vec::BoundedVec`, found struct `Vec`
   |
   = note: expected struct `bounded_vec::bounded_vec::BoundedVec<ergo_lib::chain::transaction::input::UnsignedInput, 1_usize, 65535_usize>`
              found struct `Vec<ergo_lib::chain::transaction::input::UnsignedInput>`

error[E0308]: mismatched types
  --> src\lib.rs:59:45
   |
59 |         UnsignedTransaction::new(tx_inputs, vec![], output_candidates).unwrap()
   |                                             ^^^^^^ expected enum `Option`, found struct `Vec`
   |
   = note: expected enum `Option<bounded_vec::bounded_vec::BoundedVec<ergo_lib::chain::transaction::data_input::DataInput, 1_usize, 65535_usize>>`
            found struct `Vec<_>`
   = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
  --> src\lib.rs:59:53
   |
59 |         UnsignedTransaction::new(tx_inputs, vec![], output_candidates).unwrap()
   |                                                     ^^^^^^^^^^^^^^^^^ expected struct `bounded_vec::bounded_vec::BoundedVec`, found struct `Vec`
   |
   = note: expected struct `bounded_vec::bounded_vec::BoundedVec<ergotree_ir::chain::ergo_box::ErgoBoxCandidate, 1_usize, 65535_usize>`
              found struct `Vec<ergotree_ir::chain::ergo_box::ErgoBoxCandidate>`

error[E0308]: mismatched types
   --> src\lib.rs:108:34
    |
108 |         UnsignedTransaction::new(tx_inputs, vec![], output_candidates).unwrap()
    |                                  ^^^^^^^^^ expected struct `bounded_vec::bounded_vec::BoundedVec`, found struct `Vec`
    |
    = note: expected struct `bounded_vec::bounded_vec::BoundedVec<ergo_lib::chain::transaction::input::UnsignedInput, 1_usize, 65535_usize>`
               found struct `Vec<ergo_lib::chain::transaction::input::UnsignedInput>`

error[E0308]: mismatched types
   --> src\lib.rs:108:45
    |
108 |         UnsignedTransaction::new(tx_inputs, vec![], output_candidates).unwrap()
    |                                             ^^^^^^ expected enum `Option`, found struct `Vec`
    |
    = note: expected enum `Option<bounded_vec::bounded_vec::BoundedVec<ergo_lib::chain::transaction::data_input::DataInput, 1_usize, 65535_usize>>`
             found struct `Vec<_>`
    = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
   --> src\lib.rs:108:53
    |
108 |         UnsignedTransaction::new(tx_inputs, vec![], output_candidates).unwrap()
    |                                                     ^^^^^^^^^^^^^^^^^ expected struct `bounded_vec::bounded_vec::BoundedVec`, found struct `Vec`
    |
    = note: expected struct `bounded_vec::bounded_vec::BoundedVec<ergotree_ir::chain::ergo_box::ErgoBoxCandidate, 1_usize, 65535_usize>`
               found struct `Vec<ergotree_ir::chain::ergo_box::ErgoBoxCandidate>`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `ergo-test` due to 6 previous errors
PS D:\code\rust\ergo-test>
ch1n3du commented 2 years ago

You can use .try_into() to convert the vectors to bounded vectors.


 // Action to solve the math problem
    pub fn action_solve_math_problem(
        math_problem_answer: u64,
        math_bounty_box: MathBountyBox,
        current_height: u64,
        transaction_fee: u64,
        ergs_box_for_fee: ErgsBox,
        user_address: String
    ) -> UnsignedTransaction {
        let tx_inputs = vec![
            math_bounty_box.as_unsigned_input(),
            ergs_box_for_fee.as_unsigned_input(),
        ].try_into().unwrap();

        // Leftover bounty after paying transaction fee
        let bounty_after_fee = math_bounty_box.nano_ergs() - transaction_fee;

        // Register integers are signed
        let r4 = Constant::from(math_problem_answer as i64);

        let withdraw_bounty_candidate = create_candidate(
            bounty_after_fee, 
            &user_address, 
            &vec![], 
            &vec![r4], 
            current_height
        ).unwrap();

        let transaction_fee_candidate =
            TxFeeBox::output_candidate(transaction_fee, current_height).unwrap();

        let output_candidates = vec![
            withdraw_bounty_candidate,
            transaction_fee_candidate
        ].try_into().unwrap();

        UnsignedTransaction::new(tx_inputs, None, output_candidates).unwrap()
    }```