org.fisco.bcos.web3j.abi.datatypes.Event Java Examples
The following examples show how to use
org.fisco.bcos.web3j.abi.datatypes.Event.
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: EventEncoderTest.java From web3sdk with Apache License 2.0 | 6 votes |
@Test public void testEventbuildMethodSignature0() { Event event = new Event( "g", Arrays.<TypeReference<?>>asList( new TypeReference<DynamicArray<DynamicArray<Uint256>>>() {}, new TypeReference<DynamicArray<Utf8String>>() {})); assertThat( EventEncoder.buildMethodSignature(event.getName(), event.getParameters()), is("g(uint256[][],string[])")); assertThat( EventEncoder.encode(event), is("0x2289b18cd8c6e198648b35d3bcf2ff8668984543f01927711c161bcf7b5e1bba")); assertThat( EventEncoder.buildEventSignature("g(uint256[][],string[])"), is("0x2289b18cd8c6e198648b35d3bcf2ff8668984543f01927711c161bcf7b5e1bba")); }
Example #2
Source File: EventEncoderTest.java From web3sdk with Apache License 2.0 | 6 votes |
@Test public void testEventbuildMethodSignature11() { Event event = new Event("test11", Arrays.<TypeReference<?>>asList()); assertThat( EventEncoder.buildMethodSignature(event.getName(), event.getParameters()), is("test11()")); assertThat( EventEncoder.encode(event), is("0xfa8b8ea1bf7b2a8633a34bc7af9661842883700a6d001d980310b17cf602b71f")); assertThat( EventEncoder.buildEventSignature("test11()"), is("0xfa8b8ea1bf7b2a8633a34bc7af9661842883700a6d001d980310b17cf602b71f")); }
Example #3
Source File: EventEncoderTest.java From web3sdk with Apache License 2.0 | 6 votes |
@Test public void testEventbuildMethodSignature10() { Event event = new Event( "test10", Arrays.<TypeReference<?>>asList( new TypeReference<DynamicArray<Utf8String>>() {})); assertThat( EventEncoder.buildMethodSignature(event.getName(), event.getParameters()), is("test10(string[])")); assertThat( EventEncoder.encode(event), is("0xfb9fe4911c195fb1112aaa9c3ac5a54a0c521f8cb0f4ee9290a9bff28542d051")); assertThat( EventEncoder.buildEventSignature("test10(string[])"), is("0xfb9fe4911c195fb1112aaa9c3ac5a54a0c521f8cb0f4ee9290a9bff28542d051")); }
Example #4
Source File: EventEncoderTest.java From web3sdk with Apache License 2.0 | 6 votes |
@Test public void testEventbuildMethodSignature9() { Event event = new Event( "test9", Arrays.<TypeReference<?>>asList( new TypeReference<Utf8String>() {}, new TypeReference<Uint256>() {}, new TypeReference<StaticArray6<Uint256>>() {}, new TypeReference<DynamicArray<Uint256>>() {}, new TypeReference<Bool>() {}, new TypeReference<Address>() {})); assertThat( EventEncoder.buildMethodSignature(event.getName(), event.getParameters()), is("test9(string,uint256,uint256[6],uint256[],bool,address)")); assertThat( EventEncoder.encode(event), is("0xa37d8a63087cf5837e0b9ff13d07d756479f8afdfe4b05ea3dfdc98154ef58ed")); assertThat( EventEncoder.buildEventSignature( "test9(string,uint256,uint256[6],uint256[],bool,address)"), is("0xa37d8a63087cf5837e0b9ff13d07d756479f8afdfe4b05ea3dfdc98154ef58ed")); }
Example #5
Source File: EventEncoderTest.java From web3sdk with Apache License 2.0 | 6 votes |
@Test public void testEventbuildMethodSignature8() { Event event = new Event( "test8", Arrays.<TypeReference<?>>asList( new TypeReference<Utf8String>() {}, new TypeReference<Address>() {}, new TypeReference<Uint256>() {}, new TypeReference<Int256>() {})); assertThat( EventEncoder.buildMethodSignature(event.getName(), event.getParameters()), is("test8(string,address,uint256,int256)")); assertThat( EventEncoder.encode(event), is("0xfa3d7a982eb00eec003de55d3e9266fa4b9ccd6a3a067b75b24ef6b4cb9b12c4")); assertThat( EventEncoder.buildEventSignature("test8(string,address,uint256,int256)"), is("0xfa3d7a982eb00eec003de55d3e9266fa4b9ccd6a3a067b75b24ef6b4cb9b12c4")); }
Example #6
Source File: EventEncoderTest.java From web3sdk with Apache License 2.0 | 6 votes |
@Test public void testEventbuildMethodSignature6() { Event event = new Event( "test6", Arrays.<TypeReference<?>>asList( new TypeReference<Uint256>() {}, new TypeReference<Int256>() {}, new TypeReference<Utf8String>() {}, new TypeReference<DynamicArray<Utf8String>>() {}, new TypeReference<StaticArray3<Utf8String>>() {})); assertThat( EventEncoder.buildMethodSignature(event.getName(), event.getParameters()), is("test6(uint256,int256,string,string[],string[3])")); assertThat( EventEncoder.encode(event), is("0x5199068657caa55d23ad866ba738a7f21e567e6f50aa8173ac108efdd5d3bb79")); assertThat( EventEncoder.buildEventSignature("test6(uint256,int256,string,string[],string[3])"), is("0x5199068657caa55d23ad866ba738a7f21e567e6f50aa8173ac108efdd5d3bb79")); }
Example #7
Source File: EventEncoderTest.java From web3sdk with Apache License 2.0 | 6 votes |
@Test public void testEventbuildMethodSignature5() { Event event = new Event( "test5", Arrays.<TypeReference<?>>asList( new TypeReference< DynamicArray< DynamicArray< DynamicArray< DynamicArray<Utf8String>>>>>() {})); assertThat( EventEncoder.buildMethodSignature(event.getName(), event.getParameters()), is("test5(string[][][][])")); assertThat( EventEncoder.encode(event), is("0x69f175db6ba77ff81ba5e31ca58ddfeb6b2ea420d1233fba18371dc63a12e9c1")); assertThat( EventEncoder.buildEventSignature("test5(string[][][][])"), is("0x69f175db6ba77ff81ba5e31ca58ddfeb6b2ea420d1233fba18371dc63a12e9c1")); }
Example #8
Source File: EventEncoderTest.java From web3sdk with Apache License 2.0 | 6 votes |
@Test public void testEventbuildMethodSignature4() { Event event = new Event( "test4", Arrays.<TypeReference<?>>asList( new TypeReference<Uint32>() {}, new TypeReference<Bool>() {})); assertThat( EventEncoder.buildMethodSignature(event.getName(), event.getParameters()), is("test4(uint32,bool)")); assertThat( EventEncoder.encode(event), is("0xd7ee7b8ce8fd8944f6c4fc1d3d8f656f855a5b9c130a876af272bdb06b056f9c")); assertThat( EventEncoder.buildEventSignature("test4(uint32,bool)"), is("0xd7ee7b8ce8fd8944f6c4fc1d3d8f656f855a5b9c130a876af272bdb06b056f9c")); }
Example #9
Source File: EventEncoderTest.java From web3sdk with Apache License 2.0 | 6 votes |
@Test public void testEventbuildMethodSignature3() { Event event = new Event( "test3", Arrays.<TypeReference<?>>asList( new TypeReference<StaticArray2<Bytes3>>() {})); assertThat( EventEncoder.buildMethodSignature(event.getName(), event.getParameters()), is("test3(bytes3[2])")); assertThat( EventEncoder.encode(event), is("0x8e8ba55ef93e108e0902c0aed7709f74b477e2a1a98497d860d050eb5ac8e599")); assertThat( EventEncoder.buildEventSignature("test3(bytes3[2])"), is("0x8e8ba55ef93e108e0902c0aed7709f74b477e2a1a98497d860d050eb5ac8e599")); }
Example #10
Source File: EventEncoderTest.java From web3sdk with Apache License 2.0 | 6 votes |
@Test public void testEventbuildMethodSignature2() { Event event = new Event( "f", Arrays.<TypeReference<?>>asList( new TypeReference<DynamicBytes>() {}, new TypeReference<Bool>() {}, new TypeReference<DynamicArray<Uint256>>() {})); assertThat( EventEncoder.buildMethodSignature(event.getName(), event.getParameters()), is("f(bytes,bool,uint256[])")); assertThat( EventEncoder.encode(event), is("0xa83b3f0112fa8ecc02937d734929bbaa30731fe27b20195418852fb64ac2837d")); assertThat( EventEncoder.buildEventSignature("f(bytes,bool,uint256[])"), is("0xa83b3f0112fa8ecc02937d734929bbaa30731fe27b20195418852fb64ac2837d")); }
Example #11
Source File: EventEncoderTest.java From web3sdk with Apache License 2.0 | 6 votes |
@Test public void testEventbuildMethodSignature1() { Event event = new Event( "f", Arrays.<TypeReference<?>>asList( new TypeReference<Uint>() {}, new TypeReference<DynamicArray<Uint32>>() {}, new TypeReference<Bytes10>() {}, new TypeReference<DynamicBytes>() {})); assertThat( EventEncoder.buildMethodSignature(event.getName(), event.getParameters()), is("f(uint256,uint32[],bytes10,bytes)")); assertThat( EventEncoder.encode(event), is("0x8be652465888a0c5d65fc9d0a7e898b9ca98de97185c53a54ec408fd2fd5d45d")); assertThat( EventEncoder.buildEventSignature("f(uint256,uint32[],bytes10,bytes)"), is("0x8be652465888a0c5d65fc9d0a7e898b9ca98de97185c53a54ec408fd2fd5d45d")); }
Example #12
Source File: AbiUtil.java From WeBASE-Front with Apache License 2.0 | 6 votes |
/** * receiptParse. * * @param receipt info * @param abiList info * @return */ public static Object receiptParse(TransactionReceipt receipt, List<AbiDefinition> abiList) throws FrontException { Map<String, Object> resultMap = new HashMap<>(); List<Log> logList = receipt.getLogs(); for (AbiDefinition abiDefinition : abiList) { String eventName = abiDefinition.getName(); List<String> funcInputTypes = getFuncInputType(abiDefinition); List<TypeReference<?>> finalOutputs = outputFormat(funcInputTypes); Event event = new Event(eventName,finalOutputs); Object result = null; for (Log logInfo : logList) { EventValues eventValues = Contract.staticExtractEventParameters(event, logInfo); if (eventValues != null) { result = callResultParse(funcInputTypes, eventValues.getNonIndexedValues()); break; } } if (result != null) { resultMap.put(eventName, result); } } return resultMap; }
Example #13
Source File: Contract.java From web3sdk with Apache License 2.0 | 6 votes |
public static EventValues staticExtractEventParameters(Event event, Log log) { List<String> topics = log.getTopics(); String encodedEventSignature = EventEncoder.encode(event); if (!topics.get(0).equals(encodedEventSignature)) { return null; } List<Type> indexedValues = new ArrayList<>(); List<Type> nonIndexedValues = FunctionReturnDecoder.decode(log.getData(), event.getNonIndexedParameters()); List<TypeReference<Type>> indexedParameters = event.getIndexedParameters(); for (int i = 0; i < indexedParameters.size(); i++) { Type value = FunctionReturnDecoder.decodeIndexedValue( topics.get(i + 1), indexedParameters.get(i)); indexedValues.add(value); } return new EventValues(indexedValues, nonIndexedValues); }
Example #14
Source File: ContractAbiUtil.java From WeBASE-Transaction with Apache License 2.0 | 6 votes |
/** * receiptParse. * * @param receipt info * @param abiList info * @return */ public static Object receiptParse(TransactionReceipt receipt, List<AbiDefinition> abiList) throws BaseException { Map<String, Object> resultMap = new HashMap<>(); List<Log> logList = receipt.getLogs(); for (AbiDefinition abiDefinition : abiList) { String eventName = abiDefinition.getName(); List<String> funcInputTypes = getFuncInputType(abiDefinition); List<TypeReference<?>> finalOutputs = outputFormat(funcInputTypes); Event event = new Event(eventName, finalOutputs); Object result = null; for (Log logInfo : logList) { EventValues eventValues = Contract.staticExtractEventParameters(event, logInfo); if (eventValues != null) { result = callResultParse(funcInputTypes, eventValues.getNonIndexedValues()); break; } } if (result != null) { resultMap.put(eventName, result); } } return resultMap; }
Example #15
Source File: SolidityFunctionWrapper.java From web3sdk with Apache License 2.0 | 5 votes |
private static CodeBlock buildVariableLengthEventInitializer( String eventName, List<NamedTypeName> parameterTypes) { List<Object> objects = new ArrayList<>(); objects.add(Event.class); objects.add(eventName); objects.add(Arrays.class); objects.add(TypeReference.class); for (NamedTypeName parameterType : parameterTypes) { objects.add(TypeReference.class); objects.add(parameterType.getTypeName()); } String asListParams = parameterTypes .stream() .map( type -> { if (type.isIndexed()) { return "new $T<$T>(true) {}"; } else { return "new $T<$T>() {}"; } }) .collect(Collectors.joining(", ")); return CodeBlock.builder() .addStatement( "new $T($S, \n" + "$T.<$T<?>>asList(" + asListParams + "))", objects.toArray()) .build(); }
Example #16
Source File: SolidityFunctionWrapper.java From web3sdk with Apache License 2.0 | 5 votes |
private FieldSpec createEventDefinition(String name, List<NamedTypeName> parameters) { CodeBlock initializer = buildVariableLengthEventInitializer(name, parameters); return FieldSpec.builder(Event.class, buildEventDefinitionName(name)) .addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL) .initializer(initializer) .build(); }
Example #17
Source File: Contract.java From web3sdk with Apache License 2.0 | 5 votes |
protected List<EventValuesWithLog> extractEventParametersWithLog( Event event, TransactionReceipt transactionReceipt) { return transactionReceipt .getLogs() .stream() .map(log -> extractEventParametersWithLog(event, log)) .filter(Objects::nonNull) .collect(Collectors.toList()); }
Example #18
Source File: Contract.java From web3sdk with Apache License 2.0 | 5 votes |
protected List<EventValues> extractEventParameters( Event event, TransactionReceipt transactionReceipt) { return transactionReceipt .getLogs() .stream() .map(log -> extractEventParameters(event, log)) .filter(Objects::nonNull) .collect(Collectors.toList()); }
Example #19
Source File: EventEncoderTest.java From web3sdk with Apache License 2.0 | 5 votes |
@Test public void testEventbuildMethodSignature7() { Event event = new Event( "test7", Arrays.<TypeReference<?>>asList( new TypeReference<Uint256>() {}, new TypeReference<Address>() {}, new TypeReference<Utf8String>() {}, new TypeReference<DynamicArray<Uint256>>() {}, new TypeReference<StaticArray3<Uint256>>() {}, new TypeReference<DynamicArray<Utf8String>>() {}, new TypeReference<StaticArray3<Utf8String>>() {}, new TypeReference<DynamicArray<DynamicArray<Uint256>>>() {}, new TypeReference<DynamicArray<StaticArray3<Uint256>>>() {})); assertThat( EventEncoder.buildMethodSignature(event.getName(), event.getParameters()), is( "test7(uint256,address,string,uint256[],uint256[3],string[],string[3],uint256[][],uint256[3][])")); assertThat( EventEncoder.encode(event), is("0x63c45f0c8793f28acf7f800281aaf63198c09afdef34c785429628237221a648")); assertThat( EventEncoder.buildEventSignature( "test7(uint256,address,string,uint256[],uint256[3],string[],string[3],uint256[][],uint256[3][])"), is("0x63c45f0c8793f28acf7f800281aaf63198c09afdef34c785429628237221a648")); }
Example #20
Source File: ContractAbiUtil.java From web3sdk with Apache License 2.0 | 5 votes |
/** * @param log * @param abiDefinition * @return * @throws BaseException */ public static EventValues decodeEvent(Log log, AbiDefinition abiDefinition) throws BaseException { List<TypeReference<?>> finalOutputs = paramFormat(abiDefinition.getInputs()); Event event = new Event(abiDefinition.getName(), finalOutputs); EventValues eventValues = Contract.staticExtractEventParameters(event, log); return eventValues; }
Example #21
Source File: Contract.java From web3sdk with Apache License 2.0 | 4 votes |
protected List<EventValuesWithLog> extractEventParametersWithLog(Event event, List<Log> logs) { return logs.stream() .map(log -> extractEventParametersWithLog(event, log)) .filter(Objects::nonNull) .collect(Collectors.toList()); }
Example #22
Source File: Contract.java From web3sdk with Apache License 2.0 | 4 votes |
protected EventValuesWithLog extractEventParametersWithLog(Event event, Log log) { final EventValues eventValues = staticExtractEventParameters(event, log); return (eventValues == null) ? null : new EventValuesWithLog(eventValues, log); }
Example #23
Source File: Contract.java From web3sdk with Apache License 2.0 | 4 votes |
protected EventValues extractEventParameters(Event event, Log log) { return staticExtractEventParameters(event, log); }
Example #24
Source File: EventEncoder.java From web3sdk with Apache License 2.0 | 2 votes |
public static String encode(Event event) { String methodSignature = buildMethodSignature(event.getName(), event.getParameters()); return buildEventSignature(methodSignature); }