org.ethereum.util.Utils Java Examples
The following examples show how to use
org.ethereum.util.Utils.
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: 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 #2
Source File: BlockHeader.java From ethereumj with MIT License | 6 votes |
public String toStylishString() { toStringBuff.setLength(0); toStringBuff.append(", <font color=\"${attribute_color}\"> parentHash</font>=" + toHexString(parentHash)).append("<br/>"); toStringBuff.append(", <font color=\"${attribute_color}\"> unclesHash</font>=" + toHexString(unclesHash)).append("<br/>"); toStringBuff.append(", <font color=\"${attribute_color}\"> coinbase</font>=" + toHexString(coinbase)).append("<br/>"); toStringBuff.append(", <font color=\"${attribute_color}\"> stateRoot</font>=" + toHexString(stateRoot)).append("<br/>"); toStringBuff.append(", <font color=\"${attribute_color}\"> txTrieHash</font>=" + toHexString(txTrieRoot)).append("<br/>"); toStringBuff.append(", <font color=\"${attribute_color}\"> difficulty</font>=" + toHexString(difficulty)).append("<br/>"); toStringBuff.append(", <font color=\"${attribute_color}\"> number</font>=" + number).append("<br/>"); toStringBuff.append(", <font color=\"${attribute_color}\"> minGasPrice</font>=" + minGasPrice).append("<br/>"); toStringBuff.append(", <font color=\"${attribute_color}\"> gasLimit</font>=" + gasLimit).append("<br/>"); toStringBuff.append(", <font color=\"${attribute_color}\"> gasUsed</font>=" + gasUsed).append("<br/>"); toStringBuff.append(", <font color=\"${attribute_color}\"> timestamp</font>=" + timestamp + " (" + Utils.longToDateTime(timestamp) + ")").append("<br/>"); toStringBuff.append(", <font color=\"${attribute_color}\"> extraData</font>=" + toHexString(extraData)).append("<br/>"); toStringBuff.append(", <font color=\"${attribute_color}\"> nonce</font>=" + toHexString(nonce)).append("<br/>"); return toStringBuff.toString(); }
Example #3
Source File: BlockHeader.java From ethereumj with MIT License | 6 votes |
public String toString() { toStringBuff.setLength(0); toStringBuff.append(" parentHash=" + toHexString(parentHash)).append("\n"); toStringBuff.append(" unclesHash=" + toHexString(unclesHash)).append("\n"); toStringBuff.append(" coinbase=" + toHexString(coinbase)).append("\n"); toStringBuff.append(" stateRoot=" + toHexString(stateRoot)).append("\n"); toStringBuff.append(" txTrieHash=" + toHexString(txTrieRoot)).append("\n"); toStringBuff.append(" difficulty=" + toHexString(difficulty)).append("\n"); toStringBuff.append(" number=" + number).append("\n"); toStringBuff.append(" minGasPrice=" + minGasPrice).append("\n"); toStringBuff.append(" gasLimit=" + gasLimit).append("\n"); toStringBuff.append(" gasUsed=" + gasUsed).append("\n"); toStringBuff.append(" timestamp=" + timestamp + " (" + Utils.longToDateTime(timestamp) + ")").append("\n"); toStringBuff.append(" extraData=" + toHexString(extraData)).append("\n"); toStringBuff.append(" nonce=" + toHexString(nonce)).append("\n"); return toStringBuff.toString(); }
Example #4
Source File: ContractSubmitDialog.java From ethereumj with MIT License | 5 votes |
@Override public String toString() { String addressShort = Utils.getAddressShortString(account.getEcKey().getAddress()); String valueShort = Utils.getValueShortString(account.getBalance()); String result = String.format(" By: [%s] %s", addressShort, valueShort); return result; }
Example #5
Source File: HashUtil.java From nuls-v2 with MIT License | 5 votes |
/** * @return generates random peer id for the HelloMessage */ public static byte[] randomPeerId() { byte[] peerIdBytes = new BigInteger(512, Utils.getRandom()).toByteArray(); final String peerId; if (peerIdBytes.length > 64) { peerId = Hex.toHexString(peerIdBytes, 1, 64); } else { peerId = Hex.toHexString(peerIdBytes); } return Hex.decode(peerId); }
Example #6
Source File: ContractCallDialog.java From ethereumj with MIT License | 5 votes |
@Override public String toString() { String addressShort = Utils.getAddressShortString(account.getEcKey().getAddress()); String valueShort = Utils.getValueShortString(account.getBalance()); String result = String.format(" By: [%s] %s", addressShort, valueShort); return result; }
Example #7
Source File: WalletSumPanel.java From ethereumj with MIT License | 5 votes |
public WalletSumPanel(BigInteger balance) { this.setBackground(Color.WHITE); double width = this.getSize().getWidth(); this.setPreferredSize(new Dimension(500, 50)); Border line = BorderFactory.createLineBorder(Color.LIGHT_GRAY); Border empty = new EmptyBorder(5, 8, 5, 8); CompoundBorder border = new CompoundBorder(line, empty); JLabel addressField = new JLabel(); addressField.setPreferredSize(new Dimension(300, 35)); this.add(addressField); JTextField amount = new JTextField(); amount.setBorder(border); amount.setEnabled(true); amount.setEditable(false); amount.setText(Utils.getValueShortString(balance)); amount.setPreferredSize(new Dimension(100, 35)); amount.setForeground(new Color(143, 170, 220)); amount.setHorizontalAlignment(SwingConstants.RIGHT); amount.setFont(new Font("Monospaced", 0, 13)); amount.setBackground(Color.WHITE); this.add(amount); URL payoutIconURL = ClassLoader.getSystemResource("buttons/wallet-pay.png"); ImageIcon payOutIcon = new ImageIcon(payoutIconURL); JLabel payOutLabel = new JLabel(payOutIcon); payOutLabel.setToolTipText("Payout for all address list"); payOutLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); payOutLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { JOptionPane.showMessageDialog(null, "Under construction"); } }); this.add(payOutLabel); }
Example #8
Source File: CryptoTest.java From ethereumj with MIT License | 5 votes |
@Test public void test9() { // TODO: https://tools.ietf.org/html/rfc6979#section-2.2 // TODO: https://github.com/bcgit/bc-java/blob/master/core/src/main/java/org/bouncycastle/crypto/signers/ECDSASigner.java System.out.println(new BigInteger(Hex.decode("3913517ebd3c0c65000000"))); System.out.println(Utils.getValueShortString(new BigInteger("69000000000000000000000000"))); }
Example #9
Source File: BlockHashesMessage.java From ethereumj with MIT License | 5 votes |
@Override public String toString() { if (!parsed) parse(); StringBuffer sb = Utils.getHashlistShort(this.blockHashes); return "[" + this.getCommand().name() + sb.toString() + "] (" + this.blockHashes.size() + ")"; }
Example #10
Source File: HashUtil.java From ethereumj with MIT License | 5 votes |
/** * @return generates random peer id for the HelloMessage */ public static byte[] randomPeerId() { byte[] peerIdBytes = new BigInteger(512, Utils.getRandom()).toByteArray(); String peerId = null; if (peerIdBytes.length > 64) peerId = Hex.toHexString(peerIdBytes, 1, 64); else peerId = Hex.toHexString(peerIdBytes); return Hex.decode(peerId); }
Example #11
Source File: HashUtil.java From nuls with MIT License | 5 votes |
/** * @return generates random peer id for the HelloMessage */ public static byte[] randomPeerId() { byte[] peerIdBytes = new BigInteger(512, Utils.getRandom()).toByteArray(); final String peerId; if (peerIdBytes.length > 64) { peerId = Hex.toHexString(peerIdBytes, 1, 64); } else { peerId = Hex.toHexString(peerIdBytes); } return Hex.decode(peerId); }
Example #12
Source File: Trade.java From wkcwallet-java with Apache License 2.0 | 5 votes |
/** * 第一步,获取交易次数 */ private static void step1_getTransactionCount() { TransactionCountVo transactionCount = WalletApi.getTransactionCount(keystoreInfo.getRealAddress()); BigInteger count = Utils.toBigNumber(transactionCount.getResult()); txInd = new AtomicLong(count.intValue()); System.out.println("已交易:" + count + "次"); }
Example #13
Source File: HashUtil.java From wkcwallet-java with Apache License 2.0 | 5 votes |
/** * @return generates random peer id for the HelloMessage */ public static byte[] randomPeerId() { byte[] peerIdBytes = new BigInteger(512, Utils.getRandom()).toByteArray(); final String peerId; if (peerIdBytes.length > 64) peerId = Hex.toHexString(peerIdBytes, 1, 64); else peerId = Hex.toHexString(peerIdBytes); return Hex.decode(peerId); }
Example #14
Source File: Account.java From ethereumj with MIT License | 4 votes |
public Account() { this.ecKey = new ECKey(Utils.getRandom()); address = this.ecKey.getAddress(); }
Example #15
Source File: GetBlocksMessage.java From ethereumj with MIT License | 4 votes |
public String toString() { if (!parsed) parse(); StringBuffer sb = Utils.getHashlistShort(this.blockHashes); return "[" + this.getCommand().name() + sb.toString() + "] (" + this.blockHashes.size() + ")"; }
Example #16
Source File: WalletAddressPanel.java From ethereumj with MIT License | 4 votes |
public WalletAddressPanel(final Account account) { final WalletAddressPanel walletAddressPanel = this; this.setBackground(Color.WHITE); this.setPreferredSize(new Dimension(500, 45)); JTextField addressField = new JTextField(); Border line = BorderFactory.createLineBorder(Color.LIGHT_GRAY); Border empty = new EmptyBorder(5, 8, 5, 8); CompoundBorder border = new CompoundBorder(line, empty); addressField.setBorder(border); addressField.setEnabled(true); addressField.setEditable(false); addressField.setText(Hex.toHexString(account.getEcKey().getAddress()).toUpperCase()); addressField.setForeground(new Color(143, 170, 220)); addressField.setFont(new Font("Monospaced", 0, 12)); addressField.setPreferredSize(new Dimension(300, 35)); addressField.setBackground(Color.WHITE); this.add(addressField); JTextField amount = new JTextField(); amount.setBorder(border); amount.setEnabled(true); amount.setEditable(false); amount.setText(Utils.getValueShortString(account.getBalance())); amount.setForeground(new Color(143, 170, 220)); amount.setBackground(Color.WHITE); amount.setPreferredSize(new Dimension(100, 35)); amount.setFont(new Font("Monospaced", 0, 13)); amount.setHorizontalAlignment(SwingConstants.RIGHT); this.add(amount); URL payoutIconURL = ClassLoader.getSystemResource("buttons/wallet-pay.png"); ImageIcon payOutIcon = new ImageIcon(payoutIconURL); JLabel payOutLabel = new JLabel(payOutIcon); payOutLabel.setToolTipText("Payout for address"); payOutLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); payOutLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { PayOutDialog payOutDialog = new PayOutDialog((Frame)SwingUtilities.getAncestorOfClass(JFrame.class, walletAddressPanel), account); } }); this.add(payOutLabel); }
Example #17
Source File: BlockChainTable.java From ethereumj with MIT License | 4 votes |
private void fillBlock(final BlockChainTable blockchainTable) { if (blockNumberText.getText().length() == 0) return; long blockNum = Long.parseLong(blockNumberText.getText()); if (blockNum > WorldManager.getInstance().getBlockchain().getSize() - 1) { blockNum = WorldManager.getInstance().getBlockchain().getSize() - 1; } Block block = WorldManager.getInstance().getBlockchain().getBlockByNumber(blockNum); blockN.setText("" + block.getNumber()); highlightText(blockN); minGasPrice.setText("" + block.getMinGasPrice()); highlightText(minGasPrice); gasLimit.setText("" + block.getGasLimit()); highlightText(gasLimit); gasUsed.setText("" + block.getGasUsed()); highlightText(gasUsed); timestamp.setText(Utils.longToDateTime(block.getTimestamp())); highlightText(timestamp); difficulty.setText(ByteUtil.toHexString(block.getDifficulty())); highlightText(difficulty); hash.setText(ByteUtil.toHexString(block.getHash())); highlightText(hash); parentHash.setText(ByteUtil.toHexString(block.getParentHash())); highlightText(parentHash); uncleHash.setText(ByteUtil.toHexString(block.getUnclesHash())); highlightText(uncleHash); stateRoot.setText(ByteUtil.toHexString(block.getStateRoot())); highlightText(stateRoot); trieRoot.setText(ByteUtil.toHexString(block.getTxTrieRoot())); highlightText(trieRoot); coinbase.setText(ByteUtil.toHexString(block.getCoinbase())); highlightText(coinbase); nonce.setText(ByteUtil.toHexString(block.getNonce())); highlightText(nonce); if (block.getExtraData() != null) { extraData.setText(ByteUtil.toHexString(block.getExtraData())); highlightText(extraData); } GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; transactionsPanel.removeAll(); int row = 1; for (Transaction transaction : block.getTransactionsList()) { JPanel transactionPanel = createTransactionPanel(blockchainTable, transaction); c.gridx = 0; c.gridy = row; c.weighty = 1; c.weightx = 1; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new Insets(10, 10, 0, 10); transactionsPanel.add(transactionPanel, c); row++; } transactionsPanel.repaint(); scrollPane.revalidate(); }
Example #18
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(); }