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

the trait BorshSerialize is not implemented for seahorse_util::Mutable<[f64; 32]> #97

Open
ghost opened this issue Mar 11, 2023 · 1 comment

Comments

@ghost
Copy link

ghost commented Mar 11, 2023

Trying to compile this:

declare_id('CurBt7LP1RA8rYrahVNzPTMz2JSbZtYGDXrW1Nrzi2be')

class Calculator(Account):
  owner: Pubkey
  fed_population: f64
  fed_contributor: Array[Pubkey, 6]
  model: Array[f64, 32]


@instruction
def fed_sum(owner: Signer,calculator: Calculator, commit_vector: Array[f64, 32]):
  for i in range(32):
    calculator.model[i] += commit_vector[i]

@instruction
def fed_avg(owner: Signer,calculator: Calculator):
  for i in range(32):
    calculator.model[i] += calculator.model[i]/calculator.fed_population

@instruction
def init_calculator(owner: Signer, calculator: Empty[Calculator], population: f64):
  calculator = calculator.init(payer = owner, seeds = ['Calculator', owner])
  calculator.owner = owner.key()
  calculator.fed_population = population
  for i in range(32):
    calculator.model[i] = 0.0

@instruction
def reset_calculator(owner: Signer, calculator: Calculator, population: f64):
  print(owner.key(), 'is resetting a calculator', calculator.key())

  assert owner.key() == calculator.owner, 'This is not your calculator!'

  calculator.fed_population = population
  for i in range(32):
    calculator.model[i] = 0.0

Running Seahorse build returns :

error[E0412]: cannot find type `Mutable` in this scope
   --> programs/calculator/src/lib.rs:165:1
    |
165 | #[program]
    | ^^^^^^^^^^ not found in this scope
    |
    = note: consider importing this struct:
            crate::seahorse_util::Mutable
    = note: this error originates in the attribute macro `program` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `seahorse_util::Mutable<[f64; 32]>: BorshSerialize` is not satisfied
   --> programs/calculator/src/lib.rs:229:14
    |
229 |     #[derive(Accounts)]
    |              ^^^^^^^^ the trait `BorshSerialize` is not implemented for `seahorse_util::Mutable<[f64; 32]>`
    |
    = help: the following other types implement trait `BorshSerialize`:
              &T
              ()
              (T0, T1)
              (T0, T1, T2)
              (T0, T1, T2, T3)
              (T0, T1, T2, T3, T4)
              (T0, T1, T2, T3, T4, T5)
              (T0, T1, T2, T3, T4, T5, T6)
            and 164 others
    = help: see issue #48214
    = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
    = note: this error originates in the derive macro `anchor_lang::AnchorSerialize` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `seahorse_util::Mutable<[f64; 32]>: BorshDeserialize` is not satisfied
   --> programs/calculator/src/lib.rs:229:14
    |
229 |     #[derive(Accounts)]
    |              ^^^^^^^^ the trait `BorshDeserialize` is not implemented for `seahorse_util::Mutable<[f64; 32]>`
    |
    = help: the following other types implement trait `BorshDeserialize`:
              ()
              (T0, T1)
              (T0, T1, T2)
              (T0, T1, T2, T3)
              (T0, T1, T2, T3, T4)
              (T0, T1, T2, T3, T4, T5)
              (T0, T1, T2, T3, T4, T5, T6)
              (T0, T1, T2, T3, T4, T5, T6, T7)
            and 124 others
    = help: see issue #48214
    = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
    = note: this error originates in the derive macro `anchor_lang::AnchorDeserialize` (in Nightly builds, run with -Z macro-backtrace for more info)

Some errors have detailed explanations: E0277, E0412.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `calculator` due to 3 previous errors

@ghost
Copy link
Author

ghost commented Mar 12, 2023

Same this compiles succesfully when using any integer type or floats.

Fails to compile upon using slices in the function arguements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants