Java Code Examples for org.web3j.abi.datatypes.Bool

The following examples show how to use org.web3j.abi.datatypes.Bool. 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
Source Project: client-sdk-java   Author: PlatONnetwork   File: TypeDecoder.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
static <T extends Type> T decode(String input, int offset, Class<T> type) {
    if (NumericType.class.isAssignableFrom(type)) {
        return (T) decodeNumeric(input.substring(offset), (Class<NumericType>) type);
    } else if (Address.class.isAssignableFrom(type)) {
        return (T) decodeAddress(input.substring(offset));
    } else if (Bool.class.isAssignableFrom(type)) {
        return (T) decodeBool(input, offset);
    } else if (Bytes.class.isAssignableFrom(type)) {
        return (T) decodeBytes(input, offset, (Class<Bytes>) type);
    } else if (DynamicBytes.class.isAssignableFrom(type)) {
        return (T) decodeDynamicBytes(input, offset);
    } else if (Utf8String.class.isAssignableFrom(type)) {
        return (T) decodeUtf8String(input, offset);
    } else if (Array.class.isAssignableFrom(type)) {
        throw new UnsupportedOperationException(
                "Array types must be wrapped in a TypeReference");
    } else {
        throw new UnsupportedOperationException(
                "Type cannot be encoded: " + type.getClass());
    }
}
 
Example #2
Source Project: client-sdk-java   Author: PlatONnetwork   File: TypeEncoder.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static String encode(Type parameter) {
    if (parameter instanceof NumericType) {
        return encodeNumeric(((NumericType) parameter));
    } else if (parameter instanceof Address) {
        return encodeAddress((Address) parameter);
    } else if (parameter instanceof Bool) {
        return encodeBool((Bool) parameter);
    } else if (parameter instanceof Bytes) {
        return encodeBytes((Bytes) parameter);
    } else if (parameter instanceof DynamicBytes) {
        return encodeDynamicBytes((DynamicBytes) parameter);
    } else if (parameter instanceof Utf8String) {
        return encodeString((Utf8String) parameter);
    } else if (parameter instanceof StaticArray) {
        return encodeArrayValues((StaticArray) parameter);
    } else if (parameter instanceof DynamicArray) {
        return encodeDynamicArray((DynamicArray) parameter);
    } else {
        throw new UnsupportedOperationException(
                "Type cannot be encoded: " + parameter.getClass());
    }
}
 
Example #3
Source Project: client-sdk-java   Author: PlatONnetwork   File: TypeDecoderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBoolDecodeGivenOffset() {
    // Decode second parameter as Bool
    assertThat(TypeDecoder.decode(
            "0000000000000000000000000000000000000000000000007fffffffffffffff"
                    + "0000000000000000000000000000000000000000000000000000000000000000"
                    + "0000000000000000000000000000000000000000000000007fffffffffffffff",
            64, Bool.class),
            is(new Bool(false)));

    assertThat(TypeDecoder.decode(
            "0000000000000000000000000000000000000000000000007fffffffffffffff"
                    + "0000000000000000000000000000000000000000000000000000000000000001"
                    + "0000000000000000000000000000000000000000000000007fffffffffffffff",
            64, Bool.class),
            is(new Bool(true)));
}
 
Example #4
Source Project: client-sdk-java   Author: PlatONnetwork   File: UtilsTest.java    License: 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 Project: client-sdk-java   Author: PlatONnetwork   File: FunctionEncoderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFunctionMDynamicArrayEncode1() {
    Function function = new Function(
            "sam",
            Arrays.asList(
                new DynamicBytes("dave".getBytes()),
                new Bool(true),
                new DynamicArray<>(
                        new Uint(BigInteger.ONE),
                        new Uint(BigInteger.valueOf(2)),
                        new Uint(BigInteger.valueOf(3)))),
            Collections.<TypeReference<?>>emptyList()
    );

    assertThat(FunctionEncoder.encode(function),
            is("0xa5643bf2"
                    + "0000000000000000000000000000000000000000000000000000000000000060"
                    + "0000000000000000000000000000000000000000000000000000000000000001"
                    + "00000000000000000000000000000000000000000000000000000000000000a0"
                    + "0000000000000000000000000000000000000000000000000000000000000004"
                    + "6461766500000000000000000000000000000000000000000000000000000000"
                    + "0000000000000000000000000000000000000000000000000000000000000003"
                    + "0000000000000000000000000000000000000000000000000000000000000001"
                    + "0000000000000000000000000000000000000000000000000000000000000002"
                    + "0000000000000000000000000000000000000000000000000000000000000003"));
}
 
Example #6
Source Project: client-sdk-java   Author: PlatONnetwork   File: AbiTypesMapperGenerator.java    License: Apache License 2.0 6 votes vote down vote up
private MethodSpec.Builder addTypes(MethodSpec.Builder builder, String packageName) {
    builder = addStatement(builder, packageName,
            Address.TYPE_NAME, Address.class.getSimpleName());

    builder = addStatement(builder, packageName,
            Bool.TYPE_NAME, Bool.class.getSimpleName());

    builder = addStatement(builder, packageName,
            Utf8String.TYPE_NAME, Utf8String.class.getSimpleName());

    builder = addStatement(builder, packageName,
            DynamicBytes.TYPE_NAME, DynamicBytes.class.getSimpleName());

    // TODO: Fixed array & dynamic array support
    return builder;
}
 
Example #7
Source Project: client-sdk-java   Author: PlatONnetwork   File: SolidityFunctionWrapperTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetNativeType() {
    assertThat(getNativeType(TypeName.get(Address.class)),
            equalTo(TypeName.get(String.class)));
    assertThat(getNativeType(TypeName.get(Uint256.class)),
            equalTo(TypeName.get(BigInteger.class)));
    assertThat(getNativeType(TypeName.get(Int256.class)),
            equalTo(TypeName.get(BigInteger.class)));
    assertThat(getNativeType(TypeName.get(Utf8String.class)),
            equalTo(TypeName.get(String.class)));
    assertThat(getNativeType(TypeName.get(Bool.class)),
            equalTo(TypeName.get(Boolean.class)));
    assertThat(getNativeType(TypeName.get(Bytes32.class)),
            equalTo(TypeName.get(byte[].class)));
    assertThat(getNativeType(TypeName.get(DynamicBytes.class)),
            equalTo(TypeName.get(byte[].class)));
}
 
Example #8
Source Project: etherscan-explorer   Author: bing-chou   File: TypeDecoder.java    License: GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
static <T extends Type> T decode(String input, int offset, Class<T> type) {
    if (NumericType.class.isAssignableFrom(type)) {
        return (T) decodeNumeric(input.substring(offset), (Class<NumericType>) type);
    } else if (Address.class.isAssignableFrom(type)) {
        return (T) decodeAddress(input.substring(offset));
    } else if (Bool.class.isAssignableFrom(type)) {
        return (T) decodeBool(input, offset);
    } else if (Bytes.class.isAssignableFrom(type)) {
        return (T) decodeBytes(input, offset, (Class<Bytes>) type);
    } else if (DynamicBytes.class.isAssignableFrom(type)) {
        return (T) decodeDynamicBytes(input, offset);
    } else if (Utf8String.class.isAssignableFrom(type)) {
        return (T) decodeUtf8String(input, offset);
    } else if (Array.class.isAssignableFrom(type)) {
        throw new UnsupportedOperationException(
                "Array types must be wrapped in a TypeReference");
    } else {
        throw new UnsupportedOperationException(
                "Type cannot be encoded: " + type.getClass());
    }
}
 
Example #9
Source Project: etherscan-explorer   Author: bing-chou   File: TypeEncoder.java    License: GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static String encode(Type parameter) {
    if (parameter instanceof NumericType) {
        return encodeNumeric(((NumericType) parameter));
    } else if (parameter instanceof Address) {
        return encodeAddress((Address) parameter);
    } else if (parameter instanceof Bool) {
        return encodeBool((Bool) parameter);
    } else if (parameter instanceof Bytes) {
        return encodeBytes((Bytes) parameter);
    } else if (parameter instanceof DynamicBytes) {
        return encodeDynamicBytes((DynamicBytes) parameter);
    } else if (parameter instanceof Utf8String) {
        return encodeString((Utf8String) parameter);
    } else if (parameter instanceof StaticArray) {
        return encodeArrayValues((StaticArray) parameter);
    } else if (parameter instanceof DynamicArray) {
        return encodeDynamicArray((DynamicArray) parameter);
    } else {
        throw new UnsupportedOperationException(
                "Type cannot be encoded: " + parameter.getClass());
    }
}
 
Example #10
Source Project: etherscan-explorer   Author: bing-chou   File: TypeDecoderTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testBoolDecodeGivenOffset() {
    // Decode second parameter as Bool
    assertThat(TypeDecoder.decode(
            "0000000000000000000000000000000000000000000000007fffffffffffffff"
                    + "0000000000000000000000000000000000000000000000000000000000000000"
                    + "0000000000000000000000000000000000000000000000007fffffffffffffff",
            64, Bool.class),
            is(new Bool(false)));

    assertThat(TypeDecoder.decode(
            "0000000000000000000000000000000000000000000000007fffffffffffffff"
                    + "0000000000000000000000000000000000000000000000000000000000000001"
                    + "0000000000000000000000000000000000000000000000007fffffffffffffff",
            64, Bool.class),
            is(new Bool(true)));
}
 
Example #11
Source Project: etherscan-explorer   Author: bing-chou   File: UtilsTest.java    License: 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 #12
Source Project: etherscan-explorer   Author: bing-chou   File: FunctionEncoderTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testFunctionMDynamicArrayEncode1() {
    Function function = new Function(
            "sam",
            Arrays.asList(
                new DynamicBytes("dave".getBytes()),
                new Bool(true),
                new DynamicArray<>(
                        new Uint(BigInteger.ONE),
                        new Uint(BigInteger.valueOf(2)),
                        new Uint(BigInteger.valueOf(3)))),
            Collections.<TypeReference<?>>emptyList()
    );

    assertThat(FunctionEncoder.encode(function),
            is("0xa5643bf2"
                    + "0000000000000000000000000000000000000000000000000000000000000060"
                    + "0000000000000000000000000000000000000000000000000000000000000001"
                    + "00000000000000000000000000000000000000000000000000000000000000a0"
                    + "0000000000000000000000000000000000000000000000000000000000000004"
                    + "6461766500000000000000000000000000000000000000000000000000000000"
                    + "0000000000000000000000000000000000000000000000000000000000000003"
                    + "0000000000000000000000000000000000000000000000000000000000000001"
                    + "0000000000000000000000000000000000000000000000000000000000000002"
                    + "0000000000000000000000000000000000000000000000000000000000000003"));
}
 
Example #13
Source Project: etherscan-explorer   Author: bing-chou   File: AbiTypesMapperGenerator.java    License: GNU General Public License v3.0 6 votes vote down vote up
private MethodSpec.Builder addTypes(MethodSpec.Builder builder, String packageName) {
    builder = addStatement(builder, packageName,
            Address.TYPE_NAME, Address.class.getSimpleName());

    builder = addStatement(builder, packageName,
            Bool.TYPE_NAME, Bool.class.getSimpleName());

    builder = addStatement(builder, packageName,
            Utf8String.TYPE_NAME, Utf8String.class.getSimpleName());

    builder = addStatement(builder, packageName,
            DynamicBytes.TYPE_NAME, DynamicBytes.class.getSimpleName());

    // TODO: Fixed array & dynamic array support
    return builder;
}
 
Example #14
Source Project: etherscan-explorer   Author: bing-chou   File: SolidityFunctionWrapperTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testGetNativeType() {
    assertThat(getNativeType(TypeName.get(Address.class)),
            equalTo(TypeName.get(String.class)));
    assertThat(getNativeType(TypeName.get(Uint256.class)),
            equalTo(TypeName.get(BigInteger.class)));
    assertThat(getNativeType(TypeName.get(Int256.class)),
            equalTo(TypeName.get(BigInteger.class)));
    assertThat(getNativeType(TypeName.get(Utf8String.class)),
            equalTo(TypeName.get(String.class)));
    assertThat(getNativeType(TypeName.get(Bool.class)),
            equalTo(TypeName.get(Boolean.class)));
    assertThat(getNativeType(TypeName.get(Bytes32.class)),
            equalTo(TypeName.get(byte[].class)));
    assertThat(getNativeType(TypeName.get(DynamicBytes.class)),
            equalTo(TypeName.get(byte[].class)));
}
 
Example #15
Source Project: web3j   Author: web3j   File: TypeDecoder.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
static <T extends Type> T decode(String input, int offset, Class<T> type) {
    if (NumericType.class.isAssignableFrom(type)) {
        return (T) decodeNumeric(input.substring(offset), (Class<NumericType>) type);
    } else if (Address.class.isAssignableFrom(type)) {
        return (T) decodeAddress(input.substring(offset));
    } else if (Bool.class.isAssignableFrom(type)) {
        return (T) decodeBool(input, offset);
    } else if (Bytes.class.isAssignableFrom(type)) {
        return (T) decodeBytes(input, offset, (Class<Bytes>) type);
    } else if (DynamicBytes.class.isAssignableFrom(type)) {
        return (T) decodeDynamicBytes(input, offset);
    } else if (Utf8String.class.isAssignableFrom(type)) {
        return (T) decodeUtf8String(input, offset);
    } else if (Array.class.isAssignableFrom(type)) {
        throw new UnsupportedOperationException(
                "Array types must be wrapped in a TypeReference");
    } else {
        throw new UnsupportedOperationException("Type cannot be encoded: " + type.getClass());
    }
}
 
Example #16
Source Project: web3j   Author: web3j   File: TypeDecoderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBoolDecode() throws Exception {
    assertEquals(
            TypeDecoder.decodeBool(
                    "0000000000000000000000000000000000000000000000000000000000000000", 0),
            (new Bool(false)));

    assertEquals(
            TypeDecoder.decodeBool(
                    "0000000000000000000000000000000000000000000000000000000000000001", 0),
            (new Bool(true)));

    assertEquals(TypeDecoder.instantiateType("bool", true), (new Bool(true)));

    assertEquals(TypeDecoder.instantiateType("bool", 1), (new Bool(true)));

    assertEquals(TypeDecoder.instantiateType("bool", false), (new Bool(false)));

    assertEquals(TypeDecoder.instantiateType("bool", 0), (new Bool(false)));
}
 
Example #17
Source Project: web3j   Author: web3j   File: TypeDecoderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBoolDecodeGivenOffset() {
    // Decode second parameter as Bool
    assertEquals(
            TypeDecoder.decode(
                    "0000000000000000000000000000000000000000000000007fffffffffffffff"
                            + "0000000000000000000000000000000000000000000000000000000000000000"
                            + "0000000000000000000000000000000000000000000000007fffffffffffffff",
                    64,
                    Bool.class),
            (new Bool(false)));

    assertEquals(
            TypeDecoder.decode(
                    "0000000000000000000000000000000000000000000000007fffffffffffffff"
                            + "0000000000000000000000000000000000000000000000000000000000000001"
                            + "0000000000000000000000000000000000000000000000007fffffffffffffff",
                    64,
                    Bool.class),
            (new Bool(true)));
}
 
Example #18
Source Project: web3j   Author: web3j   File: UtilsTest.java    License: 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 #19
Source Project: web3j   Author: web3j   File: Ballot.java    License: Apache License 2.0 6 votes vote down vote up
public RemoteCall<Tuple4<BigInteger, Boolean, String, BigInteger>> voters(String param0) {
    final Function function = new Function(FUNC_VOTERS,
            Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(param0)),
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}, new TypeReference<Bool>() {}, new TypeReference<Address>() {}, new TypeReference<Uint256>() {}));
    return new RemoteCall<Tuple4<BigInteger, Boolean, String, BigInteger>>(
            new Callable<Tuple4<BigInteger, Boolean, String, BigInteger>>() {
                @Override
                public Tuple4<BigInteger, Boolean, String, BigInteger> call() throws Exception {
                    List<Type> results = executeCallMultipleValueReturn(function);
                    return new Tuple4<BigInteger, Boolean, String, BigInteger>(
                            (BigInteger) results.get(0).getValue(),
                            (Boolean) results.get(1).getValue(),
                            (String) results.get(2).getValue(),
                            (BigInteger) results.get(3).getValue());
                }
            });
}
 
Example #20
Source Project: besu   Author: hyperledger   File: DefaultOnChainPrivacyGroupManagementContract.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteFunctionCall<Boolean> canExecute() {
  final org.web3j.abi.datatypes.Function function =
      new org.web3j.abi.datatypes.Function(
          FUNC_CANEXECUTE,
          Arrays.<Type>asList(),
          Arrays.<TypeReference<?>>asList(new TypeReference<Bool>() {}));
  return executeRemoteCallSingleValueReturn(function, Boolean.class);
}
 
Example #21
Source Project: besu   Author: hyperledger   File: OnChainPrivacyGroupManagementInterface.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteFunctionCall<Boolean> canExecute() {
  final Function function =
      new Function(
          FUNC_CANEXECUTE,
          Arrays.<Type>asList(),
          Arrays.<TypeReference<?>>asList(new TypeReference<Bool>() {}));
  return executeRemoteCallSingleValueReturn(function, Boolean.class);
}
 
Example #22
Source Project: besu   Author: hyperledger   File: OnChainPrivacyGroupManagementProxy.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteFunctionCall<Boolean> canExecute() {
  final Function function =
      new Function(
          FUNC_CANEXECUTE,
          Arrays.<Type>asList(),
          Arrays.<TypeReference<?>>asList(new TypeReference<Bool>() {}));
  return executeRemoteCallSingleValueReturn(function, Boolean.class);
}
 
Example #23
Source Project: besu   Author: hyperledger   File: RevertReason.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteCall<Boolean> revertWithRevertReason() {
  final Function function =
      new Function(
          FUNC_REVERTWITHREVERTREASON,
          Arrays.<Type>asList(),
          Arrays.<TypeReference<?>>asList(new TypeReference<Bool>() {}));
  return executeRemoteCallSingleValueReturn(function, Boolean.class);
}
 
Example #24
Source Project: besu   Author: hyperledger   File: RevertReason.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteCall<Boolean> revertWithoutRevertReason() {
  final Function function =
      new Function(
          FUNC_REVERTWITHOUTREVERTREASON,
          Arrays.<Type>asList(),
          Arrays.<TypeReference<?>>asList(new TypeReference<Bool>() {}));
  return executeRemoteCallSingleValueReturn(function, Boolean.class);
}
 
Example #25
Source Project: Upchain-wallet   Author: xilibi2003   File: TokenRepository.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public static String createTokenTransferData(String to, BigInteger tokenAmount) {
        List<Type> params = Arrays.<Type>asList(new Address(to), new Uint256(tokenAmount));

        List<TypeReference<?>> returnTypes = Arrays.<TypeReference<?>>asList(new TypeReference<Bool>() {
        });

        Function function = new Function("transfer", params, returnTypes);
        return FunctionEncoder.encode(function);
//        return Numeric.hexStringToByteArray(Numeric.cleanHexPrefix(encodedFunction));
    }
 
Example #26
Source Project: client-sdk-java   Author: PlatONnetwork   File: TypeEncoder.java    License: Apache License 2.0 5 votes vote down vote up
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 #27
Source Project: client-sdk-java   Author: PlatONnetwork   File: TypeEncoderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBoolEncode() {
    assertThat(TypeEncoder.encodeBool(new Bool(false)),
            is("0000000000000000000000000000000000000000000000000000000000000000"));
    assertThat(TypeEncoder.encodeBool(new Bool(true)),
            is("0000000000000000000000000000000000000000000000000000000000000001"));
}
 
Example #28
Source Project: client-sdk-java   Author: PlatONnetwork   File: TypeDecoderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBoolDecode() {
    assertThat(TypeDecoder.decodeBool(
            "0000000000000000000000000000000000000000000000000000000000000000", 0),
            is(new Bool(false)));

    assertThat(TypeDecoder.decodeBool(
            "0000000000000000000000000000000000000000000000000000000000000001", 0),
            is(new Bool(true)));
}
 
Example #29
Source Project: client-sdk-java   Author: PlatONnetwork   File: FunctionEncoderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBuildMessageSignature() {
    assertThat(
            FunctionEncoder.buildMethodSignature(
                    "baz",
                    Arrays.asList(
                            new Uint32(BigInteger.valueOf(69)),
                            new Bool(true))
            ),
            is("baz(uint32,bool)"));
}
 
Example #30
Source Project: client-sdk-java   Author: PlatONnetwork   File: FunctionEncoderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testFunctionSimpleEncode() {
    Function function = new Function(
            "baz",
            Arrays.asList(new Uint32(BigInteger.valueOf(69)), new Bool(true)),
            Collections.<TypeReference<?>>emptyList()
    );

    assertThat(FunctionEncoder.encode(function),
            is("0xcdcd77c0"
                    + "0000000000000000000000000000000000000000000000000000000000000045"
                    + "0000000000000000000000000000000000000000000000000000000000000001"
            ));
}