org.ethereum.crypto.HashUtil Java Examples
The following examples show how to use
org.ethereum.crypto.HashUtil.
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: AccountsListWindow.java From ethereumj with MIT License | 6 votes |
@Override public Object getValueAt(int rowIndex, int columnIndex) { if(columnIndex == 0) { return Hex.toHexString(data.get(rowIndex).address); } else if(columnIndex == 1 ){ if(data.get(rowIndex).accountState != null) { return Denomination.toFriendlyString(data.get(rowIndex).accountState.getBalance()); } return "---"; } else { if(data.get(rowIndex).accountState != null) { if(!Arrays.areEqual(data.get(rowIndex).accountState.getCodeHash(), HashUtil.EMPTY_DATA_HASH)) return "Yes"; } return "No"; } }
Example #2
Source File: TransactionTest.java From ethereumj with MIT License | 6 votes |
@Test /* sign transaction https://tools.ietf.org/html/rfc6979 */ public void test1() throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, IOException { //python taken exact data String txRLPRawData = "a9e880872386f26fc1000085e8d4a510008203e89413978aee95f38490e9769c39b2773ed763d9cd5f80"; // String txRLPRawData = "f82804881bc16d674ec8000094cd2a3d9f938e13cd947ec05abc7fe734df8dd8268609184e72a0006480"; byte[] cowPrivKey = Hex.decode("c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4"); ECKey key = ECKey.fromPrivate(cowPrivKey); byte[] data = Hex.decode(txRLPRawData); // step 1: serialize + RLP encode // step 2: hash = sha3(step1) byte[] txHash = HashUtil.sha3(data); String signature = key.doSign(txHash).toBase64(); System.out.println(signature); }
Example #3
Source File: RLPTest.java From ethereumj with MIT License | 6 votes |
@Test /** found bug encode list affects element value, hhh... not really at the end but keep the test */ public void test10() { /* 2 */ byte[] prevHash = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; prevHash = RLP.encodeElement(prevHash); /* 2 */ byte[] uncleList = HashUtil.sha3(RLP.encodeList(new byte[]{})); /* 3 */ byte[] coinbase = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; coinbase = RLP.encodeElement(coinbase); byte[] header = RLP.encodeList( prevHash, uncleList, coinbase); assertEquals("f856a000000000000000000000000000000000000000000000000000000000000000001dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000", Hex.toHexString(header)); }
Example #4
Source File: RepositoryImpl.java From ethereumj with MIT License | 6 votes |
public void saveCode(byte[] addr, byte[] code) { if (code == null) return; AccountState state = getAccountState(addr); if (state == null) return; if (logger.isDebugEnabled()) logger.debug("Saving code: \n address:\t [{}], \n code:\t\t [{}]", Hex.toHexString(addr), Hex.toHexString(code)); ContractDetails details = getContractDetails(addr); details.setCode(code); byte[] codeHash = HashUtil.sha3(code); state.setCodeHash(codeHash); accountStateDB.update(addr, state.getEncoded()); contractDetailsDB.put(addr, details.getEncoded()); if (logger.isDebugEnabled()) logger.debug("Code saved: \n accountstate:\t [{}]\n codeHash:\t [{}]\n details RLP:\t [{}]", Hex.toHexString(state.getEncoded()), Hex.toHexString(codeHash), Hex.toHexString(details.getEncoded())); }
Example #5
Source File: RepositoryImpl.java From nuls-v2 with MIT License | 5 votes |
@Override public synchronized void saveCode(byte[] addr, byte[] code) { byte[] codeHash = HashUtil.sha3(code); codeCache.put(codeKey(codeHash, addr), code); AccountState accountState = getOrCreateAccountState(addr); accountStateCache.put(addr, accountState.withCodeHash(codeHash)); }
Example #6
Source File: WalletTest.java From ethereumj with MIT License | 5 votes |
@Test public void testSave1() throws TransformerException, ParserConfigurationException { Wallet wallet = new Wallet(); ECKey cowKey = ECKey.fromPrivate(HashUtil.sha3("cow".getBytes())); ECKey catKey = ECKey.fromPrivate(HashUtil.sha3("cat".getBytes())); wallet.importKey(cowKey.getPrivKeyBytes()); wallet.importKey(catKey.getPrivKeyBytes()); wallet.setHigh(4354); wallet.save(); }
Example #7
Source File: WalletTest.java From ethereumj with MIT License | 5 votes |
@Test // test account balance with pending "unblocked" transaction public void accountTest_2(){ Repository repository = WorldManager.getInstance().getRepository(); ECKey cowKey = ECKey.fromPrivate(HashUtil.sha3("cow".getBytes())); repository.createAccount(cowKey.getAddress()); repository.addBalance(cowKey.getAddress(), BigInteger.TEN); Wallet wallet = new Wallet(); wallet.importKey(cowKey.getPrivKeyBytes()); Transaction tx = new Transaction( new byte[]{}, Hex.decode("09184E72A000"), Hex.decode("03E8"), cowKey.getAddress(), Hex.decode("0A"), new byte[]{} ); ECKey catKey = ECKey.fromPrivate(HashUtil.sha3("cat".getBytes())); tx.sign(catKey.getPrivKeyBytes()); wallet.applyTransaction(tx); BigInteger walletBalance = wallet.getBalance(cowKey.getAddress()); Assert.assertEquals(BigInteger.valueOf(20), walletBalance); }
Example #8
Source File: TransactionTest.java From ethereumj with MIT License | 5 votes |
@Test public void testTransactionCreateContract() { // String rlp = "f89f808609184e72a0008203e8808203e8b84b4560005444602054600f60056002600a02010b0d630000001d596002602054630000003b5860066000530860056006600202010a0d6300000036596004604054630000003b5860056060541ca0ddc901d83110ea50bc40803f42083afea1bbd420548f6392a679af8e24b21345a06620b3b512bea5f0a272703e8d6933177c23afc79516fd0ca4a204aa6e34c7e9"; byte[] senderPrivKey = HashUtil.sha3("cow".getBytes()); byte[] nonce = BigIntegers.asUnsignedByteArray(BigInteger.ZERO); byte[] gasPrice = Hex.decode("09184e72a000"); // 10000000000000 byte[] gas = Hex.decode("03e8"); // 1000 byte[] recieveAddress = null; byte[] endowment = Hex.decode("03e8"); //10000000000000000" byte[] init = Hex.decode("4560005444602054600f60056002600a02010b0d630000001d596002602054630000003b5860066000530860056006600202010a0d6300000036596004604054630000003b586005606054"); Transaction tx1 = new Transaction(nonce, gasPrice, gas, recieveAddress, endowment, init); tx1.sign(senderPrivKey); byte[] payload = tx1.getEncoded(); System.out.println(Hex.toHexString(payload)); Transaction tx2 = new Transaction(payload); // tx2.getSender(); String plainTx1 = Hex.toHexString(tx1.getEncodedRaw()); String plainTx2 = Hex.toHexString(tx2.getEncodedRaw()); // Transaction tx = new Transaction(Hex.decode(rlp)); System.out.println("tx1.hash: " + Hex.toHexString(tx1.getHash())); System.out.println("tx2.hash: " + Hex.toHexString(tx2.getHash())); System.out.println(); System.out.println("plainTx1: " + plainTx1 ); System.out.println("plainTx2: " + plainTx2 ); System.out.println( Hex.toHexString(tx2.getSender())); }
Example #9
Source File: TransactionTest.java From ethereumj with MIT License | 5 votes |
@Test /* achieve public key of the sender nonce: 01 */ public void test3() throws Exception { // cat --> 79b08ad8787060333663d19704909ee7b1903e58 // cow --> cd2a3d9f938e13cd947ec05abc7fe734df8dd826 ECKey ecKey = ECKey.fromPrivate(HashUtil.sha3("cat".getBytes())); byte[] senderPrivKey = HashUtil.sha3("cow".getBytes()); byte[] nonce = { 0x01 }; byte[] gasPrice = Hex.decode("09184e72a000"); byte[] gasLimit = Hex.decode("4255"); BigInteger value = new BigInteger("1000000000000000000000000"); Transaction tx = new Transaction(nonce, gasPrice, gasLimit, ecKey.getAddress(), value.toByteArray(), null); tx.sign(senderPrivKey); System.out.println("v\t\t\t: " + Hex.toHexString(new byte[] { tx.getSignature().v })); System.out.println("r\t\t\t: " + Hex.toHexString(BigIntegers.asUnsignedByteArray(tx.getSignature().r))); System.out.println("s\t\t\t: " + Hex.toHexString(BigIntegers.asUnsignedByteArray(tx.getSignature().s))); System.out.println("RLP encoded tx\t\t: " + Hex.toHexString(tx.getEncoded())); // retrieve the signer/sender of the transaction ECKey key = ECKey.signatureToKey(tx.getHash(), tx.getSignature().toBase64()); System.out.println("Tx unsigned RLP\t\t: " + Hex.toHexString(tx.getEncodedRaw())); System.out.println("Tx signed RLP\t\t: " + Hex.toHexString(tx.getEncoded())); System.out.println("Signature public key\t: " + Hex.toHexString(key.getPubKey())); System.out.println("Sender is\t\t: " + Hex.toHexString(key.getAddress())); Assert.assertEquals("cd2a3d9f938e13cd947ec05abc7fe734df8dd826", Hex.toHexString(key.getAddress())); }
Example #10
Source File: BlockHeader.java From ethereumj with MIT License | 5 votes |
/** * Verify that block is valid for its difficulty * * @return boolean */ public boolean validateNonce() { BigInteger max = BigInteger.valueOf(2).pow(256); byte[] target = BigIntegers.asUnsignedByteArray(32, max.divide(new BigInteger(1, this.getDifficulty()))); byte[] hash = HashUtil.sha3(this.getEncodedWithoutNonce()); byte[] concat = Arrays.concatenate(hash, this.getNonce()); byte[] result = HashUtil.sha3(concat); return FastByteComparisons.compareTo(result, 0, 32, target, 0, 32) < 0; }
Example #11
Source File: SerpentToAssemblyCompiler.java From ethereumj with MIT License | 5 votes |
public String visitMsg_func(@NotNull SerpentParser.Msg_funcContext ctx, String varName) { // msg_func: 'msg' '(' int_val ',' int_val ',' int_val ',' arr_def ',' int_val ',' int_val')' ; // msg_func: 'msg' '(' [gas] ',' [to] ',' [value] ',' arr_def ',' [in_len] ',' [out_len]')' ; String operand0 = visit(ctx.int_val(0)); String operand1 = visit(ctx.int_val(1)); String operand2 = visit(ctx.int_val(2)); String loadInData = visit(ctx.arr_def()); String inSizeCallParam = visit(ctx.int_val(3)); String outSizeCallParam = visit(ctx.int_val(4)); // TODO: 1. allocate out_memory and push ptr // TODO: 2. push ptr for in_memory allocated String randomArrayName = new String(HashUtil.randomPeerId()); int inSize = Integer.parseInt( inSizeCallParam ); int outSize = Integer.parseInt( outSizeCallParam ); arraysSize.put(randomArrayName, inSize * 32 + 32); arraysIndex.add(randomArrayName); int outSizeVal = outSize * 32 + 32; arraysSize.put(varName, outSize * 32 + 32); arraysIndex.add(varName); // [OUTDATASIZE] [OUTDATASTART] [INDATASIZE] [INDATASTART] [VALUE] [TO] [GAS] CALL // [OUTDATASIZE] [OUTDATASTART] [INDATASIZE] [INDATASTART] ***ARR_IN_SET*** [VALUE] [TO] [GAS] CALL //X_X = [ 32 + 128 + 6 * 32 ] = [ var_table_size + in_arr_size + out_arr_size ] // this code allocates the memory block for the out data, // and saves the size in typical array format [size, element_1, element_2, ...] String outArrSet = String.format( " %d MSIZE MSTORE 0 %d MSIZE ADD MSTORE8 ", outSizeVal, outSizeVal - 32 ); return String.format("%d MSIZE %s %d %s %s %s %s CALL ", outSizeVal, outArrSet ,inSize * 32, loadInData, operand2, operand1, operand0); }
Example #12
Source File: Cache.java From ethereumj with MIT License | 5 votes |
/** * Put the node in the cache if RLP encoded value is longer than 32 bytes * * @param o the Node which could be a pair-, multi-item Node or single Value * @return sha3 hash of RLP encoded node if length > 32 otherwise return node itself */ public Object put(Object o) { Value value = new Value(o); byte[] enc = value.encode(); if (enc.length >= 32) { byte[] sha = HashUtil.sha3(enc); this.nodes.put(new ByteArrayWrapper(sha), new Node(value, true)); this.isDirty = true; return sha; } return value; }
Example #13
Source File: TrieImpl.java From ethereumj with MIT License | 5 votes |
@Override public byte[] getRootHash() { if (root == null || (root instanceof byte[] && ((byte[]) root).length == 0) || (root instanceof String && "".equals((String) root))) { return ByteUtil.EMPTY_BYTE_ARRAY; } else if (root instanceof byte[]) { return (byte[]) this.getRoot(); } else { Value rootValue = new Value(this.getRoot()); byte[] val = rootValue.encode(); return HashUtil.sha3(val); } }
Example #14
Source File: WorldManager.java From ethereumj with MIT License | 5 votes |
public void init() { this.wallet = new Wallet(); byte[] cowAddr = HashUtil.sha3("cow".getBytes()); wallet.importKey(cowAddr); String secret = CONFIG.coinbaseSecret(); byte[] cbAddr = HashUtil.sha3(secret.getBytes()); wallet.importKey(cbAddr); }
Example #15
Source File: CommonConfig.java From nuls with MIT License | 5 votes |
public Source<byte[], byte[]> trieNodeSource() { if (trieNodeSource == null) { DbSource<byte[]> db = blockchainDB(); Source<byte[], byte[]> src = new PrefixLookupSource<>(db, NodeKeyCompositor.PREFIX_BYTES); trieNodeSource = new XorDataSource<>(src, HashUtil.sha3("state".getBytes())); } return trieNodeSource; }
Example #16
Source File: Pruner.java From nuls with MIT License | 5 votes |
private String strSample(Collection<byte[]> hashes) { String sample = hashes.stream().limit(3) .map(HashUtil::shortHash).collect(Collectors.joining(", ")); if (hashes.size() > 3) { sample += ", ... (" + hashes.size() + " total)"; } return sample; }
Example #17
Source File: RepositoryImpl.java From nuls-v2 with MIT License | 5 votes |
synchronized AccountState getOrCreateAccountState(byte[] addr) { AccountState ret = accountStateCache.get(addr); if (ret == null) { ret = createAccount(addr, HashUtil.EMPTY_DATA_HASH); } return ret; }
Example #18
Source File: CommonConfig.java From nuls-v2 with MIT License | 5 votes |
public Source<byte[], byte[]> trieNodeSource() { if (trieNodeSource == null) { DbSource<byte[]> db = blockchainDB(); Source<byte[], byte[]> src = new PrefixLookupSource<>(db, NodeKeyCompositor.PREFIX_BYTES); trieNodeSource = new XorDataSource<>(src, HashUtil.sha3("state".getBytes())); } return trieNodeSource; }
Example #19
Source File: Transaction.java From wkcwallet-java with Apache License 2.0 | 5 votes |
public byte[] getHash() { if(!this.parsed) { this.rlpParse(); } byte[] plainMsg = this.getEncoded(); return HashUtil.sha3(plainMsg); }
Example #20
Source File: Transaction.java From wkcwallet-java with Apache License 2.0 | 5 votes |
public byte[] getRawHash() { if(!this.parsed) { this.rlpParse(); } byte[] plainMsg = this.getEncodedRaw(); return HashUtil.sha3(plainMsg); }
Example #21
Source File: Pruner.java From nuls-v2 with MIT License | 5 votes |
private String strSample(Collection<byte[]> hashes) { String sample = hashes.stream().limit(3) .map(HashUtil::shortHash).collect(Collectors.joining(", ")); if (hashes.size() > 3) { sample += ", ... (" + hashes.size() + " total)"; } return sample; }
Example #22
Source File: RepositoryImpl.java From nuls with MIT License | 5 votes |
synchronized AccountState getOrCreateAccountState(byte[] addr) { AccountState ret = accountStateCache.get(addr); if (ret == null) { ret = createAccount(addr, HashUtil.EMPTY_DATA_HASH); } return ret; }
Example #23
Source File: RepositoryImpl.java From nuls with MIT License | 5 votes |
@Override public synchronized void saveCode(byte[] addr, byte[] code) { byte[] codeHash = HashUtil.sha3(code); codeCache.put(codeKey(codeHash, addr), code); AccountState accountState = getOrCreateAccountState(addr); accountStateCache.put(addr, accountState.withCodeHash(codeHash)); }
Example #24
Source File: RepositoryImpl.java From nuls-v2 with MIT License | 4 votes |
@Override public synchronized byte[] getCode(byte[] addr) { byte[] codeHash = getCodeHash(addr); return codeHash == null || FastByteComparisons.equal(codeHash, HashUtil.EMPTY_DATA_HASH) ? ByteUtil.EMPTY_BYTE_ARRAY : codeCache.get(codeKey(codeHash, addr)); }
Example #25
Source File: Pruner.java From nuls-v2 with MIT License | 4 votes |
public void persist(byte[] hash) { if (!ready || !withSecondStep()) { return; } logger.trace("persist [{}]", toHexString(hash)); long t = System.currentTimeMillis(); JournalSource.Update update = journal.get(hash); if (update == null) { logger.debug("skip [{}]: can't fetch update", HashUtil.shortHash(hash)); return; } // persist deleted keys int nodesDeleted = 0; for (byte[] key : update.getDeletedKeys()) { if (!filter.maybeContains(key) && !distantFilter.maybeContains(key)) { ++nodesDeleted; storage.delete(key); } } // clean up filter update.getInsertedKeys().forEach(distantFilter::remove); // delete update journal.delete(hash); if (logger.isDebugEnabled()) { int collisions = ((CountingQuotientFilter) distantFilter).getCollisionNumber(); double load = (double) ((CountingQuotientFilter) distantFilter).getEntryNumber() / ((CountingQuotientFilter) distantFilter).getMaxInsertions(); if (collisions > distantMaxCollisions.collisions) { distantMaxCollisions.collisions = collisions; distantMaxCollisions.load = load; distantMaxCollisions.deleted = nodesDeleted; } if (load > distantMaxLoad.load) { distantMaxLoad.load = load; distantMaxLoad.collisions = collisions; distantMaxLoad.deleted = nodesDeleted; } if (statsTracker % 100 == 0) { logger.debug("distant filter: max load: " + distantMaxLoad); logger.debug("distant filter: max collisions: " + distantMaxCollisions); } } if (logger.isTraceEnabled()) { logger.trace("[{}] persisted in {}ms: {}/{} ({}%) nodes deleted, filter load: {}/{}: {}, distinct collisions: {}", HashUtil.shortHash(hash), System.currentTimeMillis() - t, nodesDeleted, update.getDeletedKeys().size(), nodesDeleted * 100 / update.getDeletedKeys().size(), ((CountingQuotientFilter) distantFilter).getEntryNumber(), ((CountingQuotientFilter) distantFilter).getMaxInsertions(), String.format("%.4f", (double) ((CountingQuotientFilter) distantFilter).getEntryNumber() / ((CountingQuotientFilter) distantFilter).getMaxInsertions()), ((CountingQuotientFilter) distantFilter).getCollisionNumber()); } }
Example #26
Source File: WalletTest.java From ethereumj with MIT License | 4 votes |
@Test // Testing account for simple balance set public void accountTest_1(){ Repository repository = WorldManager.getInstance().getRepository(); ECKey cowKey = ECKey.fromPrivate(HashUtil.sha3("cow".getBytes())); repository.createAccount(cowKey.getAddress()); repository.addBalance(cowKey.getAddress(), BigInteger.TEN); Wallet wallet = new Wallet(); wallet.importKey(cowKey.getPrivKeyBytes()); BigInteger walletBalance = wallet.getBalance(cowKey.getAddress()); Assert.assertEquals(BigInteger.TEN, walletBalance); }
Example #27
Source File: BlockStoreDummy.java From nuls-v2 with MIT License | 4 votes |
@Override public byte[] getBlockHashByNumber(long blockNumber) { byte[] data = String.valueOf(blockNumber).getBytes(); return HashUtil.sha3(data); }
Example #28
Source File: StateTest.java From ethereumj with MIT License | 4 votes |
@Test // calc state after applying first tx on genesis public void test2() { // explanation: // 0) create genesis // 1) apply cost of tx to cd2a3d9f938e13cd947ec05abc7fe734df8dd826 // 2) create AccountState for 77045e71a7a2c50903d88e564cd72fab11e82051 // 3) minner gets the gas + coinbase ==> 6260000000000000 + 1500000000000000000 // 4) calc the root Trie trie = generateGenesisState(); String expected = "73d725637d76b140720cc75500cfb5ce17bf4c6089798b69a7db1a7e4d97d617"; // Get and update sender in world state byte[] cowAddress = Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826"); byte[] rlpEncodedState = trie.get(cowAddress); AccountState account_1 = new AccountState(rlpEncodedState); account_1.addToBalance(new BigInteger("-6260000000001000")); account_1.incrementNonce(); trie.update(cowAddress, account_1.getEncoded()); // Add contract to world state byte[] codeData = Hex.decode("61778e600054"); AccountState account_2 = new AccountState(BigInteger.ZERO, BigInteger.valueOf(1000)); account_2.setCodeHash(HashUtil.sha3(codeData)); byte[] contractAddress = Hex.decode("77045e71a7a2c50903d88e564cd72fab11e82051"); // generated based on sender + nonce trie.update(contractAddress, account_2.getEncoded()); // this is saved in the db // trie.update(HashUtil.sha3(codeData), codeData); // Update miner in world state byte[] minerAddress = Hex.decode("4c5f4d519dff3c16f0d54b6866e256fbbbc1a600"); AccountState account_3 = new AccountState(BigInteger.ZERO, new BigInteger("1506260000000000000")); trie.update(minerAddress, account_3.getEncoded()); assertEquals(expected, Hex.toHexString(trie.getRootHash())); /* *** GROSS DATA *** BlockData [ hash=22cf863ab836a6f5c29389d2e77f4792a3b3b52908c98ed14b1cbe91491a3e36 parentHash=77ef4fdaf389dca53236bcf7f72698e154eab2828f86fbc4fc6cd9225d285c89 unclesHash=1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347 coinbase=4c5f4d519dff3c16f0d54b6866e256fbbbc1a600 stateHash=69c21ff84a5af0b53b11c61110a16d6ad43dad37b3eb29ae8e88c936eb06456a txTrieHash=a77691cf47bec9021d3f027fc8ef2d51b758b600a79967154354b8e37108896f difficulty=3ff000 number=1 minGasPrice=10000000000000 gasLimit=999023 gasUsed=626 timestamp=1401979976 (2014.06.05 15:52:56) extraData=null nonce=0000000000000000000000000000000000000000000000005d439960040e4505 TransactionReceipt[ TransactionData [ hash=1ee6fa3149a5e9c09b54009eb6e108aaa7ecd79483d57eedcf2dff93a1505588 nonce=null, gasPrice=09184e72a000, gas=03e8, receiveAddress=0000000000000000000000000000000000000000, value=03e8, data=60016000546006601160003960066000f261778e600054, signatureV=27, signatureR=2b379f22050e3554c3fa5423d9040bb28dcc7f905300db4e67c03bcf9b27003c, signatureS=59f47793e050974e6b5fca2848b19925637b883a012693b54d712f1c4f74def5 ] , postTxState=7fa5bd00f6e03b5a5718560f1e25179b227167585a3c3da06a48f554365fb527 , cumulativeGas=0272] ] +++ 4c5f4d519dff3c16f0d54b6866e256fbbbc1a600: +++ 77045e71a7a2c50903d88e564cd72fab11e82051: $[61,77,8e,60,0,54] ([]) * cd2a3d9f938e13cd947ec05abc7fe734df8dd826: #1 1606938044258990275541962092341162602522202987522792835300376 (-6260000000001000) */ assertEquals(expected, Hex.toHexString(trie.getRootHash())); }
Example #29
Source File: Transaction.java From ethereumj with MIT License | 4 votes |
public byte[] getContractAddress() { if (!isContractCreation()) return null; return HashUtil.calcNewAddr(this.getSender(), this.getNonce()); }
Example #30
Source File: TransactionsMessageTest.java From ethereumj with MIT License | 4 votes |
@Test /* Transactions msg encode */ public void test_3() throws Exception { String expected = "f87302f870808b00d3c21bcecceda10000009479b08ad8787060333663d19704909ee7b1903e588609184e72a000824255801ca00f410a70e42b2c9854a8421d32c87c370a2b9fff0a27f9f031bb4443681d73b5a018a7dc4c4f9dee9f3dc35cb96ca15859aa27e219a8e4a8547be6bd3206979858"; BigInteger value = new BigInteger("1000000000000000000000000"); byte[] privKey = HashUtil.sha3("cat".getBytes()); ECKey ecKey = ECKey.fromPrivate(privKey); byte[] gasPrice= Hex.decode("09184e72a000"); byte[] gas = Hex.decode("4255"); Transaction tx = new Transaction(null, value.toByteArray(), ecKey.getAddress(), gasPrice, gas, null); tx.sign(privKey); tx.getEncoded(); Set<Transaction> txs = new HashSet<>(Arrays.asList(tx)); TransactionsMessage transactionsMessage = new TransactionsMessage(txs); assertEquals(EthMessageCodes.TRANSACTIONS, transactionsMessage.getCommand()); assertEquals(expected, Hex.toHexString(transactionsMessage.getEncoded())); }