org.web3j.abi.datatypes.generated.Int64 Java Examples

The following examples show how to use org.web3j.abi.datatypes.generated.Int64. 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: TypeEncoderTest.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testIntEncode() {
    Int zero = new Int64(BigInteger.ZERO);
    assertThat(TypeEncoder.encodeNumeric(zero),
            is("0000000000000000000000000000000000000000000000000000000000000000"));

    Int maxLong = new Int64(BigInteger.valueOf(Long.MAX_VALUE));
    assertThat(TypeEncoder.encodeNumeric(maxLong),
            is("0000000000000000000000000000000000000000000000007fffffffffffffff"));

    Int minLong = new Int64(BigInteger.valueOf(Long.MIN_VALUE));
    assertThat(TypeEncoder.encodeNumeric(minLong),
            is("ffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000"));

    Int minusOne = new Int(BigInteger.valueOf(-1));
    assertThat(TypeEncoder.encodeNumeric(minusOne),
            is("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
}
 
Example #2
Source File: PlatOnTypeEncoderTest.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testIntEncode() {
    Int zero = new Int64(BigInteger.ZERO);
    assertThat(PlatOnTypeEncoder.encode(zero),
            is("0000000000000000"));

    Int maxLong = new Int64(BigInteger.valueOf(Long.MAX_VALUE));
    assertThat(PlatOnTypeEncoder.encode(maxLong),
            is("7fffffffffffffff"));
    
    Int minLong = new Int64(BigInteger.valueOf(Long.MIN_VALUE));
    assertThat(PlatOnTypeEncoder.encode(minLong),
            is("8000000000000000"));

    Int minusOne = new Int64(BigInteger.valueOf(-1));
    assertThat(PlatOnTypeEncoder.encode(minusOne),
            is("ffffffffffffffff"));
}
 
Example #3
Source File: PlatOnTypeDecoderTest.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testIntDecode() {
    assertThat(PlatOnTypeDecoder.decode(
    		Numeric.hexStringToByteArray("0000000000000000"),
            Int64.class
            ),
            is(new Int64(BigInteger.ZERO)));

    assertThat(PlatOnTypeDecoder.decode(
    		Numeric.hexStringToByteArray("7fffffffffffffff"),
            Int64.class
            ),
            is(new Int64(BigInteger.valueOf(Long.MAX_VALUE))));

    assertThat(PlatOnTypeDecoder.decode(
    		Numeric.hexStringToByteArray("8000000000000000"),
            Int64.class
            ),
            is(new Int64(BigInteger.valueOf(Long.MIN_VALUE))));

    assertThat(PlatOnTypeDecoder.decode(
    		Numeric.hexStringToByteArray("ffffffffffffffff"),
            Int64.class
            ),
            is(new Int64(BigInteger.valueOf(-1))));
}
 
Example #4
Source File: UtilsTest.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetTypeName() throws ClassNotFoundException {
    assertThat(Utils.getTypeName(new TypeReference<Uint>(){}), is("uint256"));
    assertThat(Utils.getTypeName(new TypeReference<Int>(){}), is("int256"));
    assertThat(Utils.getTypeName(new TypeReference<Ufixed>(){}), is("ufixed256"));
    assertThat(Utils.getTypeName(new TypeReference<Fixed>(){}), is("fixed256"));

    assertThat(Utils.getTypeName(new TypeReference<Uint64>(){}), is("uint64"));
    assertThat(Utils.getTypeName(new TypeReference<Int64>(){}), is("int64"));
    assertThat(Utils.getTypeName(new TypeReference<Bool>(){}), is("bool"));
    assertThat(Utils.getTypeName(new TypeReference<Utf8String>(){}), is("string"));
    assertThat(Utils.getTypeName(new TypeReference<DynamicBytes>(){}), is("bytes"));

    assertThat(Utils.getTypeName(
            new TypeReference.StaticArrayTypeReference<StaticArray<Uint>>(5){}),
            is("uint256[5]"));
    assertThat(Utils.getTypeName(
            new TypeReference<DynamicArray<Uint>>(){}),
            is("uint256[]"));
}
 
Example #5
Source File: TypeEncoderTest.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testIntEncode() {
    Int zero = new Int64(BigInteger.ZERO);
    assertThat(TypeEncoder.encodeNumeric(zero),
            is("0000000000000000000000000000000000000000000000000000000000000000"));

    Int maxLong = new Int64(BigInteger.valueOf(Long.MAX_VALUE));
    assertThat(TypeEncoder.encodeNumeric(maxLong),
            is("0000000000000000000000000000000000000000000000007fffffffffffffff"));

    Int minLong = new Int64(BigInteger.valueOf(Long.MIN_VALUE));
    assertThat(TypeEncoder.encodeNumeric(minLong),
            is("ffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000"));

    Int minusOne = new Int(BigInteger.valueOf(-1));
    assertThat(TypeEncoder.encodeNumeric(minusOne),
            is("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
}
 
Example #6
Source File: UtilsTest.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testGetTypeName() throws ClassNotFoundException {
    assertThat(Utils.getTypeName(new TypeReference<Uint>(){}), is("uint256"));
    assertThat(Utils.getTypeName(new TypeReference<Int>(){}), is("int256"));
    assertThat(Utils.getTypeName(new TypeReference<Ufixed>(){}), is("ufixed256"));
    assertThat(Utils.getTypeName(new TypeReference<Fixed>(){}), is("fixed256"));

    assertThat(Utils.getTypeName(new TypeReference<Uint64>(){}), is("uint64"));
    assertThat(Utils.getTypeName(new TypeReference<Int64>(){}), is("int64"));
    assertThat(Utils.getTypeName(new TypeReference<Bool>(){}), is("bool"));
    assertThat(Utils.getTypeName(new TypeReference<Utf8String>(){}), is("string"));
    assertThat(Utils.getTypeName(new TypeReference<DynamicBytes>(){}), is("bytes"));

    assertThat(Utils.getTypeName(
            new TypeReference.StaticArrayTypeReference<StaticArray<Uint>>(5){}),
            is("uint256[5]"));
    assertThat(Utils.getTypeName(
            new TypeReference<DynamicArray<Uint>>(){}),
            is("uint256[]"));
}
 
Example #7
Source File: UtilsTest.java    From web3j with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetTypeName() {
    assertEquals(Utils.getTypeName(new TypeReference<Uint>() {}), ("uint256"));
    assertEquals(Utils.getTypeName(new TypeReference<Int>() {}), ("int256"));
    assertEquals(Utils.getTypeName(new TypeReference<Ufixed>() {}), ("ufixed256"));
    assertEquals(Utils.getTypeName(new TypeReference<Fixed>() {}), ("fixed256"));

    assertEquals(Utils.getTypeName(new TypeReference<Uint64>() {}), ("uint64"));
    assertEquals(Utils.getTypeName(new TypeReference<Int64>() {}), ("int64"));
    assertEquals(Utils.getTypeName(new TypeReference<Bool>() {}), ("bool"));
    assertEquals(Utils.getTypeName(new TypeReference<Utf8String>() {}), ("string"));
    assertEquals(Utils.getTypeName(new TypeReference<DynamicBytes>() {}), ("bytes"));

    assertEquals(
            Utils.getTypeName(
                    new TypeReference.StaticArrayTypeReference<StaticArray<Uint>>(5) {}),
            ("uint256[5]"));
    assertEquals(Utils.getTypeName(new TypeReference<DynamicArray<Uint>>() {}), ("uint256[]"));
}
 
Example #8
Source File: TypeDecoderTest.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testIntDecode() {
    assertThat(TypeDecoder.decodeNumeric(
            "0000000000000000000000000000000000000000000000000000000000000000",
            Int64.class
            ),
            is(new Int64(BigInteger.ZERO)));

    assertThat(TypeDecoder.decodeNumeric(
            "0000000000000000000000000000000000000000000000007fffffffffffffff",
            Int64.class
            ),
            is(new Int64(BigInteger.valueOf(Long.MAX_VALUE))));

    assertThat(TypeDecoder.decodeNumeric(
            "fffffffffffffffffffffffffffffffffffffffffffffff88000000000000000",
            Int64.class
            ),
            is(new Int64(BigInteger.valueOf(Long.MIN_VALUE))));

    assertThat(TypeDecoder.decodeNumeric(
            "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
            Int64.class
            ),
            is(new Int64(BigInteger.valueOf(-1))));

    assertThat(TypeDecoder.decodeNumeric(
            "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
            Int256.class
            ),
            is(new Int256(BigInteger.valueOf(-1))));
}
 
Example #9
Source File: TransferTest.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
public String sendTransaction(String privateKey, String toAddress, BigDecimal amount, long gasPrice, long gasLimit) {

        BigInteger GAS_PRICE = BigInteger.valueOf(gasPrice);
        BigInteger GAS_LIMIT = BigInteger.valueOf(gasLimit);

        Credentials credentials = Credentials.create(privateKey);

        try {

            List<RlpType> result = new ArrayList<>();
            result.add(RlpString.create(Numeric.hexStringToByteArray(PlatOnTypeEncoder.encode(new Int64(0)))));
            String txType = Hex.toHexString(RlpEncoder.encode(new RlpList(result)));

            RawTransaction rawTransaction = RawTransaction.createTransaction(getNonce(), GAS_PRICE, GAS_LIMIT, toAddress, amount.toBigInteger(),
                    txType);

            byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, new Byte("100"), credentials);
            String hexValue = Numeric.toHexString(signedMessage);

            PlatonSendTransaction transaction = web3j.platonSendRawTransaction(hexValue).send();

            return transaction.getTransactionHash();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
 
Example #10
Source File: TypeDecoderTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testIntDecode() {
    assertThat(TypeDecoder.decodeNumeric(
            "0000000000000000000000000000000000000000000000000000000000000000",
            Int64.class
            ),
            is(new Int64(BigInteger.ZERO)));

    assertThat(TypeDecoder.decodeNumeric(
            "0000000000000000000000000000000000000000000000007fffffffffffffff",
            Int64.class
            ),
            is(new Int64(BigInteger.valueOf(Long.MAX_VALUE))));

    assertThat(TypeDecoder.decodeNumeric(
            "fffffffffffffffffffffffffffffffffffffffffffffff88000000000000000",
            Int64.class
            ),
            is(new Int64(BigInteger.valueOf(Long.MIN_VALUE))));

    assertThat(TypeDecoder.decodeNumeric(
            "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
            Int64.class
            ),
            is(new Int64(BigInteger.valueOf(-1))));

    assertThat(TypeDecoder.decodeNumeric(
            "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
            Int256.class
            ),
            is(new Int256(BigInteger.valueOf(-1))));
}
 
Example #11
Source File: EventEmitter.java    From eventeum with Apache License 2.0 5 votes vote down vote up
public RemoteFunctionCall<TransactionReceipt> emitEventAdditionalTypes(BigInteger uint16Value, BigInteger int64Value, byte[] byteValue) {
    final Function function = new Function(
            FUNC_EMITEVENTADDITIONALTYPES, 
            Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint16(uint16Value), 
            new org.web3j.abi.datatypes.generated.Int64(int64Value), 
            new org.web3j.abi.datatypes.generated.Bytes1(byteValue)), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example #12
Source File: Long.java    From web3j with Apache License 2.0 4 votes vote down vote up
@Override
public NumericType toSolidityType() {
    return new Int64(getValue());
}