{"author":{"address":"0xD736da8B41457F7b5E962c889aa728AB178D60aa","user":"https://learnblockchain.cn/people/22219"},"content":{"body":"## 实现版本\r\n\r\nsolana movies 是 solana 开发教程上的一个案例。\r\n\r\n它有如下实现版本：\r\n\r\n- [rust-program](https://github.com/Unboxed-Software/solana-movie-program) 用 rust 写的智能合约，负责链上交互\r\n- [front-end](https://github.com/Unboxed-Software/solana-movie-frontend) 用户看到的 dapp 界面，用于创建影评并提交\r\n- [anchor-rust-program](https://github.com/Unboxed-Software/anchor-movie-review-program) 用 anchor 框架重写智能合约\r\n- [anchor-front-end](https://github.com/Unboxed-Software/anchor-movie-review-frontend) 用 anchor 重写 dapp 界面\r\n- [client](https://github.com/Unboxed-Software/solana-movie-client) 代替 dapp 界面，用 js 发起创建影评并提交\r\n\r\n根据原始代码，我重新修改了依赖和部分代码，搞了个能跑起来的[汇总版本](https://github.com/lalalazero1/solana-movies-example-2024)\r\n\r\n虽然大概意思能看懂，但是让我用 rust 重写一遍，我也不会。\r\n\r\n## rust 智能合约\r\n\r\n用 rust 原生写智能合约时，要在 `Cargo.toml` 标记类型和特征\r\n\r\n```toml\r\n[features]\r\nno-entrypoint = []\r\n\r\n[lib]\r\ncrate-type = [\"cdylib\", \"lib\"]\r\n```\r\n\r\n## 基于 anchor 框架的智能合约\r\n\r\n重点在于序列化和反序列化，以及排序和分页的偏移量计算。\r\n\r\n## client 代码\r\n\r\n`variant` 变量是一个标志位，0 表示添加影评，1 表示更新影评。\r\n\r\n## dapp 前端代码\r\n\r\n连接钱包和发送交易有 solana wallet adapter，但是也可以像 client 那样直接调用 @solana/web3.js 的接口，不使用现有的钱包UI和接口。","title":"在登链社区挑战100天学习web3——第4天，整合 solana movies 示例代码的实现版本"},"history":null,"timestamp":1725603467,"version":1}