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/
|
||||
11
.stackclass/compile.sh
Executable file
11
.stackclass/compile.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# This script is used to compile your program on StackClass
|
||||
#
|
||||
# This runs before .stackclass/run.sh
|
||||
#
|
||||
# Learn more: https://docs.stackclass.dev/challenges/program-interface
|
||||
|
||||
set -e # Exit on failure
|
||||
|
||||
cargo build --release
|
||||
11
.stackclass/run.sh
Executable file
11
.stackclass/run.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# This script is used to run your program on StackClass
|
||||
#
|
||||
# This runs after .stackclass/compile.sh
|
||||
#
|
||||
# Learn more: https://docs.stackclass.dev/challenges/program-interface
|
||||
|
||||
set -e # Exit on failure
|
||||
|
||||
exec target/release/stackclass-solana-voting-program "$@"
|
||||
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"
|
||||
1901
Cargo.lock
generated
Normal file
1901
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
21
Cargo.toml
Normal file
21
Cargo.toml
Normal file
@@ -0,0 +1,21 @@
|
||||
[workspace]
|
||||
members = [
|
||||
"programs/*"
|
||||
]
|
||||
resolver = "2"
|
||||
|
||||
[package]
|
||||
name = "stackclass-solana-voting-program"
|
||||
version = "0.1.0"
|
||||
authors = ["StackClass <hello@stackclass.dev>"]
|
||||
edition = "2021"
|
||||
|
||||
[profile.release]
|
||||
overflow-checks = true
|
||||
lto = "fat"
|
||||
codegen-units = 1
|
||||
|
||||
[profile.release.build-override]
|
||||
opt-level = 3
|
||||
incremental = false
|
||||
codegen-units = 1
|
||||
20
Dockerfile
Normal file
20
Dockerfile
Normal file
@@ -0,0 +1,20 @@
|
||||
# syntax=docker/dockerfile:1.7-labs
|
||||
FROM rust:1.87-slim-bookworm AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
|
||||
COPY --exclude=.git --exclude=README.md . /app
|
||||
|
||||
# This runs cargo build
|
||||
RUN .stackclass/compile.sh
|
||||
|
||||
# Final minimal image
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=builder --exclude=target /app ./
|
||||
COPY --from=builder /app/target/release/stackclass-solana-voting-program ./target/release/
|
||||
|
||||
# Set default startup command
|
||||
CMD ["./.stackclass/run.sh"]
|
||||
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"
|
||||
}
|
||||
}
|
||||
11
programs/voting-program/Cargo.toml
Normal file
11
programs/voting-program/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "voting-program"
|
||||
version = "0.1.0"
|
||||
description = "Solana voting program"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "lib"]
|
||||
|
||||
[dependencies]
|
||||
anchor-lang = { version = "0.30.1", features = ["init-if-needed"] }
|
||||
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
|
||||
}
|
||||
1
src/main.rs
Normal file
1
src/main.rs
Normal file
@@ -0,0 +1 @@
|
||||
fn main() {}
|
||||
18
stackclass.yml
Normal file
18
stackclass.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
# Set this to true if you want debug logs.
|
||||
#
|
||||
# These can be VERY verbose, so we suggest turning them off
|
||||
# unless you really need them.
|
||||
debug: false
|
||||
|
||||
# Use this to change the Rust version used to run your code
|
||||
# on StackClass.
|
||||
#
|
||||
# Available versions: rust-1.87
|
||||
language_pack: rust-1.87
|
||||
|
||||
# The executable required to build and run the this project,
|
||||
# along with its minimum required version.
|
||||
required_executable: cargo (1.87)
|
||||
|
||||
# The main source file that users can edit for this project.
|
||||
user_editable_file: programs/voting-program/src/lib.rs
|
||||
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
|
||||
}
|
||||
}
|
||||
24
your_program.sh
Executable file
24
your_program.sh
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Use this script to run your program LOCALLY.
|
||||
#
|
||||
# Note: Changing this script WILL NOT affect how StackClass runs your program.
|
||||
#
|
||||
# Learn more: https://docs.stackclass.dev/challenges/program-interface
|
||||
|
||||
set -e # Exit early if any commands fail
|
||||
|
||||
# Copied from .stackclass/compile.sh
|
||||
#
|
||||
# - Edit this to change how your program compiles locally
|
||||
# - Edit .stackclass/compile.sh to change how your program compiles remotely
|
||||
(
|
||||
cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
|
||||
cargo build --release
|
||||
)
|
||||
|
||||
# Copied from .stackclass/run.sh
|
||||
#
|
||||
# - Edit this to change how your program runs locally
|
||||
# - Edit .stackclass/run.sh to change how your program runs remotely
|
||||
exec target/release/stackclass-solana-voting-program "$@"
|
||||
Reference in New Issue
Block a user