Java Code Examples for org.spongycastle.util.encoders.Hex

The following examples show how to use org.spongycastle.util.encoders.Hex. These examples are extracted from open source projects. 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
private byte[] deployCalledContractAndGetItsAddress()
    throws ContractExeException, ReceiptCheckErrException, ContractValidateException, VMIllegalException {
  String contractName = "calledContract";
  byte[] address = Hex.decode(OWNER_ADDRESS);
  String ABI =
      "[{\"constant\":false,\"inputs\":[],\"name\":\"getZero\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],"
          + "\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]";
  String code =
      "6080604052348015600f57600080fd5b5060988061001e6000396000f300608060405260043610603e5763ffffffff7c01"
          + "000000000000000000000000000000000000000000000000000000006000350416639f3f89dc81146043575b600080fd5b34801560"
          + "4e57600080fd5b5060556067565b60408051918252519081900360200190f35b6000905600a165627a7a72305820fa4124f68cd4c9"
          + "2df5362cb343d4831acd8ed666b72eb497974cdf511ae642a90029";
  long value = 0;
  long feeLimit = 1000000000;
  long consumeUserResourcePercent = 0;

  return GVMTestUtils
      .deployContractWholeProcessReturnContractAddress(contractName, address, ABI, code, value,
          feeLimit, consumeUserResourcePercent, null,
          deposit, null);
}
 
Example 2
/**
 * constructor.
 */

public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) {
  byte[] address;
  ECKey temKey = null;
  try {
    BigInteger priK = new BigInteger(priKey, 16);
    temKey = ECKey.fromPrivate(priK);
  } catch (Exception ex) {
    ex.printStackTrace();
  }
  ECKey ecKey = temKey;
  if (ecKey == null) {
    String pubKey = loadPubKey(); //04 PubKey[128]
    if (StringUtils.isEmpty(pubKey)) {
      logger.warn("Warning: QueryAccount failed, no wallet address !!");
      return null;
    }
    byte[] pubKeyAsc = pubKey.getBytes();
    byte[] pubKeyHex = Hex.decode(pubKeyAsc);
    ecKey = ECKey.fromPublicOnly(pubKeyHex);
  }
  return grpcQueryAccount(ecKey.getAddress(), blockingStubFull);
}
 
Example 3
Source Project: aion   Source File: TrieTestWithRootHashValues.java    License: MIT License 6 votes vote down vote up
@Test
public void testDeleteLongString2() {
    String ROOT_HASH_BEFORE =
            "e020de34ca26f8d373ff2c0a8ac3a4cb9032bfa7a194c68330b7ac3584a1d388";
    String ROOT_HASH_AFTER = "334511f0c4897677b782d13a6fa1e58e18de6b24879d57ced430bad5ac831cb2";
    TrieImpl trie = new TrieImpl(mockDb);

    trie.update(ca, LONG_STRING);
    assertEquals(LONG_STRING, new String(trie.get(ca)));

    trie.update(cat, LONG_STRING);
    assertEquals(LONG_STRING, new String(trie.get(cat)));
    assertEquals(ROOT_HASH_BEFORE, Hex.toHexString(trie.getRootHash()));

    trie.delete(cat);
    assertEquals("", new String(trie.get(cat)));
    assertEquals(ROOT_HASH_AFTER, Hex.toHexString(trie.getRootHash()));
}
 
Example 4
Source Project: aion   Source File: TrieTestWithRootHashValues.java    License: MIT License 6 votes vote down vote up
@Test
public void testDeleteShortString1() {
    String ROOT_HASH_BEFORE =
            "a9539c810cc2e8fa20785bdd78ec36cc1dab4b41f0d531e80a5e5fd25c3037ee";
    String ROOT_HASH_AFTER = "fc5120b4a711bca1f5bb54769525b11b3fb9a8d6ac0b8bf08cbb248770521758";
    TrieImpl trie = new TrieImpl(mockDb);

    trie.update(cat, dog);
    assertEquals(dog, new String(trie.get(cat)));

    trie.update(ca, dude);
    assertEquals(dude, new String(trie.get(ca)));
    assertEquals(ROOT_HASH_BEFORE, Hex.toHexString(trie.getRootHash()));

    trie.delete(ca);
    assertEquals("", new String(trie.get(ca)));
    assertEquals(ROOT_HASH_AFTER, Hex.toHexString(trie.getRootHash()));
}
 
Example 5
/**
 * constructor.
 */

public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) {
  byte[] address;
  if (ecKey == null) {
    String pubKey = loadPubKey(); //04 PubKey[128]
    if (StringUtils.isEmpty(pubKey)) {
      logger.warn("Warning: QueryAccount failed, no wallet address !!");
      return null;
    }
    byte[] pubKeyAsc = pubKey.getBytes();
    byte[] pubKeyHex = Hex.decode(pubKeyAsc);
    ecKey = ECKey.fromPublicOnly(pubKeyHex);
  }
  return grpcQueryAccount(ecKey.getAddress(), blockingStubFull);
}
 
Example 6
Source Project: SightRemote   Source File: Pipeline.java    License: GNU General Public License v3.0 6 votes vote down vote up
public Pipeline(DataStorage dataStorage, StatusCallback statusCallback) {
    this.dataStorage = dataStorage;
    this.statusCallback = statusCallback;
    if (dataStorage.contains("INCOMINGKEY") && dataStorage.contains("OUTGOINGKEY")) {
        derivedKeys = new DerivedKeys();
        derivedKeys.setIncomingKey(Hex.decode(dataStorage.get("INCOMINGKEY")));
        derivedKeys.setOutgoingKey(Hex.decode(dataStorage.get("OUTGOINGKEY")));
    }
    if (dataStorage.contains("COMMID"))
        commID = Long.parseLong(dataStorage.get("COMMID"));
    if (dataStorage.contains("LASTNONCESENT"))
        lastNonceSent = new BigInteger(Hex.decode(dataStorage.get("LASTNONCESENT")));
    if (dataStorage.contains("LASTNONCERECEIVED"))
        lastNonceReceived = new BigInteger(Hex.decode(dataStorage.get("LASTNONCERECEIVED")));
    setupPipeline();
}
 
Example 7
Source Project: gsc-core   Source File: MemoryTest.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void memorySave_3() {

  Memory memoryBuffer = new Memory();
  byte[] data = Hex.decode("010101010101010101010101010101010101010101010101010101010101010101");

  memoryBuffer.write(0, data, data.length, false);

  assertTrue(1 == memoryBuffer.getChunks().size());

  byte[] chunk = memoryBuffer.getChunks().get(0);
  assertTrue(chunk[0] == 1);
  assertTrue(chunk[1] == 1);

  assertTrue(chunk[30] == 1);
  assertTrue(chunk[31] == 1);
  assertTrue(chunk[32] == 1);
  assertTrue(chunk[33] == 0);

  assertTrue(memoryBuffer.size() == 64);
}
 
Example 8
Source Project: ethereumj   Source File: ECKeyTest.java    License: MIT License 6 votes vote down vote up
@Test
  public void testVerifySignature2() {
      BigInteger r = new BigInteger("c52c114d4f5a3ba904a9b3036e5e118fe0dbb987fe3955da20f2cd8f6c21ab9c", 16);
      BigInteger s = new BigInteger("6ba4c2874299a55ad947dbc98a25ee895aabf6b625c26c435e84bfd70edf2f69", 16);
      ECDSASignature sig = ECDSASignature.fromComponents(r.toByteArray(), s.toByteArray(), (byte) 0x1b);
      byte[] rawtx = Hex.decode("f82804881bc16d674ec8000094cd2a3d9f938e13cd947ec05abc7fe734df8dd8268609184e72a0006480");
try {
	ECKey key = ECKey.signatureToKey(HashUtil.sha3(rawtx), sig.toBase64());
	System.out.println("Signature public key\t: " + Hex.toHexString(key.getPubKey()));
	System.out.println("Sender is\t\t: " + Hex.toHexString(key.getAddress()));
	assertEquals("cd2a3d9f938e13cd947ec05abc7fe734df8dd826", Hex.toHexString(key.getAddress()));
	key.verify(HashUtil.sha3(rawtx), sig);
} catch (SignatureException e) {
	fail();
}
  }
 
Example 9
Source Project: ethereumj   Source File: AccountsListWindow.java    License: MIT License 6 votes vote down vote up
@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 10
Source Project: ethereumj   Source File: LocalJSONTestSuiteTest.java    License: MIT License 6 votes vote down vote up
@Test // CallCreate parsing  //
public void test4() throws ParseException {

    String expectedData         =   "";
    String expectedDestination =   "cd1722f3947def4cf144679da39c4c32bdc35681";
    String expectedGasLimit    =   "9792";
    String expectedValue       =   "74";

    JSONParser parser = new JSONParser();
    String callCreateString = "{'data' : '','destination' : 'cd1722f3947def4cf144679da39c4c32bdc35681','gasLimit' : 9792,'value' : 74}";
    callCreateString = callCreateString.replace("'", "\"");

    JSONObject callCreateJSONObj = (JSONObject)parser.parse(callCreateString);

    CallCreate callCreate = new CallCreate(callCreateJSONObj);

    Assert.assertEquals(expectedData,         Hex.toHexString(callCreate.getData()));
    Assert.assertEquals(expectedDestination,  Hex.toHexString(callCreate.getDestination()));
    Assert.assertEquals(expectedGasLimit,     new BigInteger( callCreate.getGasLimit()).toString());
    Assert.assertEquals(expectedValue,        new BigInteger( callCreate.getValue()).toString());
}
 
Example 11
Source Project: ethereumj   Source File: VMTest.java    License: MIT License 6 votes vote down vote up
@Test // SSTORE OP
public void testSSTORE_2() {

    VM vm = new VM();

    program =  new Program(Hex.decode("602260AA57602260BB57"), invoke);
    String s_expected_key = "00000000000000000000000000000000000000000000000000000000000000BB";
    String s_expected_val = "0000000000000000000000000000000000000000000000000000000000000022";

    vm.step(program);
    vm.step(program);
    vm.step(program);
    vm.step(program);
    vm.step(program);
    vm.step(program);

    Repository repository = program.result.getRepository();
    DataWord key = new DataWord(Hex.decode(s_expected_key));
    DataWord val = repository.getStorageValue(invoke.getOwnerAddress().getNoLeadZeroesData(),  key);

    assertEquals(s_expected_val, Hex.toHexString(val.getData()).toUpperCase());
}
 
Example 12
Source Project: ethereumj   Source File: RepositoryImpl.java    License: MIT License 6 votes vote down vote up
public AccountState createAccount(byte[] addr) {

        logger.trace("createAccount: [{}]", Hex.toHexString(addr)) ;
    	this.validateAddress(addr);
    	    	
        // 1. Save AccountState
        AccountState state =  new AccountState();
        accountStateDB.update(addr, state.getEncoded());
        
        ContractDetails details = new ContractDetails();
        contractDetailsDB.put(addr, details.getEncoded());
        
        if (logger.isDebugEnabled())
            logger.debug("New account created: [{}]", Hex.toHexString(addr));

        return state;
    }
 
Example 13
Source Project: gsc-core   Source File: MemoryTest.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void memoryChunk_2() {
  Memory memoryBuffer = new Memory();

  byte[] data1 = new byte[32];
  Arrays.fill(data1, (byte) 1);

  memoryBuffer.write(0, data1, data1.length, false);
  assertTrue(32 == memoryBuffer.size());

  byte[] data = memoryBuffer.read(0, 64);

  assertArrayEquals(
      Hex.decode("0101010101010101010101010101010101010101010101010101010101010101" +
          "0000000000000000000000000000000000000000000000000000000000000000"),
      data
  );

  Assert.assertEquals(64, memoryBuffer.size());
}
 
Example 14
Source Project: ethereumj   Source File: RepositoryTest.java    License: MIT License 6 votes vote down vote up
@Test  // get/set code
public void test8() {

    byte[] addr = Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826");
    Repository repository = new RepositoryImpl();

    try {
        byte[] code0 = repository.getCode(addr);
        repository.createAccount(addr);
        byte[] code1 = repository.getCode(addr);
        AccountState accountState = repository.getAccountState(addr);
        assertTrue(code0 == null);
        assertNull(code1);
        assertNull(accountState.getCodeHash());
    } finally {
        repository.close();
    }
}
 
Example 15
Source Project: ethereumj   Source File: VMTest.java    License: MIT License 6 votes vote down vote up
@Test // MLOAD OP
public void testMLOAD_4() {

    VM vm = new VM();
    program =  new Program(Hex.decode("611234602054602053"), invoke);
    String m_expected = "0000000000000000000000000000000000000000000000000000000000000000" +
                        "0000000000000000000000000000000000000000000000000000000000001234";
    String s_expected = "0000000000000000000000000000000000000000000000000000000000001234";

    vm.step(program);
    vm.step(program);
    vm.step(program);
    vm.step(program);
    vm.step(program);

    assertEquals(m_expected, Hex.toHexString(program.memory.array()));
    assertEquals(s_expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase());
}
 
Example 16
/**
 * constructor.
 */

public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) {
  byte[] address;
  if (ecKey == null) {
    String pubKey = loadPubKey(); //04 PubKey[128]
    if (StringUtils.isEmpty(pubKey)) {
      logger.warn("Warning: QueryAccount failed, no wallet address !!");
      return null;
    }
    byte[] pubKeyAsc = pubKey.getBytes();
    byte[] pubKeyHex = Hex.decode(pubKeyAsc);
    ecKey = ECKey.fromPublicOnly(pubKeyHex);
  }
  return grpcQueryAccount(ecKey.getAddress(), blockingStubFull);
}
 
Example 17
Source Project: gsc-core   Source File: RuntimeImpl.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
public void finalization() {
    if (StringUtils.isEmpty(runtimeError)) {
        for (DataWord contract : result.getDeleteAccounts()) {
            deposit.deleteContract(MUtil.convertToGSCAddress((contract.getLast20Bytes())));
        }
    }

    if (config.vmTrace() && program != null) {
        String traceContent = program.getTrace()
                .result(result.getHReturn())
                .error(result.getException())
                .toString();

        if (config.vmTraceCompressed()) {
            traceContent = VMUtils.zipAndEncode(traceContent);
        }

        String txHash = Hex.toHexString(rootInternalTransaction.getHash());
        VMUtils.saveProgramTraceFile(config, txHash, traceContent);
    }

}
 
Example 18
Source Project: ethereumj   Source File: VMTest.java    License: MIT License 6 votes vote down vote up
@Test // MSTORE OP
public void testMSTORE_2() {

    VM vm = new VM();
    program =  new Program(Hex.decode("611234600054615566602054"), invoke);
    String expected = "0000000000000000000000000000000000000000000000000000000000001234" +
                      "0000000000000000000000000000000000000000000000000000000000005566";

    vm.step(program);
    vm.step(program);
    vm.step(program);
    vm.step(program);
    vm.step(program);
    vm.step(program);

    assertEquals(expected, Hex.toHexString(program.memory.array()));
}
 
Example 19
Source Project: ethereumj   Source File: Wallet.java    License: MIT License 6 votes vote down vote up
/***********************************************************************
   *	1) the dialog put a pending transaction on the list
   *  2) the dialog send the transaction to a net
   *  3) wherever the transaction got in from the wire it will change to approve state
   *  4) only after the approve a) Wallet state changes
   *  5) After the block is received with that tx the pending been clean up
   */
  public WalletTransaction addTransaction(Transaction transaction) {
      String hash = Hex.toHexString(transaction.getHash());
      logger.info("pending transaction placed hash: {}", hash );

      WalletTransaction walletTransaction =  this.walletTransactions.get(hash);
if (walletTransaction != null)
	walletTransaction.incApproved();
else {
	walletTransaction = new WalletTransaction(transaction);
	this.walletTransactions.put(hash, walletTransaction);
}

      this.applyTransaction(transaction);

      return walletTransaction;
  }
 
Example 20
/**
 * constructor.
 */

public Account queryAccount(String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) {
  byte[] address;
  ECKey temKey = null;
  try {
    BigInteger priK = new BigInteger(priKey, 16);
    temKey = ECKey.fromPrivate(priK);
  } catch (Exception ex) {
    ex.printStackTrace();
  }
  ECKey ecKey = temKey;
  if (ecKey == null) {
    String pubKey = loadPubKey(); //04 PubKey[128]
    if (StringUtils.isEmpty(pubKey)) {
      logger.warn("Warning: QueryAccount failed, no wallet address !!");
      return null;
    }
    byte[] pubKeyAsc = pubKey.getBytes();
    byte[] pubKeyHex = Hex.decode(pubKeyAsc);
    ecKey = ECKey.fromPublicOnly(pubKeyHex);
  }
  return grpcQueryAccount(ecKey.getAddress(), blockingStubFull);
}
 
Example 21
private static byte[] replaceLibraryAddress(String code, String libraryAddressPair) {

    String[] libraryAddressList = libraryAddressPair.split("[,]");

    for (int i = 0; i < libraryAddressList.length; i++) {
      String cur = libraryAddressList[i];

      int lastPosition = cur.lastIndexOf(":");
      if (-1 == lastPosition) {
        throw new RuntimeException("libraryAddress delimit by ':'");
      }
      String libraryName = cur.substring(0, lastPosition);
      String addr = cur.substring(lastPosition + 1);
      String libraryAddressHex = ByteArray.toHexString(Wallet.decodeFromBase58Check(addr))
          .substring(2);

      String repeated = new String(new char[40 - libraryName.length() - 2]).replace("\0", "_");
      String beReplaced = "__" + libraryName + repeated;
      Matcher m = Pattern.compile(beReplaced).matcher(code);
      code = m.replaceAll(libraryAddressHex);
    }

    return Hex.decode(code);
  }
 
Example 22
Source Project: ethereumj   Source File: VMTest.java    License: MIT License 5 votes vote down vote up
@Test // ADD OP
public void testADD_2() {

    VM vm = new VM();
    program =  new Program(Hex.decode("611002600201"), invoke);
    String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000001004";

    vm.step(program);
    vm.step(program);
    vm.step(program);

    DataWord item1 = program.stackPop();
    assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase());
}
 
Example 23
Source Project: ethereumj   Source File: VMTest.java    License: MIT License 5 votes vote down vote up
@Test // SUB OP
public void testSUB_3() {

    VM vm = new VM();
    program =  new Program(Hex.decode("614444639999666603"), invoke);
    String s_expected_1 = "0000000000000000000000000000000000000000000000000000000099992222";

    vm.step(program);
    vm.step(program);
    vm.step(program);

    DataWord item1 = program.stackPop();
    assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase());
}
 
Example 24
@Override public BigInteger estimate(Address from, Address to, byte[] data)
    throws EstimateGasException {

  Transaction transaction =
      Transaction.createEthCallTransaction(from.toHexString(true), to.toHexString(true),
          Hex.toHexString(data));

  try {
    return web3j.ethEstimateGas(transaction)
        .send()
        .getAmountUsed();
  } catch (IOException e) {
    throw new EstimateGasException("Failed to estimate gas!", e);
  }
}
 
Example 25
@Test
public void listnode() {
    ManagedChannel channel = null;
    WalletGrpc.WalletBlockingStub blockingStub = null;

    channel = ManagedChannelBuilder.forTarget("39.105.202.12:5021").usePlaintext(true).build();
    blockingStub = WalletGrpc.newBlockingStub(channel);

    GrpcAPI.AssetIssueList block1 = blockingStub.getAssetIssueByAccount(Protocol.Account.newBuilder().build());
    Protocol.Transaction transaction = blockingStub.getTransactionById(GrpcAPI.BytesMessage.newBuilder().setValue(ByteString.copyFrom(Hex.decode(""))).build());
}
 
Example 26
Source Project: ethereumj   Source File: VMTest.java    License: MIT License 5 votes vote down vote up
@Test // EXP OP
public void testEXP_1() {

    VM vm = new VM();
    program =  new Program(Hex.decode("6003600208"), invoke);
    String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000008";

    vm.step(program);
    vm.step(program);
    vm.step(program);

    DataWord item1 = program.stackPop();
    assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase());
}
 
Example 27
Source Project: ethereumj   Source File: VMCustomTest.java    License: MIT License 5 votes vote down vote up
@Test(expected=StackTooSmallException.class) // CALLDATACOPY OP mal
public void testCALLDATACOPY_6() {

    VM vm = new VM();
    program = 
            new Program(Hex.decode("6040600037"), invoke);

    try {
        vm.step(program);
        vm.step(program);
        vm.step(program);
    } finally {
        assertTrue(program.isStopped());
    }
}
 
Example 28
Source Project: ethereumj   Source File: VMTest.java    License: MIT License 5 votes vote down vote up
@Test // MOD OP
public void testMOD_3() {
    VM vm = new VM();
    program =  new Program(Hex.decode("6004600206"), invoke);
    String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000002";

    vm.step(program);
    vm.step(program);
    vm.step(program);

    DataWord item1 = program.stackPop();
    assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase());
}
 
Example 29
Source Project: ethereumj   Source File: VMTest.java    License: MIT License 5 votes vote down vote up
@Test  // SGT OP
public void testSGT_1() {

    VM vm = new VM();
    program =  new Program(Hex.decode("600160020D"), invoke);
    String expected = "0000000000000000000000000000000000000000000000000000000000000001";

    vm.step(program);
    vm.step(program);
    vm.step(program);

    assertEquals(expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase());
}
 
Example 30
public Account queryAccount(ECKey ecKey, WalletGrpc.WalletBlockingStub blockingStubFull) {
  byte[] address;
  if (ecKey == null) {
    String pubKey = loadPubKey(); //04 PubKey[128]
    if (StringUtils.isEmpty(pubKey)) {
      logger.warn("Warning: QueryAccount failed, no wallet address !!");
      return null;
    }
    byte[] pubKeyAsc = pubKey.getBytes();
    byte[] pubKeyHex = Hex.decode(pubKeyAsc);
    ecKey = ECKey.fromPublicOnly(pubKeyHex);
  }
  return grpcQueryAccount(ecKey.getAddress(), blockingStubFull);
}