Add contracts directory with template smart contract that increments a counter.
This commit is contained in:
parent
e8cefdabbe
commit
47eba79d05
6
contracts/.gitignore
vendored
Normal file
6
contracts/.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
.anchor
|
||||||
|
.DS_Store
|
||||||
|
target
|
||||||
|
**/*.rs.bk
|
||||||
|
node_modules
|
7
contracts/.prettierrc
Normal file
7
contracts/.prettierrc
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"tabWidth": 2,
|
||||||
|
"useTabs": false,
|
||||||
|
"semi": false,
|
||||||
|
"trailingComma": "es5",
|
||||||
|
"singleQuote": true
|
||||||
|
}
|
12
contracts/Anchor.toml
Normal file
12
contracts/Anchor.toml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
[programs.localnet]
|
||||||
|
dpm = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
|
||||||
|
|
||||||
|
[registry]
|
||||||
|
url = "https://anchor.projectserum.com"
|
||||||
|
|
||||||
|
[provider]
|
||||||
|
cluster = "localnet"
|
||||||
|
wallet = "/Users/jahooma/.config/solana/id.json"
|
||||||
|
|
||||||
|
[scripts]
|
||||||
|
test = "yarn run mocha -t 1000000 tests/"
|
1105
contracts/Cargo.lock
generated
Normal file
1105
contracts/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
4
contracts/Cargo.toml
Normal file
4
contracts/Cargo.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"programs/*"
|
||||||
|
]
|
12
contracts/migrations/deploy.js
Normal file
12
contracts/migrations/deploy.js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
// Migrations are an early feature. Currently, they're nothing more than this
|
||||||
|
// single deploy script that's invoked from the CLI, injecting a provider
|
||||||
|
// configured from the workspace's Anchor.toml.
|
||||||
|
|
||||||
|
const anchor = require("@project-serum/anchor");
|
||||||
|
|
||||||
|
module.exports = async function (provider) {
|
||||||
|
// Configure client to use the provider.
|
||||||
|
anchor.setProvider(provider);
|
||||||
|
|
||||||
|
// Add your deploy script here.
|
||||||
|
}
|
9
contracts/package.json
Normal file
9
contracts/package.json
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"@project-serum/anchor": "^0.18.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"chai": "^4.3.4",
|
||||||
|
"mocha": "^9.0.3"
|
||||||
|
}
|
||||||
|
}
|
19
contracts/programs/dpm/Cargo.toml
Normal file
19
contracts/programs/dpm/Cargo.toml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
[package]
|
||||||
|
name = "dpm"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Created with Anchor"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
crate-type = ["cdylib", "lib"]
|
||||||
|
name = "dpm"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
no-entrypoint = []
|
||||||
|
no-idl = []
|
||||||
|
no-log-ix-name = []
|
||||||
|
cpi = ["no-entrypoint"]
|
||||||
|
default = []
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
anchor-lang = "0.18.2"
|
2
contracts/programs/dpm/Xargo.toml
Normal file
2
contracts/programs/dpm/Xargo.toml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[target.bpfel-unknown-unknown.dependencies.std]
|
||||||
|
features = []
|
43
contracts/programs/dpm/src/lib.rs
Normal file
43
contracts/programs/dpm/src/lib.rs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
use anchor_lang::prelude::*;
|
||||||
|
|
||||||
|
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
|
||||||
|
|
||||||
|
#[program]
|
||||||
|
pub mod dpm {
|
||||||
|
use super::*;
|
||||||
|
pub fn initialize(ctx: Context<Initialize>) -> ProgramResult {
|
||||||
|
let contract = &mut ctx.accounts.contract;
|
||||||
|
contract.bets = 0;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_bet(ctx: Context<AddBet>) -> ProgramResult {
|
||||||
|
let contract = &mut ctx.accounts.contract;
|
||||||
|
contract.bets += 1;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Accounts)]
|
||||||
|
pub struct Initialize<'info> {
|
||||||
|
#[account(init, payer = user, space = 9000)]
|
||||||
|
pub contract: Account<'info, Contract>,
|
||||||
|
|
||||||
|
#[account(mut)]
|
||||||
|
pub user: Signer<'info>,
|
||||||
|
|
||||||
|
pub system_program: Program <'info, System>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Accounts)]
|
||||||
|
pub struct AddBet<'info> {
|
||||||
|
#[account(mut)]
|
||||||
|
pub contract: Account<'info, Contract>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[account]
|
||||||
|
pub struct Contract {
|
||||||
|
pub bets: u64,
|
||||||
|
}
|
50
contracts/tests/dpm.js
Normal file
50
contracts/tests/dpm.js
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
const anchor = require('@project-serum/anchor')
|
||||||
|
|
||||||
|
const { SystemProgram } = anchor.web3
|
||||||
|
|
||||||
|
const main = async () => {
|
||||||
|
console.log('🚀 Starting test...')
|
||||||
|
|
||||||
|
const provider = anchor.Provider.env()
|
||||||
|
anchor.setProvider(provider)
|
||||||
|
|
||||||
|
const program = anchor.workspace.Dpm
|
||||||
|
|
||||||
|
// Create an account keypair for our program to use.
|
||||||
|
const baseAccount = anchor.web3.Keypair.generate()
|
||||||
|
|
||||||
|
const tx = await program.rpc.initialize({
|
||||||
|
accounts: {
|
||||||
|
contract: baseAccount.publicKey,
|
||||||
|
user: provider.wallet.publicKey,
|
||||||
|
systemProgram: SystemProgram.programId,
|
||||||
|
},
|
||||||
|
signers: [baseAccount],
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log('📝 Your transaction signature', tx)
|
||||||
|
|
||||||
|
let account = await program.account.contract.fetch(baseAccount.publicKey)
|
||||||
|
console.log('👀 Bets Count', account.bets.toString())
|
||||||
|
|
||||||
|
await program.rpc.addBet({
|
||||||
|
accounts: {
|
||||||
|
contract: baseAccount.publicKey,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
account = await program.account.contract.fetch(baseAccount.publicKey)
|
||||||
|
console.log('👀 Bets Count', account.bets.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
const runMain = async () => {
|
||||||
|
try {
|
||||||
|
await main()
|
||||||
|
process.exit(0)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runMain()
|
1092
contracts/yarn.lock
Normal file
1092
contracts/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user