blob: eb53fde19e4faf523476bc5847b3822008b1c88a [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2020 RBEI and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v. 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Adhith Gopal - Initial API and Implementation
*******************************************************************************/
package org.eclipse.blockchain.core.model;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Type based accounts Currently there are 2 types 1.
* EnvironmentType.GETH_CLIENT 2. EnvironmentType.EMBEDDED_EVM
*
*/
public class Account {
private final Map<String, String> dataDir = new HashMap<>();
private final Map<String, Map<String, String>> accounts = new HashMap<>();
private final Map<String, Map<String, String>> accountBalance = new HashMap<>();
/**
* @param type
* - The environment type
* @return the accountBalance
*/
public Map<String, String> getAccountBalance(final String type) {
return this.accountBalance.computeIfAbsent(type,
v -> new LinkedHashMap<>());
}
/**
* @param type
* - The environment type
* @param accountBalance
* the accountBalance to set
*/
public void setAccountBalance(final String type,
final Map<String, String> accountBalance) {
if (!(accountBalance instanceof LinkedHashMap)) {
throw new IllegalArgumentException(
"The accountBalance should be an instance of LinkedHashMap");
}
Map<String, String> theMap = this.accountBalance.computeIfAbsent(type,
v -> new LinkedHashMap<>());
theMap.clear();// for now only account initialization is handled
theMap.putAll(accountBalance);
}
/**
* @param type
* - The environment type
* @return the dataDir
*/
public String getDataDir(final String type) {
return this.dataDir.get(type);
}
/**
* @param type
* - The environment type
* @param dataDir
* the dataDir to set
*/
public void setDataDir(final String type, final String dataDir) {
this.dataDir.put(type, dataDir);
}
/**
* @param type
* - The environment type
* @return the accounts
*/
public Map<String, String> getAccounts(final String type) {
return this.accounts.computeIfAbsent(type, v -> new LinkedHashMap<>());
}
/**
* @param type
* - The environment type
* @param accounts
* the accounts to set
*/
public void setAccounts(final String type,
final Map<String, String> accounts) {
if (!(accounts instanceof LinkedHashMap)) {
throw new IllegalArgumentException(
"The accountBalance should be an instance of LinkedHashMap");
}
Map<String, String> theMap = this.accounts.computeIfAbsent(type,
v -> new LinkedHashMap<>());
theMap.clear();
theMap.putAll(accounts);
}
}