diff --git a/common/nuls-base-api-provider/src/main/java/io/nuls/base/api/provider/block/BlockService.java b/common/nuls-base-api-provider/src/main/java/io/nuls/base/api/provider/block/BlockService.java index a0ad67c5f9..3a9d37fd42 100644 --- a/common/nuls-base-api-provider/src/main/java/io/nuls/base/api/provider/block/BlockService.java +++ b/common/nuls-base-api-provider/src/main/java/io/nuls/base/api/provider/block/BlockService.java @@ -20,4 +20,5 @@ public interface BlockService { Result getBlockHeaderByLastHeight(GetBlockHeaderByLastHeightReq req); + Result rollback(GetBlockHeaderByHeightReq getBlockHeaderByHeightReq); } diff --git a/common/nuls-base-api-provider/src/main/java/io/nuls/base/api/provider/block/BlockServiceForRpc.java b/common/nuls-base-api-provider/src/main/java/io/nuls/base/api/provider/block/BlockServiceForRpc.java index 75d649a0d0..6aa0829c43 100644 --- a/common/nuls-base-api-provider/src/main/java/io/nuls/base/api/provider/block/BlockServiceForRpc.java +++ b/common/nuls-base-api-provider/src/main/java/io/nuls/base/api/provider/block/BlockServiceForRpc.java @@ -48,6 +48,11 @@ public Result getBlockHeaderByLastHeight(GetBlockHeaderByLastHe return _call("latestBlockHeaderPo", req, this::tranderBlockHeader); } + @Override + public Result rollback(GetBlockHeaderByHeightReq req) { + return _call("roll_back", req, this::tranderBlockHeader); + } + @Override protected Result call(String method, Object req, Function res) { return callRpc(ModuleE.BL.abbr, method, req, res); diff --git a/common/nuls-core-h2/pom.xml b/common/nuls-core-h2/pom.xml deleted file mode 100644 index c90c263b0b..0000000000 --- a/common/nuls-core-h2/pom.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - common - io.nuls.v2 - 1.0.0-SNAPSHOT - - 4.0.0 - nuls-core-h2 - - - UTF-8 - 11 - 1.2.3 - - - - - - io.nuls.v2 - nuls-core - 1.0.0-SNAPSHOT - - - com.alibaba - druid - 1.1.19 - - - - org.mybatis - mybatis - 3.5.6 - - - com.github.pagehelper - pagehelper - 5.1.9 - - - - com.h2database - h2 - 1.4.196 - - - - - nuls-core-h2 - - - src/main/java - - **/*.xml - - true - - - src/test/java - - **/*.xml - - true - - - src/main/resources - - - - \ No newline at end of file diff --git a/common/nuls-core-h2/src/main/java/io/nuls/core/h2/common/BaseMapper.java b/common/nuls-core-h2/src/main/java/io/nuls/core/h2/common/BaseMapper.java deleted file mode 100644 index 5bab74e772..0000000000 --- a/common/nuls-core-h2/src/main/java/io/nuls/core/h2/common/BaseMapper.java +++ /dev/null @@ -1,104 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2017-2019 nuls.io - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package io.nuls.core.h2.common; - - -import io.nuls.core.h2.utils.Searchable; - -import java.util.List; - - -/** - * mybatis基础查询类,封装了对象的基本查询方法, - * 以下方法sql实现方式,都需自行写在mapper.xml里 - * @author zhouwei - * - */ -public interface BaseMapper { - /** - * This method was generated by MyBatis Generator. - * This method corresponds to the database table block - * - * @mbg.generated - */ - int deleteByPrimaryKey(K key); - - /** - * This method was generated by MyBatis Generator. - * This method corresponds to the database table block - * - * @mbg.generated - */ - int insert(V record); - - /** - * This method was generated by MyBatis Generator. - * This method corresponds to the database table block - * - * @mbg.generated - */ - int insertSelective(V record); - - /** - * This method was generated by MyBatis Generator. - * This method corresponds to the database table block - * - * @mbg.generated - */ - V selectByPrimaryKey(K key); - - /** - * This method was generated by MyBatis Generator. - * This method corresponds to the database table block - * - * @mbg.generated - */ - int updateByPrimaryKeySelective(V record); - - /** - * This method was generated by MyBatis Generator. - * This method corresponds to the database table block - * - * @mbg.generated - */ - int updateByPrimaryKeyWithBLOBs(V record); - - /** - * This method was generated by MyBatis Generator. - * This method corresponds to the database table block - * - * @mbg.generated - */ - int updateByPrimaryKey(V record); - - int batchInsert(List list); - - Long countAll(); - - List selectList(Searchable searchable); - - long selectCount(Searchable searchable); - - -} diff --git a/common/nuls-core-h2/src/main/java/io/nuls/core/h2/interceptor/TransactionInterceptor.java b/common/nuls-core-h2/src/main/java/io/nuls/core/h2/interceptor/TransactionInterceptor.java deleted file mode 100644 index e3c0fe30a4..0000000000 --- a/common/nuls-core-h2/src/main/java/io/nuls/core/h2/interceptor/TransactionInterceptor.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * MIT License - *

- * Copyright (c) 2017-2019 nuls.io - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package io.nuls.core.h2.interceptor; - -import io.nuls.core.h2.transactional.annotation.Transaction; -import io.nuls.core.h2.utils.MybatisDbHelper; -import io.nuls.core.core.annotation.Interceptor; -import io.nuls.core.core.inteceptor.base.BeanMethodInterceptor; -import io.nuls.core.core.inteceptor.base.BeanMethodInterceptorChain; -import org.apache.ibatis.session.SqlSession; - -import java.lang.reflect.Method; - -/** - * @author zhouwei - * @date 2017/10/13 - */ -@Interceptor(Transaction.class) -public class TransactionInterceptor implements BeanMethodInterceptor { - - private static ThreadLocal FLAG_HOLDER = new ThreadLocal() { - @Override - protected Boolean initialValue() { - return false; - } - }; - - @Override - public Object intercept(Transaction annotation, Object object, Method method, Object[] params, BeanMethodInterceptorChain interceptorChain) throws Throwable { - boolean flag = FLAG_HOLDER.get(); - Object result; - - if (!flag) { - SqlSession sqlSession = null; - try { - FLAG_HOLDER.set(true); - sqlSession = MybatisDbHelper.getSession(); - result = interceptorChain.execute(annotation, object, method, params); - sqlSession.commit(); - } catch (Exception e) { - if (sqlSession != null) { - sqlSession.rollback(); - } - throw e; - } finally { - if (sqlSession != null) { - MybatisDbHelper.close(sqlSession); - } - FLAG_HOLDER.remove(); - } - } else { - result = interceptorChain.execute(annotation, object, method, params); - } - return result; - } -} diff --git a/common/nuls-core-h2/src/main/java/io/nuls/core/h2/transactional/annotation/PROPAGATION.java b/common/nuls-core-h2/src/main/java/io/nuls/core/h2/transactional/annotation/PROPAGATION.java deleted file mode 100644 index 95de4715a2..0000000000 --- a/common/nuls-core-h2/src/main/java/io/nuls/core/h2/transactional/annotation/PROPAGATION.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2017-2019 nuls.io - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package io.nuls.core.h2.transactional.annotation; - -/** - * - * @author zhouwei - * @date 2017/10/26 - */ -public enum PROPAGATION { - NONE("none"), - REQUIRED("required"), - INDEPENDENT("independent"); - - - PROPAGATION(String value) { - this.value = value; - } - - private String value; -} diff --git a/common/nuls-core-h2/src/main/java/io/nuls/core/h2/transactional/annotation/Transaction.java b/common/nuls-core-h2/src/main/java/io/nuls/core/h2/transactional/annotation/Transaction.java deleted file mode 100644 index 5b58f4faa4..0000000000 --- a/common/nuls-core-h2/src/main/java/io/nuls/core/h2/transactional/annotation/Transaction.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2017-2019 nuls.io - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package io.nuls.core.h2.transactional.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Created by zhouwei on 2017/10/26. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.TYPE}) -public @interface Transaction { - PROPAGATION transactional() default PROPAGATION.REQUIRED; -} diff --git a/common/nuls-core-h2/src/main/java/io/nuls/core/h2/utils/Condition.java b/common/nuls-core-h2/src/main/java/io/nuls/core/h2/utils/Condition.java deleted file mode 100644 index ba1a18f9f8..0000000000 --- a/common/nuls-core-h2/src/main/java/io/nuls/core/h2/utils/Condition.java +++ /dev/null @@ -1,184 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2017-2019 nuls.io - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package io.nuls.core.h2.utils; - -/** - * 封装sql查询条件赋值, - * prefix和endfix主要针对有时候查询条件需要在整条条件语句前后加上括号等情况时赋值调用 - * 如 (a.name is null or a.password is null) - * @author zhouwei - * - */ -public class Condition { - - public static final String AND = " and "; - - public static final String OR = " or "; - - /**查询字段*/ - private String key; - - /**查询值*/ - private Object value; - - /**查询逻辑运算符号 =, != , > , < 等*/ - private SearchOperator operator; - - /**查询链接符号,默认是and*/ - private String sqlSeparator = Condition.AND; - - /**查询条件前置符号*/ - private String prefix = ""; - - /**查询条件后置符号*/ - private String endfix = ""; - - public Condition() { - - } - - public Condition(String key, SearchOperator operator, Object value) { - if(value == null) { - value = ""; - } - this.key = key; - this.operator = operator; - this.value = valueFromOperator(operator, value); - } - - - public Condition(String sqlSeparator, String key, SearchOperator operator, Object value) { - if(value == null) { - value = ""; - } - this.sqlSeparator = sqlSeparator; - this.key = key; - this.operator = operator; - this.value = valueFromOperator(operator, value); - } - - public static Condition custom(String sql) { - Condition condition = new Condition(); - - condition.operator = SearchOperator.custom; - condition.value = sql; - return condition; - } - - /**根据运算逻辑符,校验value值*/ - public Object valueFromOperator(SearchOperator operator, Object value) { - if(value == null) { - value = ""; - } - if ("true".equals(value)) { - value = true; - } - if ("false".equals(value)) { - value = false; - } - - if (operator == SearchOperator.like || operator == SearchOperator.notLike) { - return "%" + value + "%"; - } - if (operator == SearchOperator.prefixLike || operator == SearchOperator.prefixNotLike) { - return value + "%"; - } - if (operator == SearchOperator.suffixLike || operator == SearchOperator.suffixNotLike) { - return "%" + value; - } - if (operator == SearchOperator.in || operator == SearchOperator.notIn) { - if (value instanceof String) { - return "(" + value + ")"; - } - } - return value; - } - - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public Object getValue() { - return value; - } - - public void setValue(Object value) { - if(value == null) { - value = ""; - } - this.value = value; - } - - public SearchOperator getOperator() { - return operator; - } - - public void setOperator(SearchOperator operator) { - this.operator = operator; - } - - public String getSqlSeparator() { - return sqlSeparator; - } - - public void setSqlSeparator(String sqlSeparator) { - this.sqlSeparator = sqlSeparator; - } - - public String getPrefix() { - return prefix; - } - - public void setPrefix(String prefix) { - this.prefix = prefix; - } - - public String getEndfix() { - return endfix; - } - - public void setEndfix(String endfix) { - this.endfix = endfix; - } - - //获取查询条件 - public String getString() { - if(this.operator == null) { - this.operator = SearchOperator.eq; - } - - String keyStr = this.sqlSeparator + " " + this.prefix + this.key; - if("in".equals(this.operator.getSymbol()) || "not in".equals(this.operator.getSymbol())) { - return keyStr + " " + this.operator.getSymbol() + " (" + this.value + ")" + endfix; - }else { - return keyStr + " " + this.operator.getSymbol() + " " + this.value + endfix; - } - } - -} diff --git a/common/nuls-core-h2/src/main/java/io/nuls/core/h2/utils/DruidDataSourceBuilder.java b/common/nuls-core-h2/src/main/java/io/nuls/core/h2/utils/DruidDataSourceBuilder.java deleted file mode 100644 index 308934b347..0000000000 --- a/common/nuls-core-h2/src/main/java/io/nuls/core/h2/utils/DruidDataSourceBuilder.java +++ /dev/null @@ -1,10 +0,0 @@ -package io.nuls.core.h2.utils; - -import com.alibaba.druid.pool.DruidDataSource; -import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory; - -public class DruidDataSourceBuilder extends UnpooledDataSourceFactory { - public DruidDataSourceBuilder() { - this.dataSource = new DruidDataSource(); - } -} diff --git a/common/nuls-core-h2/src/main/java/io/nuls/core/h2/utils/MybatisDbHelper.java b/common/nuls-core-h2/src/main/java/io/nuls/core/h2/utils/MybatisDbHelper.java deleted file mode 100644 index d971683617..0000000000 --- a/common/nuls-core-h2/src/main/java/io/nuls/core/h2/utils/MybatisDbHelper.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.nuls.core.h2.utils; - -import org.apache.ibatis.session.SqlSession; -import org.apache.ibatis.session.SqlSessionFactory; - -public class MybatisDbHelper { - - private static SqlSessionFactory sqlSessionFactory; - - private static ThreadLocal sessionHolder = new ThreadLocal<>(); - - - public static void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) { - MybatisDbHelper.sqlSessionFactory = sqlSessionFactory; - } - - public static SqlSession getSession() { - SqlSession sqlSession = sessionHolder.get(); - if (sqlSession == null) { - sqlSession = sqlSessionFactory.openSession(false); - sessionHolder.set(sqlSession); - } - return sqlSession; - } - - public void commit() { - SqlSession sqlSession = sessionHolder.get(); - sqlSession.commit(); - } - - public static void close(SqlSession sqlSession) { - if (sqlSession == sessionHolder.get()) { - sqlSession.close(); - sessionHolder.remove(); - } - } -} diff --git a/common/nuls-core-h2/src/main/java/io/nuls/core/h2/utils/SearchOperator.java b/common/nuls-core-h2/src/main/java/io/nuls/core/h2/utils/SearchOperator.java deleted file mode 100644 index 8949c06d67..0000000000 --- a/common/nuls-core-h2/src/main/java/io/nuls/core/h2/utils/SearchOperator.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2017-2019 nuls.io - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package io.nuls.core.h2.utils; - -/** - * 查询操作符 - * - * @author zhouwei - * - */ -public enum SearchOperator { - eq("等于", "="), - ne("不等于", "!="), - gt("大于", ">"), - gte("大于等于", ">="), - lt("小于","<"), - lte("小于等于", "<="), - like("模糊匹配", "like"), - notLike("不匹配","not like"), - prefixLike("前缀模糊匹配", "like"), - prefixNotLike("前缀模糊不匹配", "not like"), - suffixLike("后缀模糊匹配", "like"), - suffixNotLike("后缀模糊不匹配", "not like"), - isNull("空", "is null"), - isNotNull("非空", "is not null"), - in("包含", "in"), - notIn("不包含", "not in"), - custom("自定义默认的", null); - - private final String info; - private final String symbol; - - SearchOperator(final String info, String symbol) { - this.info = info; - this.symbol = symbol; - } - - public String getInfo() { - return info; - } - - public String getSymbol() { - return symbol; - } -} diff --git a/common/nuls-core-h2/src/main/java/io/nuls/core/h2/utils/Searchable.java b/common/nuls-core-h2/src/main/java/io/nuls/core/h2/utils/Searchable.java deleted file mode 100644 index 4dd6e7e79a..0000000000 --- a/common/nuls-core-h2/src/main/java/io/nuls/core/h2/utils/Searchable.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2017-2019 nuls.io - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package io.nuls.core.h2.utils; - -import java.util.ArrayList; -import java.util.List; - -/** - * dao查询接口,封装查询语句工具类 - * @author zoro - * - */ -public class Searchable { - - /** - * 查询连接符,如:= != like - */ - private List operators; - - public Searchable() { - operators = new ArrayList(); - } - - public Searchable(List operators) { - this.operators = operators; - } - - /** - * 添加查询条件 - * @param c - */ - public void addCondition(Condition c) { - this.operators.add(c); - } - - - public void addCondition(String key , SearchOperator operator, Object value) { - this.addCondition(new Condition(key,operator,value)); - } - - /** - * 根据key删除某个条件 - * @param key - */ - public void removeCondition(String key) { - Condition c = null; - for(int i=0; i(); - } - - public List getOperators() { - return operators; - } - - public void setOperators(List operators) { - this.operators = operators; - } -} diff --git a/common/nuls-core-h2/src/main/resources/mybatis/mybatis-config.xml b/common/nuls-core-h2/src/main/resources/mybatis/mybatis-config.xml deleted file mode 100644 index 9836162ec7..0000000000 --- a/common/nuls-core-h2/src/main/resources/mybatis/mybatis-config.xml +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/CreateTable.java b/common/nuls-core-h2/src/test/java/io/nuls/core/h2/CreateTable.java deleted file mode 100644 index 01431c084b..0000000000 --- a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/CreateTable.java +++ /dev/null @@ -1,103 +0,0 @@ -package io.nuls.h2; - - -import java.io.*; - -/** - * @author: Charlie - * @date: 2018/11/16 - */ -public class CreateTable { - - private static String path = "." + File.separator + "sql" + File.separator; - - private static String filenameTemp = null; - - public static void main(String[] args) { - - - - } - public static boolean createFile(String fileName,String filecontent){ - Boolean bool = false; - filenameTemp = path + fileName+".sql";//文件路径+名称+文件类型 - File file = new File(filenameTemp); - try { - //如果文件不存在,则创建新的文件 - if(!file.exists()){ - file.createNewFile(); - bool = true; - System.out.println("success create file,the file is "+filenameTemp); - //创建文件成功后,写入内容到文件里 - writeFileContent(filenameTemp, filecontent); - } - } catch (Exception e) { - e.printStackTrace(); - } - - return bool; - } - - /** - * 向文件中写入内容 - * @param filepath 文件路径与名称 - * @param newstr 写入的内容 - * @return - * @throws IOException - */ - public static boolean writeFileContent(String filepath,String newstr) throws IOException{ - Boolean bool = false; - String filein = newstr+"\r\n";//新写入的行,换行 - String temp = ""; - - FileInputStream fis = null; - InputStreamReader isr = null; - BufferedReader br = null; - FileOutputStream fos = null; - PrintWriter pw = null; - try { - File file = new File(filepath);//文件路径(包括文件名称) - //将文件读入输入流 - fis = new FileInputStream(file); - isr = new InputStreamReader(fis); - br = new BufferedReader(isr); - StringBuffer buffer = new StringBuffer(); - - //文件原有内容 - for(int i=0;(temp =br.readLine())!=null;i++){ - buffer.append(temp); - // 行与行之间的分隔符 相当于“\n” - buffer = buffer.append(System.getProperty("line.separator")); - } - buffer.append(filein); - - fos = new FileOutputStream(file); - pw = new PrintWriter(fos); - pw.write(buffer.toString().toCharArray()); - pw.flush(); - bool = true; - } catch (Exception e) { - // TODO: handle exception - e.printStackTrace(); - }finally { - //不要忘记关闭 - if (pw != null) { - pw.close(); - } - if (fos != null) { - fos.close(); - } - if (br != null) { - br.close(); - } - if (isr != null) { - isr.close(); - } - if (fis != null) { - fis.close(); - } - } - return bool; - } - -} diff --git a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/H2Test.java b/common/nuls-core-h2/src/test/java/io/nuls/core/h2/H2Test.java deleted file mode 100644 index f66613a527..0000000000 --- a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/H2Test.java +++ /dev/null @@ -1,64 +0,0 @@ -package io.nuls.core.h2; - -import io.nuls.core.h2.dao.impl.BaseService; -import io.nuls.core.h2.dao.impl.TransactionServiceImpl; -import io.nuls.h2.dao.TransactionService; -import org.apache.ibatis.io.Resources; -import org.apache.ibatis.session.SqlSessionFactoryBuilder; -import org.junit.Before; -import org.junit.Test; - -import java.io.InputStream; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; - -/** - * @author: Charlie - * @date: 2018/11/14 - */ -public class H2Test { - - @Before - public void before() throws Exception{ - String resource = "mybatis/mybatis-config.xml"; - InputStream in = Resources.getResourceAsStream(resource); - BaseService.sqlSessionFactory = new SqlSessionFactoryBuilder().build(in); - //SessionManager.setSqlSessionFactory(sqlSessionFactory); - } - - @Test - public void init(){ - TransactionService ts = new TransactionServiceImpl(); - /* TransactionPo txPo = new TransactionPo(); - txPo.setAddress("address_ertyuighjk"); - txPo.setHash("hash_zxcvbnmasdfghjk"); - txPo.setAmount(800000L); - txPo.setState(0); - txPo.setType(1); - txPo.setTime(new Date().getTime()); - ts.saveTx(txPo);*/ - //ts.createTable("transaction", "transaction_index",128); - ts.createTxTables("transaction", "transaction_index",128); - } - - @Test - public void db(){ - String JDBC_URL = "jdbc:h2:file:./entity/nuls;INIT=RUNSCRIPT FROM 'classpath:sql/schema-h2-bak.sql';LOG=2;DB_CLOSE_DELAY=-1;TRACE_LEVEL_SYSTEM_OUT=1;DATABASE_TO_UPPER=FALSE"; - //连接数据库时使用的用户名 - String USER = "sa"; - //连接数据库时使用的密码 - String PASSWORD = "26"; - String DRIVER_CLASS = "org.h2.Driver"; - try { - Class.forName(DRIVER_CLASS); - Connection conn = DriverManager.getConnection(JDBC_URL, USER, PASSWORD); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (SQLException e) { - e.printStackTrace(); - } - - - } -} diff --git a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/BaseDataService.java b/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/BaseDataService.java deleted file mode 100644 index cb8c57508e..0000000000 --- a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/BaseDataService.java +++ /dev/null @@ -1,95 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2017-2019 nuls.io - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package io.nuls.h2.dao; - -import java.util.List; -import java.util.Map; - -/** - * @author zhouwei - * @date 2017/9/29 - */ -public interface BaseDataService { - - /** - * 单个数据存储 - * - * @param t 持久化数据 - * @return - */ - int save(T t); - - /** - * 批量存储 - * - * @param list 持久化数据集合 - * @return - */ - int save(List list); - - /** - * 修改数据 - * - * @param t 修改后持久化数据 - * @return - */ - int update(T t); - - int update(List list); - - /** - * 通过键值获取数据 - * - * @param k 数据的键值 - * @return - */ - T get(K k); - - /** - * 删除持久化数据 - * - * @param k 数据的键值 - * @return - */ - int delete(K k); - - /** - * @return all - */ - List getList(); - - /** - * @param params - * @return - */ - List getList(Map params); - - /** - * @return - */ - Long getCount(); - - List getPageList(Map params, int pageSize, int pageNumber, String orderBy); - -} diff --git a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/TransactionService.java b/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/TransactionService.java deleted file mode 100644 index a06922a73f..0000000000 --- a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/TransactionService.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.nuls.h2.dao; - -import com.github.pagehelper.Page; -import io.nuls.h2.entity.TransactionPO; - -import java.util.List; - -/** - * @author: Charlie - * @date: 2018/11/14 - */ -public interface TransactionService { - - Page getTxs(String address, Integer type, Integer state, - Long startTime, Long endTime, int pageNum, int pageSize, String orderBy); - - int saveTx(TransactionPO txPo); - - int saveTxs(List txPoList); - - int deleteTx(TransactionPO txPo); - - - /** - * - * - * 初始化创建存储交易的表 - * @param tableName table name - * @param indexName table index name - * @param number number of tables 分表的数量 - */ - void createTable(String tableName, String indexName, int number); - - void createTxTables(String tableName, String indexName, int number); -} diff --git a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/impl/BaseService.java b/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/impl/BaseService.java deleted file mode 100644 index ea32a4ee60..0000000000 --- a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/impl/BaseService.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * MIT License - ** - * Copyright (c) 2017-2019 nuls.io - ** - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - ** - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - ** - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package io.nuls.core.h2.dao.impl; - -import io.nuls.core.h2.common.BaseMapper; -import org.apache.ibatis.session.SqlSessionFactory; - -/** - * @author: Charlie - * @date: 2018/11/14 - */ -public abstract class BaseService { - - public static SqlSessionFactory sqlSessionFactory; - - /* private Class mapperClass; - - public BaseService(Class mapperClass) { - this.mapperClass = mapperClass; - } - - private SqlSession getSession() { - return sqlSessionFactory.openSession(true); - } - - protected T getMapper() { - SqlSession session = getSession(); - return session.getMapper(mapperClass); - } - */ -} diff --git a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/impl/TransactionServiceImpl.java b/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/impl/TransactionServiceImpl.java deleted file mode 100644 index 85ec81ba33..0000000000 --- a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/impl/TransactionServiceImpl.java +++ /dev/null @@ -1,90 +0,0 @@ -package io.nuls.core.h2.dao.impl; - -import com.github.pagehelper.Page; -import com.github.pagehelper.PageHelper; -import io.nuls.core.h2.dao.impl.mapper.TransactionMapper; -import io.nuls.core.h2.utils.SearchOperator; -import io.nuls.core.h2.utils.Searchable; -import io.nuls.h2.dao.TransactionService; -import io.nuls.h2.entity.TransactionPO; -import io.nuls.h2.entity.TxTable; -import io.nuls.core.core.annotation.Service; -import org.apache.ibatis.session.SqlSession; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author: Charlie - * @date: 2018/11/14 - */ -@Service -public class TransactionServiceImpl extends io.nuls.core.h2.dao.impl.BaseService implements TransactionService { - - @Override - public Page getTxs(String address, Integer type, Integer state, Long startTime, Long endTime, int pageNumber, int pageSize, String orderBy) { - //数据库交易查询结果集 - List transactionList = new ArrayList<>(); - Searchable searchable = new Searchable(); - if (null != type) { - searchable.addCondition("type", SearchOperator.eq, type); - } - if (null != state) { - searchable.addCondition("state", SearchOperator.eq, state); - } - - //开启分页 - PageHelper.startPage(pageNumber, pageSize); - - - return null; - } - - @Override - public int saveTx(TransactionPO txPo) { - SqlSession sqlSession = sqlSessionFactory.openSession(); - int rs = sqlSession.getMapper(TransactionMapper.class).save(txPo); - sqlSession.commit(); - sqlSession.close(); - return rs; - } - - @Override - public int saveTxs(List txPoList) { - return 0; - } - - @Override - public int deleteTx(TransactionPO txPo) { - return 0; - } - - - @Override - public void createTable(String tableName, String indexName, int number) { - SqlSession sqlSession = sqlSessionFactory.openSession(); - TransactionMapper mapper = sqlSession.getMapper(TransactionMapper.class); - for (int i = 0; i <= number; i++) { - mapper.createTable(tableName + "_" + i, indexName + "_" + i); - } - sqlSession.commit(); - sqlSession.close(); - System.out.println("OK"); - } - - - @Override - public void createTxTables(String tableName, String indexName, int number) { - SqlSession sqlSession = sqlSessionFactory.openSession(); - TransactionMapper mapper = sqlSession.getMapper(TransactionMapper.class); - List list = new ArrayList<>(); - for (int i = 0; i <= number; i++) { - TxTable txTable = new TxTable(tableName + "_" + i, indexName + "_" + i); - list.add(txTable); - } - mapper.createTxTables(list); - sqlSession.commit(); - sqlSession.close(); - System.out.println("batch OK"); - } -} diff --git a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/impl/mapper/CommonMapper.java b/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/impl/mapper/CommonMapper.java deleted file mode 100644 index a113a26fdf..0000000000 --- a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/impl/mapper/CommonMapper.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2017-2019 nuls.io - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package io.nuls.h2.dao.impl.mapper; - -import java.io.Serializable; - -/** - * mybatis查询组件使用,见sqlmap/commonMapper.xml - * @author hanchaoyong - */ -public interface CommonMapper { - -} diff --git a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/impl/mapper/CommonMapper.xml b/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/impl/mapper/CommonMapper.xml deleted file mode 100644 index 17201af325..0000000000 --- a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/impl/mapper/CommonMapper.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - ${item.sqlSeparator}${item.prefix} - - - ${item.value} - - - ${item.key} ${item.operator.symbol} - - - ${item.key} ${item.operator.symbol} - #{inItem} - - - ${item.key} ${item.operator.symbol} #{item.value} - - - ${item.endfix} - - - - - \ No newline at end of file diff --git a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/impl/mapper/TransactionMapper.java b/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/impl/mapper/TransactionMapper.java deleted file mode 100644 index e1bf31c109..0000000000 --- a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/impl/mapper/TransactionMapper.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.nuls.core.h2.dao.impl.mapper; - -import io.nuls.core.h2.common.BaseMapper; -import io.nuls.h2.entity.TransactionPO; -import io.nuls.h2.entity.TxTable; -import org.apache.ibatis.annotations.Param; - -import java.util.List; - -/** - * @author: Charlie - * @date: 2018/11/14 - */ -public interface TransactionMapper extends BaseMapper { - - void createTable(@Param("tableName") String tableName, @Param("indexName") String indexName); - - void createTxTables(@Param("list") List list); - - int save(TransactionPO transactionPo); -} diff --git a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/impl/mapper/TransactionMapper.xml b/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/impl/mapper/TransactionMapper.xml deleted file mode 100644 index 6e13b7cce6..0000000000 --- a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/dao/impl/mapper/TransactionMapper.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - CREATE TABLE ${tableName} ( - ADDRESS VARCHAR(40) not null - primary key, - HASH VARCHAR(70) not null, - TYPE TINYINT not null, - AMOUNT BIGINT not null, - STATE TINYINT not null, - TIME BIGINT not null - ); - create index IF NOT EXISTS ${indexName} - on ${tableName} (ADDRESS); - - - - - CREATE TABLE IF NOT EXISTS ${tx.tableName} ( - ADDRESS VARCHAR(40) not null - primary key, - HASH VARCHAR(70) not null, - TYPE TINYINT not null, - AMOUNT BIGINT not null, - STATE TINYINT not null, - TIME BIGINT not null - ); - create index IF NOT EXISTS ${tx.indexName} - on ${tx.tableName} (ADDRESS); - - - - - insert into TRANSACTION_888 (address, hash, `type`, amount, state, `time`) - values - (#{address}, #{hash}, #{type}, #{amount}, #{state}, #{time}) - - \ No newline at end of file diff --git a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/entity/TransactionPO.java b/common/nuls-core-h2/src/test/java/io/nuls/core/h2/entity/TransactionPO.java deleted file mode 100644 index f5626eee31..0000000000 --- a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/entity/TransactionPO.java +++ /dev/null @@ -1,83 +0,0 @@ -package io.nuls.h2.entity; - -/** - * @author: Charlie - * @date: 2018/11/14 - */ -public class TransactionPO { - - private String address; - - private String hash; - - private Integer type; - - private Long amount; - - /** - * 0:转出, 1:转入, 2:冻结 - */ - private Integer state; - - private Long time; - - - - /** - * 以账户地址来分表储存 - * 交易地址的hashCode 与 100 取模 - * 得到本条数据存在哪张表里面 - * @return - */ - public int getTableIndex(){ - return this.address.hashCode() % 100; - } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getHash() { - return hash; - } - - public void setHash(String hash) { - this.hash = hash; - } - - public Integer getType() { - return type; - } - - public void setType(Integer type) { - this.type = type; - } - - public Integer getState() { - return state; - } - - public void setState(Integer state) { - this.state = state; - } - - public Long getTime() { - return time; - } - - public void setTime(Long time) { - this.time = time; - } - - public Long getAmount() { - return amount; - } - - public void setAmount(Long amount) { - this.amount = amount; - } -} diff --git a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/entity/TxTable.java b/common/nuls-core-h2/src/test/java/io/nuls/core/h2/entity/TxTable.java deleted file mode 100644 index c97475183d..0000000000 --- a/common/nuls-core-h2/src/test/java/io/nuls/core/h2/entity/TxTable.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.nuls.h2.entity; - -/** - * @author: Charlie - * @date: 2018/11/18 - */ -public class TxTable { - private String tableName; - - private String indexName; - - public TxTable(){ - - } - - public TxTable(String tableName, String indexName) { - this.tableName = tableName; - this.indexName = indexName; - } - - public String getTableName() { - return tableName; - } - - public void setTableName(String tableName) { - this.tableName = tableName; - } - - public String getIndexName() { - return indexName; - } - - public void setIndexName(String indexName) { - this.indexName = indexName; - } -} diff --git a/common/nuls-core-h2/src/test/resources/db_config.properties b/common/nuls-core-h2/src/test/resources/db_config.properties deleted file mode 100644 index 276ce22468..0000000000 --- a/common/nuls-core-h2/src/test/resources/db_config.properties +++ /dev/null @@ -1,20 +0,0 @@ - -#h2 database -druid.driverClassName=org.h2.Driver -druid.url=jdbc:h2:file:./data/nuls;INIT=RUNSCRIPT FROM 'classpath:sql/schema-h2.sql';LOG=2;DB_CLOSE_DELAY=-1;TRACE_LEVEL_SYSTEM_OUT=1;DATABASE_TO_UPPER=FALSE -druid.username=sa -druid.password=26 - -druid.initialSize=10 -druid.minIdle=10 -druid.maxActive=50 -druid.maxWait=10000 -druid.timeBetweenEvictionRunsMillis=60000 -druid.minEvictableIdleTimeMillis=300000 -druid.poolPreparedStatements=true -druid.maxPoolPreparedStatementPerConnectionSize=20 -druid.defaultAutoCommit=true -druid.validationQuery=select 1 - -#mybatis.mapper -mybatis.mapper=io.nuls.h2.dao.impl.mapper \ No newline at end of file diff --git a/common/nuls-core-h2/src/test/resources/mybatis/mapping/CommonMapper.xml b/common/nuls-core-h2/src/test/resources/mybatis/mapping/CommonMapper.xml deleted file mode 100644 index cfd736ca18..0000000000 --- a/common/nuls-core-h2/src/test/resources/mybatis/mapping/CommonMapper.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - ${item.sqlSeparator}${item.prefix} - - - ${item.value} - - - ${item.key} ${item.operator.symbol} - - - ${item.key} ${item.operator.symbol} - #{inItem} - - - ${item.key} ${item.operator.symbol} #{item.value} - - - ${item.endfix} - - - - - \ No newline at end of file diff --git a/common/nuls-core-h2/src/test/resources/mybatis/mybatis-config-bak.xml b/common/nuls-core-h2/src/test/resources/mybatis/mybatis-config-bak.xml deleted file mode 100644 index 825724751e..0000000000 --- a/common/nuls-core-h2/src/test/resources/mybatis/mybatis-config-bak.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/common/nuls-core-h2/src/test/resources/sql/schema-h2-bak.sql b/common/nuls-core-h2/src/test/resources/sql/schema-h2-bak.sql deleted file mode 100644 index f387a29993..0000000000 --- a/common/nuls-core-h2/src/test/resources/sql/schema-h2-bak.sql +++ /dev/null @@ -1,174 +0,0 @@ - -CREATE TABLE IF NOT EXISTS `account` ( - `address` varchar(40) NOT NULL, - `create_time` bigint(14) NOT NULL, - `alias` varchar(100) DEFAULT NULL, - `pub_key` varbinary(100) DEFAULT NULL, - `pri_key` varbinary(100) DEFAULT NULL, - `encrypted_pri_key` varbinary(100) DEFAULT NULL, - `extend` varbinary(1024) DEFAULT NULL, - `status` INT DEFAULT 0, - PRIMARY KEY (`address`) -) ; - -CREATE TABLE IF NOT EXISTS `punish_log` ( - `id` varchar(32) NOT NULL, - `address` varchar(40) NOT NULL, - `type` int(1) NOT NULL, - `height` bigint(14) NOT NULL, - `round_index` bigint(14) NOT NULL, - `time` bigint(14) NOT NULL, - PRIMARY KEY (`id`) -) ; - -CREATE TABLE IF NOT EXISTS `block_header` ( - `hash` varchar(70) NOT NULL, - `height` bigint(14) NOT NULL, - `pre_hash` varchar(70) DEFAULT NULL, - `merkle_hash` varchar(70) NOT NULL, - `create_time` bigint(14) NOT NULL, - `consensus_address` varchar(40) DEFAULT NULL, - `tx_count` int(5) NOT NULL, - `round_index` bigint(14) NOT NULL, - `scriptSig` varbinary(1024) DEFAULT NULL, - `extend` varbinary(1024) NOT NULL, - `size` int(9) DEFAULT NULL, - PRIMARY KEY (`hash`), - UNIQUE KEY `block_height_idx` (`height`) -) ; - -CREATE TABLE IF NOT EXISTS `agent` ( - `id` varchar(70) NOT NULL, - `agent_address` varchar(40) NOT NULL, - `agent_name` varchar(50) NOT NULL, - `block_height` bigint(18) NOT NULL, - `packing_address` varchar(40) NOT NULL, - `deposit` bigint(18) NOT NULL, - `remark` varchar(255) NOT NULL, - `del_height` bigint(18) DEFAULT 0, - `status` INT DEFAULT 0, - `tx_hash` varchar(70) NOT NULL, - `start_time` bigint(14) NOT NULL, - `commission_rate` decimal(14,2) NOT NULL, - PRIMARY KEY (`id`) -) ; - -CREATE TABLE IF NOT EXISTS `deposit` ( - `id` varchar(70) NOT NULL, - `address` varchar(40) NOT NULL, - `agent_id` varchar(70) NOT NULL, - `deposit` bigint(18) NOT NULL, - `status` int(1) DEFAULT NULL, - `del_height` bigint(18) DEFAULT 0, - `time` bigint(14) DEFAULT NULL, - `block_height` bigint(14) DEFAULT NULL, - `tx_hash` varchar(70) NOT NULL, - PRIMARY KEY (`id`) -) ; - -CREATE TABLE IF NOT EXISTS `node` ( - `id` VARCHAR(30) NOT NULL, - `ip` varchar(20) NOT NULL, - `port` int(6) NOT NULL, - `last_time` bigint(20) NOT NULL, - `last_fail_time` bigint(20) NOT NULL, - `fail_count` int(1) NOT NULL, - `status` int(1) NOT NULL, - `magic_num` int(11) NOT NULL, - PRIMARY KEY (`id`) -) ; - -CREATE TABLE IF NOT EXISTS `node_group` ( - `name` varchar(30) NOT NULL, - PRIMARY KEY (`name`) -) ; - -CREATE TABLE IF NOT EXISTS `node_group_relation` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `node_id` varchar(30) NOT NULL, - `group_id` varchar(30) NOT NULL, - PRIMARY KEY (`id`) -) ; - -CREATE TABLE IF NOT EXISTS `sub_chain` ( - `id` varchar(30) NOT NULL, - `creator_address` varchar(40) NOT NULL, - `tx_hash` varchar(70) NOT NULL, - `g_block` varbinary(1024) NOT NULL, - `g_block_hash` varchar(70) NOT NULL, - `g_merkle_hash` varchar(70) NOT NULL, - `g_block_header` varbinary(1024) NOT NULL, - `title` varchar(255) NOT NULL, - `sign` varbinary(1024) NOT NULL, - `address_prefix` int(5) NOT NULL, - PRIMARY KEY (`id`) -) ; - -CREATE TABLE IF NOT EXISTS `transaction` ( - `hash` varchar(70) NOT NULL, - `tx_index` int(5) NOT NULL, - `type` int(5) NOT NULL, - `create_time` bigint(15) NOT NULL, - `block_height` bigint(15) NOT NULL, - `remark` varchar(100) DEFAULT NULL, - `fee` bigint(19) NOT NULL, - `txData` varbinary(307200) DEFAULT NULL, - `scriptSig` varbinary(255) DEFAULT NULL, - `size` int(9) DEFAULT NULL, - PRIMARY KEY (`hash`) -) ; - -CREATE TABLE IF NOT EXISTS `transaction_local` ( - `hash` varchar(70) NOT NULL, - `tx_index` int(5) NOT NULL, - `type` int(5) NOT NULL, - `create_time` bigint(15) NOT NULL, - `block_height` bigint(15) NOT NULL, - `remark` varchar(100) DEFAULT NULL, - `fee` bigint(19) NOT NULL, - `transferType` int(1) DEFAULT NULL, - `txData` BLOB DEFAULT NULL, - `coinData` BLOB DEFAULT NULL, - `scriptSig` varbinary(255) DEFAULT NULL, - `size` int(9) DEFAULT NULL, - `txStatus` tinyint(1) DEFAULT NULL, - PRIMARY KEY (`hash`) -) ; - -CREATE TABLE IF NOT EXISTS `tx_account_relation` ( - `tx_hash` varchar(70) NOT NULL, - `address` varchar(40) NOT NULL, - PRIMARY KEY (`tx_hash`, `address`) -) ; - -CREATE TABLE IF NOT EXISTS `utxo_input` ( - `tx_hash` varchar(70) NOT NULL, - `in_index` int(5) NOT NULL, - `from_hash` varchar(70) NOT NULL, - `from_index` int(5) NOT NULL, - PRIMARY KEY (`tx_hash`,`in_index`), - UNIQUE KEY `from_idx` (`from_hash`,`from_index`) -) ; - -CREATE TABLE IF NOT EXISTS `utxo_output` ( - `tx_hash` varchar(70) NOT NULL, - `out_index` int(5) NOT NULL, - `value` bigint(18) NOT NULL, - `lock_time` bigint(20) DEFAULT NULL, - `status` tinyint(1) NOT NULL, - `script` varbinary(1024) NOT NULL, - `address` varchar(40) NOT NULL, - PRIMARY KEY (`tx_hash`,`out_index`) -) ; - -CREATE TABLE IF NOT EXISTS `alias` ( - `alias` varchar(40) NOT NULL, - `address` varchar(40) NOT NULL, - `status` tinyint(1) DEFAULT NULL, - PRIMARY KEY (`alias`), - UNIQUE KEY `alias_address_idx` (`address`) -) ; - -create index IF NOT EXISTS block_height_idx on transaction(block_height); -create index IF NOT EXISTS status_idx on transaction_local(txStatus); -create index IF NOT EXISTS addres_idx on utxo_output(address); \ No newline at end of file diff --git a/common/nuls-core-h2/src/test/resources/sql/schema-h2.sql b/common/nuls-core-h2/src/test/resources/sql/schema-h2.sql deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/common/nuls-core/pom.xml b/common/nuls-core/pom.xml index cc86db185c..b29eba9aaf 100644 --- a/common/nuls-core/pom.xml +++ b/common/nuls-core/pom.xml @@ -95,7 +95,7 @@ junit junit - 4.12 + 4.13.1 compile diff --git a/common/nuls-core/src/main/java/io/nuls/core/core/ioc/ScanUtil.java b/common/nuls-core/src/main/java/io/nuls/core/core/ioc/ScanUtil.java index a83256a3d5..bb9863bd2f 100644 --- a/common/nuls-core/src/main/java/io/nuls/core/core/ioc/ScanUtil.java +++ b/common/nuls-core/src/main/java/io/nuls/core/core/ioc/ScanUtil.java @@ -131,7 +131,7 @@ private static void findClassJar(String packageName, String pathName, List nuls-core - nuls-core-h2 nuls-core-rpc nuls-core-rockdb nuls-base diff --git a/genesis-block_dev.json b/genesis-block_dev.json index e6dc069c74..74e38b2c66 100644 --- a/genesis-block_dev.json +++ b/genesis-block_dev.json @@ -3,7 +3,7 @@ "time": "1531152", "txs": [ { - "address": "tNULSeBaMvEtDfvZuukDf2mVyfGo3DdiN8KLRG", + "address": "tNULSeBaMoG1oaW1JZnh6Ly65Ttp6raeTFBfCG", "amount": 1000000000000000, "lockTime": 0 }, diff --git a/module/nuls-api/pom.xml b/module/nuls-api/pom.xml index afca37df71..48e5e6ef5c 100644 --- a/module/nuls-api/pom.xml +++ b/module/nuls-api/pom.xml @@ -42,6 +42,10 @@ io.nuls.v2 nuls-base-api-provider + + io.nuls.v2 + nuls-core-h2 + diff --git a/module/nuls-api/src/main/java/io/nuls/provider/api/jsonrpc/controller/AccountController.java b/module/nuls-api/src/main/java/io/nuls/provider/api/jsonrpc/controller/AccountController.java index 4ff80d65a8..3344bb000f 100644 --- a/module/nuls-api/src/main/java/io/nuls/provider/api/jsonrpc/controller/AccountController.java +++ b/module/nuls-api/src/main/java/io/nuls/provider/api/jsonrpc/controller/AccountController.java @@ -64,7 +64,6 @@ import io.nuls.v2.model.dto.SignDto; import io.nuls.v2.util.AccountTool; import io.nuls.v2.util.NulsSDKTool; -import org.checkerframework.checker.units.qual.A; import java.io.IOException; import java.math.BigInteger; @@ -93,6 +92,8 @@ public class AccountController { AccountService accountService = ServiceManager.get(AccountService.class); + private long time; + @RpcMethod("createAccount") @ApiOperation(description = "批量创建账户", order = 101, detailDesc = "创建的账户存在于本地钱包内") @Parameters(value = { @@ -180,6 +181,10 @@ public RpcResult updatePassword(List params) { if (!FormatValidUtils.validPassword(newPassword)) { return RpcResult.paramError("[newPassword] is inValid"); } + if (System.currentTimeMillis() - time < 3000L) { + return RpcResult.paramError("Access frequency limit."); + } + time = System.currentTimeMillis(); UpdatePasswordReq req = new UpdatePasswordReq(address, oldPassword, newPassword); req.setChainId(chainId); Result result = accountService.updatePassword(req); @@ -227,6 +232,11 @@ public RpcResult getPriKey(List params) { return RpcResult.paramError("[password] is inValid"); } + if (System.currentTimeMillis() - time < 3000L) { + return RpcResult.paramError("Access frequency limit."); + } + time = System.currentTimeMillis(); + GetAccountPrivateKeyByAddressReq req = new GetAccountPrivateKeyByAddressReq(password, address); req.setChainId(chainId); Result result = accountService.getAccountPrivateKey(req); @@ -369,6 +379,12 @@ public RpcResult exportKeystore(List params) { if (!FormatValidUtils.validPassword(password)) { return RpcResult.paramError("[password] is inValid"); } + + if (System.currentTimeMillis() - time < 3000L) { + return RpcResult.paramError("Access frequency limit."); + } + time = System.currentTimeMillis(); + KeyStoreReq req = new KeyStoreReq(password, address); req.setChainId(chainId); Result result = accountService.getAccountKeyStore(req); @@ -435,7 +451,6 @@ public RpcResult getAccountBalance(List params) { } - /** * 查询用户资产合计 * @param params @@ -482,6 +497,7 @@ public RpcResult getBalanceList(List params) { return rpcResult.setResult(balanceResult.getData()); } + @RpcMethod("setAlias") @ApiOperation(description = "设置账户别名", order = 108, detailDesc = "别名格式为1-20位小写字母和数字的组合,设置别名会销毁1个NULS") @Parameters({ diff --git a/module/nuls-api/src/main/java/io/nuls/provider/api/resources/AccountResource.java b/module/nuls-api/src/main/java/io/nuls/provider/api/resources/AccountResource.java index 465d35b3ee..e644583589 100644 --- a/module/nuls-api/src/main/java/io/nuls/provider/api/resources/AccountResource.java +++ b/module/nuls-api/src/main/java/io/nuls/provider/api/resources/AccountResource.java @@ -82,6 +82,7 @@ public class AccountResource { AccountService accountService = ServiceManager.get(AccountService.class); @Autowired private AccountTools accountTools; + private long time; @POST @@ -139,6 +140,10 @@ public RpcClientResult updatePassword(@PathParam("address") String address, Acco if (!FormatValidUtils.validPassword(form.getNewPassword())) { return RpcClientResult.getFailed(new ErrorData(CommonCodeConstanst.PARAMETER_ERROR.getCode(), "[newPassword] is invalid")); } + if (System.currentTimeMillis() - time < 3000L) { + return RpcClientResult.getFailed(new ErrorData(CommonCodeConstanst.PARAMETER_ERROR.getCode(), "Access frequency limit.")); + } + time = System.currentTimeMillis(); UpdatePasswordReq req = new UpdatePasswordReq(address, form.getPassword(), form.getNewPassword()); req.setChainId(config.getChainId()); Result result = accountService.updatePassword(req); @@ -167,6 +172,10 @@ public RpcClientResult getPriKey(@PathParam("address") String address, AccountPa if (address == null) { return RpcClientResult.getFailed(new ErrorData(CommonCodeConstanst.PARAMETER_ERROR.getCode(), "address is empty")); } + if (System.currentTimeMillis() - time < 3000L) { + return RpcClientResult.getFailed(new ErrorData(CommonCodeConstanst.PARAMETER_ERROR.getCode(), "Access frequency limit.")); + } + time = System.currentTimeMillis(); GetAccountPrivateKeyByAddressReq req = new GetAccountPrivateKeyByAddressReq(form.getPassword(), address); req.setChainId(config.getChainId()); Result result = accountService.getAccountPrivateKey(req); @@ -312,6 +321,10 @@ public RpcClientResult exportAccountKeyStore(@PathParam("address") String addres if (address == null) { return RpcClientResult.getFailed(new ErrorData(CommonCodeConstanst.PARAMETER_ERROR.getCode(), "address is empty")); } + if (System.currentTimeMillis() - time < 3000L) { + return RpcClientResult.getFailed(new ErrorData(CommonCodeConstanst.PARAMETER_ERROR.getCode(), "Access frequency limit.")); + } + time = System.currentTimeMillis(); BackupAccountReq req = new BackupAccountReq(form.getPassword(), address, form.getPath()); req.setChainId(config.getChainId()); Result result = accountService.backupAccount(req); diff --git a/module/nuls-api/src/main/java/io/nuls/provider/model/dto/ContractTokenInfoDto.java b/module/nuls-api/src/main/java/io/nuls/provider/model/dto/ContractTokenInfoDto.java index 5b8442ac9e..06f8397b5f 100644 --- a/module/nuls-api/src/main/java/io/nuls/provider/model/dto/ContractTokenInfoDto.java +++ b/module/nuls-api/src/main/java/io/nuls/provider/model/dto/ContractTokenInfoDto.java @@ -40,8 +40,10 @@ public class ContractTokenInfoDto { private String name; @ApiModelProperty(description = "token符号") private String symbol; - @ApiModelProperty(description = "token数量") + @ApiModelProperty(description = "token可用数量") private String amount; + @ApiModelProperty(description = "token锁定数量") + private String lockAmount; @ApiModelProperty(description = "token支持的小数位数") private long decimals; @ApiModelProperty(description = "合约创建时的区块高度") @@ -81,6 +83,14 @@ public void setAmount(String amount) { this.amount = amount; } + public String getLockAmount() { + return lockAmount; + } + + public void setLockAmount(String lockAmount) { + this.lockAmount = lockAmount; + } + public long getDecimals() { return decimals; } diff --git a/module/nuls-api/src/main/java/io/nuls/provider/rpctools/LegderTools.java b/module/nuls-api/src/main/java/io/nuls/provider/rpctools/LegderTools.java index 1fd771170f..8cf627fe23 100644 --- a/module/nuls-api/src/main/java/io/nuls/provider/rpctools/LegderTools.java +++ b/module/nuls-api/src/main/java/io/nuls/provider/rpctools/LegderTools.java @@ -9,7 +9,6 @@ import io.nuls.core.rpc.model.ModuleE; import io.nuls.provider.model.dto.ContractTokenInfoDto; import io.nuls.provider.rpctools.vo.AccountBalance; -import org.checkerframework.checker.units.qual.A; import java.math.BigInteger; import java.util.ArrayList; diff --git a/module/nuls-block/src/main/java/io/nuls/block/rpc/BlockResource.java b/module/nuls-block/src/main/java/io/nuls/block/rpc/BlockResource.java index 4edbf376da..f7254aa649 100644 --- a/module/nuls-block/src/main/java/io/nuls/block/rpc/BlockResource.java +++ b/module/nuls-block/src/main/java/io/nuls/block/rpc/BlockResource.java @@ -477,6 +477,42 @@ public Response getBlockByHeight(Map map) { } } + /** + * 根据高度获取区块 + * + * @param map + * @return + */ + @CmdAnnotation(cmd = "roll_back", version = 1.0, description = "Roll back a number of blocks") + @Parameters({ + @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链ID"), + @Parameter(parameterName = "height", requestType = @TypeDescriptor(value = long.class), parameterDes = "区块高度") + }) + @ResponseData(name = "返回值", description = "successful", responseType = @TypeDescriptor(value = String.class)) + public Response rollback(Map map) { + try { + int chainId = Integer.parseInt(map.get(Constants.CHAIN_ID).toString()); + ChainContext context = ContextManager.getContext(chainId); + if (context == null) { + return success(); + } + long count = Long.parseLong(map.get("height").toString()); + Block block = service.getLatestBlock(chainId); + for (long height = block.getHeader().getHeight(); height > block.getHeader().getHeight() - count; height--) { + service.rollbackBlock(chainId, height, true); + } + Map responseData = new HashMap<>(2); + if (block == null) { + return success(responseData); + } + responseData.put("value", "success"); + return success(responseData); + } catch (Exception e) { + COMMON_LOG.error("", e); + return failed(e.getMessage()); + } + } + /** * 根据hash获取区块头 * @@ -499,7 +535,7 @@ public Response getBlockHeaderByHash(Map map) { NulsHash hash = NulsHash.fromHex(map.get("hash").toString()); BlockHeader blockHeader = service.getBlockHeader(chainId, hash); Map responseData = new HashMap<>(2); - if(blockHeader == null) { + if (blockHeader == null) { return success(responseData); } responseData.put("value", RPCUtil.encode(blockHeader.serialize())); @@ -532,7 +568,7 @@ public Response getBlockHeaderPoByHash(Map map) { NulsHash hash = NulsHash.fromHex(map.get("hash").toString()); BlockHeaderPo blockHeader = service.getBlockHeaderPo(chainId, hash); Map responseData = new HashMap<>(2); - if(blockHeader == null) { + if (blockHeader == null) { return success(responseData); } responseData.put("value", RPCUtil.encode(blockHeader.serialize())); @@ -565,7 +601,7 @@ public Response getBlockByHash(Map map) { NulsHash hash = NulsHash.fromHex(map.get("hash").toString()); Block block = service.getBlock(chainId, hash); Map responseData = new HashMap<>(2); - if(block == null) { + if (block == null) { return success(responseData); } responseData.put("value", RPCUtil.encode(block.serialize())); diff --git a/module/nuls-cmd-client/src/main/java/io/nuls/cmd/client/CommandHandler.java b/module/nuls-cmd-client/src/main/java/io/nuls/cmd/client/CommandHandler.java index d573082d69..d5ef521773 100644 --- a/module/nuls-cmd-client/src/main/java/io/nuls/cmd/client/CommandHandler.java +++ b/module/nuls-cmd-client/src/main/java/io/nuls/cmd/client/CommandHandler.java @@ -31,6 +31,7 @@ import io.nuls.cmd.client.processor.account.*; import io.nuls.cmd.client.processor.block.GetBestBlockHeaderProcessor; import io.nuls.cmd.client.processor.block.GetBlockHeaderProcessor; +import io.nuls.cmd.client.processor.block.RollbackProcessor; import io.nuls.cmd.client.processor.consensus.*; import io.nuls.cmd.client.processor.contract.*; import io.nuls.cmd.client.processor.crosschain.*; @@ -119,6 +120,7 @@ public void afterPropertiesSet() throws NulsException { register(getBean(GetBestBlockHeaderProcessor.class)); //get block header by hash or height register(getBean(GetBlockHeaderProcessor.class)); + register(getBean(RollbackProcessor.class)); //get tx by hash register(getBean(GetTxProcessor.class)); diff --git a/module/nuls-cmd-client/src/main/java/io/nuls/cmd/client/processor/block/RollbackProcessor.java b/module/nuls-cmd-client/src/main/java/io/nuls/cmd/client/processor/block/RollbackProcessor.java new file mode 100644 index 0000000000..42b14cb677 --- /dev/null +++ b/module/nuls-cmd-client/src/main/java/io/nuls/cmd/client/processor/block/RollbackProcessor.java @@ -0,0 +1,97 @@ +/* + * MIT License + * + * Copyright (c) 2017-2019 nuls.io + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +package io.nuls.cmd.client.processor.block; + + +import io.nuls.base.api.provider.Result; +import io.nuls.base.api.provider.ServiceManager; +import io.nuls.base.api.provider.block.BlockService; +import io.nuls.base.api.provider.block.facade.BlockHeaderData; +import io.nuls.base.api.provider.block.facade.GetBlockHeaderByHashReq; +import io.nuls.base.api.provider.block.facade.GetBlockHeaderByHeightReq; +import io.nuls.base.api.provider.block.facade.GetBlockHeaderByLastHeightReq; +import io.nuls.cmd.client.CommandBuilder; +import io.nuls.cmd.client.CommandResult; +import io.nuls.cmd.client.processor.CommandGroup; +import io.nuls.cmd.client.processor.CommandProcessor; +import io.nuls.core.core.annotation.Component; + +import java.util.regex.Matcher; + +/** + * @author: Charlie + */ +@Component +public class RollbackProcessor implements CommandProcessor { + + + BlockService blockService = ServiceManager.get(BlockService.class); + + @Override + public String getCommand() { + return "rollback"; + } + + @Override + public CommandGroup getGroup() { + return CommandGroup.Block; + } + + @Override + public String getHelp() { + CommandBuilder builder = new CommandBuilder(); + builder.newLine(getCommandDescription()) + .newLine("\t block count - Required"); + return builder.toString(); + } + + @Override + public String getCommandDescription() { + return "rollback -- Roll back a number of blocks"; + } + + @Override + public boolean argsValidate(String[] args) { + checkArgsNumber(args,1); + return true; + } + + @Override + public CommandResult execute(String[] args) { + String hash = args[1]; + Matcher matcher = IS_NUMBERIC.matcher(args[1]); + Long height = Long.parseLong(args[1]); + if(height>1000){ + return CommandResult.getFailed("The count is too big"); + } + Result result = blockService.rollback(new GetBlockHeaderByHeightReq(height)); + + if(result.isFailed()){ + return CommandResult.getFailed(result); + } + return CommandResult.getSuccess(result); + } +} diff --git a/module/nuls-cross-chain/cross-chain/src/main/java/io/nuls/crosschain/nuls/srorage/imp/RegisteredCrossChainServiceImpl.java b/module/nuls-cross-chain/cross-chain/src/main/java/io/nuls/crosschain/nuls/srorage/imp/RegisteredCrossChainServiceImpl.java index ef3324a60f..8da5113e7e 100644 --- a/module/nuls-cross-chain/cross-chain/src/main/java/io/nuls/crosschain/nuls/srorage/imp/RegisteredCrossChainServiceImpl.java +++ b/module/nuls-cross-chain/cross-chain/src/main/java/io/nuls/crosschain/nuls/srorage/imp/RegisteredCrossChainServiceImpl.java @@ -60,6 +60,7 @@ public RegisteredChainMessage get() { public boolean canCross(int assetChainId, int assetId) { RegisteredChainMessage all = get(); if(all == null || all.getChainInfoList() == null){ + Log.error("数据为空了"); return false; } return all.getChainInfoList().stream(). diff --git a/module/nuls-cross-chain/cross-chain/src/main/java/io/nuls/crosschain/nuls/utils/validator/CrossTxValidator.java b/module/nuls-cross-chain/cross-chain/src/main/java/io/nuls/crosschain/nuls/utils/validator/CrossTxValidator.java index f7bc957e84..51c72674a5 100644 --- a/module/nuls-cross-chain/cross-chain/src/main/java/io/nuls/crosschain/nuls/utils/validator/CrossTxValidator.java +++ b/module/nuls-cross-chain/cross-chain/src/main/java/io/nuls/crosschain/nuls/utils/validator/CrossTxValidator.java @@ -92,9 +92,9 @@ public boolean validateTx(Chain chain, Transaction tx, BlockHeader blockHeader) if (AddressTool.validContractAddress(from.getAddress(),AddressTool.getChainIdByAddress(from.getAddress()))) { continue; } - + //todo if (!registeredCrossChainService.canCross(from.getAssetsChainId(),from.getAssetsId())){ - throw new NulsException(NulsCrossChainErrorCode.ASSET_NOT_REG_CROSS_CHAIN); +// throw new NulsException(NulsCrossChainErrorCode.ASSET_NOT_REG_CROSS_CHAIN); } } diff --git a/module/nuls-cross-chain/cross-chain/src/test/java/io/nuls/test/TxSendTester.java b/module/nuls-cross-chain/cross-chain/src/test/java/io/nuls/test/TxSendTester.java index ef177e621a..ae7bbb5fbd 100644 --- a/module/nuls-cross-chain/cross-chain/src/test/java/io/nuls/test/TxSendTester.java +++ b/module/nuls-cross-chain/cross-chain/src/test/java/io/nuls/test/TxSendTester.java @@ -28,32 +28,708 @@ public class TxSendTester { @Test public void test() throws Exception { - NoUse.mockModule(); +// NoUse.mockModule(); String prikey = ""; ECKey ecKey = ECKey.fromPrivate(HexUtil.decode(prikey)); - byte[] address = AddressTool.getAddress(ecKey.getPubKey(), 2); + byte[] address = AddressTool.getAddress(ecKey.getPubKey(), 1); ResetChainInfoTransaction tx = new ResetChainInfoTransaction(); tx.setTime(System.currentTimeMillis() / 1000); ResetChainInfoData txData = new ResetChainInfoData(); - txData.setJson("{\"chainId\":2,\"chainName\":\"nuls2\",\"minAvailableNodeNum\":0,\"maxSignatureCount\":0,\"signatureByzantineRatio\":0,\"addressPrefix\":\"tNULS\",\"assetInfoList\":[{\"assetId\":1,\"symbol\":\"NULS\",\"assetName\":\"\",\"usable\":true,\"decimalPlaces\":8},{\"assetId\":8,\"symbol\":\"T1\",\"assetName\":\"t1\",\"usable\":true,\"decimalPlaces\":9}],\"verifierList\":[],\"registerTime\":0}"); + txData.setJson("{\n" + + " \"chainId\":1,\n" + + " \"chainName\":\"nuls\",\n" + + " \"minAvailableNodeNum\":0,\n" + + " \"maxSignatureCount\":100,\n" + + " \"signatureByzantineRatio\":66,\n" + + " \"addressPrefix\":\"NULS\",\n" + + " \"assetInfoList\":[\n" + + " {\n" + + " \"assetId\":1,\n" + + " \"symbol\":\"NULS\",\n" + + " \"assetName\":\"\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":18,\n" + + " \"symbol\":\"LCC\",\n" + + " \"assetName\":\"LCC\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":6\n" + + " },\n" + + " {\n" + + " \"assetId\":4,\n" + + " \"symbol\":\"OBEE\",\n" + + " \"assetName\":\"ObeeNetwork\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":5,\n" + + " \"symbol\":\"Galan\",\n" + + " \"assetName\":\"GAN\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":25,\n" + + " \"symbol\":\"TPU\",\n" + + " \"assetName\":\"TPUSaas\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":33,\n" + + " \"symbol\":\"Goblin\",\n" + + " \"assetName\":\"Goblin\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":45,\n" + + " \"symbol\":\"DATT\",\n" + + " \"assetName\":\"DATT\",\n" + + " \"usable\":false,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":13,\n" + + " \"symbol\":\"DATT\",\n" + + " \"assetName\":\"DATT\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":55,\n" + + " \"symbol\":\"BCNT\",\n" + + " \"assetName\":\"BCNToken\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":19,\n" + + " \"symbol\":\"PETC\",\n" + + " \"assetName\":\"PetCoin\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":17,\n" + + " \"symbol\":\"LCC\",\n" + + " \"assetName\":\"LCC\",\n" + + " \"usable\":false,\n" + + " \"decimalPlaces\":6\n" + + " },\n" + + " {\n" + + " \"assetId\":77,\n" + + " \"symbol\":\"CROS\",\n" + + " \"assetName\":\"cros_test\",\n" + + " \"usable\":false,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":57,\n" + + " \"symbol\":\"Goblin\",\n" + + " \"assetName\":\"Goblin\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":21,\n" + + " \"symbol\":\"EHT\",\n" + + " \"assetName\":\"Earhart\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":87,\n" + + " \"symbol\":\"TRG\",\n" + + " \"assetName\":\"TokenRepublic\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":81,\n" + + " \"symbol\":\"VIBK\",\n" + + " \"assetName\":\"Vibook\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":98,\n" + + " \"symbol\":\"BNF\",\n" + + " \"assetName\":\"BonFi\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":114,\n" + + " \"symbol\":\"KTLYO\",\n" + + " \"assetName\":\"KatalyoToken\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":124,\n" + + " \"symbol\":\"SNEGY\",\n" + + " \"assetName\":\"Sonergy\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":133,\n" + + " \"symbol\":\"FMP\",\n" + + " \"assetName\":\"BitsFlea_Point\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":4\n" + + " },\n" + + " {\n" + + " \"assetId\":128,\n" + + " \"symbol\":\"CBT\",\n" + + " \"assetName\":\"CBToken\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":90,\n" + + " \"symbol\":\"ARCH\",\n" + + " \"assetName\":\"ARCHCOIN\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":10\n" + + " },\n" + + " {\n" + + " \"assetId\":103,\n" + + " \"symbol\":\"MCP\",\n" + + " \"assetName\":\"MyCryptoPlay\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":96,\n" + + " \"symbol\":\"CBLT\",\n" + + " \"assetName\":\"Cobalt\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":91,\n" + + " \"symbol\":\"JTT\",\n" + + " \"assetName\":\"JustTest\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":112,\n" + + " \"symbol\":\"RYIP\",\n" + + " \"assetName\":\"RYIPLATINUM\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":117,\n" + + " \"symbol\":\"MES\",\n" + + " \"assetName\":\"MesChain\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":113,\n" + + " \"symbol\":\"NIA\",\n" + + " \"assetName\":\"Nydronia\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":107,\n" + + " \"symbol\":\"EGR\",\n" + + " \"assetName\":\"EgorasToken\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":116,\n" + + " \"symbol\":\"GHD\",\n" + + " \"assetName\":\"Giftedhands\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":131,\n" + + " \"symbol\":\"ZERO\",\n" + + " \"assetName\":\"ZERO_Token\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":130,\n" + + " \"symbol\":\"FAR\",\n" + + " \"assetName\":\"FarSwap\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":99,\n" + + " \"symbol\":\"RVX\",\n" + + " \"assetName\":\"RiveX\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":136,\n" + + " \"symbol\":\"GGTK\",\n" + + " \"assetName\":\"GGToken\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":146,\n" + + " \"symbol\":\"NABOX\",\n" + + " \"assetName\":\"Nabox_Token\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":132,\n" + + " \"symbol\":\"SHD\",\n" + + " \"assetName\":\"SHIELD\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":143,\n" + + " \"symbol\":\"XNINJA\",\n" + + " \"assetName\":\"XNinjaSwap\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":119,\n" + + " \"symbol\":\"PEET\",\n" + + " \"assetName\":\"Peet\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":149,\n" + + " \"symbol\":\"TICO\",\n" + + " \"assetName\":\"TICOEXToken\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":148,\n" + + " \"symbol\":\"JDI\",\n" + + " \"assetName\":\"JDIToken\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":147,\n" + + " \"symbol\":\"KFI\",\n" + + " \"assetName\":\"KeFiToken\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":152,\n" + + " \"symbol\":\"ARTDECO\",\n" + + " \"assetName\":\"ARTDECO\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":150,\n" + + " \"symbol\":\"TROP\",\n" + + " \"assetName\":\"Interop\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":151,\n" + + " \"symbol\":\"NFD\",\n" + + " \"assetName\":\"NonFungibleDefi\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":157,\n" + + " \"symbol\":\"SMG\",\n" + + " \"assetName\":\"SmaugsNFT\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":158,\n" + + " \"symbol\":\"ICH\",\n" + + " \"assetName\":\"Ideachaincoin\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":159,\n" + + " \"symbol\":\"KSF\",\n" + + " \"assetName\":\"KesefFinance\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":139,\n" + + " \"symbol\":\"Vox\",\n" + + " \"assetName\":\"Vox\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":162,\n" + + " \"symbol\":\"TOM\",\n" + + " \"assetName\":\"TOM\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":156,\n" + + " \"symbol\":\"PTE\",\n" + + " \"assetName\":\"Peet\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":160,\n" + + " \"symbol\":\"APPN\",\n" + + " \"assetName\":\"APPN\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":163,\n" + + " \"symbol\":\"DEFIY\",\n" + + " \"assetName\":\"DeFiFarms\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":164,\n" + + " \"symbol\":\"LIVENFT\",\n" + + " \"assetName\":\"LiveNFTToken\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":170,\n" + + " \"symbol\":\"TXO\",\n" + + " \"assetName\":\"Texo\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":169,\n" + + " \"symbol\":\"8BIT\",\n" + + " \"assetName\":\"8bit\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":168,\n" + + " \"symbol\":\"FIRE\",\n" + + " \"assetName\":\"GreenFire\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":167,\n" + + " \"symbol\":\"VNT\",\n" + + " \"assetName\":\"VENTION\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":171,\n" + + " \"symbol\":\"GMX\",\n" + + " \"assetName\":\"GameX\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":172,\n" + + " \"symbol\":\"CCFI\",\n" + + " \"assetName\":\"CloudCoinFinance\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":176,\n" + + " \"symbol\":\"PRB\",\n" + + " \"assetName\":\"PremiumBlock\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":179,\n" + + " \"symbol\":\"NFTC\",\n" + + " \"assetName\":\"NFTCircle\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":2\n" + + " },\n" + + " {\n" + + " \"assetId\":174,\n" + + " \"symbol\":\"XYL\",\n" + + " \"assetName\":\"xyl\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":175,\n" + + " \"symbol\":\"BDAM\",\n" + + " \"assetName\":\"BDAMCoin\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":177,\n" + + " \"symbol\":\"DNF\",\n" + + " \"assetName\":\"DNFT\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":178,\n" + + " \"symbol\":\"WHX\",\n" + + " \"assetName\":\"WHITEX\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":183,\n" + + " \"symbol\":\"ZOZO\",\n" + + " \"assetName\":\"ZoZotoken\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":181,\n" + + " \"symbol\":\"EMC2\",\n" + + " \"assetName\":\"EINSTEINTOKEN\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":9\n" + + " },\n" + + " {\n" + + " \"assetId\":180,\n" + + " \"symbol\":\"MVH\",\n" + + " \"assetName\":\"MovieCash\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":191,\n" + + " \"symbol\":\"GCC\",\n" + + " \"assetName\":\"GLOBALCOMMCOIN\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":194,\n" + + " \"symbol\":\"OLD\",\n" + + " \"assetName\":\"Oldtimer\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":198,\n" + + " \"symbol\":\"DGP\",\n" + + " \"assetName\":\"DGPAYMENT\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":225,\n" + + " \"symbol\":\"ZINA\",\n" + + " \"assetName\":\"Zinari\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":226,\n" + + " \"symbol\":\"FUSE\",\n" + + " \"assetName\":\"Niftyfuse\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":196,\n" + + " \"symbol\":\"AVN\",\n" + + " \"assetName\":\"AVNRichToken\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":234,\n" + + " \"symbol\":\"LAND\",\n" + + " \"assetName\":\"Landshare\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":237,\n" + + " \"symbol\":\"Alkom\",\n" + + " \"assetName\":\"Alkom\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":235,\n" + + " \"symbol\":\"TIC\",\n" + + " \"assetName\":\"TreasureIsland\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":187,\n" + + " \"symbol\":\"XTMC\",\n" + + " \"assetName\":\"XTMCSWAPAPP\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":18\n" + + " },\n" + + " {\n" + + " \"assetId\":242,\n" + + " \"symbol\":\"VOLT\",\n" + + " \"assetName\":\"Volterra\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":240,\n" + + " \"symbol\":\"UV\",\n" + + " \"assetName\":\"Unityventures\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":8\n" + + " },\n" + + " {\n" + + " \"assetId\":0,\n" + + " \"symbol\":\"OxSGD\",\n" + + " \"assetName\":\"OxSGD\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":4\n" + + " },\n" + + " {\n" + + " \"assetId\":276,\n" + + " \"symbol\":\"OxSGD\",\n" + + " \"assetName\":\"OxSGD\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":4\n" + + " },\n" + + " {\n" + + " \"assetId\":281,\n" + + " \"symbol\":\"OxUSD\",\n" + + " \"assetName\":\"OxUSD\",\n" + + " \"usable\":true,\n" + + " \"decimalPlaces\":4\n" + + " }\n" + + " ],\n" + + " \"verifierList\":[ \n" + + " \"NULSd6Hga4mQkHAnQdhUiMmv1V3kQ4a84JaSb\",\n" + + "\"NULSd6HgU65xXgWR2jrXEKwXivQj6WCBYVhoA\",\n" + + "\"NULSd6HgX1bNap7DxUftecymeB7VjdHz4HvKU\",\n" + + "\"NULSd6HgetcSk3cZz5ps92mQUzaptUxv6WRcT\",\n" + + "\"NULSd6HgY2LiyEDvMjsHqZpyajxSXEgk1mcxs\",\n" + + "\"NULSd6HgapEiSk1PMYBZtbWBRMcCyjm7Vgjri\",\n" + + "\"NULSd6HgirJR5i3SkwADF96QHP6uhLvBHE2yQ\",\n" + + "\"NULSd6Hghpud5oDJ6FPXNwLiiU8xryqE1sYmv\",\n" + + "\"NULSd6HgaSJ21zt1Qppb4rbuec2AkuaQLgnk8\",\n" + + "\"NULSd6Hgb7SV891gcu1FB2V6pRDvSUcfd75o6\",\n" + + "\"NULSd6HgbJmUep4wyreghHDk28AusSCrSuDMF\",\n" + + "\"NULSd6HgcR5ouh1aDU3oktEoJGQConj4sr1KR\",\n" + + "\"NULSd6HghM5wyVjegBaDsCkW9dvBnkuucejxw\",\n" + + "\"NULSd6HgapV9vQS5NKCaJSMWa2uHgWxX13nGJ\",\n" + + "\"NULSd6HgjKGXg6dk1K7vagf4kLDktf7DwsoXg\",\n" + + "\"NULSd6HgZcP5H8Fg4y5Wf8AwiZ8nVhVZ4jBcS\",\n" + + "\"NULSd6HgbhkGyxzvvosnRYWgnLAusCuWrtLNT\",\n" + + "\"NULSd6HgU7dsGGbvWZBFcnLjGiJHz7ZA8x6to\",\n" + + "\"NULSd6HghrhYaMdRcskPkM8vB65XX9v88EJEv\",\n" + + "\"NULSd6HgXaZUYDy8DCopGMwEPnervgKbtqFDS\",\n" + + "\"NULSd6HgcC78MaUw7tDo88rmg61tHCvZoEaXP\",\n" + + "\"NULSd6Hga7pDvwJeQ3ufen3rubekkDFtWNZDg\",\n" + + "\"NULSd6HgYLo5hPNcgqKtNtpA8dhC3Y37v5Ra9\",\n" + + "\"NULSd6Hghv5CQdQwfjATtw76MuWTnP7DT4xER\",\n" + + "\"NULSd6HgZeQRuhxXZbCAELYHNVEm8bvSULR27\",\n" + + "\"NULSd6HgiCCVyZvs162WNS6Gzvf22aFN8Y47P\",\n" + + "\"NULSd6HgdcJnk1R18vS73DGj38EtWMMdipogY\",\n" + + "\"NULSd6HgWTKbD7YBAAvP7NjKik4nRWuSw76Ny\",\n" + + "\"NULSd6HgYTwiDWmisFDqgDzcK8Sf197G3L28Z\",\n" + + "\"NULSd6Hgj56Sotnk28qnRWoeQ2Ew3KuPAXnpg\",\n" + + "\"NULSd6HgjHLnaPdyPYADSZy9UqewvJFEkAUP1\",\n" + + "\"NULSd6HgbcWZAxSGf38JxX9opKwgVuC6B8Hin\",\n" + + "\"NULSd6HgjF8iCrjpymFy6LVRmEjQG8AFayFDi\",\n" + + "\"NULSd6HgcUQ4paNjBiRSXevwpYGhVVnvwdks8\",\n" + + "\"NULSd6HgfVbGkmqCD1ycCPj2ZMJ7hYLrBu6eM\",\n" + + "\"NULSd6Hghpg9Nk7BNrsAccV49FAVyvMqCVWnv\",\n" + + "\"NULSd6HgX4mBo5v9nwESRwFn9Ns9LUqYAE91L\",\n" + + "\"NULSd6Hgh1HF2wmtRRTZTwYiVUGVriJnm8Ucs\",\n" + + "\"NULSd6HgZDQifPEXXTmUa2RzLLCrS4kzauf5C\",\n" + + "\"NULSd6HgVsgcK6Mt4cPyyPBZ9umZnacb7bAr7\",\n" + + "\"NULSd6HgdMZ6fzUp4my8VkascvWx2LcKJNFMp\",\n" + + "\"NULSd6HgVtmHWQsKidqHuTB1cV9kGPVciXNXk\",\n" + + "\"NULSd6HgVrfwxnmh7ycBddC8NDQ5LqDz6vK69\",\n" + + "\"NULSd6Hge5eGAaryhAQtZjHxSNw1qwDtHARHJ\",\n" + + "\"NULSd6HgcXGFs46UbyNDUaLuE4AviF5GCTbyh\",\n" + + "\"NULSd6HgeLusFRaAJNkR9ofm5Rx32F1whpKe4\",\n" + + "\"NULSd6Hgd81Ce2HqUmgFxwLvwPNXknGbaaNMu\",\n" + + "\"NULSd6HggQ1xMawWTMWyPtKWciMfR4CTavLrp\",\n" + + "\"NULSd6HgWvZUZTRzTURM8hRmWBvpzVmHTB1gn\",\n" + + "\"NULSd6HghnX3XnuFFTLfzx6TEzMsX6RKeZWsu\",\n" + + "\"NULSd6HgW5vV415MNoY2JTCaxa7NhcaHSo8Fg\",\n" + + "\"NULSd6Hgezi6y7LCRW4iLrXELyvH36fN12wHK\",\n" + + "\"NULSd6HgctDviYK6yDBKJd6WGhRRkByLhUrva\",\n" + + "\"NULSd6HgZbtnPKbxWAhg994HNQG76wSs4RAPq\",\n" + + "\"NULSd6HgZBcw88QkNen1wdM7EVaJ595kkHddN\",\n" + + "\"NULSd6HgiQ5CTko7Zx59vcBeHyxPAJQ7P8T48\",\n" + + "\"NULSd6HgXfnDCizGjLfBxrkV59WN4uTGzHMdi\",\n" + + "\"NULSd6HggpjM8RB5WbjzLc7bLvQDjHuRcongN\",\n" + + "\"NULSd6HgZZiqYSDiyz3xGN4tzNhgrho9EN59H\",\n" + + "\"NULSd6HgdNumANdW3LxB7NEZd4oa7otR4LkPN\",\n" + + "\"NULSd6HgcpKcxYFkeRDg8MJrSEF1A1SkH2KRM\",\n" + + "\"NULSd6HgXhUTCKGEwHiGmnPmWFAvXyANTdjrn\",\n" + + "\"NULSd6Hgh5VupJJ7Evabv9QQ2Pst8mjPS4dXT\",\n" + + "\"NULSd6HgWyGYLML5CadRiND5RJghYc5vbiycJ\",\n" + + "\"NULSd6HgfLT3nmbxtHZm8CsiTwjs1HxXJtmDT\",\n" + + "\"NULSd6HgggfeRCjx5Ka4LVRug4i6q5ymfaag8\",\n" + + "\"NULSd6HgYE7AKJmkAoPtjXxSHPkqxzmyPebkT\",\n" + + "\"NULSd6HghcXawGBzwaufEoHchhWJrsJwSsitY\",\n" + + "\"NULSd6HgfwTZKqKVnV3awiDKnEbF7RjZufWCN\",\n" + + "\"NULSd6Hgfd4H28qGCrzGdhgX2G5PKj6rejsUG\",\n" + + "\"NULSd6HgeTroMh3M59hbMWqeYqbgVXioa8Jmz\",\n" + + "\"NULSd6HgefSM6RkURTdWu1i9mB96ufGfxqg71\",\n" + + "\"NULSd6HghMrN2DTVmcBgiomKhvUETkg6c6N8E\",\n" + + "\"NULSd6HgZivXvXs4su6cuyFzgtBTkk9fTqxyy\",\n" + + "\"NULSd6HgWWEmZSxffcNVHc1kjbebkejWjVtpV\",\n" + + "\"NULSd6HgbBmFpomGuvmSa76dirtzAt2rWKn4w\",\n" + + "\"NULSd6HgXNrFd9NJMF5ExuSnGteKgHSKsfmXX\",\n" + + "\"NULSd6HgiYHK1WWeNWk1Dx1wUb1usQXQXic11\",\n" + + "\"NULSd6Hge7xHDnvsSpnzbR2gWHd31zJ1How11\",\n" + + "\"NULSd6Hgc5VNP4rF4wxdiXEQKpBKUE4w5RS22\",\n" + + "\"NULSd6HgeQwXLdre69ArkqVZNDqMLU4CaAz33\",\n" + + "\"NULSd6HgcjAKAgq8jjXgBCcNLEJUvJEYcoj44\",\n" + + "\"NULSd6HgiDdTjcuvhqzm3bomyBFZmosV3ei55\"\n" + + " ],\n" + + " \"registerTime\":0\n" + + " }"); tx.setTxData(txData.serialize()); CoinData coinData = new CoinData(); CoinFrom from = new CoinFrom(); from.setAddress(address); - from.setAmount(BigInteger.valueOf(1000000)); - from.setAssetsChainId(2); + from.setAmount(BigInteger.valueOf(30000000)); + from.setAssetsChainId(1); from.setAssetsId(1); from.setLocked((byte) 0); - from.setNonce(HexUtil.decode("ace23d6fad9760d0")); + from.setNonce(HexUtil.decode("7bf509a99dbeceb5")); coinData.getFrom().add(from); CoinTo to = new CoinTo(); to.setAddress(address); to.setAmount(BigInteger.ZERO); to.setAssetsId(1); - to.setAssetsChainId(2); + to.setAssetsChainId(1); to.setLockTime(0); coinData.getTo().add(to); @@ -71,7 +747,8 @@ public void test() throws Exception { tx.setTransactionSignature(transactionSignature.serialize()); Log.info(tx.getHash().toHex()); Log.info(HexUtil.encode(tx.serialize())); - sendTx(2, HexUtil.encode(tx.serialize())); + Log.info("" + tx.size()); +// sendTx(2, HexUtil.encode(tx.serialize())); } @SuppressWarnings("unchecked") diff --git a/module/nuls-smart-contract/pom.xml b/module/nuls-smart-contract/pom.xml index b008d2c164..d2b01d588d 100644 --- a/module/nuls-smart-contract/pom.xml +++ b/module/nuls-smart-contract/pom.xml @@ -138,6 +138,12 @@ sdk4j 1.1.6.RELEASE test + + + org.mybatis + mybatis + + diff --git a/module/nuls-smart-contract/src/main/java/io/nuls/contract/helper/ContractHelper.java b/module/nuls-smart-contract/src/main/java/io/nuls/contract/helper/ContractHelper.java index 01d3dd412d..2bf087dc35 100644 --- a/module/nuls-smart-contract/src/main/java/io/nuls/contract/helper/ContractHelper.java +++ b/module/nuls-smart-contract/src/main/java/io/nuls/contract/helper/ContractHelper.java @@ -515,6 +515,7 @@ public Result getContractAddressInfo(int chainId, byte[] return contractAddressStorageService.getContractAddressInfo(chainId, contractAddressBytes); } + private Set unlockedNrc20Set = new HashSet<>(); public Result getContractToken(int chainId, BlockHeader blockHeader, String address, String contractAddress) { try { if (StringUtils.isBlank(contractAddress) || StringUtils.isBlank(address)) { @@ -545,10 +546,23 @@ public Result getContractToken(int chainId, BlockHeader block result = getFailed(); result.setMsg(ContractUtil.simplifyErrorMsg(programResult.getErrorMessage())); } else { + BigInteger lockAmount = BigInteger.ZERO; + if (!unlockedNrc20Set.contains(contractAddress)) { + ProgramResult lockedProgramResult = this.invokeViewMethod(chainId, null, false, currentStateRoot, blockHeight, contractAddressBytes, "lockedBalanceOf", null, ContractUtil.twoDimensionalArray(new Object[]{address})); + if (!lockedProgramResult.isSuccess()) { + String errorMessage = lockedProgramResult.getErrorMessage(); + if (errorMessage != null && errorMessage.contains("can't find method")) { + unlockedNrc20Set.add(contractAddress); + } + } else { + lockAmount = new BigInteger(lockedProgramResult.getResult()); + } + } result = getSuccess(); ContractTokenInfo tokenInfo = new ContractTokenInfo(contractAddress, po.getNrc20TokenName(), po.getDecimals(), new BigInteger(programResult.getResult()), po.getNrc20TokenSymbol(), po.getBlockHeight()); ProgramExecutor track = getProgramExecutor(chainId).begin(currentStateRoot); tokenInfo.setStatus(ContractStatus.getStatus(track.status(AddressTool.getAddress(tokenInfo.getContractAddress())).ordinal())); + tokenInfo.setLockAmount(lockAmount); result.setData(tokenInfo); } return result; diff --git a/module/nuls-smart-contract/src/main/java/io/nuls/contract/model/bo/ContractTokenInfo.java b/module/nuls-smart-contract/src/main/java/io/nuls/contract/model/bo/ContractTokenInfo.java index d4882b53b1..2fb31984c1 100644 --- a/module/nuls-smart-contract/src/main/java/io/nuls/contract/model/bo/ContractTokenInfo.java +++ b/module/nuls-smart-contract/src/main/java/io/nuls/contract/model/bo/ContractTokenInfo.java @@ -39,6 +39,7 @@ public class ContractTokenInfo { private String name; private String symbol; private BigInteger amount; + private BigInteger lockAmount; private long decimals; private long blockHeight; private ContractStatus status; @@ -49,12 +50,21 @@ public ContractTokenInfo() { public ContractTokenInfo(String contractAddress, String name, long decimals, BigInteger amount, String symbol, long blockHeight) { this.name = name; this.amount = amount; + this.lockAmount = BigInteger.ZERO; this.contractAddress = contractAddress; this.decimals = decimals; this.symbol = symbol; this.blockHeight = blockHeight; } + public BigInteger getLockAmount() { + return lockAmount; + } + + public void setLockAmount(BigInteger lockAmount) { + this.lockAmount = lockAmount; + } + public ContractTokenInfo setName(String name) { this.name = name; return this; diff --git a/module/nuls-smart-contract/src/main/java/io/nuls/contract/model/dto/ContractTokenInfoDto.java b/module/nuls-smart-contract/src/main/java/io/nuls/contract/model/dto/ContractTokenInfoDto.java index 4b0db0d169..042f6d3f28 100644 --- a/module/nuls-smart-contract/src/main/java/io/nuls/contract/model/dto/ContractTokenInfoDto.java +++ b/module/nuls-smart-contract/src/main/java/io/nuls/contract/model/dto/ContractTokenInfoDto.java @@ -42,8 +42,10 @@ public class ContractTokenInfoDto { private String name; @ApiModelProperty(description = "token符号") private String symbol; - @ApiModelProperty(description = "token数量") + @ApiModelProperty(description = "token可用数量") private String amount; + @ApiModelProperty(description = "token锁定数量") + private String lockAmount; @ApiModelProperty(description = "token支持的小数位数") private long decimals; @ApiModelProperty(description = "合约创建时的区块高度") @@ -62,6 +64,7 @@ public ContractTokenInfoDto(ContractTokenInfo info) { this.name = info.getName(); this.symbol = info.getSymbol(); this.amount = ContractUtil.bigInteger2String(info.getAmount()); + this.lockAmount = ContractUtil.bigInteger2String(info.getLockAmount()); this.decimals = info.getDecimals(); this.blockHeight = info.getBlockHeight(); this.status = info.getStatus().status(); @@ -99,6 +102,14 @@ public void setAmount(String amount) { this.amount = amount; } + public String getLockAmount() { + return lockAmount; + } + + public void setLockAmount(String lockAmount) { + this.lockAmount = lockAmount; + } + public long getDecimals() { return decimals; } diff --git a/module/nuls-smart-contract/src/test/java/io/nuls/contract/serialize/TxSerialization.java b/module/nuls-smart-contract/src/test/java/io/nuls/contract/serialize/TxSerialization.java index 60909ddac4..16e8993eb3 100644 --- a/module/nuls-smart-contract/src/test/java/io/nuls/contract/serialize/TxSerialization.java +++ b/module/nuls-smart-contract/src/test/java/io/nuls/contract/serialize/TxSerialization.java @@ -30,6 +30,7 @@ import io.nuls.base.data.*; import io.nuls.base.signture.SignatureUtil; import io.nuls.contract.model.txdata.CallContractData; +import io.nuls.contract.model.txdata.ContractData; import io.nuls.contract.model.txdata.CreateContractData; import io.nuls.core.crypto.HexUtil; import io.nuls.core.exception.NulsException; @@ -44,6 +45,7 @@ import java.io.IOException; import java.math.BigInteger; import java.nio.charset.StandardCharsets; +import java.util.Base64; import java.util.HashSet; import java.util.Set; @@ -102,9 +104,20 @@ public void testType18() throws NulsException, IOException { @Test public void test26() throws NulsException { - String hex="1a00082f126100041a000000d20217020001bc9cf2a09f0d1dbe7ab0a7dca2ccb87d12da6a99020008000008af2f0000000000000000000000000000000000000000000000000000000008000000000000000000170200022744df0b0cc3c0056c6d496db212d680c7f422250200010040420f000000000000000000000000000000000000000000000000000000000008f52629ee1ce14627000117050001bc9cf2a09f0d1dbe7ab0a7dca2ccb87d12da6a99020008000008af2f00000000000000000000000000000000000000000000000000000000000000000000000000"; + String hex="1000c710266100aa010001c3d790463856a0e8b0f8f10ea8f4703dcd1b24e2010002a9ae0501816eee73f8a2b2048197bec81d0247d50000000000000000000000000000000000000000000000000000000000000000d9800000000000001900000000000000087472616e73666572000201254e554c53643648676675704e70515876507774787339594c77787466747561656942596f420118313030303030303030303030303030303030303030303030480117010001c3d790463856a0e8b0f8f10ea8f4703dcd1b24e201000100d11b0e000000000000000000000000000000000000000000000000000000000008f3506f703333db3d00006921037331dd5df517ae177951b47c29d94e1bc850fada766a9a83fb0042436d43d1da46304402206ac8e190d01a5d70fd5e72dab79ab66cdf6ec754fd7e1d669539e6b577762e82022061a113288b2d1c7d45417183948e01d374b3057a9514a46a1faba39261f8c365"; Transaction tx = new Transaction(); tx.parse(HexUtil.decode(hex), 0); + CallContractData data = new CallContractData(); + data.parse(tx.getTxData(), 0); + System.out.println(); + } + + @Test + public void desContractData() throws NulsException { + String base64 = "AQABw9eQRjhWoOiw+PEOqPRwPc0bJOIBAAKprgUBgW7uc/iisgSBl77IHQJH1QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA2YAAAAAAAAAZAAAAAAAAAAh0cmFuc2ZlcgACASVOVUxTZDZIZ2Z1cE5wUVh2UHd0eHM5WUx3eHRmdHVhZWlCWW9CARgxMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDA="; + byte[] decode = Base64.getDecoder().decode(base64); + CallContractData data = new CallContractData(); + data.parse(decode, 0); System.out.println(); } diff --git a/module/nuls-smart-contract/src/test/java/io/nuls/contract/tx/nrc20/ContractNRC20TokenSendTxTest.java b/module/nuls-smart-contract/src/test/java/io/nuls/contract/tx/nrc20/ContractNRC20TokenSendTxTest.java index f2f9db2971..5c02fd791d 100644 --- a/module/nuls-smart-contract/src/test/java/io/nuls/contract/tx/nrc20/ContractNRC20TokenSendTxTest.java +++ b/module/nuls-smart-contract/src/test/java/io/nuls/contract/tx/nrc20/ContractNRC20TokenSendTxTest.java @@ -67,7 +67,7 @@ public void createContract() throws Exception { String symbol = "KongQiBi"; String amount = BigDecimal.TEN.pow(10).toPlainString(); String decimals = "2"; - Map params = this.makeCreateParams(sender, contractCode, "kqb", remark, name, symbol, amount, decimals); + Map params = this.makeCreateParams("tNULSeBaMoG1oaW1JZnh6Ly65Ttp6raeTFBfCG", contractCode, "kqb", remark, name, symbol, amount, decimals); Response cmdResp2 = ResponseMessageProcessor.requestAndResponse(ModuleE.SC.abbr, CREATE, params); Map result = (HashMap) (((HashMap) cmdResp2.getResponseData()).get(CREATE)); assertTrue(cmdResp2, result); diff --git a/module/nuls-transaction/pom.xml b/module/nuls-transaction/pom.xml index fd41bb3cff..72c3b9e522 100644 --- a/module/nuls-transaction/pom.xml +++ b/module/nuls-transaction/pom.xml @@ -11,11 +11,6 @@ nuls-transaction - - io.nuls.v2 - nuls-core-h2 - ${core.version} - com.google.code.gson gson diff --git a/testfile b/testfile deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/version b/version index 10c2c0c3d6..c6436a8536 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.10.0 +2.10.2