/* | |
* Copyright (c) Robert Bosch GmbH. All rights reserved. | |
*/ | |
package org.eclipse.blockchain.core; | |
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 | |
* | |
* @author ADG5COB | |
*/ | |
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); | |
} | |
} |