Java Code Examples for org.spongycastle.util.Arrays#areEqual()

The following examples show how to use org.spongycastle.util.Arrays#areEqual() . 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 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 2
Source File: AccountState.java    From ethereumj with MIT License 5 votes vote down vote up
public String toString() {
	String ret =  "Nonce: " 		+ this.getNonce().toString() 							+ "\n" + 
				  "Balance: " 		+ Denomination.toFriendlyString(getBalance()) 			+ "\n";
	
	if(this.getStateRoot()!= null && !Arrays.areEqual(this.getStateRoot(), EMPTY_BYTE_ARRAY))
		ret += "State Root: " 	+ Hex.toHexString(this.getStateRoot()) 	+ "\n";
	if(this.getCodeHash() != null && !Arrays.areEqual(this.getCodeHash(), EMPTY_DATA_HASH))
		ret += "Code Hash: " 	+ Hex.toHexString(this.getCodeHash());
	
	return ret;
}
 
Example 3
Source File: ExtendedKey.java    From BlockchainWallet-Crypto with GNU General Public License v3.0 4 votes vote down vote up
public static ExtendedKey parse(String serialized) throws ValidationException {
    byte[] data = Base58Check.base58ToBytes(serialized);
    if (data.length != 78) {
        throw new ValidationException("invalid extended key");
    }
    byte[] type = Arrays.copyOf(data, 4);
    boolean hasPrivate;
    if (Arrays.areEqual(type, xprv) || Arrays.areEqual(type, tprv)) {
        hasPrivate = true;
    } else if (Arrays.areEqual(type, xpub) || Arrays.areEqual(type, tpub)) {
        hasPrivate = false;
    } else {
        throw new ValidationException("invalid magic number for an extended key");
    }

    int depth = data[4] & 0xff;

    int parent = data[5] & 0xff;
    parent <<= 8;
    parent |= data[6] & 0xff;
    parent <<= 8;
    parent |= data[7] & 0xff;
    parent <<= 8;
    parent |= data[8] & 0xff;

    int sequence = data[9] & 0xff;
    sequence <<= 8;
    sequence |= data[10] & 0xff;
    sequence <<= 8;
    sequence |= data[11] & 0xff;
    sequence <<= 8;
    sequence |= data[12] & 0xff;

    byte[] chainCode = Arrays.copyOfRange(data, 13, 13 + 32);
    byte[] pubOrPriv = Arrays.copyOfRange(data, 13 + 32, data.length);
    Key key;
    if (hasPrivate) {
        key = new ECKeyPair(new BigInteger(1, pubOrPriv), true);
    } else {
        key = new ECPublicKey(pubOrPriv, true);
    }
    return new ExtendedKey(key, chainCode, depth, parent, sequence);
}
 
Example 4
Source File: Block.java    From nuls with MIT License 4 votes vote down vote up
public boolean isEqual(Block block) {
    return Arrays.areEqual(this.getHash(), block.getHash());
}