From 4037dc40c86661f724843516018a17b1ab6ba103 Mon Sep 17 00:00:00 2001 From: nicksavers Date: Wed, 2 Jul 2014 15:33:41 +0200 Subject: [PATCH] Public method to get repository --- ethereumj-core/src/main/java/org/ethereum/core/Block.java | 2 +- .../src/main/java/org/ethereum/core/Genesis.java | 8 ++++---- .../main/java/org/ethereum/gui/ContractCallDialog.java | 8 ++++---- .../src/main/java/org/ethereum/manager/WorldManager.java | 7 +++++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/core/Block.java b/ethereumj-core/src/main/java/org/ethereum/core/Block.java index 0e07b3c4..e1da59f1 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Block.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Block.java @@ -71,7 +71,7 @@ public class Block { timestamp, extraData, nonce); this.txsState = new Trie(null); - byte[] stateRoot = WorldManager.instance.repository.getRootHash(); + byte[] stateRoot = WorldManager.instance.getRepository().getRootHash(); this.header.setStateRoot(stateRoot); this.header.setTxTrieRoot(txsState.getRootHash()); diff --git a/ethereumj-core/src/main/java/org/ethereum/core/Genesis.java b/ethereumj-core/src/main/java/org/ethereum/core/Genesis.java index fdb0d96f..472eaadf 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Genesis.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Genesis.java @@ -67,15 +67,15 @@ public class Genesis extends Block { // The proof-of-concept series include a development premine, making the state root hash // some value stateRoot. The latest documentation should be consulted for the value of the state root. for (String address : premine) { - WorldManager.instance.repository.createAccount(Hex.decode(address)); - WorldManager.instance.repository.addBalance (Hex.decode(address), BigInteger.valueOf(2).pow(200) ); + WorldManager.instance.getRepository().createAccount(Hex.decode(address)); + WorldManager.instance.getRepository().addBalance (Hex.decode(address), BigInteger.valueOf(2).pow(200) ); } - this.setStateRoot( WorldManager.instance.repository.getRootHash() ); + this.setStateRoot( WorldManager.instance.getRepository().getRootHash() ); logger.info("Genesis-hash: " + Hex.toHexString(this.getHash())); logger.info("Genesis-stateRoot: " + Hex.toHexString(this.getStateRoot())); - WorldManager.instance.repository.dumpState(0, 0, null); + WorldManager.instance.getRepository().dumpState(0, 0, null); } public static Block getInstance() { diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/ContractCallDialog.java b/ethereumj-core/src/main/java/org/ethereum/gui/ContractCallDialog.java index 2358fa8c..8d1998df 100644 --- a/ethereumj-core/src/main/java/org/ethereum/gui/ContractCallDialog.java +++ b/ethereumj-core/src/main/java/org/ethereum/gui/ContractCallDialog.java @@ -226,8 +226,8 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog { } byte[] contractAddress = Hex.decode( contractAddr ); - final byte[] programCode = WorldManager.instance.repository.getCode(contractAddress); - final Map storageMap = WorldManager.instance.repository.getContractDetails(contractAddress).getStorage(); + final byte[] programCode = WorldManager.instance.getRepository().getCode(contractAddress); + final Map storageMap = WorldManager.instance.getRepository().getContractDetails(contractAddress).getStorage(); contractDataInput.setBounds(70, 80, 350, 145); contractDataInput.setViewportView(msgDataTA); @@ -301,13 +301,13 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog { private void playContractCall() { byte[] contractAddress = Hex.decode(contractAddrInput.getText()); - ContractDetails contractDetails = WorldManager.instance.repository.getContractDetails(contractAddress); + ContractDetails contractDetails = WorldManager.instance.getRepository().getContractDetails(contractAddress); if (contractDetails == null) { alertStatusMsg("No contract for that address"); return; } - byte[] programCode = WorldManager.instance.repository.getCode(contractAddress); + byte[] programCode = WorldManager.instance.getRepository().getCode(contractAddress); if (programCode == null || programCode.length == 0) { alertStatusMsg("Such account exist but no code in the db"); return; diff --git a/ethereumj-core/src/main/java/org/ethereum/manager/WorldManager.java b/ethereumj-core/src/main/java/org/ethereum/manager/WorldManager.java index 3ec6b421..d8de7225 100644 --- a/ethereumj-core/src/main/java/org/ethereum/manager/WorldManager.java +++ b/ethereumj-core/src/main/java/org/ethereum/manager/WorldManager.java @@ -42,6 +42,7 @@ public class WorldManager { private Logger stateLogger = LoggerFactory.getLogger("state"); private Blockchain blockChain; + private Repository repository = new Repository(); private Wallet wallet = new Wallet(); private Map pendingTransactions = Collections @@ -49,8 +50,6 @@ public class WorldManager { public DatabaseImpl chainDB = new DatabaseImpl("blockchain"); - public Repository repository = new Repository(); - public static WorldManager instance = new WorldManager(); public WorldManager() { @@ -320,6 +319,10 @@ public class WorldManager { } } + public Repository getRepository() { + return repository; + } + public Blockchain getBlockChain() { return blockChain; }