Initial commit from template
This commit is contained in:
16
.eslintrc.js
Normal file
16
.eslintrc.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
module.exports = {
|
||||||
|
env: {
|
||||||
|
es2021: true,
|
||||||
|
node: true,
|
||||||
|
},
|
||||||
|
extends: ["eslint:recommended", "@typescript-eslint/recommended"],
|
||||||
|
parser: "@typescript-eslint/parser",
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 12,
|
||||||
|
sourceType: "module",
|
||||||
|
},
|
||||||
|
plugins: ["@typescript-eslint"],
|
||||||
|
rules: {
|
||||||
|
// Add custom rules here
|
||||||
|
},
|
||||||
|
};
|
||||||
28
.gitignore
vendored
Normal file
28
.gitignore
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# Dependencies
|
||||||
|
node_modules/
|
||||||
|
target/
|
||||||
|
dist/
|
||||||
|
|
||||||
|
# Environment variables
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
|
|
||||||
|
# IDE files
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# OS files
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Coverage
|
||||||
|
coverage/
|
||||||
|
.nyc_output/
|
||||||
|
|
||||||
|
# Anchor
|
||||||
|
.anchor/
|
||||||
|
test-ledger/
|
||||||
9
Anchor.toml
Normal file
9
Anchor.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[provider]
|
||||||
|
cluster = "devnet"
|
||||||
|
wallet = "~/.config/solana/id.json"
|
||||||
|
|
||||||
|
[programs.devnet]
|
||||||
|
voting_program = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
|
||||||
|
|
||||||
|
[scripts]
|
||||||
|
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
|
||||||
9
Cargo.toml
Normal file
9
Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"programs/*",
|
||||||
|
"tests",
|
||||||
|
]
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
lto = true
|
||||||
|
opt-level = 3
|
||||||
14
migrations/deploy.ts
Normal file
14
migrations/deploy.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Migrations are managed by Anchor
|
||||||
|
// This file can be used for custom deployment scripts
|
||||||
|
|
||||||
|
import * as anchor from "@coral-xyz/anchor";
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
console.log("Running deployment script...");
|
||||||
|
// Custom deployment logic can be added here
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
process.exitCode = 1;
|
||||||
|
});
|
||||||
24
package.json
Normal file
24
package.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"name": "solana-voting",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "Solana voting program built with Anchor",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "anchor test",
|
||||||
|
"lint": "eslint --ext .ts tests/",
|
||||||
|
"build": "anchor build",
|
||||||
|
"deploy": "anchor deploy"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@coral-xyz/anchor": "^0.29.0",
|
||||||
|
"@solana/web3.js": "^1.87.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/mocha": "^10.0.0",
|
||||||
|
"@types/node": "^20.0.0",
|
||||||
|
"eslint": "^8.0.0",
|
||||||
|
"mocha": "^10.0.0",
|
||||||
|
"ts-mocha": "^10.0.0",
|
||||||
|
"typescript": "^5.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
12
programs/voting-program/Cargo.toml
Normal file
12
programs/voting-program/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "voting-program"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Solana voting program"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
crate-type = ["cdylib", "lib"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
anchor-lang = { version = "0.29.0", features = ["init", "derive"] }
|
||||||
|
anchor-spl = "0.29.0"
|
||||||
42
programs/voting-program/src/lib.rs
Normal file
42
programs/voting-program/src/lib.rs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
use anchor_lang::prelude::*;
|
||||||
|
|
||||||
|
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
|
||||||
|
|
||||||
|
#[program]
|
||||||
|
pub mod voting_program {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub fn initialize_proposal(
|
||||||
|
ctx: Context<InitializeProposal>,
|
||||||
|
title: String,
|
||||||
|
options: Vec<String>,
|
||||||
|
) -> Result<()> {
|
||||||
|
// Students will implement this function
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn vote(ctx: Context<Vote>, option_index: u32) -> Result<()> {
|
||||||
|
// Students will implement this function
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[account]
|
||||||
|
pub struct Proposal {
|
||||||
|
// Students will complete this struct
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Accounts)]
|
||||||
|
pub struct InitializeProposal<'info> {
|
||||||
|
// Students will complete this struct
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Accounts)]
|
||||||
|
pub struct Vote<'info> {
|
||||||
|
// Students will complete this struct
|
||||||
|
}
|
||||||
|
|
||||||
|
#[error_code]
|
||||||
|
pub enum VotingError {
|
||||||
|
// Students will define error codes
|
||||||
|
}
|
||||||
15
tests/voting-program.ts
Normal file
15
tests/voting-program.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import * as anchor from "@coral-xyz/anchor";
|
||||||
|
import { Program } from "@coral-xyz/anchor";
|
||||||
|
import { VotingProgram } from "../target/types/voting_program";
|
||||||
|
|
||||||
|
describe("voting-program", () => {
|
||||||
|
// Configure the client to use the local cluster.
|
||||||
|
const provider = anchor.AnchorProvider.env();
|
||||||
|
anchor.setProvider(provider);
|
||||||
|
|
||||||
|
const program = anchor.workspace.VotingProgram as Program<VotingProgram>;
|
||||||
|
|
||||||
|
it("Is initialized!", async () => {
|
||||||
|
// Students will write test cases here
|
||||||
|
});
|
||||||
|
});
|
||||||
15
tsconfig.json
Normal file
15
tsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"types": ["mocha", "chai"],
|
||||||
|
"typeRoots": ["./node_modules/@types"],
|
||||||
|
"lib": ["es2020"],
|
||||||
|
"module": "commonjs",
|
||||||
|
"target": "es2020",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"resolveJsonModule": true
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user