Giter Site home page Giter Site logo

Comments (10)

paul-schaaf avatar paul-schaaf commented on September 24, 2024

I'm not able to reproduce this. Are you you using version 0.22.0 of the cli and the imported anchor-lang?

from anchor-book.

S-Burns avatar S-Burns commented on September 24, 2024

0.22.0 on Ubuntu WSL on Windows 10 loaded via the AWM & the same errors thrown with 0.20.1 installed with NPM before the upgrade. Following instructions on both verbatim.

from anchor-book.

S-Burns avatar S-Burns commented on September 24, 2024

Possible to upload the finalized versions of the modified lib.rs files etc.; maybe at the end of the book example...I think there are other requests for this.

from anchor-book.

paul-schaaf avatar paul-schaaf commented on September 24, 2024

have you uninstalled the npm version?

Ill upload the files tmr when Im back at my laptop

from anchor-book.

S-Burns avatar S-Burns commented on September 24, 2024

Yes. The NPM version was successfully removed. Anchor was off the machine, then reinstalled with the AWM and restarted with latest.

from anchor-book.

paul-schaaf avatar paul-schaaf commented on September 24, 2024

in the Cargo.toml of the program itself does it say anchor-lang = 0.22.0?

from anchor-book.

S-Burns avatar S-Burns commented on September 24, 2024

No. Now updated from 0.20.1 but this error is thrown...

error[E0412]: cannot find type ProgramResult in this scope
--> programs/tic-tac-toe/src/lib.rs:11:52
|
11 | pub fn initialize(ctx: Context) -> ProgramResult {
| ^^^^^^^^^^^^^ not found in this scope

warning: unused import: num_traits
--> programs/tic-tac-toe/src/lib.rs:6:5
|
6 | use num_traits::*;
| ^^^^^^^^^^
|
= note: #[warn(unused_imports)] on by default

For more information about this error, try rustc --explain E0412.
warning: tic-tac-toe (lib) generated 1 warning
error: could not compile tic-tac-toe due to previous error; 1 warning emitted

from anchor-book.

paul-schaaf avatar paul-schaaf commented on September 24, 2024

this is a bug in the cli. Just change ProgramResult to Result<()> or copy the code from the book.

from anchor-book.

S-Burns avatar S-Burns commented on September 24, 2024

Success. Much thanks! Here is the complete, updated lib.rs for reference.

`use anchor_lang::prelude::*;

declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");

use num_derive::;
use num_traits::
;

#[program]
pub mod tic_tac_toe {
use super::*;
pub fn initialize(ctx: Context) -> Result<()> {
Ok(())
}
}

#[derive(Accounts)]
pub struct Initialize {}

#[account]
#[derive(Default)]
pub struct Game {
players: [Pubkey; 2], // 64
turn: u8, // 1
board: [[Option; 3]; 3], // 9 * (1 + 1) = 18
state: GameState, // 32 + 1
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, PartialEq, Eq)]
pub enum GameState {
Active,
Tie,
Won { winner: Pubkey },
}

#[derive(
AnchorSerialize, AnchorDeserialize, FromPrimitive, ToPrimitive, Copy, Clone, PartialEq, Eq,
)]
pub enum Sign {
X,
O,
}

impl Default for GameState {
fn default() -> Self {
Self::Active
}
}

#[derive(Accounts)]
pub struct SetupGame<'info> {
#[account(init, payer = player_one)]
pub game: Account<'info, Game>,
#[account(mut)]
pub player_one: Signer<'info>,
pub system_program: Program<'info, System>,
}

pub fn setup_game(ctx: Context, player_two: Pubkey) -> Result<()> {
let game = &mut ctx.accounts.game;
game.players = [ctx.accounts.player_one.key(), player_two];
game.turn = 1;
Ok(())
}
`

from anchor-book.

paul-schaaf avatar paul-schaaf commented on September 24, 2024

great! Im uploading the program to the repo currently

from anchor-book.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.