@@ -1,11 +1,12 @@ | |||||
package com.jd.blockchain.contract; | package com.jd.blockchain.contract; | ||||
import java.util.Set; | |||||
import com.jd.blockchain.crypto.HashDigest; | import com.jd.blockchain.crypto.HashDigest; | ||||
import com.jd.blockchain.ledger.BlockchainIdentity; | import com.jd.blockchain.ledger.BlockchainIdentity; | ||||
import com.jd.blockchain.ledger.BytesValueList; | |||||
import com.jd.blockchain.ledger.TransactionRequest; | import com.jd.blockchain.ledger.TransactionRequest; | ||||
import java.util.Set; | |||||
public interface ContractEventContext { | public interface ContractEventContext { | ||||
@@ -42,7 +43,7 @@ public interface ContractEventContext { | |||||
* | * | ||||
* @return | * @return | ||||
*/ | */ | ||||
byte[] getArgs(); | |||||
BytesValueList getArgs(); | |||||
/** | /** | ||||
* 账本操作上下文; | * 账本操作上下文; | ||||
@@ -14,6 +14,7 @@ import com.jd.blockchain.contract.param.WRAP_LONG; | |||||
import com.jd.blockchain.contract.param.WRAP_SHORT; | import com.jd.blockchain.contract.param.WRAP_SHORT; | ||||
import com.jd.blockchain.contract.param.WRAP_STRING; | import com.jd.blockchain.contract.param.WRAP_STRING; | ||||
import com.jd.blockchain.ledger.BytesValue; | import com.jd.blockchain.ledger.BytesValue; | ||||
import com.jd.blockchain.ledger.BytesValueList; | |||||
import com.jd.blockchain.utils.io.BytesUtils; | import com.jd.blockchain.utils.io.BytesUtils; | ||||
public class ContractSerializeUtils { | public class ContractSerializeUtils { | ||||
@@ -82,7 +83,7 @@ public class ContractSerializeUtils { | |||||
return BinaryProtocol.encode(wrapData, serialClass); | return BinaryProtocol.encode(wrapData, serialClass); | ||||
} | } | ||||
public static byte[] serializeArray(Object[] datas) { | |||||
public static BytesValueList serializeArray(Object[] datas) { | |||||
if (datas == null || datas.length == 0) { | if (datas == null || datas.length == 0) { | ||||
return null; | return null; | ||||
} | } | ||||
@@ -4,6 +4,7 @@ import java.util.Set; | |||||
import com.jd.blockchain.crypto.HashDigest; | import com.jd.blockchain.crypto.HashDigest; | ||||
import com.jd.blockchain.ledger.BlockchainIdentity; | import com.jd.blockchain.ledger.BlockchainIdentity; | ||||
import com.jd.blockchain.ledger.BytesValueList; | |||||
import com.jd.blockchain.ledger.TransactionRequest; | import com.jd.blockchain.ledger.TransactionRequest; | ||||
/** | /** | ||||
@@ -13,7 +14,7 @@ import com.jd.blockchain.ledger.TransactionRequest; | |||||
public class LocalContractEventContext implements ContractEventContext,Cloneable { | public class LocalContractEventContext implements ContractEventContext,Cloneable { | ||||
private HashDigest ledgeHash; | private HashDigest ledgeHash; | ||||
private String event; | private String event; | ||||
private byte[] args; | |||||
private BytesValueList args; | |||||
private TransactionRequest transactionRequest; | private TransactionRequest transactionRequest; | ||||
private Set<BlockchainIdentity> txSigners; | private Set<BlockchainIdentity> txSigners; | ||||
private LedgerContext ledgerContext; | private LedgerContext ledgerContext; | ||||
@@ -44,7 +45,7 @@ public class LocalContractEventContext implements ContractEventContext,Cloneable | |||||
} | } | ||||
@Override | @Override | ||||
public byte[] getArgs() { | |||||
public BytesValueList getArgs() { | |||||
return args; | return args; | ||||
} | } | ||||
@@ -92,7 +93,7 @@ public class LocalContractEventContext implements ContractEventContext,Cloneable | |||||
// return this; | // return this; | ||||
// } | // } | ||||
public LocalContractEventContext setArgs(byte[] args) { | |||||
public LocalContractEventContext setArgs(BytesValueList args) { | |||||
this.args = args; | this.args = args; | ||||
return this; | return this; | ||||
} | } | ||||
@@ -1,11 +1,13 @@ | |||||
package com.jd.blockchain.ledger; | package com.jd.blockchain.ledger; | ||||
import com.jd.blockchain.binaryproto.DataContract; | import com.jd.blockchain.binaryproto.DataContract; | ||||
import com.jd.blockchain.binaryproto.DataField; | |||||
import com.jd.blockchain.consts.DataCodes; | import com.jd.blockchain.consts.DataCodes; | ||||
@DataContract(code = DataCodes.BYTES_VALUE_LIST) | @DataContract(code = DataCodes.BYTES_VALUE_LIST) | ||||
public interface BytesValueList { | public interface BytesValueList { | ||||
@DataField(order = 0, refContract = true, list = true) | |||||
BytesValue[] getValues(); | BytesValue[] getValues(); | ||||
} | } |
@@ -7,6 +7,8 @@ import com.jd.blockchain.consts.DataCodes; | |||||
import com.jd.blockchain.utils.Bytes; | import com.jd.blockchain.utils.Bytes; | ||||
/** | /** | ||||
* 发送合约事件的操作; | |||||
* | |||||
* @author huanghaiquan | * @author huanghaiquan | ||||
* | * | ||||
*/ | */ | ||||
@@ -35,6 +37,6 @@ public interface ContractEventSendOperation extends Operation { | |||||
* @return | * @return | ||||
*/ | */ | ||||
@DataField(order = 4, primitiveType = PrimitiveType.BYTES) | @DataField(order = 4, primitiveType = PrimitiveType.BYTES) | ||||
byte[] getArgs(); | |||||
BytesValueList getArgs(); | |||||
} | } |
@@ -6,6 +6,7 @@ import java.util.List; | |||||
import com.jd.blockchain.ledger.BlockchainIdentity; | import com.jd.blockchain.ledger.BlockchainIdentity; | ||||
import com.jd.blockchain.ledger.BytesValue; | import com.jd.blockchain.ledger.BytesValue; | ||||
import com.jd.blockchain.ledger.BytesValueList; | |||||
import com.jd.blockchain.ledger.ContractCodeDeployOperation; | import com.jd.blockchain.ledger.ContractCodeDeployOperation; | ||||
import com.jd.blockchain.ledger.ContractEventSendOperation; | import com.jd.blockchain.ledger.ContractEventSendOperation; | ||||
import com.jd.blockchain.ledger.DataAccountKVSetOperation; | import com.jd.blockchain.ledger.DataAccountKVSetOperation; | ||||
@@ -258,12 +259,12 @@ public class BlockchainOperationFactory implements ClientOperator, LedgerInitOpe | |||||
private class ContractEventSendOperationBuilderFilter implements ContractEventSendOperationBuilder { | private class ContractEventSendOperationBuilderFilter implements ContractEventSendOperationBuilder { | ||||
@Override | @Override | ||||
public ContractEventSendOperation send(String address, String event, byte[] args) { | |||||
public ContractEventSendOperation send(String address, String event, BytesValueList args) { | |||||
return send(Bytes.fromBase58(address), event, args); | return send(Bytes.fromBase58(address), event, args); | ||||
} | } | ||||
@Override | @Override | ||||
public synchronized ContractEventSendOperation send(Bytes address, String event, byte[] args) { | |||||
public synchronized ContractEventSendOperation send(Bytes address, String event, BytesValueList args) { | |||||
ContractEventSendOpTemplate op = new ContractEventSendOpTemplate(address, event, args); | ContractEventSendOpTemplate op = new ContractEventSendOpTemplate(address, event, args); | ||||
operationList.add(op); | operationList.add(op); | ||||
return op; | return op; | ||||
@@ -1,6 +1,7 @@ | |||||
package com.jd.blockchain.transaction; | package com.jd.blockchain.transaction; | ||||
import com.jd.blockchain.binaryproto.DataContractRegistry; | import com.jd.blockchain.binaryproto.DataContractRegistry; | ||||
import com.jd.blockchain.ledger.BytesValueList; | |||||
import com.jd.blockchain.ledger.ContractEventSendOperation; | import com.jd.blockchain.ledger.ContractEventSendOperation; | ||||
import com.jd.blockchain.utils.Bytes; | import com.jd.blockchain.utils.Bytes; | ||||
@@ -11,12 +12,12 @@ public class ContractEventSendOpTemplate implements ContractEventSendOperation { | |||||
} | } | ||||
private Bytes contractAddress; | private Bytes contractAddress; | ||||
private byte[] args; | |||||
private BytesValueList args; | |||||
private String event; | private String event; | ||||
private ContractInvocation invocation; | private ContractInvocation invocation; | ||||
public ContractEventSendOpTemplate(Bytes contractAddress, String event, byte[] args) { | |||||
public ContractEventSendOpTemplate(Bytes contractAddress, String event, BytesValueList args) { | |||||
this.contractAddress = contractAddress; | this.contractAddress = contractAddress; | ||||
this.event = event; | this.event = event; | ||||
this.args = args; | this.args = args; | ||||
@@ -33,7 +34,7 @@ public class ContractEventSendOpTemplate implements ContractEventSendOperation { | |||||
} | } | ||||
@Override | @Override | ||||
public byte[] getArgs() { | |||||
public BytesValueList getArgs() { | |||||
return args; | return args; | ||||
} | } | ||||
@@ -1,5 +1,6 @@ | |||||
package com.jd.blockchain.transaction; | package com.jd.blockchain.transaction; | ||||
import com.jd.blockchain.ledger.BytesValueList; | |||||
import com.jd.blockchain.ledger.ContractEventSendOperation; | import com.jd.blockchain.ledger.ContractEventSendOperation; | ||||
import com.jd.blockchain.utils.Bytes; | import com.jd.blockchain.utils.Bytes; | ||||
@@ -11,7 +12,7 @@ public interface ContractEventSendOperationBuilder { | |||||
* @param args 事件参数; | * @param args 事件参数; | ||||
* @return | * @return | ||||
*/ | */ | ||||
ContractEventSendOperation send(String address, String event, byte[] args); | |||||
ContractEventSendOperation send(String address, String event, BytesValueList args); | |||||
/** | /** | ||||
* @param address 合约地址; | * @param address 合约地址; | ||||
@@ -19,5 +20,5 @@ public interface ContractEventSendOperationBuilder { | |||||
* @param args 事件参数; | * @param args 事件参数; | ||||
* @return | * @return | ||||
*/ | */ | ||||
ContractEventSendOperation send(Bytes address, String event, byte[] args); | |||||
ContractEventSendOperation send(Bytes address, String event, BytesValueList args); | |||||
} | } |
@@ -7,6 +7,7 @@ import java.util.Arrays; | |||||
import com.jd.blockchain.contract.ContractException; | import com.jd.blockchain.contract.ContractException; | ||||
import com.jd.blockchain.contract.ContractSerializeUtils; | import com.jd.blockchain.contract.ContractSerializeUtils; | ||||
import com.jd.blockchain.contract.ContractType; | import com.jd.blockchain.contract.ContractType; | ||||
import com.jd.blockchain.ledger.BytesValueList; | |||||
import com.jd.blockchain.utils.Bytes; | import com.jd.blockchain.utils.Bytes; | ||||
import com.jd.blockchain.utils.IllegalDataException; | import com.jd.blockchain.utils.IllegalDataException; | ||||
@@ -51,10 +52,9 @@ public class ContractInvocationHandler implements InvocationHandler { | |||||
method.toString())); | method.toString())); | ||||
} | } | ||||
// 序列化调用参数; | // 序列化调用参数; | ||||
byte[] argBytes = serializeArgs(args); | |||||
BytesValueList argBytes = serializeArgs(args); | |||||
// 定义合约调用操作; | // 定义合约调用操作; | ||||
@SuppressWarnings("deprecation") | |||||
ContractEventSendOpTemplate opTemplate = (ContractEventSendOpTemplate) sendOpBuilder.send(contractAddress, | ContractEventSendOpTemplate opTemplate = (ContractEventSendOpTemplate) sendOpBuilder.send(contractAddress, | ||||
event, argBytes); | event, argBytes); | ||||
@@ -71,7 +71,7 @@ public class ContractInvocationHandler implements InvocationHandler { | |||||
return getDefaultValue(method.getReturnType()); | return getDefaultValue(method.getReturnType()); | ||||
} | } | ||||
private byte[] serializeArgs(Object[] args) { | |||||
private BytesValueList serializeArgs(Object[] args) { | |||||
return ContractSerializeUtils.serializeArray(args); | return ContractSerializeUtils.serializeArray(args); | ||||
} | } | ||||
@@ -12,6 +12,7 @@ import com.jd.blockchain.contract.LedgerContext; | |||||
import com.jd.blockchain.crypto.HashDigest; | import com.jd.blockchain.crypto.HashDigest; | ||||
import com.jd.blockchain.ledger.BlockchainIdentity; | import com.jd.blockchain.ledger.BlockchainIdentity; | ||||
import com.jd.blockchain.ledger.BytesValue; | import com.jd.blockchain.ledger.BytesValue; | ||||
import com.jd.blockchain.ledger.BytesValueList; | |||||
import com.jd.blockchain.ledger.ContractEventSendOperation; | import com.jd.blockchain.ledger.ContractEventSendOperation; | ||||
import com.jd.blockchain.ledger.Operation; | import com.jd.blockchain.ledger.Operation; | ||||
import com.jd.blockchain.ledger.TransactionRequest; | import com.jd.blockchain.ledger.TransactionRequest; | ||||
@@ -134,7 +135,7 @@ public class MockerContractExeHandle implements OperationHandle { | |||||
} | } | ||||
@Override | @Override | ||||
public byte[] getArgs() { | |||||
public BytesValueList getArgs() { | |||||
return null; | return null; | ||||
} | } | ||||