Move date oracle to config program (#7105)

automerge
This commit is contained in:
Greg Fitzgerald
2019-11-22 16:10:53 -07:00
committed by Grimes
parent 2a42ddbcbf
commit f040987c9f
6 changed files with 6 additions and 4 deletions

View File

@@ -1,58 +0,0 @@
///
/// A library for creating a trusted date oracle.
///
use bincode::{deserialize, serialized_size};
use chrono::{
prelude::{Date, DateTime, TimeZone, Utc},
serde::ts_seconds,
};
use serde_derive::{Deserialize, Serialize};
use solana_config_program::{config_instruction, ConfigState};
use solana_sdk::{instruction::Instruction, pubkey::Pubkey};
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
pub struct DateConfig {
#[serde(with = "ts_seconds")]
pub date_time: DateTime<Utc>,
}
impl Default for DateConfig {
fn default() -> Self {
Self {
date_time: Utc.timestamp(0, 0),
}
}
}
impl DateConfig {
pub fn new(date: Date<Utc>) -> Self {
Self {
date_time: date.and_hms(0, 0, 0),
}
}
pub fn deserialize(input: &[u8]) -> Option<Self> {
deserialize(input).ok()
}
}
impl ConfigState for DateConfig {
fn max_space() -> u64 {
serialized_size(&Self::default()).unwrap()
}
}
/// Create a date account. The date is set to the Unix epoch.
pub fn create_account(
payer_pubkey: &Pubkey,
date_pubkey: &Pubkey,
lamports: u64,
) -> Vec<Instruction> {
config_instruction::create_account::<DateConfig>(payer_pubkey, date_pubkey, lamports, vec![])
}
/// Set the date in the date account. The account pubkey must be signed in the
/// transaction containing this instruction.
pub fn store(date_pubkey: &Pubkey, date: Date<Utc>) -> Instruction {
let date_config = DateConfig::new(date);
config_instruction::store(&date_pubkey, true, vec![], &date_config)
}

View File

@@ -1,4 +1,3 @@
pub mod date_instruction;
pub mod vest_instruction;
pub mod vest_processor;
pub mod vest_schedule;

View File

@@ -1,10 +1,10 @@
//! vest program
use crate::date_instruction::DateConfig;
use crate::{
vest_instruction::{VestError, VestInstruction},
vest_state::VestState,
};
use chrono::prelude::*;
use solana_config_program::date_instruction::DateConfig;
use solana_config_program::get_config_data;
use solana_sdk::{
account::{Account, KeyedAccount},
@@ -143,9 +143,9 @@ pub fn process_instruction(
#[cfg(test)]
mod tests {
use super::*;
use crate::date_instruction;
use crate::id;
use crate::vest_instruction;
use solana_config_program::date_instruction;
use solana_runtime::bank::Bank;
use solana_runtime::bank_client::BankClient;
use solana_sdk::client::SyncClient;