org.ethereum.db.ContractDetails Java Examples
The following examples show how to use
org.ethereum.db.ContractDetails.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Program.java From ethereumj with MIT License | 6 votes |
public void saveOpTrace(){ Op op = new Op(); op.setPc(pc); op.setOp(ops[pc]); op.saveGas(getGas()); ContractDetails contractDetails = this.result.getRepository(). getContractDetails(this.programAddress.getLast20Bytes()); op.saveStorageMap(contractDetails.getStorage()); op.saveMemory(memory); op.saveStack(stack); programTrace.addOp(op); }
Example #2
Source File: JSONHelper.java From ethereumj with MIT License | 6 votes |
public static void dumpState(ObjectNode statesNode, String address, AccountState state, ContractDetails details) { List<DataWord> storageKeys = new ArrayList<>(details.getStorage().keySet()); Collections.sort((List<DataWord>) storageKeys); ObjectNode account = statesNode.objectNode(); ObjectNode storage = statesNode.objectNode(); for (DataWord key : storageKeys) { storage.put("0x" + Hex.toHexString(key.getData()), "0x" + Hex.toHexString(details.getStorage().get(key).getNoLeadZeroesData())); } account.put("balance", state.getBalance() == null ? "0" : state.getBalance().toString()); // account.put("codeHash", details.getCodeHash() == null ? "0x" : "0x" + Hex.toHexString(details.getCodeHash())); account.put("code", details.getCode() == null ? "0x" : "0x" + Hex.toHexString(details.getCode())); account.put("nonce", state.getNonce() == null ? "0" : state.getNonce().toString()); account.put("storage", storage); account.put("storage_root", state.getStateRoot() == null ? "" : Hex.toHexString(state.getStateRoot())); statesNode.put(address, account); }
Example #3
Source File: StateExplorerWindow.java From ethereumj with MIT License | 6 votes |
private String accountDetailsString(byte[] account, StateDataTableModel dataModel){ String ret = ""; // 1) print account address ret = "Account: " + Hex.toHexString(account) + "\n"; //2) print state AccountState state = WorldManager.getInstance().getRepository().getAccountState(account); if(state != null) ret += state.toString() + "\n"; //3) print storage ContractDetails contractDetails = WorldManager.getInstance().getRepository().getContractDetails(account); if(contractDetails != null) { Map<DataWord, DataWord> accountStorage = contractDetails.getStorage(); dataModel.setData(accountStorage); } //4) code print byte[] code = WorldManager.getInstance().getRepository().getCode(account); if(code != null) { ret += "\n\nCode:\n"; ret += Program.stringify(code, 0, ""); } return ret; }
Example #4
Source File: ContractCallDialog.java From ethereumj with MIT License | 6 votes |
private void playContractCall() { byte[] addr = Utils.addressStringToBytes(contractAddrInput.getText()); if(addr == null) { alertStatusMsg("Not a valid contract address"); return; } ContractDetails contractDetails = UIEthereumManager.ethereum .getRepository().getContractDetails(addr); if (contractDetails == null) { alertStatusMsg("No contract for that address"); return; } final byte[] programCode = contractDetails.getCode(); if (programCode == null || programCode.length == 0) { alertStatusMsg("Such account exist but no code in the db"); return; } Transaction tx = createTransaction(); if (tx == null) return; Block lastBlock = UIEthereumManager.ethereum.getBlockchain().getLastBlock(); ProgramPlayDialog.createAndShowGUI(programCode, tx, lastBlock); }
Example #5
Source File: JSONHelper.java From ethereumj with MIT License | 5 votes |
public static void dumpBlock(ObjectNode blockNode, Block block, long gasUsed, byte[] state, List<ByteArrayWrapper> keys, Repository repository) { blockNode.put("coinbase", Hex.toHexString(block.getCoinbase())); blockNode.put("difficulty", new BigInteger(1, block.calcDifficulty()).toString()); blockNode.put("extra_data", "0x"); blockNode.put("gas_limit", String.valueOf(block.calcGasLimit())); blockNode.put("gas_used", String.valueOf(gasUsed)); blockNode.put("min_gas_price", String.valueOf(block.getMinGasPrice())); blockNode.put("nonce", "0x" + Hex.toHexString(block.getNonce())); blockNode.put("number", String.valueOf(block.getNumber())); blockNode.put("prevhash", "0x" + Hex.toHexString(block.getParentHash())); ObjectNode statesNode = blockNode.objectNode(); for (ByteArrayWrapper key : keys) { byte[] keyBytes = key.getData(); AccountState accountState = repository.getAccountState(keyBytes); ContractDetails details = repository.getContractDetails(keyBytes); JSONHelper.dumpState(statesNode, Hex.toHexString(keyBytes), accountState, details); } blockNode.put("state", statesNode); blockNode.put("state_root", Hex.toHexString(state)); blockNode.put("timestamp", String.valueOf(block.getTimestamp())); ArrayNode transactionsNode = blockNode.arrayNode(); blockNode.put("transactions", transactionsNode); blockNode.put("tx_list_root", ByteUtil.toHexString(block.getTxTrieRoot())); blockNode.put("uncles_hash", "0x" + Hex.toHexString(block.getUnclesHash())); // JSONHelper.dumpTransactions(blockNode, // stateRoot, codeHash, code, storage); }
Example #6
Source File: Repository.java From nuls-v2 with MIT License | 4 votes |
void updateBatch(HashMap<ByteArrayWrapper, AccountState> accountStates, HashMap<ByteArrayWrapper, ContractDetails> contractDetailes);
Example #7
Source File: Repository.java From nuls-v2 with MIT License | 4 votes |
void loadAccount(byte[] addr, HashMap<ByteArrayWrapper, AccountState> cacheAccounts, HashMap<ByteArrayWrapper, ContractDetails> cacheDetails);
Example #8
Source File: Repository.java From nuls with MIT License | 4 votes |
void updateBatch(HashMap<ByteArrayWrapper, AccountState> accountStates, HashMap<ByteArrayWrapper, ContractDetails> contractDetailes);
Example #9
Source File: Repository.java From nuls with MIT License | 4 votes |
void loadAccount(byte[] addr, HashMap<ByteArrayWrapper, AccountState> cacheAccounts, HashMap<ByteArrayWrapper, ContractDetails> cacheDetails);
Example #10
Source File: Program.java From ethereumj with MIT License | 4 votes |
public void fullTrace() { if (logger.isTraceEnabled() || listener != null) { StringBuilder stackData = new StringBuilder(); for (int i = 0; i < stack.size(); ++i) { stackData.append(" ").append(stack.get(i)); if (i < stack.size() - 1) stackData.append("\n"); } if (stackData.length() > 0) stackData.insert(0, "\n"); ContractDetails contractDetails = this.result.getRepository(). getContractDetails(this.programAddress.getLast20Bytes()); StringBuilder storageData = new StringBuilder(); if(contractDetails != null) { List<DataWord> storageKeys = new ArrayList<>(contractDetails.getStorage().keySet()); Collections.sort((List<DataWord>) storageKeys); for (DataWord key : storageKeys) { storageData.append(" ").append(key).append(" -> "). append(contractDetails.getStorage().get(key)).append("\n"); } if (storageData.length() > 0) storageData.insert(0, "\n"); } StringBuilder memoryData = new StringBuilder(); StringBuilder oneLine = new StringBuilder(); for (int i = 0; memory != null && i < memory.limit(); ++i) { byte value = memory.get(i); oneLine.append(ByteUtil.oneByteToHexString(value)).append(" "); if ((i + 1) % 16 == 0) { String tmp = String.format("[%4s]-[%4s]", Integer.toString(i - 15, 16), Integer.toString(i, 16)).replace(" ", "0"); memoryData.append("" ).append(tmp).append(" "); memoryData.append(oneLine); if (i < memory.limit()) memoryData.append("\n"); oneLine.setLength(0); } } if (memoryData.length() > 0) memoryData.insert(0, "\n"); StringBuilder opsString = new StringBuilder(); for (int i = 0; i < ops.length; ++i) { String tmpString = Integer.toString(ops[i] & 0xFF, 16); tmpString = tmpString.length() == 1? "0" + tmpString : tmpString; if (i != pc) opsString.append(tmpString); else opsString.append(" >>").append(tmpString).append(""); } if (pc >= ops.length) opsString.append(" >>"); if (opsString.length() > 0) opsString.insert(0, "\n "); logger.trace(" -- OPS -- {}", opsString); logger.trace(" -- STACK -- {}", stackData); logger.trace(" -- MEMORY -- {}", memoryData); logger.trace(" -- STORAGE -- {}\n", storageData); logger.trace("\n Spent Gas: [{}]/[{}]\n Left Gas: [{}]\n", result.getGasUsed(), invokeData.getGas().longValue(), getGas().longValue()); StringBuilder globalOutput = new StringBuilder("\n"); if (stackData.length() > 0) stackData.append("\n"); if (pc != 0) globalOutput.append("[Op: ").append(OpCode.code(lastOp).name()).append("]\n"); globalOutput.append(" -- OPS -- ").append(opsString).append("\n"); globalOutput.append(" -- STACK -- ").append(stackData).append("\n"); globalOutput.append(" -- MEMORY -- ").append(memoryData).append("\n"); globalOutput.append(" -- STORAGE -- ").append(storageData).append("\n"); if (result.getHReturn() != null) globalOutput.append("\n HReturn: ").append( Hex.toHexString(result.getHReturn().array())); // sophisticated assumption that msg.data != codedata // means we are calling the contract not creating it byte[] txData = invokeData.getDataCopy(DataWord.ZERO, getDataSize()); if (!Arrays.equals(txData, ops)) globalOutput.append("\n msg.data: ").append(Hex.toHexString(txData)); globalOutput.append("\n\n Spent Gas: ").append(result.getGasUsed()); if (listener != null) listener.output(globalOutput.toString()); } }
Example #11
Source File: ContractCallDialog.java From ethereumj with MIT License | 4 votes |
private void populateContractDetails() { byte[] addr = Utils.addressStringToBytes(contractAddrInput.getText()); if(addr == null) { alertStatusMsg("Not a valid contract address"); return; } ContractDetails contractDetails = UIEthereumManager.ethereum .getRepository().getContractDetails(addr); if (contractDetails == null) { alertStatusMsg("No contract for that address"); return; } final byte[] programCode = contractDetails.getCode(); if (programCode == null || programCode.length == 0) { alertStatusMsg("Such account exist but no code in the db"); return; } final Map storageMap = contractDetails.getStorage(); contractDataInput.setBounds(70, 80, 350, 145); contractDataInput.setViewportView(msgDataTA); URL expandIconURL = ClassLoader.getSystemResource("buttons/add-23x23.png"); ImageIcon expandIcon = new ImageIcon(expandIconURL); final JLabel expandLabel = new JLabel(expandIcon); expandLabel.setToolTipText("Cancel"); expandLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); expandLabel.setBounds(235, 232, 23, 23); this.getContentPane().add(expandLabel); expandLabel.setVisible(true); final Border border = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED); final JPanel detailPanel = new JPanel(); detailPanel.setBorder(border); detailPanel.setBounds(135, 242, 230, 2); final JPanel spacer = new JPanel(); spacer.setForeground(Color.white); spacer.setBackground(Color.white); spacer.setBorder(null); spacer.setBounds(225, 232, 40, 20); this.getContentPane().add(spacer); this.getContentPane().add(detailPanel); expandLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { ContractCallDialog.this.setSize(500, 530); ContractCallDialog.this.creatorAddressCombo.setBounds(70, 367, 230, 36); ContractCallDialog.this.gasInput.setBounds(330, 360, 90, 45); ContractCallDialog.this.rejectLabel.setBounds(260, 425, 45, 45); ContractCallDialog.this.approveLabel.setBounds(200, 425, 45, 45); ContractCallDialog.this.statusMsg.setBounds(50, 460, 400, 50); spacer.setVisible(false); expandLabel.setVisible(false); detailPanel.setVisible(false); JTextField contractCode = new JTextField(15); contractCode.setText(Hex.toHexString( programCode )); GUIUtils.addStyle(contractCode, "Code: "); contractCode.setBounds(70, 230, 350, 45); JTable storage = new JTable(2, 2); storage.setTableHeader(null); storage.setShowGrid(false); storage.setIntercellSpacing(new Dimension(15, 0)); storage.setCellSelectionEnabled(false); GUIUtils.addStyle(storage); JTableStorageModel tableModel = new JTableStorageModel(storageMap); storage.setModel(tableModel); JScrollPane scrollPane = new JScrollPane(storage); scrollPane.setBorder(null); scrollPane.getViewport().setBackground(Color.WHITE); scrollPane.setBounds(70, 290, 350, 50); ContractCallDialog.this.getContentPane().add(contractCode); ContractCallDialog.this.getContentPane().add(scrollPane); } }); this.repaint(); }
Example #12
Source File: Repository.java From nuls-v2 with MIT License | 2 votes |
/** * Retrieve contract details for a given account from the database * * @param addr of the account * @return new contract details */ ContractDetails getContractDetails(byte[] addr);
Example #13
Source File: Repository.java From nuls with MIT License | 2 votes |
/** * Retrieve contract details for a given account from the database * * @param addr of the account * @return new contract details */ ContractDetails getContractDetails(byte[] addr);
Example #14
Source File: Repository.java From ethereumj with MIT License | 2 votes |
/** * Retrieve contract details for a given account from the database * * @param addr of the account * @return new contract details */ public ContractDetails getContractDetails(byte[] addr);