From 65600f9a1f2c92b194f8e6df57d4b35ee2799ca1 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Tue, 16 Feb 2021 10:26:02 -0700 Subject: [PATCH] Move fn to sdk --- programs/stake/src/stake_state.rs | 9 +-------- sdk/program/src/instruction.rs | 7 +++++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/programs/stake/src/stake_state.rs b/programs/stake/src/stake_state.rs index 2bc1d19fd2..73534d07e2 100644 --- a/programs/stake/src/stake_state.rs +++ b/programs/stake/src/stake_state.rs @@ -14,7 +14,7 @@ use solana_sdk::{ account_utils::{State, StateMut}, clock::{Clock, Epoch, UnixTimestamp}, ic_msg, - instruction::InstructionError, + instruction::{checked_add, InstructionError}, keyed_account::KeyedAccount, process_instruction::InvokeContext, pubkey::Pubkey, @@ -54,13 +54,6 @@ impl Default for StakeState { } } -fn checked_add(a: u64, b: u64) -> Result { - match a.checked_add(b) { - Some(sum) => Ok(sum), - None => Err(InstructionError::InsufficientFunds), - } -} - impl StakeState { pub fn get_rent_exempt_reserve(rent: &Rent) -> u64 { rent.minimum_balance(std::mem::size_of::()) diff --git a/sdk/program/src/instruction.rs b/sdk/program/src/instruction.rs index bf5db9df4f..3d0686ab6d 100644 --- a/sdk/program/src/instruction.rs +++ b/sdk/program/src/instruction.rs @@ -209,6 +209,13 @@ impl Instruction { } } +pub fn checked_add(a: u64, b: u64) -> Result { + match a.checked_add(b) { + Some(sum) => Ok(sum), + None => Err(InstructionError::InsufficientFunds), + } +} + /// Account metadata used to define Instructions #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] pub struct AccountMeta {