ameliatastic / seahorse-lang

Write Anchor-compatible Solana programs in Python
Apache License 2.0
320 stars 46 forks source link

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

Open ghost opened 1 year ago

ghost commented 1 year ago

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 commented 1 year ago

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

Fails to compile upon using slices in the function arguements