Bump all native programs up a level
Don't categorize programs by a single backend.
This commit is contained in:
20
programs/rewards_api/Cargo.toml
Normal file
20
programs/rewards_api/Cargo.toml
Normal file
@@ -0,0 +1,20 @@
|
||||
[package]
|
||||
name = "solana-rewards-api"
|
||||
version = "0.12.0"
|
||||
description = "Solana rewards API"
|
||||
authors = ["Solana Maintainers <maintainers@solana.com>"]
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
license = "Apache-2.0"
|
||||
homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
bincode = "1.1.2"
|
||||
serde = "1.0.89"
|
||||
serde_derive = "1.0.89"
|
||||
solana-sdk = { path = "../../sdk", version = "0.12.0" }
|
||||
solana-vote-api = { path = "../vote_api", version = "0.12.0" }
|
||||
|
||||
[lib]
|
||||
name = "solana_rewards_api"
|
||||
crate-type = ["lib"]
|
18
programs/rewards_api/src/lib.rs
Normal file
18
programs/rewards_api/src/lib.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
pub mod rewards_instruction;
|
||||
pub mod rewards_state;
|
||||
pub mod rewards_transaction;
|
||||
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
const REWARDS_PROGRAM_ID: [u8; 32] = [
|
||||
133, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0,
|
||||
];
|
||||
|
||||
pub fn check_id(program_id: &Pubkey) -> bool {
|
||||
program_id.as_ref() == REWARDS_PROGRAM_ID
|
||||
}
|
||||
|
||||
pub fn id() -> Pubkey {
|
||||
Pubkey::new(&REWARDS_PROGRAM_ID)
|
||||
}
|
19
programs/rewards_api/src/rewards_instruction.rs
Normal file
19
programs/rewards_api/src/rewards_instruction.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use crate::id;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::transaction_builder::BuilderInstruction;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||
pub enum RewardsInstruction {
|
||||
RedeemVoteCredits,
|
||||
}
|
||||
|
||||
impl RewardsInstruction {
|
||||
pub fn new_redeem_vote_credits(vote_id: Pubkey, rewards_id: Pubkey) -> BuilderInstruction {
|
||||
BuilderInstruction::new(
|
||||
id(),
|
||||
&RewardsInstruction::RedeemVoteCredits,
|
||||
vec![(vote_id, true), (rewards_id, false)],
|
||||
)
|
||||
}
|
||||
}
|
13
programs/rewards_api/src/rewards_state.rs
Normal file
13
programs/rewards_api/src/rewards_state.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
use bincode::serialized_size;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct RewardsState {}
|
||||
|
||||
impl RewardsState {
|
||||
/// Upper limit on the serialized size of RewardsState.
|
||||
pub fn max_size() -> usize {
|
||||
let rewards_state = RewardsState::default();
|
||||
serialized_size(&rewards_state).unwrap() as usize
|
||||
}
|
||||
}
|
50
programs/rewards_api/src/rewards_transaction.rs
Normal file
50
programs/rewards_api/src/rewards_transaction.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
//! The `rewards_transaction` module provides functionality for creating a global
|
||||
//! rewards account and enabling stakers to redeem credits from their vote accounts.
|
||||
|
||||
use crate::id;
|
||||
use crate::rewards_instruction::RewardsInstruction;
|
||||
use crate::rewards_state::RewardsState;
|
||||
use solana_sdk::hash::Hash;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::system_transaction::SystemTransaction;
|
||||
use solana_sdk::transaction::Transaction;
|
||||
use solana_sdk::transaction_builder::TransactionBuilder;
|
||||
use solana_vote_api::vote_instruction::VoteInstruction;
|
||||
|
||||
pub struct RewardsTransaction {}
|
||||
|
||||
impl RewardsTransaction {
|
||||
pub fn new_account(
|
||||
from_keypair: &Keypair,
|
||||
rewards_id: Pubkey,
|
||||
blockhash: Hash,
|
||||
num_tokens: u64,
|
||||
fee: u64,
|
||||
) -> Transaction {
|
||||
SystemTransaction::new_program_account(
|
||||
from_keypair,
|
||||
rewards_id,
|
||||
blockhash,
|
||||
num_tokens,
|
||||
RewardsState::max_size() as u64,
|
||||
id(),
|
||||
fee,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn new_redeem_credits(
|
||||
vote_keypair: &Keypair,
|
||||
rewards_id: Pubkey,
|
||||
blockhash: Hash,
|
||||
fee: u64,
|
||||
) -> Transaction {
|
||||
let vote_id = vote_keypair.pubkey();
|
||||
TransactionBuilder::new(fee)
|
||||
.push(RewardsInstruction::new_redeem_vote_credits(
|
||||
vote_id, rewards_id,
|
||||
))
|
||||
.push(VoteInstruction::new_clear_credits(vote_id))
|
||||
.sign(&[vote_keypair], blockhash)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user