Explorar el Código

feat: add cross task

Wren hace 1 año
padre
commit
cdf0bf18cc

+ 2 - 2
src/main/java/com/ichaoj/ams/script/zksync/era/ZkSyncEraScript.java

@@ -97,14 +97,14 @@
 //                new Address(airdropWallet.getAddress()),
 //                new Uint8(1)));
 //        // build SwapSteps  --step1
-//        DynamicArray<StaticStruct> steps = new DynamicArray<>(StaticStruct.class, ListUtil.of(new StaticStruct(
+//        org.web3j.abi.datatypes.DynamicArray<StaticStruct> steps = new org.web3j.abi.datatypes.DynamicArray<>(StaticStruct.class, ListUtil.of(new StaticStruct(
 //                poolAddress,
 //                new DynamicBytes(Numeric.hexStringToByteArray(data)),
 //                new Address(ZERO_ADDRESS),
 //                new DynamicBytes(Numeric.hexStringToByteArray("0x")))));
 //        BigInteger swapAmount = Convert.toWei(params.get("swapAmount").getValue(), Convert.Unit.ETHER).toBigInteger();
 //        // build SwapPaths --step2
-//        DynamicArray<StaticStruct> paths = new DynamicArray<>(StaticStruct.class, ListUtil.of(new StaticStruct(
+//        org.web3j.abi.datatypes.DynamicArray<StaticStruct> paths = new org.web3j.abi.datatypes.DynamicArray<>(StaticStruct.class, ListUtil.of(new StaticStruct(
 //                steps,
 //                new Address(ZERO_ADDRESS),
 //                new Uint(swapAmount))));

+ 84 - 0
src/main/java/org/web3j/abi/datatypes/DynamicArray.java

@@ -0,0 +1,84 @@
+package org.web3j.abi.datatypes;/*
+ * Copyright 2019 Web3 Labs Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+import lombok.SneakyThrows;
+
+import java.util.List;
+
+/**
+ * Dynamic array type.
+ * @author wrenj
+ */
+public class DynamicArray<T extends Type> extends Array<T> {
+
+    @Deprecated
+    @SafeVarargs
+    @SuppressWarnings({"unchecked"})
+    public DynamicArray(T... values) {
+        super(
+                StructType.class.isAssignableFrom(values[0].getClass())
+                        ? (Class<T>) values[0].getClass()
+                        : (Class<T>) AbiTypes.getType(values[0].getTypeAsString()),
+                values);
+    }
+
+    @Deprecated
+    @SuppressWarnings("unchecked")
+    public DynamicArray(List<T> values) {
+        super(
+                StructType.class.isAssignableFrom(values.get(0).getClass())
+                        ? (Class<T>) values.get(0).getClass()
+                        : (Class<T>) AbiTypes.getType(values.get(0).getTypeAsString()),
+                values);
+    }
+
+    @Deprecated
+    @SuppressWarnings("unchecked")
+    private DynamicArray(String type) {
+        super((Class<T>) AbiTypes.getType(type));
+    }
+
+    @Deprecated
+    public static DynamicArray empty(String type) {
+        return new DynamicArray(type);
+    }
+
+    public DynamicArray(Class<T> type, List<T> values) {
+        super(type, values);
+    }
+
+    @Override
+    public int bytes32PaddedLength() {
+        return super.bytes32PaddedLength() + MAX_BYTE_LENGTH;
+    }
+
+    @SafeVarargs
+    public DynamicArray(Class<T> type, T... values) {
+        super(type, values);
+    }
+
+    @SneakyThrows
+    @Override
+    public String getTypeAsString() {
+        String type;
+        if (value == null || value.size() == 0) {
+            return "bytes" + "[]";
+        }
+        if (StructType.class.isAssignableFrom(value.get(0).getClass())) {
+            type = value.get(0).getTypeAsString();
+        } else {
+            type = AbiTypes.getTypeAString(getComponentType());
+        }
+        return type + "[]";
+    }
+}