Skip to content
This repository was archived by the owner on Jul 23, 2024. It is now read-only.

Commit 19aef6b

Browse files
author
kale
authored
Merge pull request #218 from klaytn/release/v1.6.0
[Master] release/v1.6.0 QA Sign-off
2 parents fba5d41 + 7900ef1 commit 19aef6b

File tree

190 files changed

+12717
-91
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+12717
-91
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# @global-owner1 and @global-owner2 will be requested for
77
# review when someone opens a pull request.
88
#* @global-owner1 @global-owner2
9-
* @kjhman21 @jimni1222 @sirano11
9+
* @kjhman21 @jimni1222 @sirano11 @aeharvlee
1010

1111
# Order is important; the last matching pattern takes the most
1212
# precedence. When someone opens a pull request that only

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ plugins {
2020

2121
allprojects {
2222

23-
version '1.5.7'
23+
version '1.6.0'
2424
group 'com.klaytn.caver'
2525
description 'caver-java project'
2626

core/src/main/java/com/klaytn/caver/abi/ABI.java

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616

1717
package com.klaytn.caver.abi;
1818

19+
import com.klaytn.caver.abi.datatypes.*;
1920
import com.klaytn.caver.contract.ContractEvent;
2021
import com.klaytn.caver.contract.ContractIOType;
2122
import com.klaytn.caver.contract.ContractMethod;
22-
import org.web3j.abi.*;
23-
import org.web3j.abi.datatypes.*;
2423
import org.web3j.crypto.Hash;
2524
import org.web3j.utils.Numeric;
2625

@@ -31,6 +30,8 @@
3130
import java.util.List;
3231
import java.util.stream.Collectors;
3332

33+
import static com.klaytn.caver.abi.TypeEncoder.isDynamic;
34+
3435
/**
3536
* Representing a ABI type encode / decode.
3637
*/
@@ -48,7 +49,7 @@ public static String encodeFunctionCall(ContractMethod method, List<Object> para
4849
List<String> solTypeList = new ArrayList();
4950

5051
for (ContractIOType contractIOType : method.getInputs()) {
51-
solTypeList.add(contractIOType.getType());
52+
solTypeList.add(contractIOType.getTypeAsString());
5253
}
5354

5455
return encodeFunctionCall(functionSignature, solTypeList, params);
@@ -133,12 +134,13 @@ public static String buildFunctionString(ContractMethod method) {
133134
result.append(method.getName());
134135
result.append("(");
135136
String params = method.getInputs().stream()
136-
.map(ContractIOType::getType)
137+
.map(ContractIOType::getTypeAsString)
137138
.collect(Collectors.joining(","));
138139
result.append(params);
139140
result.append(")");
140141

141-
return result.toString();
142+
//remove "tuple" string
143+
return result.toString().replace("tuple", "");
142144
}
143145

144146
/**
@@ -171,12 +173,13 @@ public static String buildEventString(ContractEvent event) {
171173
result.append(event.getName());
172174
result.append("(");
173175
String params = event.getInputs().stream()
174-
.map(ContractIOType::getType)
176+
.map(ContractIOType::getTypeAsString)
175177
.collect(Collectors.joining(","));
176178
result.append(params);
177179
result.append(")");
178180

179-
return result.toString();
181+
//remove "tuple" string
182+
return result.toString().replace("tuple", "");
180183
}
181184

182185
/**
@@ -209,7 +212,7 @@ public static String encodeParameter(String solidityType, Object value) throws C
209212
public static String encodeParameters(ContractMethod method, List<Object> values) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
210213
List<String> solTypeList = new ArrayList<>();
211214
for(ContractIOType type : method.getInputs()) {
212-
solTypeList.add(type.getType());
215+
solTypeList.add(type.getTypeAsString());
213216
}
214217

215218
return encodeParameters(solTypeList, values);
@@ -251,25 +254,26 @@ public static String encodeParameter(Type parameter) {
251254
* @return String
252255
*/
253256
public static String encodeParameters(List<Type> parameters) {
254-
int dynamicDataOffset = getLength(parameters) * Type.MAX_BYTE_LENGTH;
255-
StringBuilder result = new StringBuilder();
256-
StringBuilder dynamicData = new StringBuilder();
257-
258-
for (Type parameter:parameters) {
259-
String encodedValue = TypeEncoder.encode(parameter);
260-
261-
if (isDynamic(parameter)) {
262-
String encodedDataOffset = TypeEncoder.encode(new Uint(BigInteger.valueOf(dynamicDataOffset)));
263-
result.append(encodedDataOffset);
264-
dynamicData.append(encodedValue);
265-
dynamicDataOffset += encodedValue.length() >> 1;
266-
} else {
267-
result.append(encodedValue);
268-
}
269-
}
270-
result.append(dynamicData);
271-
272-
return result.toString();
257+
return new DefaultFunctionEncoder().encodeParameters(parameters);
258+
// int dynamicDataOffset = getLength(parameters) * Type.MAX_BYTE_LENGTH;
259+
// StringBuilder result = new StringBuilder();
260+
// StringBuilder dynamicData = new StringBuilder();
261+
//
262+
// for (Type parameter:parameters) {
263+
// String encodedValue = TypeEncoder.encode(parameter);
264+
//
265+
// if (isDynamic(parameter)) {
266+
// String encodedDataOffset = TypeEncoder.encode(new Uint(BigInteger.valueOf(dynamicDataOffset)));
267+
// result.append(encodedDataOffset);
268+
// dynamicData.append(encodedValue);
269+
// dynamicDataOffset += encodedValue.length() >> 1;
270+
// } else {
271+
// result.append(encodedValue);
272+
// }
273+
// }
274+
// result.append(dynamicData);
275+
//
276+
// return result.toString();
273277
}
274278

275279
/**
@@ -311,7 +315,7 @@ public static List<Type> decodeParameters(ContractMethod method, String encoded)
311315
List<TypeReference<Type>> resultParams = new ArrayList<>();
312316

313317
for(ContractIOType ioType: method.getOutputs()) {
314-
resultParams.add(TypeReference.makeTypeReference(ioType.getType()));
318+
resultParams.add(TypeReference.makeTypeReference(ioType.getTypeAsString()));
315319
}
316320

317321
return FunctionReturnDecoder.decode(encoded, resultParams);
@@ -331,9 +335,9 @@ public static EventValues decodeLog(List<ContractIOType> inputs, String data, Li
331335

332336
for(ContractIOType input: inputs) {
333337
if(input.isIndexed()) {
334-
indexedList.add(TypeReference.makeTypeReference(input.getType()));
338+
indexedList.add(TypeReference.makeTypeReference(input.getTypeAsString()));
335339
} else {
336-
nonIndexedList.add(TypeReference.makeTypeReference(input.getType()));
340+
nonIndexedList.add(TypeReference.makeTypeReference(input.getTypeAsString()));
337341
}
338342
}
339343

@@ -349,21 +353,21 @@ public static EventValues decodeLog(List<ContractIOType> inputs, String data, Li
349353
return new EventValues(indexedValues, nonIndexedValues);
350354
}
351355

352-
private static int getLength(List<Type> parameters) {
353-
int count = 0;
354-
for (Type type:parameters) {
355-
if (type instanceof StaticArray) {
356-
count += ((StaticArray) type).getValue().size();
357-
} else {
358-
count++;
359-
}
360-
}
361-
return count;
362-
}
363-
364-
private static boolean isDynamic(Type parameter) {
365-
return parameter instanceof DynamicBytes
366-
|| parameter instanceof Utf8String
367-
|| parameter instanceof DynamicArray;
368-
}
356+
// private static int getLength(List<Type> parameters) {
357+
// int count = 0;
358+
// for (Type type:parameters) {
359+
// if (type instanceof StaticArray) {
360+
// count += ((StaticArray) type).getValue().size();
361+
// } else {
362+
// count++;
363+
// }
364+
// }
365+
// return count;
366+
// }
367+
368+
// private static boolean isDynamic(Type parameter) {
369+
// return parameter instanceof DynamicBytes
370+
// || parameter instanceof Utf8String
371+
// || parameter instanceof DynamicArray;
372+
// }
369373
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Modifications copyright 2021 The caver-java Authors
3+
* Copyright 2019 Web3 Labs Ltd.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
* This file is derived from web3j/abi/src/main/java/org/web3j/abi/DefaultFunctionEncoder.java (2021/04/05).
18+
* Modified and improved for the caver-java development.
19+
*/
20+
21+
package com.klaytn.caver.abi;
22+
23+
import com.klaytn.caver.abi.datatypes.*;
24+
25+
import java.math.BigInteger;
26+
import java.util.List;
27+
28+
public class DefaultFunctionEncoder extends FunctionEncoder {
29+
30+
@Override
31+
public String encodeFunction(final Function function) {
32+
final List<Type> parameters = function.getInputParameters();
33+
34+
final String methodSignature = buildMethodSignature(function.getName(), parameters);
35+
final String methodId = buildMethodId(methodSignature);
36+
37+
final StringBuilder result = new StringBuilder();
38+
result.append(methodId);
39+
40+
return encodeParameters(parameters, result);
41+
}
42+
43+
@Override
44+
public String encodeParameters(final List<Type> parameters) {
45+
return encodeParameters(parameters, new StringBuilder());
46+
}
47+
48+
private static String encodeParameters(
49+
final List<Type> parameters, final StringBuilder result) {
50+
51+
int dynamicDataOffset = getLength(parameters) * Type.MAX_BYTE_LENGTH;
52+
final StringBuilder dynamicData = new StringBuilder();
53+
54+
for (Type parameter : parameters) {
55+
final String encodedValue = TypeEncoder.encode(parameter);
56+
57+
if (TypeEncoder.isDynamic(parameter)) {
58+
final String encodedDataOffset =
59+
TypeEncoder.encodeNumeric(new Uint(BigInteger.valueOf(dynamicDataOffset)));
60+
result.append(encodedDataOffset);
61+
dynamicData.append(encodedValue);
62+
dynamicDataOffset += encodedValue.length() >> 1;
63+
} else {
64+
result.append(encodedValue);
65+
}
66+
}
67+
result.append(dynamicData);
68+
69+
return result.toString();
70+
}
71+
72+
@SuppressWarnings("unchecked")
73+
private static int getLength(final List<Type> parameters) {
74+
int count = 0;
75+
for (final Type type : parameters) {
76+
if(type instanceof StaticStruct) {
77+
count += Utils.getStaticStructComponentSize((StaticStruct) type);
78+
} else if (type instanceof StaticArray) {
79+
if(TypeEncoder.isDynamic(type)) {
80+
count++;
81+
} else {
82+
count += Utils.getStaticArrayElementSize((StaticArray)type);
83+
}
84+
} else {
85+
count++;
86+
}
87+
}
88+
return count;
89+
}
90+
}

0 commit comments

Comments
 (0)