| @@ -192,7 +192,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); | |||
| you may not use this file except in compliance with the License. | |||
| You may obtain a copy of the License at | |||
| http://www.apache.org/licenses/LICENSE-2.0 | |||
| http://www.apache.org/licenses/LICENSE-2.0 | |||
| Unless required by applicable law or agreed to in writing, software | |||
| distributed under the License is distributed on an "AS IS" BASIS, | |||
| @@ -1,10 +1,12 @@ | |||
| package com.jd.blockchain.consts; | |||
| /** | |||
| * A const registeration of codes of all data contracts in ledger model; | |||
| * | |||
| * @author huanghaiquan | |||
| * | |||
| */ | |||
| public interface TypeCodes { | |||
| public interface DataCodes { | |||
| public static final int BYTES_VALUE = 0x80; | |||
| @@ -59,11 +61,11 @@ public interface TypeCodes { | |||
| public static final int METADATA_CONSENSUS_PARTICIPANT = 0x621; | |||
| // public static final int METADATA_CONSENSUS_NODE = 0x630; | |||
| // public static final int METADATA_CONSENSUS_NODE = 0x630; | |||
| public static final int METADATA_CONSENSUS_SETTING = 0x631; | |||
| // public static final int METADATA_PARTICIPANT_INFO = 0x640; | |||
| // public static final int METADATA_PARTICIPANT_INFO = 0x640; | |||
| public static final int METADATA_CRYPTO_SETTING = 0x642; | |||
| @@ -87,7 +89,7 @@ public interface TypeCodes { | |||
| public static final int ENUM_TYPE_TRANSACTION_STATE = 0xB22; | |||
| public static final int ENUM_TYPE_DATA_TYPE= 0xB23; | |||
| public static final int ENUM_TYPE_BYTES_VALUE_TYPE = 0xB23; | |||
| public static final int DIGITALSIGNATURE = 0xB30; | |||
| @@ -103,8 +105,6 @@ public interface TypeCodes { | |||
| public static final int REQUEST_ENDPOINT = 0xD20; | |||
| // ------------------ 共识相关 ---------------- | |||
| public static final int CONSENSUS = 0x1000; | |||
| @@ -112,12 +112,11 @@ public interface TypeCodes { | |||
| public static final int CONSENSUS_ACTION_REQUEST = CONSENSUS | 0x01; | |||
| public static final int CONSENSUS_ACTION_RESPONSE = CONSENSUS | 0x02; | |||
| public static final int CONSENSUS_SETTINGS = CONSENSUS | 0x03; | |||
| public static final int CONSENSUS_NODE_SETTINGS = CONSENSUS | 0x04; | |||
| public static final int CONSENSUS_CLI_INCOMING_SETTINGS = CONSENSUS | 0x05; | |||
| // ------------------ 共识相关(BFTSMART) ---------------- | |||
| @@ -126,7 +125,7 @@ public interface TypeCodes { | |||
| public static final int CONSENSUS_BFTSMART_SETTINGS = CONSENSUS_BFTSMART | 0x01; | |||
| public static final int CONSENSUS_BFTSMART_NODE_SETTINGS = CONSENSUS_BFTSMART | 0x02; | |||
| public static final int CONSENSUS_BFTSMART_CLI_INCOMING_SETTINGS = CONSENSUS_BFTSMART | 0x03; | |||
| public static final int CONSENSUS_BFTSMART_BLOCK_SETTINGS = CONSENSUS_BFTSMART | 0x04; | |||
| @@ -144,5 +143,4 @@ public interface TypeCodes { | |||
| public static final int CONSENSUS_MSGQUEUE_BLOCK_SETTINGS = CONSENSUS_MSGQUEUE | 0x05; | |||
| } | |||
| @@ -10,7 +10,7 @@ import com.jd.blockchain.utils.io.BytesOutputBuffer; | |||
| import com.jd.blockchain.utils.io.BytesSlice; | |||
| import com.jd.blockchain.utils.io.BytesUtils; | |||
| public class BinaryEncodingUtils { | |||
| public class BinaryProtocol { | |||
| public static void encode(Object data, Class<?> contractType, OutputStream out) { | |||
| @@ -2,7 +2,6 @@ package com.jd.blockchain.binaryproto; | |||
| import com.jd.blockchain.utils.io.BytesInputStream; | |||
| import com.jd.blockchain.utils.io.BytesOutputBuffer; | |||
| import com.jd.blockchain.utils.io.BytesSlice; | |||
| /** | |||
| * 二进制编码器; | |||
| @@ -13,6 +13,9 @@ public class DataContractRegistry { | |||
| private DataContractRegistry() { | |||
| } | |||
| //TODO: Refactor contract type registering in service provider mode; | |||
| public static DataContractEncoder register(Class<?> contractType) { | |||
| DataContractEncoder encoder = DataContractContext.resolve(contractType); | |||
| return encoder; | |||
| @@ -5,8 +5,6 @@ import java.lang.annotation.Retention; | |||
| import java.lang.annotation.RetentionPolicy; | |||
| import java.lang.annotation.Target; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| /** | |||
| * 标记一个接口的字段作为数据契约的字段; | |||
| * <p> | |||
| @@ -39,11 +37,11 @@ public @interface DataField { | |||
| * 基本数据类型; | |||
| * <p> | |||
| * | |||
| * 如果字段的类型属于 {@link ValueType} 枚举中的基本数据类型,则需要显式指定一种具体的类型; | |||
| * 如果字段的类型属于 {@link PrimitiveType} 枚举中的基本数据类型,则需要显式指定一种具体的类型; | |||
| * | |||
| * @return | |||
| */ | |||
| ValueType primitiveType() default ValueType.NIL; | |||
| PrimitiveType primitiveType() default PrimitiveType.NIL; | |||
| /** | |||
| * 是否是枚举类型; | |||
| @@ -80,8 +78,8 @@ public @interface DataField { | |||
| /** | |||
| * 最大长度,单位为“byte” | |||
| * <p> | |||
| * 仅对于文本、字节数组、大整数等相关的数据类型有效(即:{@link ValueType} 枚举中编码大于等于 0x20 | |||
| * {@link ValueType#TEXT}的数据类型); | |||
| * 仅对于文本、字节数组、大整数等相关的数据类型有效(即:{@link PrimitiveType} 枚举中编码大于等于 0x20 | |||
| * {@link PrimitiveType#TEXT}的数据类型); | |||
| * | |||
| * @return | |||
| */ | |||
| @@ -0,0 +1,24 @@ | |||
| package com.jd.blockchain.binaryproto; | |||
| public interface DataType { | |||
| /** | |||
| * 空值; | |||
| */ | |||
| public static final byte NIL = (byte) 0x00; | |||
| /** | |||
| * 布尔; | |||
| */ | |||
| public static final byte BOOLEAN = (byte) 0x01; | |||
| /** | |||
| * 数值; | |||
| */ | |||
| public static final byte NUMERIC = (byte) 0x10; | |||
| public static final byte TEXT = (byte) 0x20; | |||
| public static final byte BINARY = (byte) 0x40; | |||
| } | |||
| @@ -5,8 +5,6 @@ import java.lang.annotation.Retention; | |||
| import java.lang.annotation.RetentionPolicy; | |||
| import java.lang.annotation.Target; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| @Target({ ElementType.FIELD, ElementType.METHOD }) | |||
| @Retention(RetentionPolicy.RUNTIME) | |||
| public @interface EnumField { | |||
| @@ -15,11 +13,11 @@ public @interface EnumField { | |||
| * 枚举值的类型; | |||
| * | |||
| * <p> | |||
| * 注:只支持 {@link ValueType#INT8} ~ {@link ValueType#INT32} 这几种类型; | |||
| * 注:只支持 {@link PrimitiveType#INT8} ~ {@link PrimitiveType#INT32} 这几种类型; | |||
| * | |||
| * | |||
| * @return | |||
| */ | |||
| ValueType type(); | |||
| PrimitiveType type(); | |||
| } | |||
| @@ -1,9 +1,5 @@ | |||
| package com.jd.blockchain.binaryproto; | |||
| import java.util.Set; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| public interface EnumSpecification { | |||
| int getCode(); | |||
| @@ -14,7 +10,7 @@ public interface EnumSpecification { | |||
| long getVersion(); | |||
| ValueType getValueType(); | |||
| PrimitiveType getValueType(); | |||
| int[] getItemValues(); | |||
| @@ -1,7 +1,5 @@ | |||
| package com.jd.blockchain.binaryproto; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| /** | |||
| * 表示数据契约字段的格式标准; | |||
| * | |||
| @@ -35,11 +33,11 @@ public interface FieldSpec { | |||
| * 字段的值的类型; | |||
| * <p> | |||
| * 如果不是字段的值不是基本类型,则返回 null(即: {@link DataField#primitiveType()} 设置为 | |||
| * {@link ValueType#NIL}); | |||
| * {@link PrimitiveType#NIL}); | |||
| * | |||
| * @return | |||
| */ | |||
| ValueType getPrimitiveType(); | |||
| PrimitiveType getPrimitiveType(); | |||
| /** | |||
| * 字段的值引用的枚举契约; | |||
| @@ -0,0 +1,92 @@ | |||
| package com.jd.blockchain.binaryproto; | |||
| /** | |||
| * 键值操作的数据类型; | |||
| * | |||
| * @author huanghaiquan | |||
| * | |||
| */ | |||
| public enum PrimitiveType { | |||
| /** | |||
| * 空; | |||
| */ | |||
| NIL(DataType.NIL), | |||
| /** | |||
| * 布尔型; | |||
| */ | |||
| BOOLEAN(DataType.BOOLEAN), | |||
| /** | |||
| * 数值型: | |||
| */ | |||
| INT8((byte) (DataType.NUMERIC | 0x01)), | |||
| INT16((byte) (DataType.NUMERIC | 0x02)), | |||
| INT32((byte) (DataType.NUMERIC | 0x03)), | |||
| INT64((byte) (DataType.NUMERIC | 0x04)), | |||
| /** | |||
| * 日期时间; | |||
| */ | |||
| DATETIME((byte) (DataType.NUMERIC | 0x08)), | |||
| /** | |||
| * 文本数据; | |||
| */ | |||
| TEXT(DataType.TEXT), | |||
| /** | |||
| * 文本数据; | |||
| */ | |||
| JSON((byte) (DataType.TEXT | 0x01)), | |||
| /** | |||
| * 文本数据; | |||
| */ | |||
| XML((byte) (DataType.TEXT | 0x02)), | |||
| /** | |||
| * 二进制数据; | |||
| */ | |||
| BYTES(DataType.BINARY), | |||
| /** | |||
| * 大整数; | |||
| */ | |||
| BIG_INT((byte) (DataType.BINARY | 0x01)), | |||
| /** | |||
| * 图片; | |||
| */ | |||
| IMG((byte) (DataType.BINARY | 0x02)), | |||
| /** | |||
| * 视频; | |||
| */ | |||
| VIDEO((byte) (DataType.BINARY | 0x03)), | |||
| /** | |||
| * 位置坐标; | |||
| */ | |||
| LOCATION((byte) (DataType.BINARY | 0x04)); | |||
| public final byte CODE; | |||
| private PrimitiveType(byte code) { | |||
| this.CODE = code; | |||
| } | |||
| public static PrimitiveType valueOf(byte code) { | |||
| for (PrimitiveType dataType : PrimitiveType.values()) { | |||
| if (dataType.CODE == code) { | |||
| return dataType; | |||
| } | |||
| } | |||
| throw new IllegalArgumentException("Code[" + code + "] not suppported by PrimitiveType!"); | |||
| } | |||
| } | |||
| @@ -2,7 +2,6 @@ package com.jd.blockchain.binaryproto.impl; | |||
| import com.jd.blockchain.utils.io.BytesInputStream; | |||
| import com.jd.blockchain.utils.io.BytesOutputBuffer; | |||
| import com.jd.blockchain.utils.io.BytesSlice; | |||
| import com.jd.blockchain.utils.io.NumberMask; | |||
| public abstract class AbstractDynamicValueConverter implements DynamicValueConverter { | |||
| @@ -5,7 +5,6 @@ import java.lang.reflect.Method; | |||
| import java.util.ArrayList; | |||
| import java.util.Arrays; | |||
| import java.util.Collection; | |||
| import java.util.Collections; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @@ -18,12 +17,12 @@ import com.jd.blockchain.binaryproto.DataContractEncoder; | |||
| import com.jd.blockchain.binaryproto.DataContractException; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.binaryproto.DataSpecification; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.binaryproto.EnumContract; | |||
| import com.jd.blockchain.binaryproto.EnumField; | |||
| import com.jd.blockchain.binaryproto.EnumSpecification; | |||
| import com.jd.blockchain.binaryproto.FieldSpec; | |||
| import com.jd.blockchain.binaryproto.impl.EnumSpecificationInfo.EnumConstant; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.utils.io.BytesSerializable; | |||
| import com.jd.blockchain.utils.io.BytesUtils; | |||
| import com.jd.blockchain.utils.security.SHA256Hash; | |||
| @@ -66,23 +65,23 @@ public class DataContractContext { | |||
| private static Map<Class<?>, EnumSpecification> enumContractSpecMap = new ConcurrentHashMap<>(); | |||
| private static Map<ValueType, Map<Class<?>, ValueConverter>> primitiveTypeConverters = new HashMap<>(); | |||
| private static Map<PrimitiveType, Map<Class<?>, ValueConverter>> primitiveTypeConverters = new HashMap<>(); | |||
| static { | |||
| addConverterMapping(ValueType.BOOLEAN, boolean.class, new BoolConverter()); | |||
| addConverterMapping(ValueType.BOOLEAN, Boolean.class, new BoolWrapperConverter()); | |||
| addConverterMapping(ValueType.INT8, byte.class, new Int8ByteConverter()); | |||
| addConverterMapping(ValueType.INT8, Byte.class, new Int8ByteWrapperConverter()); | |||
| addConverterMapping(ValueType.INT16, short.class, new Int16ShortConverter()); | |||
| addConverterMapping(ValueType.INT16, Short.class, new Int16ShortWrapperConverter()); | |||
| addConverterMapping(ValueType.INT16, char.class, new Int16CharConverter()); | |||
| addConverterMapping(ValueType.INT16, Character.class, new Int16CharWrapperConverter()); | |||
| addConverterMapping(ValueType.INT32, int.class, new Int32IntConverter()); | |||
| addConverterMapping(ValueType.INT32, Integer.class, new Int32IntWrapperConverter()); | |||
| addConverterMapping(ValueType.INT64, long.class, new Int64LongConverter()); | |||
| addConverterMapping(ValueType.INT64, Long.class, new Int64LongWrapperConverter()); | |||
| addConverterMapping(ValueType.TEXT, String.class, new StringValueConverter()); | |||
| addConverterMapping(ValueType.BYTES, byte[].class, new BytesValueConverter()); | |||
| addConverterMapping(PrimitiveType.BOOLEAN, boolean.class, new BoolConverter()); | |||
| addConverterMapping(PrimitiveType.BOOLEAN, Boolean.class, new BoolWrapperConverter()); | |||
| addConverterMapping(PrimitiveType.INT8, byte.class, new Int8ByteConverter()); | |||
| addConverterMapping(PrimitiveType.INT8, Byte.class, new Int8ByteWrapperConverter()); | |||
| addConverterMapping(PrimitiveType.INT16, short.class, new Int16ShortConverter()); | |||
| addConverterMapping(PrimitiveType.INT16, Short.class, new Int16ShortWrapperConverter()); | |||
| addConverterMapping(PrimitiveType.INT16, char.class, new Int16CharConverter()); | |||
| addConverterMapping(PrimitiveType.INT16, Character.class, new Int16CharWrapperConverter()); | |||
| addConverterMapping(PrimitiveType.INT32, int.class, new Int32IntConverter()); | |||
| addConverterMapping(PrimitiveType.INT32, Integer.class, new Int32IntWrapperConverter()); | |||
| addConverterMapping(PrimitiveType.INT64, long.class, new Int64LongConverter()); | |||
| addConverterMapping(PrimitiveType.INT64, Long.class, new Int64LongWrapperConverter()); | |||
| addConverterMapping(PrimitiveType.TEXT, String.class, new StringValueConverter()); | |||
| addConverterMapping(PrimitiveType.BYTES, byte[].class, new BytesValueConverter()); | |||
| ENCODER_LOOKUP = new DataContractEncoderLookup() { | |||
| @Override | |||
| @@ -102,7 +101,7 @@ public class DataContractContext { | |||
| }; | |||
| } | |||
| private static void addConverterMapping(ValueType protocalType, Class<?> javaType, ValueConverter converter) { | |||
| private static void addConverterMapping(PrimitiveType protocalType, Class<?> javaType, ValueConverter converter) { | |||
| Map<Class<?>, ValueConverter> converterMap = primitiveTypeConverters.get(protocalType); | |||
| if (converterMap == null) { | |||
| converterMap = new HashMap<>(); | |||
| @@ -111,14 +110,14 @@ public class DataContractContext { | |||
| converterMap.put(javaType, converter); | |||
| } | |||
| private static ValueConverter getPrimitiveTypeConverter(ValueType protocalType, Class<?> javaType) { | |||
| private static ValueConverter getPrimitiveTypeConverter(PrimitiveType protocalType, Class<?> javaType) { | |||
| Map<Class<?>, ValueConverter> converterMap = primitiveTypeConverters.get(protocalType); | |||
| if (converterMap != null) { | |||
| ValueConverter converter = converterMap.get(javaType); | |||
| if (converter != null) { | |||
| return converter; | |||
| } | |||
| if (ValueType.BYTES == protocalType && BytesSerializable.class.isAssignableFrom(javaType)) { | |||
| if (PrimitiveType.BYTES == protocalType && BytesSerializable.class.isAssignableFrom(javaType)) { | |||
| converter = new BytesSerializableValueConverter(javaType); | |||
| converterMap.put(javaType, converter); | |||
| return converter; | |||
| @@ -367,7 +366,7 @@ public class DataContractContext { | |||
| EnumSpecificationInfo enumSpec = (EnumSpecificationInfo) fieldInfo.fieldSpec.getRefEnum(); | |||
| int[] values = enumSpec.getItemValues(); | |||
| Object[] constants = enumSpec.getConstants(); | |||
| ValueType codeType = enumSpec.getValueType(); | |||
| PrimitiveType codeType = enumSpec.getValueType(); | |||
| ValueConverter baseConverter = getPrimitiveTypeConverter(codeType, enumSpec.getDataType()); | |||
| @@ -411,8 +410,8 @@ public class DataContractContext { | |||
| private static BinarySliceSpec buildSlice(FieldSpecInfo fieldSpec) { | |||
| boolean fixed = false; | |||
| int len = -1; | |||
| ValueType fixedValueType = null; | |||
| if (fieldSpec.getPrimitiveType() != null && fieldSpec.getPrimitiveType() != ValueType.NIL) { | |||
| PrimitiveType fixedValueType = null; | |||
| if (fieldSpec.getPrimitiveType() != null && fieldSpec.getPrimitiveType() != PrimitiveType.NIL) { | |||
| fixedValueType = fieldSpec.getPrimitiveType(); | |||
| } else if (fieldSpec.getRefEnum() != null) { | |||
| fixedValueType = fieldSpec.getRefEnum().getValueType(); | |||
| @@ -547,7 +546,7 @@ public class DataContractContext { | |||
| } | |||
| int maxSize = annoField.maxSize(); | |||
| ValueType primitiveType = annoField.primitiveType(); | |||
| PrimitiveType primitiveType = annoField.primitiveType(); | |||
| if (primitiveType != null) { | |||
| primitiveType = verifyPrimitiveType(primitiveType, dataType, accessor); | |||
| } | |||
| @@ -651,7 +650,7 @@ public class DataContractContext { | |||
| * @param dataType | |||
| * @return | |||
| */ | |||
| private static ValueType verifyPrimitiveType(ValueType primitiveType, Class<?> dataType, Method accessor) { | |||
| private static PrimitiveType verifyPrimitiveType(PrimitiveType primitiveType, Class<?> dataType, Method accessor) { | |||
| switch (primitiveType) { | |||
| case NIL: | |||
| return null; | |||
| @@ -763,6 +762,7 @@ public class DataContractContext { | |||
| public Method reader; | |||
| @SuppressWarnings("unused") | |||
| public DataField annoField; | |||
| public FieldDeclaredInfo(Method accessor, DataField annoField, FieldSpecInfo fieldSpec) { | |||
| @@ -1,6 +1,5 @@ | |||
| package com.jd.blockchain.binaryproto.impl; | |||
| import java.util.ArrayList; | |||
| import java.util.Arrays; | |||
| import java.util.Collections; | |||
| import java.util.List; | |||
| @@ -3,15 +3,15 @@ package com.jd.blockchain.binaryproto.impl; | |||
| import java.util.LinkedHashSet; | |||
| import java.util.Set; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.binaryproto.EnumSpecification; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| /** | |||
| * Created by zhangshuang3 on 2018/6/21. | |||
| */ | |||
| public class EnumSpecificationInfo implements EnumSpecification { | |||
| private ValueType valueType; | |||
| private PrimitiveType valueType; | |||
| private Class<?> dataType; | |||
| @@ -24,7 +24,7 @@ public class EnumSpecificationInfo implements EnumSpecification { | |||
| // private Map<Object, Object> itemCodeMapping = new HashMap<>(); | |||
| // private Map<Object, Object> codeItemMapping = new HashMap<>(); | |||
| public EnumSpecificationInfo(ValueType valueType, int code, long version, String name, String description, Class<?> dataType) { | |||
| public EnumSpecificationInfo(PrimitiveType valueType, int code, long version, String name, String description, Class<?> dataType) { | |||
| this.valueType = valueType; | |||
| this.code = code; | |||
| this.version = version; | |||
| @@ -54,7 +54,7 @@ public class EnumSpecificationInfo implements EnumSpecification { | |||
| } | |||
| @Override | |||
| public ValueType getValueType() { | |||
| public PrimitiveType getValueType() { | |||
| return this.valueType; | |||
| } | |||
| @@ -1,14 +1,14 @@ | |||
| package com.jd.blockchain.binaryproto.impl; | |||
| import com.jd.blockchain.binaryproto.DataContractException; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.utils.io.BytesSlice; | |||
| public class EnumValueConverter implements FixedValueConverter { | |||
| private Class<?> enumType; | |||
| private ValueType codeType; | |||
| private PrimitiveType codeType; | |||
| private int[] values; | |||
| @@ -16,7 +16,7 @@ public class EnumValueConverter implements FixedValueConverter { | |||
| private FixedValueConverter valueConverter; | |||
| public EnumValueConverter(Class<?> enumType, ValueType codeType, int[] values, Object[] constants, FixedValueConverter valueConverter) { | |||
| public EnumValueConverter(Class<?> enumType, PrimitiveType codeType, int[] values, Object[] constants, FixedValueConverter valueConverter) { | |||
| this.enumType = enumType; | |||
| this.values = values; | |||
| this.constants = constants; | |||
| @@ -1,9 +1,9 @@ | |||
| package com.jd.blockchain.binaryproto.impl; | |||
| import com.jd.blockchain.binaryproto.DataSpecification; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.binaryproto.EnumSpecification; | |||
| import com.jd.blockchain.binaryproto.FieldSpec; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| public class FieldSpecInfo implements FieldSpec { | |||
| @@ -15,7 +15,7 @@ public class FieldSpecInfo implements FieldSpec { | |||
| private boolean repeatable; | |||
| private ValueType primitiveType; | |||
| private PrimitiveType primitiveType; | |||
| private EnumSpecification enumSpec; | |||
| @@ -27,7 +27,7 @@ public class FieldSpecInfo implements FieldSpec { | |||
| private boolean isGenericContract = false; | |||
| public FieldSpecInfo(int order, String name, String decription, ValueType primitiveType, boolean repeatable, | |||
| public FieldSpecInfo(int order, String name, String decription, PrimitiveType primitiveType, boolean repeatable, | |||
| int maxSize, Class<?> dataType) { | |||
| if (primitiveType == null) { | |||
| throw new IllegalArgumentException("primitiveType is null!"); | |||
| @@ -71,7 +71,7 @@ public class FieldSpecInfo implements FieldSpec { | |||
| } | |||
| @Override | |||
| public ValueType getPrimitiveType() { | |||
| public PrimitiveType getPrimitiveType() { | |||
| return primitiveType; | |||
| } | |||
| @@ -7,7 +7,7 @@ import static org.junit.Assert.assertTrue; | |||
| import org.junit.Test; | |||
| import com.jd.blockchain.binaryproto.BinaryEncodingUtils; | |||
| import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
| import com.jd.blockchain.binaryproto.DataContractException; | |||
| import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
| import com.jd.blockchain.utils.Bytes; | |||
| @@ -37,7 +37,7 @@ public class BinaryEncodingTest { | |||
| pd.setConfig(Bytes.fromString("Configuration of something.")); | |||
| pd.setNetworkAddress(networkAddress); | |||
| byte[] bytes = BinaryEncodingUtils.encode(pd, PrimitiveDatas.class); | |||
| byte[] bytes = BinaryProtocol.encode(pd, PrimitiveDatas.class); | |||
| int offset = 0; | |||
| int code = BytesUtils.toInt(bytes, offset); | |||
| offset += 12; | |||
| @@ -109,7 +109,7 @@ public class BinaryEncodingTest { | |||
| public void testEncoding_Null() { | |||
| DataContractRegistry.register(PrimitiveDatas.class); | |||
| byte[] bytes = BinaryEncodingUtils.encode(null, PrimitiveDatas.class); | |||
| byte[] bytes = BinaryProtocol.encode(null, PrimitiveDatas.class); | |||
| int offset = 0; | |||
| int code = BytesUtils.toInt(bytes, offset); | |||
| offset += 12;// 暂不校验 version; | |||
| @@ -138,8 +138,8 @@ public class BinaryEncodingTest { | |||
| pd.setConfig(Bytes.fromString("Configuration of something.")); | |||
| pd.setNetworkAddress(networkAddress); | |||
| byte[] bytes = BinaryEncodingUtils.encode(pd, PrimitiveDatas.class); | |||
| PrimitiveDatas decodeData = BinaryEncodingUtils.decode(bytes); | |||
| byte[] bytes = BinaryProtocol.encode(pd, PrimitiveDatas.class); | |||
| PrimitiveDatas decodeData = BinaryProtocol.decode(bytes); | |||
| assertEquals(pd.getId(), decodeData.getId()); | |||
| assertEquals(pd.isEnable(), decodeData.isEnable()); | |||
| assertEquals(pd.isBoy(), decodeData.isBoy()); | |||
| @@ -163,7 +163,7 @@ public class BinaryEncodingTest { | |||
| EnumDatasImpl enumDatas = new EnumDatasImpl(); | |||
| enumDatas.setLevel(EnumLevel.V1); | |||
| byte[] bytes = BinaryEncodingUtils.encode(enumDatas, EnumDatas.class); | |||
| byte[] bytes = BinaryProtocol.encode(enumDatas, EnumDatas.class); | |||
| int offset = 0; | |||
| int code = BytesUtils.toInt(bytes, offset); | |||
| offset += 12; | |||
| @@ -186,8 +186,8 @@ public class BinaryEncodingTest { | |||
| EnumDatasImpl enumDatas = new EnumDatasImpl(); | |||
| enumDatas.setLevel(EnumLevel.V1); | |||
| byte[] bytes = BinaryEncodingUtils.encode(enumDatas, EnumDatas.class); | |||
| EnumDatas decodeData = BinaryEncodingUtils.decode(bytes); | |||
| byte[] bytes = BinaryProtocol.encode(enumDatas, EnumDatas.class); | |||
| EnumDatas decodeData = BinaryProtocol.decode(bytes); | |||
| assertEquals(enumDatas.getLevel(), decodeData.getLevel()); | |||
| } | |||
| @@ -215,7 +215,7 @@ public class BinaryEncodingTest { | |||
| refContractDatas.setPrimitiveDatas(primitiveDatas); | |||
| byte[] bytes = BinaryEncodingUtils.encode(refContractDatas, RefContractDatas.class); | |||
| byte[] bytes = BinaryProtocol.encode(refContractDatas, RefContractDatas.class); | |||
| int offset = 0; | |||
| int code = BytesUtils.toInt(bytes, offset); | |||
| offset += 12; | |||
| @@ -248,7 +248,7 @@ public class BinaryEncodingTest { | |||
| RefContractDatasImpl refContractDatas = new RefContractDatasImpl(); | |||
| byte[] bytes = BinaryEncodingUtils.encode(refContractDatas, RefContractDatas.class); | |||
| byte[] bytes = BinaryProtocol.encode(refContractDatas, RefContractDatas.class); | |||
| int offset = 0; | |||
| int code = BytesUtils.toInt(bytes, offset); | |||
| offset += 12; | |||
| @@ -295,8 +295,8 @@ public class BinaryEncodingTest { | |||
| refContractDatas.setPrimitiveDatas(primitiveDatas); | |||
| byte[] bytes = BinaryEncodingUtils.encode(refContractDatas, RefContractDatas.class); | |||
| RefContractDatas decodeData = BinaryEncodingUtils.decode(bytes); | |||
| byte[] bytes = BinaryProtocol.encode(refContractDatas, RefContractDatas.class); | |||
| RefContractDatas decodeData = BinaryProtocol.decode(bytes); | |||
| assertEquals(refContractDatas.getPrimitive().getId(), decodeData.getPrimitive().getId()); | |||
| assertEquals(refContractDatas.getPrimitive().isEnable(), decodeData.getPrimitive().isEnable()); | |||
| @@ -329,7 +329,7 @@ public class BinaryEncodingTest { | |||
| operations[0] = subOperation; | |||
| genericRefContractDatas.setOperations(operations); | |||
| byte[] bytes = BinaryEncodingUtils.encode(genericRefContractDatas, GenericRefContractDatas.class); | |||
| byte[] bytes = BinaryProtocol.encode(genericRefContractDatas, GenericRefContractDatas.class); | |||
| int offset = 0; | |||
| int code = BytesUtils.toInt(bytes, offset); | |||
| offset += 12; | |||
| @@ -391,9 +391,9 @@ public class BinaryEncodingTest { | |||
| operations[0] = subOperation; | |||
| genericRefContractDatas.setOperations(operations); | |||
| byte[] bytes = BinaryEncodingUtils.encode(genericRefContractDatas, GenericRefContractDatas.class); | |||
| byte[] bytes = BinaryProtocol.encode(genericRefContractDatas, GenericRefContractDatas.class); | |||
| GenericRefContractDatas decodeData = BinaryEncodingUtils.decode(bytes); | |||
| GenericRefContractDatas decodeData = BinaryProtocol.decode(bytes); | |||
| assertEquals("Jerry", ((SubOperation) (decodeData.getOperations()[0])).getUserName()); | |||
| } | |||
| @@ -432,7 +432,7 @@ public class BinaryEncodingTest { | |||
| operations[0] = subOperation; | |||
| compositeDatas.setOperations(operations); | |||
| byte[] bytes = BinaryEncodingUtils.encode(compositeDatas, CompositeDatas.class); | |||
| byte[] bytes = BinaryProtocol.encode(compositeDatas, CompositeDatas.class); | |||
| int offset = 0; | |||
| int code = BytesUtils.toInt(bytes, offset); | |||
| @@ -508,8 +508,8 @@ public class BinaryEncodingTest { | |||
| operations[0] = subOperation; | |||
| compositeDatas.setOperations(operations); | |||
| byte[] bytes = BinaryEncodingUtils.encode(compositeDatas, CompositeDatas.class); | |||
| CompositeDatas decodeData = BinaryEncodingUtils.decode(bytes); | |||
| byte[] bytes = BinaryProtocol.encode(compositeDatas, CompositeDatas.class); | |||
| CompositeDatas decodeData = BinaryProtocol.decode(bytes); | |||
| assertEquals(compositeDatas.isEnable(), decodeData.isEnable()); | |||
| assertEquals(compositeDatas.getAge(), decodeData.getAge()); | |||
| @@ -2,8 +2,7 @@ package test.com.jd.blockchain.binaryproto; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.utils.Bytes; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| /** | |||
| * Created by zhangshuang3 on 2018/11/30. | |||
| @@ -11,7 +10,7 @@ import com.jd.blockchain.utils.ValueType; | |||
| @DataContract(code = 0xc, name = "CompositeDatas", description = "") | |||
| public interface CompositeDatas { | |||
| @DataField(order = 1, primitiveType = ValueType.BOOLEAN) | |||
| @DataField(order = 1, primitiveType = PrimitiveType.BOOLEAN) | |||
| boolean isEnable(); | |||
| @DataField(order = 2, refEnum = true) | |||
| @@ -23,7 +22,7 @@ public interface CompositeDatas { | |||
| @DataField(order=4, list = true, refContract=true, genericContract = true) | |||
| Operation[] getOperations(); | |||
| @DataField(order = 5, primitiveType = ValueType.INT16) | |||
| @DataField(order = 5, primitiveType = PrimitiveType.INT16) | |||
| short getAge(); | |||
| } | |||
| @@ -1,8 +1,8 @@ | |||
| package test.com.jd.blockchain.binaryproto; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.binaryproto.EnumContract; | |||
| import com.jd.blockchain.binaryproto.EnumField; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| /** | |||
| * Created by zhangshuang3 on 2018/11/29. | |||
| @@ -14,7 +14,7 @@ public enum EnumLevel { | |||
| V2((byte) 2); | |||
| @EnumField(type= ValueType.INT8) | |||
| @EnumField(type= PrimitiveType.INT8) | |||
| public final byte CODE; | |||
| public byte getCode() { | |||
| return CODE; | |||
| @@ -2,8 +2,7 @@ package test.com.jd.blockchain.binaryproto; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.utils.Bytes; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| /** | |||
| * Created by zhangshuang3 on 2018/7/11. | |||
| @@ -11,22 +10,22 @@ import com.jd.blockchain.utils.ValueType; | |||
| @DataContract(code = 0x06, name = "Primitive", description = "") | |||
| public interface FieldOrderConflictedDatas { | |||
| @DataField(order = 2, primitiveType = ValueType.BOOLEAN) | |||
| @DataField(order = 2, primitiveType = PrimitiveType.BOOLEAN) | |||
| boolean isEnable(); | |||
| @DataField(order = 3, primitiveType = ValueType.INT8) | |||
| @DataField(order = 3, primitiveType = PrimitiveType.INT8) | |||
| byte isBoy(); | |||
| @DataField(order = 7, primitiveType = ValueType.INT16) | |||
| @DataField(order = 7, primitiveType = PrimitiveType.INT16) | |||
| short getAge(); | |||
| @DataField(order = -1, primitiveType = ValueType.INT32) | |||
| @DataField(order = -1, primitiveType = PrimitiveType.INT32) | |||
| int getId(); | |||
| @DataField(order = 6, primitiveType = ValueType.TEXT) | |||
| @DataField(order = 6, primitiveType = PrimitiveType.TEXT) | |||
| String getName(); | |||
| @DataField(order = 7, primitiveType = ValueType.INT64) | |||
| @DataField(order = 7, primitiveType = PrimitiveType.INT64) | |||
| long getValue(); | |||
| @@ -1,8 +1,6 @@ | |||
| package test.com.jd.blockchain.binaryproto; | |||
| import java.util.ArrayList; | |||
| import java.util.Collection; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| /** | |||
| @@ -2,8 +2,8 @@ package test.com.jd.blockchain.binaryproto; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.utils.Bytes; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.utils.net.NetworkAddress; | |||
| /** | |||
| @@ -12,37 +12,37 @@ import com.jd.blockchain.utils.net.NetworkAddress; | |||
| @DataContract(code = 0x05, name = "Primitive", description = "") | |||
| public interface PrimitiveDatas { | |||
| @DataField(order = 2, primitiveType = ValueType.BOOLEAN) | |||
| @DataField(order = 2, primitiveType = PrimitiveType.BOOLEAN) | |||
| boolean isEnable(); | |||
| @DataField(order = 3, primitiveType = ValueType.INT8) | |||
| @DataField(order = 3, primitiveType = PrimitiveType.INT8) | |||
| byte isBoy(); | |||
| @DataField(order = 4, primitiveType = ValueType.INT16) | |||
| @DataField(order = 4, primitiveType = PrimitiveType.INT16) | |||
| short getAge(); | |||
| @DataField(order = -1, primitiveType = ValueType.INT32) | |||
| @DataField(order = -1, primitiveType = PrimitiveType.INT32) | |||
| int getId(); | |||
| @DataField(order = 6, primitiveType = ValueType.TEXT) | |||
| @DataField(order = 6, primitiveType = PrimitiveType.TEXT) | |||
| String getName(); | |||
| @DataField(order = 7, primitiveType = ValueType.INT64) | |||
| @DataField(order = 7, primitiveType = PrimitiveType.INT64) | |||
| long getValue(); | |||
| @DataField(order = 12, primitiveType = ValueType.BYTES) | |||
| @DataField(order = 12, primitiveType = PrimitiveType.BYTES) | |||
| byte[] getImage(); | |||
| @DataField(order = 100, primitiveType = ValueType.INT16) | |||
| @DataField(order = 100, primitiveType = PrimitiveType.INT16) | |||
| char getFlag(); | |||
| @DataField(order = 200, primitiveType = ValueType.BYTES) | |||
| @DataField(order = 200, primitiveType = PrimitiveType.BYTES) | |||
| Bytes getConfig(); | |||
| @DataField(order = 201, primitiveType = ValueType.BYTES) | |||
| @DataField(order = 201, primitiveType = PrimitiveType.BYTES) | |||
| Bytes getSetting(); | |||
| @DataField(order = 202, primitiveType = ValueType.BYTES) | |||
| @DataField(order = 202, primitiveType = PrimitiveType.BYTES) | |||
| NetworkAddress getNetworkAddr(); | |||
| } | |||
| @@ -1,7 +1,5 @@ | |||
| package test.com.jd.blockchain.binaryproto; | |||
| import org.omg.CORBA.PUBLIC_MEMBER; | |||
| import com.jd.blockchain.utils.Bytes; | |||
| import com.jd.blockchain.utils.net.NetworkAddress; | |||
| @@ -2,7 +2,6 @@ package test.com.jd.blockchain.binaryproto; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| /** | |||
| * Created by zhangshuang3 on 2018/11/29. | |||
| @@ -2,7 +2,7 @@ package test.com.jd.blockchain.binaryproto; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| /** | |||
| * Created by zhangshuang3 on 2018/11/29. | |||
| @@ -10,7 +10,7 @@ import com.jd.blockchain.utils.ValueType; | |||
| @DataContract(code = 0xa, name = "SubOperation", description = "") | |||
| public interface SubOperation extends Operation { | |||
| @DataField(order=1, primitiveType = ValueType.TEXT) | |||
| @DataField(order=1, primitiveType = PrimitiveType.TEXT) | |||
| String getUserName(); | |||
| } | |||
| @@ -1,16 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract; | |||
| // | |||
| //import com.jd.blockchain.binaryproto.DataContract; | |||
| //import com.jd.blockchain.binaryproto.DataField; | |||
| //import com.jd.blockchain.binaryproto.ValueType; | |||
| // | |||
| //@DataContract(code=0x02, name="Address" , description="") | |||
| //public interface Address { | |||
| // | |||
| // @DataField(order=1, primitiveType=ValueType.TEXT) | |||
| // String getStreet(); | |||
| // | |||
| // @DataField(order=2, primitiveType=ValueType.INT32) | |||
| // int getNumber(); | |||
| // | |||
| //} | |||
| @@ -2,7 +2,7 @@ package test.com.jd.blockchain.binaryproto.contract; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| /** | |||
| * Created by zhangshuang3 on 2018/7/9. | |||
| @@ -10,10 +10,10 @@ import com.jd.blockchain.utils.ValueType; | |||
| @DataContract(code=0x02, name="Address" , description="") | |||
| public interface AddressCodeDuplicate { | |||
| @DataField(order=1, primitiveType= ValueType.TEXT) | |||
| @DataField(order=1, primitiveType= PrimitiveType.TEXT) | |||
| String getStreet(); | |||
| @DataField(order=2, primitiveType=ValueType.INT32) | |||
| @DataField(order=2, primitiveType=PrimitiveType.INT32) | |||
| int getNumber(); | |||
| } | |||
| @@ -2,7 +2,7 @@ package test.com.jd.blockchain.binaryproto.contract; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| /** | |||
| * Created by zhangshuang3 on 2018/7/9. | |||
| @@ -10,10 +10,10 @@ import com.jd.blockchain.utils.ValueType; | |||
| @DataContract(code=0x03, name="Address" , description="") | |||
| public interface AddressOrderDuplicate { | |||
| @DataField(order=1, primitiveType= ValueType.TEXT) | |||
| @DataField(order=1, primitiveType= PrimitiveType.TEXT) | |||
| String getStreet(); | |||
| @DataField(order=1, primitiveType=ValueType.INT32) | |||
| @DataField(order=1, primitiveType=PrimitiveType.INT32) | |||
| int getNumber(); | |||
| } | |||
| @@ -2,7 +2,7 @@ package test.com.jd.blockchain.binaryproto.contract; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| /** | |||
| * Created by zhangshuang3 on 2018/7/11. | |||
| @@ -10,16 +10,16 @@ import com.jd.blockchain.utils.ValueType; | |||
| @DataContract(code=0x08, name="Array" , description="") | |||
| public interface Array { | |||
| @DataField(order=1, primitiveType= ValueType.INT32, list=true) | |||
| @DataField(order=1, primitiveType= PrimitiveType.INT32, list=true) | |||
| int[] getScores(); | |||
| @DataField(order=2, primitiveType=ValueType.TEXT, list=true) | |||
| @DataField(order=2, primitiveType=PrimitiveType.TEXT, list=true) | |||
| String[] getFeatures(); | |||
| @DataField(order=3, primitiveType=ValueType.BYTES) | |||
| @DataField(order=3, primitiveType=PrimitiveType.BYTES) | |||
| byte[] getFamilyMemberAges(); | |||
| @DataField(order=4, primitiveType=ValueType.INT64, list=true) | |||
| @DataField(order=4, primitiveType=PrimitiveType.INT64, list=true) | |||
| long[] getFamilyMemberIds(); | |||
| } | |||
| @@ -1,158 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract; | |||
| // | |||
| //import com.jd.blockchain.binaryproto.EnumContract; | |||
| //import com.jd.blockchain.binaryproto.EnumField; | |||
| //import com.jd.blockchain.binaryproto.ValueType; | |||
| //import com.jd.blockchain.crypto.CryptoAlgorithmType; | |||
| //import my.utils.io.BytesUtils; | |||
| // | |||
| ///** | |||
| // * Created by zhangshuang3 on 2018/7/30. | |||
| // */ | |||
| //@EnumContract(code=0x0102) | |||
| //public enum CryptoAlgorithm { | |||
| // | |||
| // // Hash 类; | |||
| // // SHA_128(CryptoAlgorithmMask.HASH, (byte) 0x01, false, false), | |||
| // | |||
| // SHA_256(CryptoAlgorithmType.HASH, (byte) 0x01, false, false), | |||
| // | |||
| // RIPLE160(CryptoAlgorithmType.HASH, (byte) 0x02, false, false), | |||
| // | |||
| // SM3(CryptoAlgorithmType.HASH, (byte) 0x03, false, false), | |||
| // | |||
| // // 非对称签名/加密算法; | |||
| // | |||
| // /** | |||
| // * RSA 签名算法;可签名,可加密; | |||
| // */ | |||
| // RSA(CryptoAlgorithmType.ASYMMETRIC, (byte) 0x01, true, true), | |||
| // | |||
| // /** | |||
| // * ED25519 签名算法;只用于签名,没有加密特性; | |||
| // */ | |||
| // ED25519(CryptoAlgorithmType.ASYMMETRIC, (byte) 0x02, true, false), | |||
| // | |||
| // /** | |||
| // * ECDSA 签名算法;只用于签名,没有加密特性;??? | |||
| // */ | |||
| // ECDSA(CryptoAlgorithmType.ASYMMETRIC, (byte) 0x03, true, false), | |||
| // | |||
| // /** | |||
| // * 国密 SM2 算法;可签名,可加密; | |||
| // */ | |||
| // SM2(CryptoAlgorithmType.ASYMMETRIC, (byte) 0x04, true, true), | |||
| // | |||
| // // 对称加密; | |||
| // /** | |||
| // * AES 算法;可加密; | |||
| // */ | |||
| // AES(CryptoAlgorithmType.SYMMETRIC, (byte) 0x01, false, true), | |||
| // | |||
| // SM4(CryptoAlgorithmType.SYMMETRIC, (byte) 0x02, false, true), | |||
| // | |||
| // // 随机性; | |||
| // /** | |||
| // * ????? 一种随机数算法,待定; | |||
| // */ | |||
| // JAVA_SECURE(CryptoAlgorithmType.RANDOM, (byte) 0x01, false, false); | |||
| // | |||
| // /** | |||
| // * 密码算法的代号;<br> | |||
| // * 注:只占16位; | |||
| // */ | |||
| // @EnumField(type = ValueType.INT8) | |||
| // public final byte CODE; | |||
| // | |||
| // private final boolean signable; | |||
| // | |||
| // private final boolean encryptable; | |||
| // | |||
| // private CryptoAlgorithm(byte algType, byte algId, boolean signable, boolean encryptable) { | |||
| // this.CODE = (byte) (algType | algId); | |||
| // this.signable = signable; | |||
| // this.encryptable = encryptable; | |||
| // } | |||
| // | |||
| // /** | |||
| // * 是否属于摘要算法; | |||
| // * | |||
| // * @return | |||
| // */ | |||
| // public boolean isHash() { | |||
| // return (CODE & CryptoAlgorithmType.HASH) == CryptoAlgorithmType.HASH; | |||
| // } | |||
| // | |||
| // /** | |||
| // * 是否属于非对称密码算法; | |||
| // * | |||
| // * @return | |||
| // */ | |||
| // public boolean isAsymmetric() { | |||
| // return (CODE & CryptoAlgorithmType.ASYMMETRIC) == CryptoAlgorithmType.ASYMMETRIC; | |||
| // } | |||
| // | |||
| // /** | |||
| // * 是否属于对称密码算法; | |||
| // * | |||
| // * @return | |||
| // */ | |||
| // public boolean isSymmetric() { | |||
| // return (CODE & CryptoAlgorithmType.SYMMETRIC) == CryptoAlgorithmType.SYMMETRIC; | |||
| // } | |||
| // | |||
| // /** | |||
| // * 是否属于随机数算法; | |||
| // * | |||
| // * @return | |||
| // */ | |||
| // public boolean isRandom() { | |||
| // return (CODE & CryptoAlgorithmType.RANDOM) == CryptoAlgorithmType.RANDOM; | |||
| // } | |||
| // | |||
| // /** | |||
| // * 是否支持签名操作; | |||
| // * | |||
| // * @return | |||
| // */ | |||
| // public boolean isSignable() { | |||
| // return signable; | |||
| // } | |||
| // | |||
| // /** | |||
| // * 是否支持加密操作; | |||
| // * | |||
| // * @return | |||
| // */ | |||
| // public boolean isEncryptable() { | |||
| // return encryptable; | |||
| // } | |||
| // | |||
| // /** | |||
| // * 返回指定编码对应的枚举实例;<br> | |||
| // * | |||
| // * 如果不存在,则返回 null; | |||
| // * | |||
| // * @param code | |||
| // * @return | |||
| // */ | |||
| // public static CryptoAlgorithm valueOf(byte code) { | |||
| // for (CryptoAlgorithm alg : CryptoAlgorithm.values()) { | |||
| // if (alg.CODE == code) { | |||
| // return alg; | |||
| // } | |||
| // } | |||
| // throw new IllegalArgumentException("CryptoAlgorithm doesn't support enum code[" + code + "]!"); | |||
| // } | |||
| // | |||
| // // /** | |||
| // // * @return | |||
| // // */ | |||
| // // public byte[] toBytes() { | |||
| // // byte[] bytes = BytesUtils.toBytes(CODE); | |||
| // // byte[] result = new byte[BYTES_SIZE]; | |||
| // // System.arraycopy(bytes, 2, result, 0, 2); | |||
| // // // TODO: 只返回最后2个字节; | |||
| // // return result; | |||
| // // } | |||
| //} | |||
| @@ -1,41 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract; | |||
| // | |||
| //import com.jd.blockchain.binaryproto.DataContract; | |||
| //import com.jd.blockchain.binaryproto.DataField; | |||
| //import com.jd.blockchain.binaryproto.ValueType; | |||
| // | |||
| ///** | |||
| // * Created by zhangshuang3 on 2018/7/30. | |||
| // */ | |||
| //@DataContract(code=0x0d, name="CryptoSetting", description = "Crypto setting") | |||
| //public interface CryptoSetting { | |||
| // | |||
| // /** | |||
| // * 系统中使用的 Hash 算法; <br> | |||
| // * | |||
| // * 对于历史数据,如果它未发生更改,则总是按照该数据产生时采用的算法进行校验,即使当时指定的Hash算法和当前的不同;<br> | |||
| // * | |||
| // * 如果对数据进行了更新,则采用新的 Hash 算法来计算生成完整性证明; | |||
| // * | |||
| // * @return | |||
| // */ | |||
| // @DataField(order=1, refEnum=true) | |||
| // public HashAlgorithm getHashAlgorithm(); | |||
| // | |||
| // @DataField(order=2, refEnum=true) | |||
| // public CryptoAlgorithm getHashAlgorithm1(); | |||
| // | |||
| // /** | |||
| // * 当有完整性证明的数据被从持久化介质中加载时,是否对其进行完整性校验(重新计算 hash 比对是否一致); <br> | |||
| // * | |||
| // * 如果为 true ,则自动进行校验,如果校验失败,会引发异常; <br> | |||
| // * | |||
| // * 注意:开启此选项将对性能会产生负面影响,因此使用者需要在性能和数据安全性之间做出权衡; | |||
| // * | |||
| // * @return | |||
| // */ | |||
| // @DataField(order=3, primitiveType= ValueType.BOOLEAN) | |||
| // public boolean getAutoVerifyHash();//func name is getxxxxx type | |||
| // | |||
| //} | |||
| // | |||
| @@ -1,50 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract; | |||
| // | |||
| //import com.jd.blockchain.binaryproto.EnumContract; | |||
| //import com.jd.blockchain.binaryproto.EnumField; | |||
| //import com.jd.blockchain.binaryproto.ValueType; | |||
| // | |||
| ///** | |||
| // * Created by zhangshuang3 on 2018/7/30. | |||
| // */ | |||
| //@EnumContract(code=0x0101) | |||
| //public enum HashAlgorithm { | |||
| // | |||
| // RIPE160((byte) 1), | |||
| // | |||
| // SHA256((byte) 2), | |||
| // | |||
| // SM3((byte) 4); | |||
| // | |||
| // @EnumField(type = ValueType.INT8) | |||
| // public final byte CODE; | |||
| // | |||
| // private HashAlgorithm(byte algorithm) { | |||
| // CODE = algorithm; | |||
| // } | |||
| // | |||
| // public byte getAlgorithm() { | |||
| // return CODE; | |||
| // } | |||
| // | |||
| // public static HashAlgorithm valueOf(byte algorithm) { | |||
| // for (HashAlgorithm hashAlgorithm : HashAlgorithm.values()) { | |||
| // if (hashAlgorithm.CODE == algorithm) { | |||
| // return hashAlgorithm; | |||
| // } | |||
| // } | |||
| // throw new IllegalArgumentException("Unsupported hash algorithm [" + algorithm + "]!"); | |||
| // } | |||
| // | |||
| // public static void checkHashAlgorithm(HashAlgorithm algorithm) { | |||
| // switch (algorithm) { | |||
| // case RIPE160: | |||
| // break; | |||
| // case SHA256: | |||
| // break; | |||
| // default: | |||
| // throw new IllegalArgumentException("Unsupported hash algorithm [" + algorithm + "]!"); | |||
| // } | |||
| // } | |||
| //} | |||
| // | |||
| @@ -1,28 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract; | |||
| // | |||
| //import com.jd.blockchain.binaryproto.DataContract; | |||
| //import com.jd.blockchain.binaryproto.DataField; | |||
| //import com.jd.blockchain.binaryproto.ValueType; | |||
| //import com.jd.blockchain.crypto.hash.HashDigest; | |||
| // | |||
| ///** | |||
| // * Created by zhangshuang3 on 2018/7/30. | |||
| // */ | |||
| //@DataContract(code=0x12, name="LedgerBlock", description ="LedgerBlock") | |||
| //public interface LedgerBlock extends LedgerDataSnapshot{ | |||
| // | |||
| // @DataField(order=1, refHashDigest=true) | |||
| // HashDigest getHash(); | |||
| // | |||
| // @DataField(order=2, refHashDigest=true) | |||
| // HashDigest getPreviousHash(); | |||
| // | |||
| // @DataField(order=3, refHashDigest=true) | |||
| // HashDigest getLedgerHash(); | |||
| // | |||
| // @DataField(order=4, primitiveType=ValueType.INT64) | |||
| // long getHeight(); | |||
| // | |||
| // @DataField(order=5, refHashDigest=true) | |||
| // HashDigest getTransactionSetHash(); | |||
| //} | |||
| @@ -1,34 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract; | |||
| // | |||
| //import com.jd.blockchain.binaryproto.DataContract; | |||
| //import com.jd.blockchain.binaryproto.DataField; | |||
| //import com.jd.blockchain.crypto.hash.HashDigest; | |||
| // | |||
| ///** | |||
| // * Created by zhangshuang3 on 2018/7/30. | |||
| // */ | |||
| //@DataContract(code=0x11, name="LedgerDataSnapshot", description ="LedgerDataSnapshot") | |||
| //public interface LedgerDataSnapshot { | |||
| // | |||
| // @DataField(order=1, refHashDigest=true) | |||
| // HashDigest getAdminAccountHash(); | |||
| // | |||
| // @DataField(order=2, refHashDigest=true) | |||
| // HashDigest getUserAccountSetHash(); | |||
| // | |||
| // @DataField(order=3, refHashDigest=true) | |||
| // HashDigest getUserPrivilegeHash(); | |||
| // | |||
| // @DataField(order=4, refHashDigest=true) | |||
| // HashDigest getDataAccountSetHash(); | |||
| // | |||
| // @DataField(order=5, refHashDigest=true) | |||
| // HashDigest getDataPrivilegeHash(); | |||
| // | |||
| // @DataField(order=6, refHashDigest=true) | |||
| // HashDigest getContractAccountSetHash(); | |||
| // | |||
| // @DataField(order=7, refHashDigest=true) | |||
| // HashDigest getContractPrivilegeHash(); | |||
| // | |||
| //} | |||
| @@ -1,25 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract; | |||
| // | |||
| //import com.jd.blockchain.binaryproto.DataContract; | |||
| //import com.jd.blockchain.binaryproto.DataField; | |||
| //import com.jd.blockchain.binaryproto.ValueType; | |||
| // | |||
| ///** | |||
| // * Created by zhangshuang3 on 2018/7/30. | |||
| // */ | |||
| //@DataContract(code=0x0b, name="LedgerMetadata", description = "Ledger meta data") | |||
| //public interface LedgerMetadata { | |||
| // | |||
| // @DataField(order=1, primitiveType= ValueType.INT8, list=true) | |||
| // byte[] getSeed(); | |||
| // | |||
| // @DataField(order = 2, refContract=true) | |||
| // LedgerSetting getSetting(); | |||
| // | |||
| // @DataField(order=3, primitiveType=ValueType.INT8, list=true) | |||
| // byte[] getPrivilegesHash(); | |||
| // | |||
| // @DataField(order=4, primitiveType=ValueType.INT8, list=true) | |||
| // byte[] getParticipantsHash(); | |||
| // | |||
| //} | |||
| @@ -1,21 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract; | |||
| // | |||
| //import com.jd.blockchain.binaryproto.DataContract; | |||
| //import com.jd.blockchain.binaryproto.DataField; | |||
| // | |||
| ///** | |||
| // * Created by zhangshuang3 on 2018/7/30. | |||
| // */ | |||
| //@DataContract(code=0x0c, name="LedgerSetting", description = "Ledger setting") | |||
| //public interface LedgerSetting { | |||
| // | |||
| // //@DataField(order=1, refContract=true) | |||
| // //ConsensusSetting getConsensusSetting(); | |||
| // | |||
| // @DataField(order=2, refContract=true) | |||
| // CryptoSetting getCryptoSetting(); | |||
| // | |||
| // @DataField(order=3, refContract=true) | |||
| // PrivilegeModelSetting getPrivilegesModelSetting(); | |||
| // | |||
| //} | |||
| @@ -1,8 +1,8 @@ | |||
| package test.com.jd.blockchain.binaryproto.contract; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.binaryproto.EnumContract; | |||
| import com.jd.blockchain.binaryproto.EnumField; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| @EnumContract(code=0x0100) | |||
| public enum Level { | |||
| @@ -11,7 +11,7 @@ public enum Level { | |||
| V2((byte) 2); | |||
| @EnumField(type=ValueType.INT8) | |||
| @EnumField(type=PrimitiveType.INT8) | |||
| public final byte CODE; | |||
| public byte getCode() { | |||
| return CODE; | |||
| @@ -1,18 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract; | |||
| // | |||
| //import com.jd.blockchain.binaryproto.DataContract; | |||
| //import com.jd.blockchain.binaryproto.DataField; | |||
| //import com.jd.blockchain.binaryproto.ValueType; | |||
| // | |||
| ///** | |||
| // * Created by zhangshuang3 on 2018/7/30. | |||
| // */ | |||
| //@DataContract(code=0x10, name="Privilege", description ="Privilege") | |||
| //public interface Privilege { | |||
| // | |||
| // //SortedSet<Byte> getOpCodes(); implement later | |||
| // | |||
| // @DataField(order=2, primitiveType= ValueType.INT64) | |||
| // long getVersion(); | |||
| // | |||
| //} | |||
| @@ -2,7 +2,7 @@ package test.com.jd.blockchain.binaryproto.contract; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| /** | |||
| * Created by zhangshuang3 on 2018/7/30. | |||
| @@ -10,7 +10,7 @@ import com.jd.blockchain.utils.ValueType; | |||
| @DataContract(code=0x0f, name="PrivilegeModelSetting", description ="Privilege Model setting") | |||
| public interface PrivilegeModelSetting { | |||
| @DataField(order=1, primitiveType= ValueType.INT64) | |||
| @DataField(order=1, primitiveType= PrimitiveType.INT64) | |||
| long getLatestVersion(); | |||
| //@DataField(order=2, refContract=true) | |||
| @@ -1,20 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract; | |||
| //import com.jd.blockchain.binaryproto.DataContract; | |||
| //import com.jd.blockchain.binaryproto.DataField; | |||
| /** | |||
| * Created by zhangshuang3 on 2018/7/11. | |||
| */ | |||
| /* | |||
| @DataContract(code=0x07, name="RefContract" , description="") | |||
| public interface RefContract { | |||
| @DataField(order=1, refContract=true) | |||
| Address getAddress(); | |||
| @DataField(order=2, refContract=true) | |||
| Address getAddress1(); | |||
| } | |||
| */ | |||
| @@ -1,41 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract; | |||
| //import com.jd.blockchain.binaryproto.DataContract; | |||
| //import com.jd.blockchain.binaryproto.DataField; | |||
| //import com.jd.blockchain.binaryproto.ValueType; | |||
| /* | |||
| @DataContract(code=0x01, name="测试数据契约1", description = "用于测试的数据契约") | |||
| public interface Student { | |||
| @DataField(order=1, primitiveType=ValueType.INT32) | |||
| int getId(); | |||
| @DataField(order=2, primitiveType=ValueType.INT8) | |||
| byte getFamilyMemberNum(); | |||
| @DataField(order=3, primitiveType=ValueType.TEXT) | |||
| String getName(); | |||
| @DataField(order=4, primitiveType=ValueType.INT16) | |||
| short getAge(); | |||
| @DataField(order=5, refEnum=true) | |||
| Level getLevel(); | |||
| @DataField(order=6, refContract=true) | |||
| Address getAddress(); | |||
| @DataField(order=7, primitiveType=ValueType.INT32, list=true) | |||
| int[] getScores(); | |||
| @DataField(order=8, primitiveType=ValueType.TEXT, list=true) | |||
| String[] getFeatures(); | |||
| @DataField(order=9, primitiveType=ValueType.INT8, list=true) | |||
| byte[] getFamilyMemberAges(); | |||
| @DataField(order=10, primitiveType=ValueType.INT64, list=true) | |||
| long[] getFamilyMemberIds(); | |||
| } | |||
| */ | |||
| @@ -1,44 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract; | |||
| //import com.jd.blockchain.binaryproto.DataContract; | |||
| //import com.jd.blockchain.binaryproto.DataField; | |||
| //import com.jd.blockchain.binaryproto.ValueType; | |||
| /** | |||
| * Created by zhangshuang3 on 2018/7/9. | |||
| */ | |||
| /* | |||
| @DataContract(code=0x04, name="测试数据契约1", description = "用于测试的数据契约") | |||
| public interface StudentInvert { | |||
| @DataField(order=10, primitiveType=ValueType.INT64, list=true) | |||
| long[] getFamilyMemberIds(); | |||
| @DataField(order=9, primitiveType=ValueType.INT8, list=true) | |||
| byte[] getFamilyMemberAges(); | |||
| @DataField(order=8, primitiveType=ValueType.TEXT, list=true) | |||
| String[] getFeatures(); | |||
| @DataField(order=7, primitiveType=ValueType.INT32, list=true) | |||
| int[] getScores(); | |||
| @DataField(order=6, refContract=true) | |||
| Address getAddress(); | |||
| @DataField(order=5, refEnum=true) | |||
| Level getLevel(); | |||
| @DataField(order=4, primitiveType=ValueType.INT16) | |||
| short getAge(); | |||
| @DataField(order=3, primitiveType=ValueType.TEXT) | |||
| String getName(); | |||
| @DataField(order=2, primitiveType=ValueType.INT8) | |||
| byte getFamilyMemberNum(); | |||
| @DataField(order=1, primitiveType= ValueType.INT32) | |||
| int getId(); | |||
| } | |||
| */ | |||
| @@ -1,31 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract; | |||
| //import com.jd.blockchain.binaryproto.DataContract; | |||
| //import com.jd.blockchain.binaryproto.DataField; | |||
| //import com.jd.blockchain.binaryproto.ValueType; | |||
| //import com.jd.blockchain.crypto.asymmetric.PubKey; | |||
| //import my.utils.io.ByteArray; | |||
| /** | |||
| * Created by zhangshuang3 on 2018/7/25. | |||
| */ | |||
| /* | |||
| @DataContract(code=0x09, name="UserAccount", description = "用户账户") | |||
| public interface User { | |||
| @DataField(order=1, primitiveType= ValueType.TEXT) | |||
| String getAddress(); | |||
| @DataField(order=2, refPubKey = true) | |||
| PubKey getPubKey(); | |||
| @DataField(order=3, refPubKey = true) | |||
| PubKey getDataPubKey(); | |||
| @DataField(order=4, primitiveType = ValueType.BYTES) | |||
| ByteArray getDataHash(); | |||
| @DataField(order=5, primitiveType = ValueType.BYTES) | |||
| ByteArray getPrivilegeHash(); | |||
| } | |||
| */ | |||
| @@ -1,29 +0,0 @@ | |||
| /* | |||
| package test.com.jd.blockchain.binaryproto.contract.impl; | |||
| import test.com.jd.blockchain.binaryproto.contract.Address; | |||
| public class AddressImpl implements Address { | |||
| private String street; | |||
| private int number; | |||
| @Override | |||
| public String getStreet() { | |||
| // TODO Auto-generated method stub | |||
| return this.street; | |||
| } | |||
| public void setStreet(String street) { | |||
| this.street = street; | |||
| } | |||
| @Override | |||
| public int getNumber() { | |||
| // TODO Auto-generated method stub | |||
| return this.number; | |||
| } | |||
| public void setNumber(int number) { | |||
| this.number = number; | |||
| } | |||
| } | |||
| */ | |||
| @@ -1,40 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract.impl; | |||
| //import test.com.jd.blockchain.binaryproto.contract.CryptoAlgorithm; | |||
| //import test.com.jd.blockchain.binaryproto.contract.CryptoSetting; | |||
| //import test.com.jd.blockchain.binaryproto.contract.HashAlgorithm; | |||
| /** | |||
| * Created by zhangshuang3 on 2018/7/30. | |||
| */ | |||
| /* | |||
| public class CryptoSettingImpl implements CryptoSetting { | |||
| private HashAlgorithm hashAlgorithm; | |||
| private CryptoAlgorithm cryptoAlgorithm; | |||
| private boolean isAuto; | |||
| @Override | |||
| public HashAlgorithm getHashAlgorithm() { | |||
| return this.hashAlgorithm; | |||
| } | |||
| public void setHashAlgorithm(HashAlgorithm hashAlgorithm) { | |||
| this.hashAlgorithm = hashAlgorithm; | |||
| } | |||
| @Override | |||
| public CryptoAlgorithm getHashAlgorithm1() { | |||
| return this.cryptoAlgorithm; | |||
| } | |||
| public void setHashAlgorithm1(CryptoAlgorithm cryptoAlgorithm) { | |||
| this.cryptoAlgorithm = cryptoAlgorithm; | |||
| } | |||
| @Override | |||
| public boolean getAutoVerifyHash() { | |||
| return isAuto; | |||
| } | |||
| public void setAutoVerifyHash(boolean isAuto) { | |||
| this.isAuto = isAuto; | |||
| } | |||
| } | |||
| */ | |||
| @@ -1,147 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract.impl; | |||
| //import com.jd.blockchain.binaryproto.DConstructor; | |||
| //import com.jd.blockchain.binaryproto.DataField; | |||
| //import com.jd.blockchain.binaryproto.FieldSetter; | |||
| //import com.jd.blockchain.crypto.hash.HashDigest; | |||
| //import test.com.jd.blockchain.binaryproto.contract.Address; | |||
| //import test.com.jd.blockchain.binaryproto.contract.LedgerBlock; | |||
| /** | |||
| * Created by zhangshuang3 on 2018/7/30. | |||
| */ | |||
| /* | |||
| public class LedgerBlockImpl implements LedgerBlock { | |||
| private HashDigest hash; | |||
| private long height; | |||
| private HashDigest ledgerHash; | |||
| private HashDigest previousHash; | |||
| private HashDigest adminAccountHash; | |||
| private HashDigest userAccountSetHash; | |||
| private HashDigest userPrivilegeHash; | |||
| private HashDigest dataAccountSetHash; | |||
| private HashDigest dataPrivilegeHash; | |||
| private HashDigest contractAccountSetHash; | |||
| private HashDigest contractPrivilegeHash; | |||
| private HashDigest transactionSetHash; | |||
| public void setAdminAccountHash(HashDigest adminAccountHash) { | |||
| this.adminAccountHash = adminAccountHash; | |||
| } | |||
| public void setUserAccountSetHash(HashDigest userAccountSetHash) { | |||
| this.userAccountSetHash = userAccountSetHash; | |||
| } | |||
| public void setUserPrivilegeHash(HashDigest userPrivilegeHash) { | |||
| this.userPrivilegeHash = userPrivilegeHash; | |||
| } | |||
| public void setDataAccountSetHash(HashDigest dataAccountSetHash) { | |||
| this.dataAccountSetHash = dataAccountSetHash; | |||
| } | |||
| public void setDataPrivilegeHash(HashDigest dataPrivilegeHash) { | |||
| this.dataPrivilegeHash = dataPrivilegeHash; | |||
| } | |||
| public void setContractAccountSetHash(HashDigest contractAccountSetHash) { | |||
| this.contractAccountSetHash = contractAccountSetHash; | |||
| } | |||
| public void setContractPrivilegeHash(HashDigest contractPrivilegeHash) { | |||
| this.contractPrivilegeHash = contractPrivilegeHash; | |||
| } | |||
| public void setTransactionSetHash(HashDigest transactionSetHash) { | |||
| this.transactionSetHash = transactionSetHash; | |||
| } | |||
| public LedgerBlockImpl() { | |||
| } | |||
| @DConstructor(name="LedgerBlockImpl") | |||
| public LedgerBlockImpl(@FieldSetter(name="getHeight", type="long") long height, @FieldSetter(name="getLedgerHash", type="HashDigest") HashDigest ledgerHash, @FieldSetter(name="getPreviousHash", type="HashDigest") HashDigest previousHash) { | |||
| this.height = height; | |||
| this.ledgerHash = ledgerHash; | |||
| this.previousHash = previousHash; | |||
| } | |||
| @Override | |||
| public HashDigest getHash() { | |||
| return hash; | |||
| } | |||
| @Override | |||
| public HashDigest getPreviousHash() { | |||
| return previousHash; | |||
| } | |||
| @Override | |||
| public HashDigest getLedgerHash() { | |||
| return ledgerHash; | |||
| } | |||
| @Override | |||
| public long getHeight() { | |||
| return height; | |||
| } | |||
| @Override | |||
| public HashDigest getAdminAccountHash() { | |||
| return adminAccountHash; | |||
| } | |||
| @Override | |||
| public HashDigest getUserAccountSetHash() { | |||
| return userAccountSetHash; | |||
| } | |||
| @Override | |||
| public HashDigest getUserPrivilegeHash() { | |||
| return userPrivilegeHash; | |||
| } | |||
| @Override | |||
| public HashDigest getDataAccountSetHash() { | |||
| return dataAccountSetHash; | |||
| } | |||
| @Override | |||
| public HashDigest getDataPrivilegeHash() { | |||
| return dataPrivilegeHash; | |||
| } | |||
| @Override | |||
| public HashDigest getContractAccountSetHash() { | |||
| return contractAccountSetHash; | |||
| } | |||
| @Override | |||
| public HashDigest getContractPrivilegeHash() { | |||
| return contractPrivilegeHash; | |||
| } | |||
| @Override | |||
| public HashDigest getTransactionSetHash() { | |||
| return transactionSetHash; | |||
| } | |||
| public void setHash(HashDigest blockHash) { | |||
| this.hash = blockHash; | |||
| } | |||
| } | |||
| */ | |||
| @@ -1,56 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract.impl; | |||
| //import test.com.jd.blockchain.binaryproto.contract.*; | |||
| //import test.com.jd.blockchain.binaryproto.contract.LedgerMetadata; | |||
| //import test.com.jd.blockchain.binaryproto.contract.LedgerSetting; | |||
| /** | |||
| * Created by zhangshuang3 on 2018/7/30. | |||
| */ | |||
| /* | |||
| public class LedgerMetadataImpl implements LedgerMetadata { | |||
| private byte[] seed; | |||
| private LedgerSetting setting; | |||
| private byte[] privilegesHash; | |||
| private byte[] participantsHash; | |||
| @Override | |||
| public byte[] getSeed() { | |||
| return seed; | |||
| } | |||
| @Override | |||
| public LedgerSetting getSetting() { | |||
| return setting; | |||
| } | |||
| @Override | |||
| public byte[] getPrivilegesHash() { | |||
| return privilegesHash; | |||
| } | |||
| @Override | |||
| public byte[] getParticipantsHash() { | |||
| return participantsHash; | |||
| } | |||
| public void setSeed(byte[] seed) { | |||
| this.seed = seed; | |||
| } | |||
| public void setSetting(LedgerSetting setting) { | |||
| this.setting = setting; | |||
| } | |||
| public void setPrivilegesHash(byte[] privilegesHash) { | |||
| this.privilegesHash = privilegesHash; | |||
| } | |||
| public void setParticipantsHash(byte[] participantsHash) { | |||
| this.participantsHash = participantsHash; | |||
| } | |||
| } | |||
| */ | |||
| @@ -1,30 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract.impl; | |||
| //import test.com.jd.blockchain.binaryproto.contract.LedgerSetting; | |||
| //import test.com.jd.blockchain.binaryproto.contract.CryptoSetting; | |||
| //import test.com.jd.blockchain.binaryproto.contract.PrivilegeModelSetting; | |||
| /** | |||
| * Created by zhangshuang3 on 2018/7/30. | |||
| */ | |||
| /* | |||
| public class LedgerSettingImpl implements LedgerSetting { | |||
| private CryptoSetting cryptoSetting; | |||
| private PrivilegeModelSetting privilegeModelSetting; | |||
| @Override | |||
| public CryptoSetting getCryptoSetting() { | |||
| return this.cryptoSetting; | |||
| } | |||
| public void setCryptoSetting(CryptoSetting cryptoSetting) { | |||
| this.cryptoSetting = cryptoSetting; | |||
| } | |||
| @Override | |||
| public PrivilegeModelSetting getPrivilegesModelSetting() { | |||
| return this.privilegeModelSetting; | |||
| } | |||
| public void setPrivilegesModelSetting(PrivilegeModelSetting privilegeModelSetting) { | |||
| this.privilegeModelSetting = privilegeModelSetting; | |||
| } | |||
| } | |||
| */ | |||
| @@ -1,32 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract.impl; | |||
| //import test.com.jd.blockchain.binaryproto.contract.Address; | |||
| //import test.com.jd.blockchain.binaryproto.contract.RefContract; | |||
| /** | |||
| * Created by zhangshuang3 on 2018/7/11. | |||
| */ | |||
| /* | |||
| public class RefContractImpl implements RefContract { | |||
| private Address address; | |||
| private Address address1; | |||
| @Override | |||
| public Address getAddress() { | |||
| // TODO Auto-generated method stub | |||
| return this.address; | |||
| } | |||
| public void setAddress(Address address) { | |||
| this.address = address; | |||
| } | |||
| @Override | |||
| public Address getAddress1() { | |||
| // TODO Auto-generated method stub | |||
| return this.address1; | |||
| } | |||
| public void setAddress1(Address address) { | |||
| this.address1 = address; | |||
| } | |||
| } | |||
| */ | |||
| @@ -1,108 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract.impl; | |||
| //import test.com.jd.blockchain.binaryproto.contract.Address; | |||
| //import test.com.jd.blockchain.binaryproto.contract.Level; | |||
| //import test.com.jd.blockchain.binaryproto.contract.Student; | |||
| //import test.com.jd.blockchain.binaryproto.contract.StudentInvert; | |||
| /* | |||
| public class StudentImpl implements Student,StudentInvert { | |||
| private int id; | |||
| private short age; | |||
| private String name; | |||
| private Level level; | |||
| private Address address; | |||
| private int[] scores; | |||
| private String[] features; | |||
| private byte familyMemberNum; | |||
| private byte[] familyMemberAges; | |||
| private long[] familyMemberIds; | |||
| @Override | |||
| public int getId() { | |||
| return id; | |||
| } | |||
| public void setId(int id) { | |||
| this.id = id; | |||
| } | |||
| @Override | |||
| public String getName() { | |||
| // TODO Auto-generated method stub | |||
| return this.name; | |||
| } | |||
| public void setName(String name) { | |||
| this.name = name; | |||
| } | |||
| @Override | |||
| public Level getLevel() { | |||
| // TODO Auto-generated method stub | |||
| return this.level; | |||
| } | |||
| public void setLevel(Level level) { | |||
| this.level = level; | |||
| } | |||
| @Override | |||
| public Address getAddress() { | |||
| // TODO Auto-generated method stub | |||
| return this.address; | |||
| } | |||
| public void setAddress(Address address) { | |||
| this.address = address; | |||
| } | |||
| public short getAge() { | |||
| return age; | |||
| } | |||
| public void setAge(short age) { | |||
| this.age = age; | |||
| } | |||
| @Override | |||
| public int[] getScores() { | |||
| // TODO Auto-generated method stub | |||
| return this.scores; | |||
| } | |||
| public void setScores(int[] scores) { | |||
| this.scores = scores; | |||
| } | |||
| @Override | |||
| public String[] getFeatures() { | |||
| return this.features; | |||
| } | |||
| public void setFeatures(String[] features) { | |||
| this.features = features; | |||
| } | |||
| @Override | |||
| public byte getFamilyMemberNum() { | |||
| return this.familyMemberNum; | |||
| } | |||
| public void setFamilyMemberNum(byte familyMemberNum) { | |||
| this.familyMemberNum = familyMemberNum; | |||
| } | |||
| @Override | |||
| public byte[] getFamilyMemberAges() { | |||
| return this.familyMemberAges; | |||
| } | |||
| public void setFamilyMemberAges(byte[] familyMemberAge) { | |||
| this.familyMemberAges = familyMemberAge; | |||
| } | |||
| @Override | |||
| public long[] getFamilyMemberIds() { | |||
| return this.familyMemberIds; | |||
| } | |||
| public void setFamilyMemberIds(long[] familyMemberId) { | |||
| this.familyMemberIds = familyMemberId; | |||
| } | |||
| } | |||
| */ | |||
| @@ -1,51 +0,0 @@ | |||
| //package test.com.jd.blockchain.binaryproto.contract.impl; | |||
| //import com.jd.blockchain.binaryproto.DConstructor; | |||
| //import com.jd.blockchain.binaryproto.FieldSetter; | |||
| //import com.jd.blockchain.crypto.asymmetric.PubKey; | |||
| //import my.utils.io.ByteArray; | |||
| //import test.com.jd.blockchain.binaryproto.contract.User; | |||
| /** | |||
| * Created by zhangshuang3 on 2018/7/24. | |||
| */ | |||
| /* | |||
| public class UserImpl implements User { | |||
| String address; | |||
| PubKey pubKey; | |||
| PubKey dataPubKey; | |||
| ByteArray dataHash; | |||
| ByteArray privHash; | |||
| @DConstructor(name = "UserImpl") | |||
| public UserImpl(@FieldSetter(name = "getAddress", type = "String") String address, @FieldSetter(name = "getPubKey",type = "PubKey") PubKey pubKey, @FieldSetter(name = "getDataPubKey",type = "PubKey") PubKey dataPubKey, | |||
| @FieldSetter(name = "getDataHash", type = "byte[]") byte[] dataHash, @FieldSetter(name = "getPrivilegeHash", type = "byte[]") byte[] privHash) { | |||
| this.address = address; | |||
| this.pubKey = pubKey; | |||
| this.dataPubKey = dataPubKey; | |||
| this.dataHash = ByteArray.wrap(dataHash); | |||
| this.privHash = ByteArray.wrap(privHash); | |||
| } | |||
| @Override | |||
| public String getAddress() { | |||
| return address; | |||
| } | |||
| @Override | |||
| public PubKey getPubKey() { | |||
| return pubKey; | |||
| } | |||
| @Override | |||
| public PubKey getDataPubKey() { | |||
| return dataPubKey; | |||
| } | |||
| @Override | |||
| public ByteArray getDataHash() { | |||
| return dataHash; | |||
| } | |||
| @Override | |||
| public ByteArray getPrivilegeHash() { | |||
| return privHash; | |||
| } | |||
| } | |||
| */ | |||
| @@ -2,21 +2,21 @@ package com.jd.blockchain.consensus.bftsmart; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consensus.ClientIncomingSettings; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| import com.jd.blockchain.crypto.PubKey; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| @DataContract(code = TypeCodes.CONSENSUS_BFTSMART_CLI_INCOMING_SETTINGS) | |||
| @DataContract(code = DataCodes.CONSENSUS_BFTSMART_CLI_INCOMING_SETTINGS) | |||
| public interface BftsmartClientIncomingSettings extends ClientIncomingSettings { | |||
| @DataField(order = 1, primitiveType = ValueType.BYTES) | |||
| @DataField(order = 1, primitiveType = PrimitiveType.BYTES) | |||
| byte[] getTopology(); | |||
| @DataField(order = 2, primitiveType = ValueType.BYTES) | |||
| @DataField(order = 2, primitiveType = PrimitiveType.BYTES) | |||
| byte[] getTomConfig(); | |||
| @DataField(order = 3, primitiveType=ValueType.BYTES) | |||
| @DataField(order = 3, primitiveType=PrimitiveType.BYTES) | |||
| PubKey getPubKey(); | |||
| } | |||
| @@ -2,16 +2,16 @@ package com.jd.blockchain.consensus.bftsmart; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| @DataContract(code = TypeCodes.CONSENSUS_BFTSMART_BLOCK_SETTINGS) | |||
| @DataContract(code = DataCodes.CONSENSUS_BFTSMART_BLOCK_SETTINGS) | |||
| public interface BftsmartCommitBlockSettings { | |||
| @DataField(order = 0, primitiveType = ValueType.INT32) | |||
| @DataField(order = 0, primitiveType = PrimitiveType.INT32) | |||
| int getTxSizePerBlock(); | |||
| @DataField(order = 1, primitiveType = ValueType.INT64) | |||
| @DataField(order = 1, primitiveType = PrimitiveType.INT64) | |||
| long getMaxDelayMilliSecondsPerBlock(); | |||
| } | |||
| @@ -2,16 +2,16 @@ package com.jd.blockchain.consensus.bftsmart; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consensus.ConsensusSettings; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| import com.jd.blockchain.utils.Property; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.utils.serialize.binary.BinarySerializeUtils; | |||
| @DataContract(code = TypeCodes.CONSENSUS_BFTSMART_SETTINGS) | |||
| @DataContract(code = DataCodes.CONSENSUS_BFTSMART_SETTINGS) | |||
| public interface BftsmartConsensusSettings extends ConsensusSettings { | |||
| @DataField(order = 1, primitiveType = ValueType.BYTES, list=true) | |||
| @DataField(order = 1, primitiveType = PrimitiveType.BYTES, list=true) | |||
| Property[] getSystemConfigs(); | |||
| @DataField(order = 2, refContract = true) | |||
| @@ -2,13 +2,13 @@ package com.jd.blockchain.consensus.bftsmart; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consensus.NodeSettings; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| import com.jd.blockchain.crypto.PubKey; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.utils.net.NetworkAddress; | |||
| @DataContract(code = TypeCodes.CONSENSUS_BFTSMART_NODE_SETTINGS) | |||
| @DataContract(code = DataCodes.CONSENSUS_BFTSMART_NODE_SETTINGS) | |||
| public interface BftsmartNodeSettings extends NodeSettings { | |||
| /** | |||
| @@ -31,7 +31,7 @@ public interface BftsmartNodeSettings extends NodeSettings { | |||
| * | |||
| * @return | |||
| */ | |||
| @DataField(order = 2, primitiveType = ValueType.INT32) | |||
| @DataField(order = 2, primitiveType = PrimitiveType.INT32) | |||
| int getId(); | |||
| /** | |||
| @@ -39,7 +39,7 @@ public interface BftsmartNodeSettings extends NodeSettings { | |||
| * | |||
| * @return | |||
| */ | |||
| @DataField(order = 3, primitiveType = ValueType.BYTES) | |||
| @DataField(order = 3, primitiveType = PrimitiveType.BYTES) | |||
| NetworkAddress getNetworkAddress(); | |||
| } | |||
| @@ -1,6 +1,6 @@ | |||
| package com.jd.blockchain.consensus.bftsmart; | |||
| import com.jd.blockchain.binaryproto.BinaryEncodingUtils; | |||
| import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
| import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
| import com.jd.blockchain.consensus.*; | |||
| import com.jd.blockchain.utils.io.BytesEncoder; | |||
| @@ -40,14 +40,14 @@ public class BftsmartSettingsFactory implements SettingsFactory { | |||
| @Override | |||
| public byte[] encode(ConsensusSettings data) { | |||
| if (data instanceof BftsmartConsensusSettings) { | |||
| return BinaryEncodingUtils.encode(data, BftsmartConsensusSettings.class); | |||
| return BinaryProtocol.encode(data, BftsmartConsensusSettings.class); | |||
| } | |||
| throw new IllegalArgumentException("Settings data isn't supported! Accept BftsmartConsensusSettings only!"); | |||
| } | |||
| @Override | |||
| public ConsensusSettings decode(byte[] bytes) { | |||
| return BinaryEncodingUtils.decodeAs(bytes, BftsmartConsensusSettings.class); | |||
| return BinaryProtocol.decodeAs(bytes, BftsmartConsensusSettings.class); | |||
| } | |||
| } | |||
| @@ -57,14 +57,14 @@ public class BftsmartSettingsFactory implements SettingsFactory { | |||
| @Override | |||
| public byte[] encode(ClientIncomingSettings data) { | |||
| if (data instanceof BftsmartClientIncomingSettings) { | |||
| return BinaryEncodingUtils.encode(data, BftsmartClientIncomingSettings.class); | |||
| return BinaryProtocol.encode(data, BftsmartClientIncomingSettings.class); | |||
| } | |||
| throw new IllegalArgumentException("Settings data isn't supported! Accept BftsmartClientIncomingSettings only!"); | |||
| } | |||
| @Override | |||
| public ClientIncomingSettings decode(byte[] bytes) { | |||
| return BinaryEncodingUtils.decodeAs(bytes, BftsmartClientIncomingSettings.class); | |||
| return BinaryProtocol.decodeAs(bytes, BftsmartClientIncomingSettings.class); | |||
| } | |||
| } | |||
| @@ -2,10 +2,10 @@ package com.jd.blockchain.consensus; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| import com.jd.blockchain.crypto.PubKey; | |||
| import com.jd.blockchain.crypto.SignatureDigest; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| /** | |||
| * 客户端的身份证明; | |||
| @@ -13,7 +13,7 @@ import com.jd.blockchain.utils.ValueType; | |||
| * @author huanghaiquan | |||
| * | |||
| */ | |||
| @DataContract(code = TypeCodes.CLIENT_IDENTIFICATION) | |||
| @DataContract(code = DataCodes.CLIENT_IDENTIFICATION) | |||
| public interface ClientIdentification { | |||
| /** | |||
| @@ -21,7 +21,7 @@ public interface ClientIdentification { | |||
| * | |||
| * @return | |||
| */ | |||
| @DataField(order = 0, primitiveType = ValueType.BYTES) | |||
| @DataField(order = 0, primitiveType = PrimitiveType.BYTES) | |||
| byte[] getIdentityInfo(); | |||
| /** | |||
| @@ -29,7 +29,7 @@ public interface ClientIdentification { | |||
| * | |||
| * @return | |||
| */ | |||
| @DataField(order = 1, primitiveType = ValueType.BYTES) | |||
| @DataField(order = 1, primitiveType = PrimitiveType.BYTES) | |||
| PubKey getPubKey(); | |||
| /** | |||
| @@ -37,7 +37,7 @@ public interface ClientIdentification { | |||
| * | |||
| * @return | |||
| */ | |||
| @DataField(order = 2, primitiveType = ValueType.BYTES) | |||
| @DataField(order = 2, primitiveType = PrimitiveType.BYTES) | |||
| SignatureDigest getSignature(); | |||
| /** | |||
| @@ -45,6 +45,6 @@ public interface ClientIdentification { | |||
| * | |||
| * @return | |||
| */ | |||
| @DataField(order = 3, primitiveType = ValueType.TEXT) | |||
| @DataField(order = 3, primitiveType = PrimitiveType.TEXT) | |||
| String getProviderName(); | |||
| } | |||
| @@ -10,7 +10,7 @@ package com.jd.blockchain.consensus; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| /** | |||
| * | |||
| @@ -18,7 +18,7 @@ import com.jd.blockchain.consts.TypeCodes; | |||
| * @create 2018/12/19 | |||
| * @since 1.0.0 | |||
| */ | |||
| @DataContract(code = TypeCodes.CLIENT_IDENTIFICATIONS) | |||
| @DataContract(code = DataCodes.CLIENT_IDENTIFICATIONS) | |||
| public interface ClientIdentifications { | |||
| @DataField(order = 0, list = true, refContract = true, genericContract = true) | |||
| @@ -2,8 +2,8 @@ package com.jd.blockchain.consensus; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| /** | |||
| * 共识网络的客户接入参数; | |||
| @@ -11,7 +11,7 @@ import com.jd.blockchain.utils.ValueType; | |||
| * @author huanghaiquan | |||
| * | |||
| */ | |||
| @DataContract(code = TypeCodes.CONSENSUS_CLI_INCOMING_SETTINGS) | |||
| @DataContract(code = DataCodes.CONSENSUS_CLI_INCOMING_SETTINGS) | |||
| public interface ClientIncomingSettings { | |||
| /** | |||
| @@ -19,7 +19,7 @@ public interface ClientIncomingSettings { | |||
| * | |||
| * @return | |||
| */ | |||
| @DataField(order = 0, primitiveType = ValueType.INT32) | |||
| @DataField(order = 0, primitiveType = PrimitiveType.INT32) | |||
| int getClientId(); | |||
| /** | |||
| @@ -27,7 +27,7 @@ public interface ClientIncomingSettings { | |||
| * | |||
| * @return | |||
| */ | |||
| @DataField(order = 1, primitiveType = ValueType.TEXT) | |||
| @DataField(order = 1, primitiveType = PrimitiveType.TEXT) | |||
| String getProviderName(); | |||
| /** | |||
| @@ -2,7 +2,7 @@ package com.jd.blockchain.consensus; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| /** | |||
| * 共识网络的配置参数; | |||
| @@ -10,7 +10,7 @@ import com.jd.blockchain.consts.TypeCodes; | |||
| * @author huanghaiquan | |||
| * | |||
| */ | |||
| @DataContract(code = TypeCodes.CONSENSUS_SETTINGS) | |||
| @DataContract(code = DataCodes.CONSENSUS_SETTINGS) | |||
| public interface ConsensusSettings { | |||
| /** | |||
| @@ -2,9 +2,9 @@ package com.jd.blockchain.consensus; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| import com.jd.blockchain.crypto.PubKey; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| /** | |||
| * 节点的配置参数; | |||
| @@ -12,7 +12,7 @@ import com.jd.blockchain.utils.ValueType; | |||
| * @author huanghaiquan | |||
| * | |||
| */ | |||
| @DataContract(code=TypeCodes.CONSENSUS_NODE_SETTINGS) | |||
| @DataContract(code=DataCodes.CONSENSUS_NODE_SETTINGS) | |||
| public interface NodeSettings { | |||
| /** | |||
| @@ -22,7 +22,7 @@ public interface NodeSettings { | |||
| * | |||
| * @return | |||
| */ | |||
| @DataField(order=0, primitiveType=ValueType.TEXT) | |||
| @DataField(order=0, primitiveType=PrimitiveType.TEXT) | |||
| String getAddress(); | |||
| /** | |||
| @@ -30,6 +30,6 @@ public interface NodeSettings { | |||
| * | |||
| * @return | |||
| */ | |||
| @DataField(order = 1, primitiveType = ValueType.BYTES) | |||
| @DataField(order = 1, primitiveType = PrimitiveType.BYTES) | |||
| PubKey getPubKey(); | |||
| } | |||
| @@ -2,27 +2,27 @@ package com.jd.blockchain.consensus.action; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| @DataContract(code= TypeCodes.CONSENSUS_ACTION_REQUEST) | |||
| @DataContract(code= DataCodes.CONSENSUS_ACTION_REQUEST) | |||
| public interface ActionRequest { | |||
| @DataField(order=1, list=true, primitiveType= ValueType.INT8) | |||
| @DataField(order=1, list=true, primitiveType= PrimitiveType.INT8) | |||
| byte[] getGroupId(); | |||
| @DataField(order=2, primitiveType=ValueType.TEXT) | |||
| @DataField(order=2, primitiveType=PrimitiveType.TEXT) | |||
| String getHandleType(); | |||
| @DataField(order=3, primitiveType=ValueType.TEXT) | |||
| @DataField(order=3, primitiveType=PrimitiveType.TEXT) | |||
| String getHandleMethod(); | |||
| // String getMessageType(); | |||
| @DataField(order=4, list=true, primitiveType= ValueType.INT8) | |||
| @DataField(order=4, list=true, primitiveType= PrimitiveType.INT8) | |||
| byte[] getMessageBody(); | |||
| @DataField(order=5, primitiveType= ValueType.TEXT) | |||
| @DataField(order=5, primitiveType= PrimitiveType.TEXT) | |||
| String getTransactionType(); | |||
| // String getReponseType(); | |||
| @@ -2,22 +2,22 @@ package com.jd.blockchain.consensus.action; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| @DataContract(code= TypeCodes.CONSENSUS_ACTION_RESPONSE) | |||
| @DataContract(code= DataCodes.CONSENSUS_ACTION_RESPONSE) | |||
| public interface ActionResponse { | |||
| @DataField(order=1, list=true, primitiveType= ValueType.INT8) | |||
| @DataField(order=1, list=true, primitiveType= PrimitiveType.INT8) | |||
| byte[] getMessage(); | |||
| @DataField(order=2, primitiveType=ValueType.BOOLEAN) | |||
| @DataField(order=2, primitiveType=PrimitiveType.BOOLEAN) | |||
| boolean getError(); | |||
| @DataField(order=3, primitiveType=ValueType.TEXT) | |||
| @DataField(order=3, primitiveType=PrimitiveType.TEXT) | |||
| String getErrorMessage(); | |||
| @DataField(order=4, primitiveType=ValueType.TEXT) | |||
| @DataField(order=4, primitiveType=PrimitiveType.TEXT) | |||
| String getErrorType(); | |||
| } | |||
| @@ -8,7 +8,7 @@ | |||
| */ | |||
| package com.jd.blockchain.consensus.mq.config; | |||
| import com.jd.blockchain.binaryproto.BinaryEncodingUtils; | |||
| import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
| import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
| import com.jd.blockchain.consensus.ClientIncomingSettings; | |||
| import com.jd.blockchain.consensus.ConsensusSettings; | |||
| @@ -75,14 +75,14 @@ public class MsgQueueSettingsFactory implements SettingsFactory { | |||
| @Override | |||
| public byte[] encode(ConsensusSettings data) { | |||
| if (data instanceof MsgQueueConsensusSettings) { | |||
| return BinaryEncodingUtils.encode(data, MsgQueueConsensusSettings.class); | |||
| return BinaryProtocol.encode(data, MsgQueueConsensusSettings.class); | |||
| } | |||
| throw new IllegalArgumentException("Settings data isn't supported! Accept MsgQueueConsensusSettings only!"); | |||
| } | |||
| @Override | |||
| public MsgQueueConsensusSettings decode(byte[] bytes) { | |||
| return BinaryEncodingUtils.decodeAs(bytes, MsgQueueConsensusSettings.class); | |||
| return BinaryProtocol.decodeAs(bytes, MsgQueueConsensusSettings.class); | |||
| } | |||
| } | |||
| @@ -91,14 +91,14 @@ public class MsgQueueSettingsFactory implements SettingsFactory { | |||
| @Override | |||
| public byte[] encode(ClientIncomingSettings data) { | |||
| if (data instanceof MsgQueueClientIncomingSettings) { | |||
| return BinaryEncodingUtils.encode(data, MsgQueueClientIncomingSettings.class); | |||
| return BinaryProtocol.encode(data, MsgQueueClientIncomingSettings.class); | |||
| } | |||
| throw new IllegalArgumentException("Settings data isn't supported! Accept MsgQueueClientIncomingSettings only!"); | |||
| } | |||
| @Override | |||
| public MsgQueueClientIncomingSettings decode(byte[] bytes) { | |||
| return BinaryEncodingUtils.decodeAs(bytes, MsgQueueClientIncomingSettings.class); | |||
| return BinaryProtocol.decodeAs(bytes, MsgQueueClientIncomingSettings.class); | |||
| } | |||
| } | |||
| @@ -10,8 +10,8 @@ package com.jd.blockchain.consensus.mq.settings; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| /** | |||
| * | |||
| @@ -19,12 +19,12 @@ import com.jd.blockchain.utils.ValueType; | |||
| * @create 2018/12/13 | |||
| * @since 1.0.0 | |||
| */ | |||
| @DataContract(code = TypeCodes.CONSENSUS_MSGQUEUE_BLOCK_SETTINGS) | |||
| @DataContract(code = DataCodes.CONSENSUS_MSGQUEUE_BLOCK_SETTINGS) | |||
| public interface MsgQueueBlockSettings { | |||
| @DataField(order = 0, primitiveType = ValueType.INT32) | |||
| @DataField(order = 0, primitiveType = PrimitiveType.INT32) | |||
| int getTxSizePerBlock(); | |||
| @DataField(order = 1, primitiveType = ValueType.INT64) | |||
| @DataField(order = 1, primitiveType = PrimitiveType.INT64) | |||
| long getMaxDelayMilliSecondsPerBlock(); | |||
| } | |||
| @@ -10,11 +10,11 @@ package com.jd.blockchain.consensus.mq.settings; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consensus.ClientIncomingSettings; | |||
| import com.jd.blockchain.consensus.ConsensusSettings; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| import com.jd.blockchain.crypto.PubKey; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| /** | |||
| * | |||
| @@ -22,9 +22,9 @@ import com.jd.blockchain.utils.ValueType; | |||
| * @create 2018/12/13 | |||
| * @since 1.0.0 | |||
| */ | |||
| @DataContract(code = TypeCodes.CONSENSUS_MSGQUEUE_CLI_INCOMING_SETTINGS) | |||
| @DataContract(code = DataCodes.CONSENSUS_MSGQUEUE_CLI_INCOMING_SETTINGS) | |||
| public interface MsgQueueClientIncomingSettings extends ClientIncomingSettings { | |||
| @DataField(order = 1, primitiveType=ValueType.BYTES) | |||
| @DataField(order = 1, primitiveType=PrimitiveType.BYTES) | |||
| PubKey getPubKey(); | |||
| } | |||
| @@ -10,11 +10,11 @@ package com.jd.blockchain.consensus.mq.settings; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consensus.ConsensusSettings; | |||
| import com.jd.blockchain.consensus.mq.config.MsgQueueBlockConfig; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| import com.jd.blockchain.utils.Property; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| /** | |||
| * | |||
| @@ -22,7 +22,7 @@ import com.jd.blockchain.utils.ValueType; | |||
| * @create 2018/12/13 | |||
| * @since 1.0.0 | |||
| */ | |||
| @DataContract(code = TypeCodes.CONSENSUS_MSGQUEUE_SETTINGS) | |||
| @DataContract(code = DataCodes.CONSENSUS_MSGQUEUE_SETTINGS) | |||
| public interface MsgQueueConsensusSettings extends ConsensusSettings { | |||
| @DataField(order = 0, refContract = true) | |||
| @@ -10,8 +10,8 @@ package com.jd.blockchain.consensus.mq.settings; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| /** | |||
| * | |||
| @@ -19,18 +19,18 @@ import com.jd.blockchain.utils.ValueType; | |||
| * @create 2018/12/12 | |||
| * @since 1.0.0 | |||
| */ | |||
| @DataContract(code = TypeCodes.CONSENSUS_MSGQUEUE_NETWORK_SETTINGS) | |||
| @DataContract(code = DataCodes.CONSENSUS_MSGQUEUE_NETWORK_SETTINGS) | |||
| public interface MsgQueueNetworkSettings { | |||
| @DataField(order = 0, primitiveType = ValueType.TEXT) | |||
| @DataField(order = 0, primitiveType = PrimitiveType.TEXT) | |||
| String getServer(); | |||
| @DataField(order = 1, primitiveType = ValueType.TEXT) | |||
| @DataField(order = 1, primitiveType = PrimitiveType.TEXT) | |||
| String getTxTopic(); | |||
| @DataField(order = 2, primitiveType = ValueType.TEXT) | |||
| @DataField(order = 2, primitiveType = PrimitiveType.TEXT) | |||
| String getBlTopic(); | |||
| @DataField(order = 3, primitiveType = ValueType.TEXT) | |||
| @DataField(order = 3, primitiveType = PrimitiveType.TEXT) | |||
| String getMsgTopic(); | |||
| } | |||
| @@ -10,7 +10,7 @@ package com.jd.blockchain.consensus.mq.settings; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.consensus.NodeSettings; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| /** | |||
| * | |||
| @@ -19,7 +19,7 @@ import com.jd.blockchain.consts.TypeCodes; | |||
| * @since 1.0.0 | |||
| */ | |||
| @DataContract(code=TypeCodes.CONSENSUS_MSGQUEUE_NODE_SETTINGS) | |||
| @DataContract(code=DataCodes.CONSENSUS_MSGQUEUE_NODE_SETTINGS) | |||
| public interface MsgQueueNodeSettings extends NodeSettings { | |||
| } | |||
| @@ -1,22 +1,27 @@ | |||
| 合约相关说明 | |||
| 1.编译合约入口:ContractCompilerCmdTest.java; | |||
| 2.账本调用合约测试入口:ContractEventSendOperationHandleTest.java; | |||
| ### 合约相关说明 | |||
| 1. 编译合约入口:ContractCompilerCmdTest.java; | |||
| 2. 账本调用合约测试入口:ContractEventSendOperationHandleTest.java; | |||
| ### 单元测试注意事项 | |||
| 使用ContractEventSendOperationHandleTest.java进行单元测试,注意事项: | |||
| 1.设置合约使用PUB_CLASS_PATH、CORE_CLASS_PATH位置(sys-contract.properties); | |||
| 1. 设置合约使用PUB_CLASS_PATH、CORE_CLASS_PATH位置(sys-contract.properties); | |||
| PUB包在根目录中的contract-libs文件夹;core包需要编译来生成。具体如下: | |||
| 1)进入contract-jar模块,执行maven命令:mvn clean assembly:assembly | |||
| 2)生成的core包位于模块的target中的contract-jar-xxx所在的coreLib中; | |||
| 3)将此coreLib目录作为CORE_CLASS_PATH指向的目录。 | |||
| 2.编译生成合约压缩包,即执行:ContractCompilerCmdTest.java对应的mainTestOk(); | |||
| - 进入contract-jar模块,执行maven命令: | |||
| ``` | |||
| mvn clean assembly:assembly | |||
| ``` | |||
| - 生成的core包位于模块的target中的contract-jar-xxx所在的coreLib中; | |||
| - 将此coreLib目录作为CORE_CLASS_PATH指向的目录。 | |||
| 2. 编译生成合约压缩包,即执行:ContractCompilerCmdTest.java对应的mainTestOk(); | |||
| 在编译之前,修改sys-contract.properties文件的变量CONTRACT_FROM_PATH(合约源文件位置)、CONTRACT_SAVE_TO_PATH(合约保存位置)。 | |||
| 3.在合约保存位置中可看到生成的压缩包:xxx.contract;然后执行 ContractEventSendOperationHandleTest.java测试用例test1()即可。 | |||
| 20180910版本改造 | |||
| 1.在contract-jar中添加了mvn assembly处理逻辑,将合约用到的lib包全部放置其target/xxx/pubLib文件夹中,执行:mvn clean assembly:assembly | |||
| 2.修改了sys-contract.properties文件,新增了CONTRACT_CLASS_LIBS参数,将CONTRACT_CLASS_PATH专用于存储路径,CONTRACT_CLASS_LIBS来存放所有的jar包; | |||
| 3.删减了contract-libs文件夹中需要动态生成的jar; | |||
| 3. 在合约保存位置中可看到生成的压缩包:xxx.contract;然后执行 ContractEventSendOperationHandleTest.java测试用例test1()即可。 | |||
| ### 20180910版本改造 | |||
| 1. 在contract-jar中添加了mvn assembly处理逻辑,将合约用到的lib包全部放置其target/xxx/pubLib文件夹中,执行: | |||
| ``` | |||
| mvn clean assembly:assembly | |||
| ``` | |||
| 2. 修改了sys-contract.properties文件,新增了CONTRACT_CLASS_LIBS参数; | |||
| - 将CONTRACT_CLASS_PATH专用于存储路径 | |||
| - CONTRACT_CLASS_LIBS来存放所有的jar包 | |||
| 3. 删减了contract-libs文件夹中需要动态生成的jar。 | |||
| @@ -12,7 +12,7 @@ | |||
| <dependencies> | |||
| <dependency> | |||
| <groupId>com.jd.blockchain</groupId> | |||
| <artifactId>contract-model</artifactId> | |||
| <artifactId>ledger-model</artifactId> | |||
| <version>${project.version}</version> | |||
| </dependency> | |||
| <dependency> | |||
| @@ -27,7 +27,6 @@ | |||
| <plugin> | |||
| <groupId>org.apache.maven.plugins</groupId> | |||
| <artifactId>maven-deploy-plugin</artifactId> | |||
| <version>2.8.2</version> | |||
| <configuration> | |||
| <skip>true</skip> | |||
| </configuration> | |||
| @@ -1,13 +0,0 @@ | |||
| package com.jd.blockchain.contract; | |||
| import com.jd.blockchain.contract.model.ContractEventContext; | |||
| public interface ContractCode { | |||
| String getAddress(); | |||
| long getVersion(); | |||
| void processEvent(ContractEventContext eventContext); | |||
| } | |||
| @@ -0,0 +1,14 @@ | |||
| package com.jd.blockchain.contract.engine; | |||
| import com.jd.blockchain.contract.ContractEventContext; | |||
| import com.jd.blockchain.utils.Bytes; | |||
| public interface ContractCode { | |||
| Bytes getAddress(); | |||
| long getVersion(); | |||
| void processEvent(ContractEventContext eventContext); | |||
| } | |||
| @@ -1,4 +1,6 @@ | |||
| package com.jd.blockchain.contract; | |||
| package com.jd.blockchain.contract.engine; | |||
| import com.jd.blockchain.utils.Bytes; | |||
| /** | |||
| * 合约引擎; | |||
| @@ -16,7 +18,7 @@ public interface ContractEngine { | |||
| * @param address | |||
| * @return | |||
| */ | |||
| ContractCode getContract(String address, long version); | |||
| ContractCode getContract(Bytes address, long version); | |||
| /** | |||
| * 装入合约代码;<br> | |||
| @@ -27,6 +29,6 @@ public interface ContractEngine { | |||
| * @param code | |||
| * @return | |||
| */ | |||
| ContractCode setupContract(String address, long version, byte[] code); | |||
| ContractCode setupContract(Bytes address, long version, byte[] code); | |||
| } | |||
| @@ -1,4 +1,4 @@ | |||
| package com.jd.blockchain.contract; | |||
| package com.jd.blockchain.contract.engine; | |||
| public interface ContractServiceProvider { | |||
| @@ -1,4 +1,4 @@ | |||
| package com.jd.blockchain.contract; | |||
| package com.jd.blockchain.contract.engine; | |||
| import java.util.Map; | |||
| import java.util.concurrent.ConcurrentHashMap; | |||
| @@ -1,21 +1,21 @@ | |||
| package com.jd.blockchain.contract.jvm; | |||
| import com.jd.blockchain.contract.ContractCode; | |||
| import com.jd.blockchain.contract.ContractEngine; | |||
| import com.jd.blockchain.contract.engine.ContractCode; | |||
| import com.jd.blockchain.contract.engine.ContractEngine; | |||
| import com.jd.blockchain.runtime.Module; | |||
| import com.jd.blockchain.runtime.RuntimeContext; | |||
| import com.jd.blockchain.utils.Bytes; | |||
| public class JVMContractEngine implements ContractEngine { | |||
| private RuntimeContext runtimeContext = RuntimeContext.get(); | |||
| // private RuntimeContext runtimeContext = ModularRuntimeContext.setup(System.getProperty("user.dir")); | |||
| private String getCodeName(String address, long version) { | |||
| return address + "_" + version; | |||
| private String getCodeName(Bytes address, long version) { | |||
| return address.toBase58() + "_" + version; | |||
| } | |||
| @Override | |||
| public ContractCode getContract(String address, long version) { | |||
| public ContractCode getContract(Bytes address, long version) { | |||
| String codeName = getCodeName(address, version); | |||
| Module module = runtimeContext.getDynamicModule(codeName); | |||
| if (module == null) { | |||
| @@ -25,7 +25,7 @@ public class JVMContractEngine implements ContractEngine { | |||
| } | |||
| @Override | |||
| public ContractCode setupContract(String address, long version, byte[] code) { | |||
| public ContractCode setupContract(Bytes address, long version, byte[] code) { | |||
| //is there the contractCode before setup? if yes ,then return; | |||
| ContractCode contractCode = getContract(address,version); | |||
| if(contractCode != null){ | |||
| @@ -1,7 +1,7 @@ | |||
| package com.jd.blockchain.contract.jvm; | |||
| import com.jd.blockchain.contract.ContractEngine; | |||
| import com.jd.blockchain.contract.ContractServiceProvider; | |||
| import com.jd.blockchain.contract.engine.ContractEngine; | |||
| import com.jd.blockchain.contract.engine.ContractServiceProvider; | |||
| public class JVMContractServiceProvider implements ContractServiceProvider { | |||
| @Override | |||
| @@ -1,22 +1,20 @@ | |||
| package com.jd.blockchain.contract.jvm; | |||
| import com.jd.blockchain.contract.ContractCode; | |||
| import com.jd.blockchain.contract.model.ContractEvent; | |||
| import com.jd.blockchain.contract.model.ContractEventContext; | |||
| import com.jd.blockchain.runtime.Module; | |||
| import com.jd.blockchain.utils.BaseConstant; | |||
| import java.lang.annotation.Annotation; | |||
| import java.lang.reflect.Method; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.util.ReflectionUtils; | |||
| import static com.jd.blockchain.utils.BaseConstant.CONTRACT_MAIN_CLASS_KEY; | |||
| import java.lang.annotation.Annotation; | |||
| import java.lang.reflect.Method; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| import java.util.Properties; | |||
| import com.jd.blockchain.contract.ContractEvent; | |||
| import com.jd.blockchain.contract.ContractEventContext; | |||
| import com.jd.blockchain.contract.engine.ContractCode; | |||
| import com.jd.blockchain.runtime.Module; | |||
| import com.jd.blockchain.utils.BaseConstant; | |||
| import com.jd.blockchain.utils.Bytes; | |||
| /** | |||
| * contract code based jvm | |||
| @@ -25,18 +23,18 @@ import java.util.Properties; | |||
| public class JavaContractCode implements ContractCode { | |||
| private static final Logger LOGGER = LoggerFactory.getLogger(JavaContractCode.class); | |||
| private Module codeModule; | |||
| private String address; | |||
| private Bytes address; | |||
| private long version; | |||
| private ContractEventContext contractEventContext; | |||
| public JavaContractCode(String address, long version, Module codeModule) { | |||
| public JavaContractCode(Bytes address, long version, Module codeModule) { | |||
| this.address = address; | |||
| this.version = version; | |||
| this.codeModule = codeModule; | |||
| } | |||
| @Override | |||
| public String getAddress() { | |||
| public Bytes getAddress() { | |||
| return address; | |||
| } | |||
| @@ -9,32 +9,33 @@ | |||
| </parent> | |||
| <artifactId>contract-maven-plugin</artifactId> | |||
| <packaging>maven-plugin</packaging> | |||
| <properties> | |||
| <contract.version>${parent.version}</contract.version> | |||
| <utils.version>${parent.version}</utils.version> | |||
| <junit.version>4.12</junit.version> | |||
| </properties> | |||
| <version>0.9.0-SNAPSHOT</version> | |||
| <dependencies> | |||
| <dependency> | |||
| <groupId>junit</groupId> | |||
| <artifactId>junit</artifactId> | |||
| <scope>test</scope> | |||
| <groupId>com.jd.blockchain</groupId> | |||
| <artifactId>ledger-model</artifactId> | |||
| <version>${project.version}</version> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>com.jd.blockchain</groupId> | |||
| <artifactId>contract-model</artifactId> | |||
| <version>${contract.version}</version> | |||
| <artifactId>utils-common</artifactId> | |||
| <version>${project.version}</version> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>com.jd.blockchain</groupId> | |||
| <artifactId>utils-common</artifactId> | |||
| <version>${utils.version}</version> | |||
| <artifactId>sdk-client</artifactId> | |||
| <version>${project.version}</version> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>com.jd.blockchain</groupId> | |||
| <artifactId>tools-keygen</artifactId> | |||
| <version>${project.version}</version> | |||
| </dependency> | |||
| <!-- https://mvnrepository.com/artifact/org.apache.maven.plugin-tools/maven-plugin-annotations --> | |||
| <dependency> | |||
| <groupId>org.apache.maven.plugin-tools</groupId> | |||
| @@ -83,29 +84,30 @@ | |||
| <showWarnings>false</showWarnings> | |||
| </configuration> | |||
| </plugin> | |||
| <!--<plugin>--> | |||
| <!--<artifactId>maven-assembly-plugin</artifactId>--> | |||
| <!--<configuration>--> | |||
| <!--<archive>--> | |||
| <!--<manifest>--> | |||
| <!--<!–这里要替换成jar包main方法所在类 –>--> | |||
| <!--<mainClass>com.jd.blockchain.ContractDeployMojo</mainClass>--> | |||
| <!--</manifest>--> | |||
| <!--</archive>--> | |||
| <!--<descriptorRefs>--> | |||
| <!--<descriptojar-rRef>jar-with-dependencies</descriptojar-rRef>--> | |||
| <!--</descriptorRefs>--> | |||
| <!--</configuration>--> | |||
| <!--<executions>--> | |||
| <!--<execution>--> | |||
| <!--<id>make-assembly</id> <!– this is used for inheritance merges –>--> | |||
| <!--<phase>package</phase> <!– 指定在打包节点执行jar包合并操作 –>--> | |||
| <!--<goals>--> | |||
| <!--<goal>single</goal>--> | |||
| <!--</goals>--> | |||
| <!--</execution>--> | |||
| <!--</executions>--> | |||
| <!--</plugin>--> | |||
| <!--<plugin> --> | |||
| <!--<artifactId>maven-assembly-plugin</artifactId> --> | |||
| <!--<configuration> --> | |||
| <!--<archive> --> | |||
| <!--<manifest> --> | |||
| <!--<!–这里要替换成jar包main方法所在类 –> --> | |||
| <!--<mainClass>com.jd.blockchain.ContractDeployMojo</mainClass> --> | |||
| <!--</manifest> --> | |||
| <!--</archive> --> | |||
| <!--<descriptorRefs> --> | |||
| <!--<descriptojar-rRef>jar-with-dependencies</descriptojar-rRef> --> | |||
| <!--</descriptorRefs> --> | |||
| <!--</configuration> --> | |||
| <!--<executions> --> | |||
| <!--<execution> --> | |||
| <!--<id>make-assembly</id> <!– this is used for inheritance merges | |||
| –> --> | |||
| <!--<phase>package</phase> <!– 指定在打包节点执行jar包合并操作 –> --> | |||
| <!--<goals> --> | |||
| <!--<goal>single</goal> --> | |||
| <!--</goals> --> | |||
| <!--</execution> --> | |||
| <!--</executions> --> | |||
| <!--</plugin> --> | |||
| <plugin> | |||
| <groupId>org.apache.maven.plugins</groupId> | |||
| @@ -1,4 +1,4 @@ | |||
| package com.jd.blockchain.contract.model; | |||
| package com.jd.blockchain; | |||
| import java.io.File; | |||
| import java.io.FileInputStream; | |||
| @@ -160,25 +160,28 @@ public enum ContractDeployExeUtil { | |||
| return deploy(ledgerHash, contractIdentity, ownerKey, chainCode); | |||
| } | |||
| public boolean exeContract(String ledger,String ownerPubPath, String ownerPrvPath, | |||
| String ownerPassword,String event,String contractArgs){ | |||
| BlockchainKeypair ownerKey = getKeyPair(ownerPubPath, ownerPrvPath, ownerPassword); | |||
| HashDigest ledgerHash = new HashDigest(Base58Utils.decode(ledger)); | |||
| // 定义交易,传输最简单的数字、字符串、提取合约中的地址; | |||
| TransactionTemplate txTpl = bcsrv.newTransaction(ledgerHash); | |||
| txTpl.contractEvents().send(getContractAddress(),event,contractArgs.getBytes()); | |||
| // 签名; | |||
| PreparedTransaction ptx = txTpl.prepare(); | |||
| ptx.sign(ownerKey); | |||
| // 提交并等待共识返回; | |||
| TransactionResponse txResp = ptx.commit(); | |||
| // 验证结果; | |||
| return txResp.isSuccess(); | |||
| } | |||
| // 暂不支持从插件执行合约;此外,由于合约参数调用的格式发生变化,故此方法被废弃;by: huanghaiquan at 2019-04-30; | |||
| // public boolean exeContract(String ledger,String ownerPubPath, String ownerPrvPath, | |||
| // String ownerPassword,String event,String contractArgs){ | |||
| // BlockchainKeypair ownerKey = getKeyPair(ownerPubPath, ownerPrvPath, ownerPassword); | |||
| // HashDigest ledgerHash = new HashDigest(Base58Utils.decode(ledger)); | |||
| // | |||
| // // 定义交易,传输最简单的数字、字符串、提取合约中的地址; | |||
| // TransactionTemplate txTpl = bcsrv.newTransaction(ledgerHash); | |||
| // txTpl.contractEvents().send(getContractAddress(),event,contractArgs.getBytes()); | |||
| // | |||
| // // 签名; | |||
| // PreparedTransaction ptx = txTpl.prepare(); | |||
| // ptx.sign(ownerKey); | |||
| // | |||
| // // 提交并等待共识返回; | |||
| // TransactionResponse txResp = ptx.commit(); | |||
| // | |||
| // // 验证结果; | |||
| // return txResp.isSuccess(); | |||
| // } | |||
| public Bytes getContractAddress() { | |||
| return contractAddress; | |||
| @@ -1,6 +1,5 @@ | |||
| package com.jd.blockchain; | |||
| import com.jd.blockchain.contract.model.ContractDeployExeUtil; | |||
| import com.jd.blockchain.crypto.HashDigest; | |||
| import com.jd.blockchain.crypto.PrivKey; | |||
| import com.jd.blockchain.crypto.PubKey; | |||
| @@ -1,37 +0,0 @@ | |||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | |||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||
| <modelVersion>4.0.0</modelVersion> | |||
| <parent> | |||
| <groupId>com.jd.blockchain</groupId> | |||
| <artifactId>contract</artifactId> | |||
| <version>0.9.0-SNAPSHOT</version> | |||
| </parent> | |||
| <artifactId>contract-model</artifactId> | |||
| <dependencies> | |||
| <dependency> | |||
| <groupId>com.jd.blockchain</groupId> | |||
| <artifactId>sdk-client</artifactId> | |||
| <version>${project.version}</version> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>com.jd.blockchain</groupId> | |||
| <artifactId>tools-keygen</artifactId> | |||
| <version>${project.version}</version> | |||
| <exclusions> | |||
| <exclusion> | |||
| <artifactId>crypto-framework</artifactId> | |||
| <groupId>com.jd.blockchain</groupId> | |||
| </exclusion> | |||
| </exclusions> | |||
| </dependency> | |||
| <!--<dependency>--> | |||
| <!--<groupId>com.jd.blockchain</groupId>--> | |||
| <!--<artifactId>tools-initializer</artifactId>--> | |||
| <!--<version>${project.version}</version>--> | |||
| <!--</dependency>--> | |||
| </dependencies> | |||
| </project> | |||
| @@ -1,11 +0,0 @@ | |||
| package com.jd.blockchain.contract.model; | |||
| import com.jd.blockchain.ledger.data.DataAccountOperator; | |||
| import com.jd.blockchain.ledger.data.UserOperator; | |||
| import com.jd.blockchain.sdk.BlockchainQueryService; | |||
| public interface LedgerContext extends BlockchainQueryService, UserOperator, DataAccountOperator{ | |||
| } | |||
| @@ -1,7 +0,0 @@ | |||
| #项目源文件存放的位置; | |||
| PROJECT_BASE_DIR=e:\\gitCode\\block\\prototype\\ | |||
| #合同使用的类库存放的位置,可能不在项目中,故采用全新的地址; | |||
| LEDGER_BASE_CLASS_PATH=e:\\gitCode\\block\\prototype\\libs\\ | |||
| BLACKLIST=java.io;java.net;java.util.Random | |||
| #type:public,private | |||
| CONTRACT_CLASSLOADER_TYPE=private | |||
| @@ -10,7 +10,6 @@ | |||
| <packaging>pom</packaging> | |||
| <modules> | |||
| <module>contract-model</module> | |||
| <module>contract-framework</module> | |||
| <module>contract-jvm</module> | |||
| <module>contract-maven-plugin</module> | |||
| @@ -5,11 +5,11 @@ import java.io.OutputStream; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| import com.jd.blockchain.utils.io.BytesUtils; | |||
| @DataContract(code = TypeCodes.CRYPTO_ALGORITHM) | |||
| @DataContract(code = DataCodes.CRYPTO_ALGORITHM) | |||
| public interface CryptoAlgorithm { | |||
| /** | |||
| @@ -63,7 +63,7 @@ public interface CryptoAlgorithm { | |||
| * {@link #EXT_ALGORITHM}) 5 种); 接下来4位标识密钥类型(包括:{@link #SYMMETRIC_KEY}, | |||
| * {@link #ASYMMETRIC_KEY}); 最后8位是算法唯一ID; | |||
| */ | |||
| @DataField(primitiveType = ValueType.INT16, order = 0) | |||
| @DataField(primitiveType = PrimitiveType.INT16, order = 0) | |||
| short code(); | |||
| /** | |||
| @@ -1,7 +1,7 @@ | |||
| package com.jd.blockchain.gateway; | |||
| import com.jd.blockchain.ledger.data.TransactionService; | |||
| import com.jd.blockchain.sdk.BlockchainQueryService; | |||
| import com.jd.blockchain.transaction.BlockchainQueryService; | |||
| import com.jd.blockchain.transaction.TransactionService; | |||
| public interface PeerService { | |||
| @@ -7,9 +7,9 @@ import org.springframework.stereotype.Component; | |||
| import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
| import com.jd.blockchain.gateway.PeerConnector; | |||
| import com.jd.blockchain.gateway.PeerService; | |||
| import com.jd.blockchain.ledger.data.TransactionService; | |||
| import com.jd.blockchain.sdk.BlockchainQueryService; | |||
| import com.jd.blockchain.sdk.service.PeerBlockchainServiceFactory; | |||
| import com.jd.blockchain.transaction.BlockchainQueryService; | |||
| import com.jd.blockchain.transaction.TransactionService; | |||
| import com.jd.blockchain.utils.net.NetworkAddress; | |||
| import java.util.List; | |||
| @@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.RequestMethod; | |||
| import org.springframework.web.bind.annotation.ResponseBody; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import com.jd.blockchain.binaryproto.BinaryEncodingUtils; | |||
| import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
| import com.jd.blockchain.crypto.Crypto; | |||
| import com.jd.blockchain.crypto.HashDigest; | |||
| import com.jd.blockchain.crypto.SignatureFunction; | |||
| @@ -16,7 +16,7 @@ import com.jd.blockchain.ledger.DigitalSignature; | |||
| import com.jd.blockchain.ledger.TransactionContent; | |||
| import com.jd.blockchain.ledger.TransactionRequest; | |||
| import com.jd.blockchain.ledger.TransactionResponse; | |||
| import com.jd.blockchain.ledger.data.TransactionService; | |||
| import com.jd.blockchain.transaction.TransactionService; | |||
| import com.jd.blockchain.utils.BusinessException; | |||
| import com.jd.blockchain.web.converters.BinaryMessageConverter; | |||
| @@ -53,7 +53,7 @@ public class TxProcessingController implements TransactionService { | |||
| throw new IllegalStateException("Not implemented!"); | |||
| } else { | |||
| // 验证签名; | |||
| byte[] content = BinaryEncodingUtils.encode(txRequest.getTransactionContent(), TransactionContent.class); | |||
| byte[] content = BinaryProtocol.encode(txRequest.getTransactionContent(), TransactionContent.class); | |||
| for (DigitalSignature sign : partiSigns) { | |||
| SignatureFunction signFunc = Crypto | |||
| .getSignatureFunction(sign.getPubKey().getAlgorithm()); | |||
| @@ -3,7 +3,7 @@ package com.jd.blockchain.ledger.core; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| import com.jd.blockchain.binaryproto.BinaryEncodingUtils; | |||
| import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
| import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
| import com.jd.blockchain.crypto.AddressEncoding; | |||
| import com.jd.blockchain.crypto.HashDigest; | |||
| @@ -99,7 +99,7 @@ public class AccountSet implements Transactional, MerkleProvable { | |||
| // } | |||
| private AccountHeader deserialize(byte[] txBytes) { | |||
| return BinaryEncodingUtils.decode(txBytes); | |||
| return BinaryProtocol.decode(txBytes); | |||
| } | |||
| /** | |||
| @@ -289,13 +289,13 @@ public class AccountSet implements Transactional, MerkleProvable { | |||
| private VersioningAccount deserialize(byte[] bytes, CryptoSetting cryptoSetting, String keyPrefix, | |||
| ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly, long version) { | |||
| AccountHeader accInfo = BinaryEncodingUtils.decode(bytes); | |||
| AccountHeader accInfo = BinaryProtocol.decode(bytes); | |||
| return new VersioningAccount(accInfo.getAddress(), accInfo.getPubKey(), accInfo.getRootHash(), cryptoSetting, | |||
| keyPrefix, exStorage, verStorage, readonly, accessPolicy, version); | |||
| } | |||
| private byte[] serialize(AccountHeader account) { | |||
| return BinaryEncodingUtils.encode(account, AccountHeader.class); | |||
| return BinaryProtocol.encode(account, AccountHeader.class); | |||
| } | |||
| @Override | |||
| @@ -8,11 +8,8 @@ import com.jd.blockchain.utils.io.BytesUtils; | |||
| public class ContractAccount implements AccountHeader { | |||
| // private static final String CONTRACT_INFO_PREFIX = "INFO" + | |||
| // LedgerConsts.KEY_SEPERATOR; | |||
| private static final Bytes CONTRACT_INFO_PREFIX = Bytes.fromString("INFO" + LedgerConsts.KEY_SEPERATOR); | |||
| // private static final String CHAIN_CODE_KEY = "CHAIN-CODE"; | |||
| private static final Bytes CHAIN_CODE_KEY = Bytes.fromString("CHAIN-CODE"); | |||
| private BaseAccount accBase; | |||
| @@ -74,7 +71,6 @@ public class ContractAccount implements AccountHeader { | |||
| private Bytes encodePropertyKey(Bytes key) { | |||
| return CONTRACT_INFO_PREFIX.concat(key); | |||
| // return key.concatTo(CONTRACT_INFO_PREFIX); | |||
| } | |||
| } | |||
| @@ -1,6 +1,7 @@ | |||
| package com.jd.blockchain.ledger.core; | |||
| import com.jd.blockchain.binaryproto.BinaryEncodingUtils; | |||
| import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.crypto.HashDigest; | |||
| import com.jd.blockchain.crypto.PubKey; | |||
| import com.jd.blockchain.ledger.AccountHeader; | |||
| @@ -8,7 +9,6 @@ import com.jd.blockchain.ledger.BytesValue; | |||
| import com.jd.blockchain.ledger.KVDataEntry; | |||
| import com.jd.blockchain.ledger.KVDataObject; | |||
| import com.jd.blockchain.utils.Bytes; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| import com.jd.blockchain.utils.serialize.binary.BinarySerializeUtils; | |||
| public class DataAccount implements AccountHeader, MerkleProvable { | |||
| @@ -141,8 +141,8 @@ public class DataAccount implements AccountHeader, MerkleProvable { | |||
| value = baseAccount.dataset.getValuesAtIndex(fromIndex); | |||
| key = baseAccount.dataset.getKeyAtIndex(fromIndex); | |||
| ver = baseAccount.dataset.getVersion(key); | |||
| BytesValue decodeData = BinaryEncodingUtils.decode(value); | |||
| kvDataEntries[i] = new KVDataObject(key, ver, ValueType.valueOf(decodeData.getType().CODE), decodeData.getValue().toBytes()); | |||
| BytesValue decodeData = BinaryProtocol.decode(value); | |||
| kvDataEntries[i] = new KVDataObject(key, ver, PrimitiveType.valueOf(decodeData.getType().CODE), decodeData.getValue().toBytes()); | |||
| fromIndex++; | |||
| } | |||
| @@ -3,7 +3,7 @@ package com.jd.blockchain.ledger.core; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import com.jd.blockchain.binaryproto.BinaryEncodingUtils; | |||
| import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
| import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
| import com.jd.blockchain.crypto.Crypto; | |||
| import com.jd.blockchain.crypto.HashDigest; | |||
| @@ -288,11 +288,11 @@ public class LedgerAdminAccount implements Transactional, LedgerAdministration { | |||
| } | |||
| private LedgerMetadata deserializeMetadata(byte[] bytes) { | |||
| return BinaryEncodingUtils.decode(bytes); | |||
| return BinaryProtocol.decode(bytes); | |||
| } | |||
| private byte[] serializeMetadata(LedgerMetadataImpl config) { | |||
| return BinaryEncodingUtils.encode(config, LedgerMetadata.class); | |||
| return BinaryProtocol.encode(config, LedgerMetadata.class); | |||
| } | |||
| @Override | |||
| @@ -2,10 +2,10 @@ package com.jd.blockchain.ledger.core; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| import com.jd.blockchain.crypto.HashDigest; | |||
| import com.jd.blockchain.crypto.SignatureDigest; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| /** | |||
| * 账本初始化决定; | |||
| @@ -13,7 +13,7 @@ import com.jd.blockchain.utils.ValueType; | |||
| * @author huanghaiquan | |||
| * | |||
| */ | |||
| @DataContract(code = TypeCodes.METADATA_INIT_DECISION) | |||
| @DataContract(code = DataCodes.METADATA_INIT_DECISION) | |||
| public interface LedgerInitDecision { | |||
| /** | |||
| @@ -21,14 +21,14 @@ public interface LedgerInitDecision { | |||
| * | |||
| * @return | |||
| */ | |||
| @DataField(order=1, primitiveType=ValueType.INT32) | |||
| @DataField(order=1, primitiveType=PrimitiveType.INT32) | |||
| int getParticipantId(); | |||
| /** | |||
| * 新建账本的哈希; | |||
| * @return | |||
| */ | |||
| @DataField(order=2, primitiveType = ValueType.BYTES) | |||
| @DataField(order=2, primitiveType = PrimitiveType.BYTES) | |||
| HashDigest getLedgerHash(); | |||
| /** | |||
| @@ -40,7 +40,7 @@ public interface LedgerInitDecision { | |||
| * | |||
| * @return | |||
| */ | |||
| @DataField(order=3, primitiveType = ValueType.BYTES) | |||
| @DataField(order=3, primitiveType = PrimitiveType.BYTES) | |||
| SignatureDigest getSignature(); | |||
| } | |||
| @@ -2,10 +2,10 @@ package com.jd.blockchain.ledger.core; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| import com.jd.blockchain.crypto.SignatureDigest; | |||
| import com.jd.blockchain.ledger.LedgerInitOperation; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| /** | |||
| * 账本初始化许可; | |||
| @@ -13,7 +13,7 @@ import com.jd.blockchain.utils.ValueType; | |||
| * @author huanghaiquan | |||
| * | |||
| */ | |||
| @DataContract(code = TypeCodes.METADATA_INIT_PERMISSION) | |||
| @DataContract(code = DataCodes.METADATA_INIT_PERMISSION) | |||
| public interface LedgerInitPermission { | |||
| /** | |||
| @@ -21,7 +21,7 @@ public interface LedgerInitPermission { | |||
| * | |||
| * @return | |||
| */ | |||
| @DataField(order = 1, primitiveType = ValueType.INT32) | |||
| @DataField(order = 1, primitiveType = PrimitiveType.INT32) | |||
| int getParticipantId(); | |||
| /** | |||
| @@ -39,7 +39,7 @@ public interface LedgerInitPermission { | |||
| * | |||
| * @return | |||
| */ | |||
| @DataField(order = 2, primitiveType = ValueType.BYTES) | |||
| @DataField(order = 2, primitiveType = PrimitiveType.BYTES) | |||
| SignatureDigest getTransactionSignature(); | |||
| } | |||
| @@ -2,11 +2,11 @@ package com.jd.blockchain.ledger.core; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| import com.jd.blockchain.crypto.HashDigest; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| @DataContract(code = TypeCodes.METADATA) | |||
| @DataContract(code = DataCodes.METADATA) | |||
| public interface LedgerMetadata { | |||
| /** | |||
| @@ -14,7 +14,7 @@ public interface LedgerMetadata { | |||
| * | |||
| * @return | |||
| */ | |||
| @DataField(order = 1, primitiveType = ValueType.BYTES) | |||
| @DataField(order = 1, primitiveType = PrimitiveType.BYTES) | |||
| byte[] getSeed(); | |||
| /** | |||
| @@ -22,7 +22,7 @@ public interface LedgerMetadata { | |||
| * | |||
| * @return | |||
| */ | |||
| @DataField(order = 2, primitiveType = ValueType.BYTES) | |||
| @DataField(order = 2, primitiveType = PrimitiveType.BYTES) | |||
| HashDigest getParticipantsHash(); | |||
| /** | |||
| @@ -2,18 +2,18 @@ package com.jd.blockchain.ledger.core; | |||
| import com.jd.blockchain.binaryproto.DataContract; | |||
| import com.jd.blockchain.binaryproto.DataField; | |||
| import com.jd.blockchain.consts.TypeCodes; | |||
| import com.jd.blockchain.binaryproto.PrimitiveType; | |||
| import com.jd.blockchain.consts.DataCodes; | |||
| import com.jd.blockchain.ledger.CryptoSetting; | |||
| import com.jd.blockchain.utils.Bytes; | |||
| import com.jd.blockchain.utils.ValueType; | |||
| @DataContract(code = TypeCodes.METADATA_LEDGER_SETTING) | |||
| @DataContract(code = DataCodes.METADATA_LEDGER_SETTING) | |||
| public interface LedgerSetting { | |||
| @DataField(order=0, primitiveType=ValueType.TEXT) | |||
| @DataField(order=0, primitiveType=PrimitiveType.TEXT) | |||
| String getConsensusProvider(); | |||
| @DataField(order=1, primitiveType=ValueType.BYTES) | |||
| @DataField(order=1, primitiveType=PrimitiveType.BYTES) | |||
| Bytes getConsensusSetting(); | |||
| @DataField(order=2, refContract=true) | |||
| @@ -1,6 +1,6 @@ | |||
| package com.jd.blockchain.ledger.core; | |||
| import com.jd.blockchain.binaryproto.BinaryEncodingUtils; | |||
| import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
| import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
| import com.jd.blockchain.crypto.HashDigest; | |||
| import com.jd.blockchain.ledger.ParticipantNode; | |||
| @@ -65,7 +65,7 @@ public class ParticipantDataSet implements Transactional, MerkleProvable { | |||
| */ | |||
| public void addConsensusParticipant(ParticipantNode participant) { | |||
| Bytes key = encodeKey(participant.getAddress()); | |||
| byte[] participantBytes = BinaryEncodingUtils.encode(participant, ParticipantNode.class); | |||
| byte[] participantBytes = BinaryProtocol.encode(participant, ParticipantNode.class); | |||
| long nv = dataset.setValue(key, participantBytes, -1); | |||
| if (nv < 0) { | |||
| throw new LedgerException("Participant already exist! --[id=" + key + "]"); | |||
| @@ -92,7 +92,7 @@ public class ParticipantDataSet implements Transactional, MerkleProvable { | |||
| if (bytes == null) { | |||
| return null; | |||
| } | |||
| return BinaryEncodingUtils.decode(bytes); | |||
| return BinaryProtocol.decode(bytes); | |||
| } | |||
| public ParticipantNode[] getParticipants() { | |||
| @@ -100,7 +100,7 @@ public class ParticipantDataSet implements Transactional, MerkleProvable { | |||
| ParticipantNode[] pns = new ParticipantNode[bytes.length]; | |||
| for (int i = 0; i < pns.length; i++) { | |||
| pns[i] = BinaryEncodingUtils.decode(bytes[i]); | |||
| pns[i] = BinaryProtocol.decode(bytes[i]); | |||
| } | |||
| return pns; | |||
| } | |||