Java Code Examples for org.web3j.utils.Numeric#toHexStringNoPrefix()
The following examples show how to use
org.web3j.utils.Numeric#toHexStringNoPrefix() .
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: WasmFunctionEncoder.java From client-sdk-java with Apache License 2.0 | 6 votes |
public static String encodeConstructor(String code, List<?> inputParameters) { List<Object> parameters = new ArrayList<>(); // parameters.add(DEPLOY_METHOD_NAME); parameters.add(fnvOne64Hash(DEPLOY_METHOD_NAME)); for (Object o : inputParameters) { if (!o.equals(Void.class)) { parameters.add(o); } } byte[] parameterData = RLPCodec.encode(parameters); byte[] codeBinary = Numeric.hexStringToByteArray(code); Object[] objs = new Object[] { codeBinary, parameterData }; byte[] data = RLPCodec.encode(objs); byte[] result = new byte[MAGIC_NUM.length + data.length]; System.arraycopy(MAGIC_NUM, 0, result, 0, MAGIC_NUM.length); System.arraycopy(data, 0, result, MAGIC_NUM.length, data.length); return Numeric.toHexStringNoPrefix(result); }
Example 2
Source File: PlatOnTypeEncoder.java From client-sdk-java with Apache License 2.0 | 6 votes |
private static String encodeInt(IntType intType) { byte[] rawValue = toByteArray(intType); byte paddingValue = getPaddingValue(intType); byte[] paddedRawValue = new byte[intType.getBitSize()/8]; if (paddingValue != 0) { for (int i = 0; i < paddedRawValue.length; i++) { paddedRawValue[i] = paddingValue; } } System.arraycopy( rawValue, 0, paddedRawValue, paddedRawValue.length - rawValue.length, rawValue.length); return Numeric.toHexStringNoPrefix(paddedRawValue); }
Example 3
Source File: TypeEncoder.java From client-sdk-java with Apache License 2.0 | 6 votes |
static String encodeNumeric(NumericType numericType) { byte[] rawValue = toByteArray(numericType); byte paddingValue = getPaddingValue(numericType); byte[] paddedRawValue = new byte[MAX_BYTE_LENGTH]; if (paddingValue != 0) { for (int i = 0; i < paddedRawValue.length; i++) { paddedRawValue[i] = paddingValue; } } System.arraycopy( rawValue, 0, paddedRawValue, MAX_BYTE_LENGTH - rawValue.length, rawValue.length); return Numeric.toHexStringNoPrefix(paddedRawValue); }
Example 4
Source File: TypeEncoder.java From etherscan-explorer with GNU General Public License v3.0 | 6 votes |
static String encodeNumeric(NumericType numericType) { byte[] rawValue = toByteArray(numericType); byte paddingValue = getPaddingValue(numericType); byte[] paddedRawValue = new byte[MAX_BYTE_LENGTH]; if (paddingValue != 0) { for (int i = 0; i < paddedRawValue.length; i++) { paddedRawValue[i] = paddingValue; } } System.arraycopy( rawValue, 0, paddedRawValue, MAX_BYTE_LENGTH - rawValue.length, rawValue.length); return Numeric.toHexStringNoPrefix(paddedRawValue); }
Example 5
Source File: KeysTest.java From web3j with Apache License 2.0 | 5 votes |
@Test public void testGetAddressZeroPadded() { byte[] address = Keys.getAddress( Numeric.toBytesPadded(BigInteger.valueOf(0x1234), Keys.PUBLIC_KEY_SIZE)); String expected = Numeric.toHexStringNoPrefix(address); String value = "1234"; assertEquals( Keys.getAddress( "0x" + Strings.zeros(Keys.PUBLIC_KEY_LENGTH_IN_HEX - value.length()) + value), (expected)); }
Example 6
Source File: WasmFunctionEncoder.java From client-sdk-java with Apache License 2.0 | 5 votes |
public static String encode(WasmFunction function) { List<Object> parameters = new ArrayList<>(); // parameters.add(function.getName()); parameters.add(fnvOne64Hash(function.getName())); for (Object o : function.getInputParameters()) { if (!o.equals(Void.class)) { parameters.add(o); } } byte[] data = RLPCodec.encode(parameters); return Numeric.toHexStringNoPrefix(data); }
Example 7
Source File: KeysTest.java From web3j with Apache License 2.0 | 5 votes |
@Test public void testGetAddressSmallPublicKey() { byte[] address = Keys.getAddress( Numeric.toBytesPadded(BigInteger.valueOf(0x1234), Keys.PUBLIC_KEY_SIZE)); String expected = Numeric.toHexStringNoPrefix(address); assertEquals(Keys.getAddress("0x1234"), (expected)); }
Example 8
Source File: TypeEncoder.java From web3j with Apache License 2.0 | 5 votes |
static String encodeBytes(BytesType bytesType) { byte[] value = bytesType.getValue(); int length = value.length; int mod = length % MAX_BYTE_LENGTH; byte[] dest; if (mod != 0) { int padding = MAX_BYTE_LENGTH - mod; dest = new byte[length + padding]; System.arraycopy(value, 0, dest, 0, length); } else { dest = value; } return Numeric.toHexStringNoPrefix(dest); }
Example 9
Source File: TypeEncoder.java From web3j with Apache License 2.0 | 5 votes |
static String encodeBool(Bool value) { byte[] rawValue = new byte[MAX_BYTE_LENGTH]; if (value.getValue()) { rawValue[rawValue.length - 1] = 1; } return Numeric.toHexStringNoPrefix(rawValue); }
Example 10
Source File: TypeEncoder.java From web3j with Apache License 2.0 | 5 votes |
static String encodeNumeric(NumericType numericType) { byte[] rawValue = toByteArray(numericType); byte paddingValue = getPaddingValue(numericType); byte[] paddedRawValue = new byte[MAX_BYTE_LENGTH]; if (paddingValue != 0) { for (int i = 0; i < paddedRawValue.length; i++) { paddedRawValue[i] = paddingValue; } } System.arraycopy( rawValue, 0, paddedRawValue, MAX_BYTE_LENGTH - rawValue.length, rawValue.length); return Numeric.toHexStringNoPrefix(paddedRawValue); }
Example 11
Source File: KeysTest.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
@Test public void testGetAddressZeroPadded() { byte[] address = Keys.getAddress( Numeric.toBytesPadded(BigInteger.valueOf(0x1234), Keys.PUBLIC_KEY_SIZE)); String expected = Numeric.toHexStringNoPrefix(address); String value = "1234"; assertThat(Keys.getAddress("0x" + Strings.zeros(Keys.PUBLIC_KEY_LENGTH_IN_HEX - value.length()) + value), equalTo(expected)); }
Example 12
Source File: KeysTest.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
@Test public void testGetAddressSmallPublicKey() { byte[] address = Keys.getAddress( Numeric.toBytesPadded(BigInteger.valueOf(0x1234), Keys.PUBLIC_KEY_SIZE)); String expected = Numeric.toHexStringNoPrefix(address); assertThat(Keys.getAddress("0x1234"), equalTo(expected)); }
Example 13
Source File: TypeEncoder.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
static String encodeBytes(BytesType bytesType) { byte[] value = bytesType.getValue(); int length = value.length; int mod = length % MAX_BYTE_LENGTH; byte[] dest; if (mod != 0) { int padding = MAX_BYTE_LENGTH - mod; dest = new byte[length + padding]; System.arraycopy(value, 0, dest, 0, length); } else { dest = value; } return Numeric.toHexStringNoPrefix(dest); }
Example 14
Source File: TypeEncoder.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
static String encodeBool(Bool value) { byte[] rawValue = new byte[MAX_BYTE_LENGTH]; if (value.getValue()) { rawValue[rawValue.length - 1] = 1; } return Numeric.toHexStringNoPrefix(rawValue); }
Example 15
Source File: KeysTest.java From client-sdk-java with Apache License 2.0 | 5 votes |
@Test public void testGetAddressZeroPadded() { byte[] address = Keys.getAddress( Numeric.toBytesPadded(BigInteger.valueOf(0x1234), Keys.PUBLIC_KEY_SIZE)); String expected = Numeric.toHexStringNoPrefix(address); String value = "1234"; assertThat(Keys.getAddress("0x" + Strings.zeros(Keys.PUBLIC_KEY_LENGTH_IN_HEX - value.length()) + value), equalTo(expected)); }
Example 16
Source File: KeysTest.java From client-sdk-java with Apache License 2.0 | 5 votes |
@Test public void testGetAddressSmallPublicKey() { byte[] address = Keys.getAddress( Numeric.toBytesPadded(BigInteger.valueOf(0x1234), Keys.PUBLIC_KEY_SIZE)); String expected = Numeric.toHexStringNoPrefix(address); assertThat(Keys.getAddress("0x1234"), equalTo(expected)); }
Example 17
Source File: TypeEncoder.java From client-sdk-java with Apache License 2.0 | 5 votes |
static String encodeBytes(BytesType bytesType) { byte[] value = bytesType.getValue(); int length = value.length; int mod = length % MAX_BYTE_LENGTH; byte[] dest; if (mod != 0) { int padding = MAX_BYTE_LENGTH - mod; dest = new byte[length + padding]; System.arraycopy(value, 0, dest, 0, length); } else { dest = value; } return Numeric.toHexStringNoPrefix(dest); }
Example 18
Source File: TypeEncoder.java From client-sdk-java with Apache License 2.0 | 5 votes |
static String encodeBool(Bool value) { byte[] rawValue = new byte[MAX_BYTE_LENGTH]; if (value.getValue()) { rawValue[rawValue.length - 1] = 1; } return Numeric.toHexStringNoPrefix(rawValue); }