|
14 | 14 | // You should have received a copy of the GNU Affero General Public License |
15 | 15 | // along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | 16 |
|
17 | | -use crate::check; |
18 | | -use crate::core::{CheckTxHandler, TransactionExecutor}; |
19 | | -use crate::internal::{add_balance, get_sequence, sub_balance}; |
| 17 | +use crate::core::{AccountManager, CheckTxHandler, TransactionExecutor}; |
| 18 | +use crate::error::Error; |
| 19 | +use crate::internal::{add_balance, get_account, get_sequence, sub_balance}; |
20 | 20 | use crate::types::{Action, SignedTransaction}; |
| 21 | +use crate::{check, get_context}; |
| 22 | +use ckey::Ed25519Public as Public; |
21 | 23 | use coordinator::types::{ErrorCode, TransactionExecutionOutcome}; |
22 | 24 |
|
23 | 25 | #[allow(dead_code)] |
@@ -61,3 +63,32 @@ impl TransactionExecutor for Executor { |
61 | 63 | Ok(vec![]) |
62 | 64 | } |
63 | 65 | } |
| 66 | + |
| 67 | +#[allow(dead_code)] |
| 68 | +pub struct Manager {} |
| 69 | + |
| 70 | +impl AccountManager for Manager { |
| 71 | + fn add_balance(&self, account_id: &Public, val: u64) { |
| 72 | + add_balance(account_id, val) |
| 73 | + } |
| 74 | + |
| 75 | + fn sub_balance(&self, account_id: &Public, val: u64) -> Result<(), Error> { |
| 76 | + sub_balance(account_id, val) |
| 77 | + } |
| 78 | + |
| 79 | + fn set_balance(&self, account_id: &Public, val: u64) { |
| 80 | + let context = get_context(); |
| 81 | + let mut account = get_account(account_id); |
| 82 | + |
| 83 | + account.balance = val; |
| 84 | + context.set(account_id, account.to_vec()); |
| 85 | + } |
| 86 | + |
| 87 | + fn increment_sequence(&self, account_id: &Public) { |
| 88 | + let context = get_context(); |
| 89 | + let mut account = get_account(account_id); |
| 90 | + |
| 91 | + account.sequence += 1; |
| 92 | + context.set(account_id, account.to_vec()); |
| 93 | + } |
| 94 | +} |
0 commit comments