# Conflicts: # source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/client/BftsmartConsensusClient.java # source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/ContractEventSendOperationHandle.java # source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/ContractEventSendOperation.java # source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/TransactionContent.java # source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/TransactionContentBody.java # source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ContractEventSendOpTemplate.java # source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/TxBuilder.java # source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/TxContentBlob.javatags/1.0.0
@@ -1,26 +1,30 @@ | |||
package com.jd.blockchain.ledger; | |||
import com.jd.blockchain.binaryproto.DataContract; | |||
import com.jd.blockchain.binaryproto.DataField; | |||
import com.jd.blockchain.binaryproto.PrimitiveType; | |||
import com.jd.blockchain.consts.DataCodes; | |||
import com.jd.blockchain.utils.Bytes; | |||
/** | |||
* @author huanghaiquan | |||
* | |||
*/ | |||
@DataContract(code= DataCodes.TX_OP_CONTRACT_EVENT_SEND) | |||
public interface ContractEventSendOperation extends Operation { | |||
@DataField(order=2, primitiveType=PrimitiveType.BYTES) | |||
Bytes getContractAddress(); | |||
@DataField(order=3, primitiveType=PrimitiveType.TEXT) | |||
String getEvent(); | |||
@DataField(order=4, primitiveType=PrimitiveType.BYTES) | |||
byte[] getArgs(); | |||
} | |||
package com.jd.blockchain.ledger; | |||
import com.jd.blockchain.binaryproto.DataContract; | |||
import com.jd.blockchain.binaryproto.DataField; | |||
import com.jd.blockchain.binaryproto.PrimitiveType; | |||
import com.jd.blockchain.consts.DataCodes; | |||
import com.jd.blockchain.utils.Bytes; | |||
/** | |||
* @author huanghaiquan | |||
* | |||
*/ | |||
@DataContract(code= DataCodes.TX_OP_CONTRACT_EVENT_SEND) | |||
public interface ContractEventSendOperation extends Operation { | |||
@DataField(order=2, primitiveType=PrimitiveType.BYTES) | |||
Bytes getContractAddress(); | |||
@DataField(order=3, primitiveType=PrimitiveType.TEXT) | |||
String getEvent(); | |||
@DataField(order=4, primitiveType=PrimitiveType.BYTES) | |||
byte[] getArgs(); | |||
//获得交易操作时间; | |||
@DataField(order=5, primitiveType=PrimitiveType.INT64) | |||
Long getTxOpTime(); | |||
} |
@@ -1,21 +1,21 @@ | |||
package com.jd.blockchain.ledger; | |||
import com.jd.blockchain.binaryproto.DataContract; | |||
import com.jd.blockchain.binaryproto.DataField; | |||
import com.jd.blockchain.binaryproto.PrimitiveType; | |||
import com.jd.blockchain.consts.DataCodes; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
/** | |||
* 交易内容; | |||
* | |||
* @author huanghaiquan | |||
* | |||
*/ | |||
@DataContract(code= DataCodes.TX_CONTENT) | |||
public interface TransactionContent extends TransactionContentBody, HashObject { | |||
@Override | |||
@DataField(order=1, primitiveType = PrimitiveType.BYTES) | |||
HashDigest getHash(); | |||
} | |||
package com.jd.blockchain.ledger; | |||
import com.jd.blockchain.binaryproto.DataContract; | |||
import com.jd.blockchain.binaryproto.DataField; | |||
import com.jd.blockchain.binaryproto.PrimitiveType; | |||
import com.jd.blockchain.consts.DataCodes; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
/** | |||
* 交易内容; | |||
* | |||
* @author huanghaiquan | |||
* | |||
*/ | |||
@DataContract(code= DataCodes.TX_CONTENT) | |||
public interface TransactionContent extends TransactionContentBody, HashObject { | |||
@Override | |||
@DataField(order=1, primitiveType = PrimitiveType.BYTES) | |||
HashDigest getHash(); | |||
} |
@@ -1,36 +1,36 @@ | |||
package com.jd.blockchain.ledger; | |||
import com.jd.blockchain.binaryproto.DataContract; | |||
import com.jd.blockchain.binaryproto.DataField; | |||
import com.jd.blockchain.binaryproto.PrimitiveType; | |||
import com.jd.blockchain.consts.DataCodes; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
/** | |||
* 交易内容; | |||
* | |||
* @author huanghaiquan | |||
* | |||
*/ | |||
@DataContract(code = DataCodes.TX_CONTENT_BODY) | |||
public interface TransactionContentBody { | |||
/** | |||
* 执行交易的账本地址; | |||
* | |||
* 注:除了账本的创世交易之外,任何交易的账本地址都不允许为 null; | |||
* | |||
* @return | |||
*/ | |||
@DataField(order = 1, primitiveType = PrimitiveType.BYTES) | |||
HashDigest getLedgerHash(); | |||
/** | |||
* 操作列表; | |||
* | |||
* @return | |||
*/ | |||
@DataField(order = 2, list = true, refContract = true, genericContract = true) | |||
Operation[] getOperations(); | |||
} | |||
package com.jd.blockchain.ledger; | |||
import com.jd.blockchain.binaryproto.DataContract; | |||
import com.jd.blockchain.binaryproto.DataField; | |||
import com.jd.blockchain.binaryproto.PrimitiveType; | |||
import com.jd.blockchain.consts.DataCodes; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
/** | |||
* 交易内容; | |||
* | |||
* @author huanghaiquan | |||
* | |||
*/ | |||
@DataContract(code = DataCodes.TX_CONTENT_BODY) | |||
public interface TransactionContentBody { | |||
/** | |||
* 执行交易的账本地址; | |||
* | |||
* 注:除了账本的创世交易之外,任何交易的账本地址都不允许为 null; | |||
* | |||
* @return | |||
*/ | |||
@DataField(order = 1, primitiveType = PrimitiveType.BYTES) | |||
HashDigest getLedgerHash(); | |||
/** | |||
* 操作列表; | |||
* | |||
* @return | |||
*/ | |||
@DataField(order = 2, list = true, refContract = true, genericContract = true) | |||
Operation[] getOperations(); | |||
} |
@@ -1,40 +1,47 @@ | |||
package com.jd.blockchain.transaction; | |||
import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
import com.jd.blockchain.ledger.ContractEventSendOperation; | |||
import com.jd.blockchain.utils.Bytes; | |||
public class ContractEventSendOpTemplate implements ContractEventSendOperation { | |||
static { | |||
DataContractRegistry.register(ContractEventSendOperation.class); | |||
} | |||
private Bytes contractAddress; | |||
private byte[] args; | |||
private String event; | |||
public ContractEventSendOpTemplate() { | |||
} | |||
public ContractEventSendOpTemplate(Bytes contractAddress, String event, byte[] args) { | |||
this.contractAddress = contractAddress; | |||
this.event = event; | |||
this.args = args; | |||
} | |||
@Override | |||
public Bytes getContractAddress() { | |||
return contractAddress; | |||
} | |||
@Override | |||
public String getEvent() { | |||
return event; | |||
} | |||
@Override | |||
public byte[] getArgs() { | |||
return args; | |||
} | |||
} | |||
package com.jd.blockchain.transaction; | |||
import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
import com.jd.blockchain.ledger.ContractEventSendOperation; | |||
import com.jd.blockchain.utils.Bytes; | |||
public class ContractEventSendOpTemplate implements ContractEventSendOperation { | |||
static { | |||
DataContractRegistry.register(ContractEventSendOperation.class); | |||
} | |||
private Bytes contractAddress; | |||
private byte[] args; | |||
private String event; | |||
//交易操作时间; | |||
private Long txOpTime; | |||
public ContractEventSendOpTemplate() { | |||
} | |||
public ContractEventSendOpTemplate(Bytes contractAddress, String event, byte[] args) { | |||
this.contractAddress = contractAddress; | |||
this.event = event; | |||
this.args = args; | |||
this.txOpTime = System.currentTimeMillis(); | |||
} | |||
@Override | |||
public Bytes getContractAddress() { | |||
return contractAddress; | |||
} | |||
@Override | |||
public String getEvent() { | |||
return event; | |||
} | |||
@Override | |||
public byte[] getArgs() { | |||
return args; | |||
} | |||
@Override | |||
public Long getTxOpTime() { | |||
return txOpTime; | |||
} | |||
} |
@@ -1,93 +1,93 @@ | |||
package com.jd.blockchain.transaction; | |||
import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
import com.jd.blockchain.crypto.Crypto; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.TransactionBuilder; | |||
import com.jd.blockchain.ledger.TransactionContent; | |||
import com.jd.blockchain.ledger.TransactionContentBody; | |||
import com.jd.blockchain.ledger.TransactionRequestBuilder; | |||
import com.jd.blockchain.utils.Bytes; | |||
public class TxBuilder implements TransactionBuilder { | |||
static { | |||
DataContractRegistry.register(TransactionContentBody.class); | |||
} | |||
private BlockchainOperationFactory opFactory = new BlockchainOperationFactory(); | |||
private static final String DEFAULT_HASH_ALGORITHM = "SHA256"; | |||
private HashDigest ledgerHash; | |||
public TxBuilder(HashDigest ledgerHash) { | |||
this.ledgerHash = ledgerHash; | |||
} | |||
@Override | |||
public HashDigest getLedgerHash() { | |||
return ledgerHash; | |||
} | |||
@Override | |||
public TransactionRequestBuilder prepareRequest() { | |||
TransactionContent txContent = prepareContent(); | |||
return new TxRequestBuilder(txContent); | |||
} | |||
@Override | |||
public TransactionContent prepareContent() { | |||
TxContentBlob txContent = new TxContentBlob(ledgerHash); | |||
txContent.addOperations(opFactory.getOperations()); | |||
byte[] contentBodyBytes = BinaryProtocol.encode(txContent, TransactionContentBody.class); | |||
HashDigest contentHash = Crypto.getHashFunction(DEFAULT_HASH_ALGORITHM).hash(contentBodyBytes); | |||
txContent.setHash(contentHash); | |||
return txContent; | |||
} | |||
@Override | |||
public LedgerInitOperationBuilder ledgers() { | |||
return opFactory.ledgers(); | |||
} | |||
@Override | |||
public UserRegisterOperationBuilder users() { | |||
return opFactory.users(); | |||
} | |||
@Override | |||
public DataAccountRegisterOperationBuilder dataAccounts() { | |||
return opFactory.dataAccounts(); | |||
} | |||
@Override | |||
public DataAccountKVSetOperationBuilder dataAccount(String accountAddress) { | |||
return opFactory.dataAccount(accountAddress); | |||
} | |||
@Override | |||
public DataAccountKVSetOperationBuilder dataAccount(Bytes accountAddress) { | |||
return opFactory.dataAccount(accountAddress); | |||
} | |||
@Override | |||
public ContractCodeDeployOperationBuilder contracts() { | |||
return opFactory.contracts(); | |||
} | |||
@Override | |||
public ContractEventSendOperationBuilder contractEvents() { | |||
return opFactory.contractEvents(); | |||
} | |||
@Override | |||
public <T> T contract(String address, Class<T> contractIntf) { | |||
// TODO Auto-generated method stub | |||
throw new IllegalStateException("Not implemented."); | |||
} | |||
} | |||
package com.jd.blockchain.transaction; | |||
import com.jd.blockchain.binaryproto.BinaryProtocol; | |||
import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
import com.jd.blockchain.crypto.Crypto; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.TransactionBuilder; | |||
import com.jd.blockchain.ledger.TransactionContent; | |||
import com.jd.blockchain.ledger.TransactionContentBody; | |||
import com.jd.blockchain.ledger.TransactionRequestBuilder; | |||
import com.jd.blockchain.utils.Bytes; | |||
public class TxBuilder implements TransactionBuilder { | |||
static { | |||
DataContractRegistry.register(TransactionContentBody.class); | |||
} | |||
private BlockchainOperationFactory opFactory = new BlockchainOperationFactory(); | |||
private static final String DEFAULT_HASH_ALGORITHM = "SHA256"; | |||
private HashDigest ledgerHash; | |||
public TxBuilder(HashDigest ledgerHash) { | |||
this.ledgerHash = ledgerHash; | |||
} | |||
@Override | |||
public HashDigest getLedgerHash() { | |||
return ledgerHash; | |||
} | |||
@Override | |||
public TransactionRequestBuilder prepareRequest() { | |||
TransactionContent txContent = prepareContent(); | |||
return new TxRequestBuilder(txContent); | |||
} | |||
@Override | |||
public TransactionContent prepareContent() { | |||
TxContentBlob txContent = new TxContentBlob(ledgerHash); | |||
txContent.addOperations(opFactory.getOperations()); | |||
byte[] contentBodyBytes = BinaryProtocol.encode(txContent, TransactionContentBody.class); | |||
HashDigest contentHash = Crypto.getHashFunction(DEFAULT_HASH_ALGORITHM).hash(contentBodyBytes); | |||
txContent.setHash(contentHash); | |||
return txContent; | |||
} | |||
@Override | |||
public LedgerInitOperationBuilder ledgers() { | |||
return opFactory.ledgers(); | |||
} | |||
@Override | |||
public UserRegisterOperationBuilder users() { | |||
return opFactory.users(); | |||
} | |||
@Override | |||
public DataAccountRegisterOperationBuilder dataAccounts() { | |||
return opFactory.dataAccounts(); | |||
} | |||
@Override | |||
public DataAccountKVSetOperationBuilder dataAccount(String accountAddress) { | |||
return opFactory.dataAccount(accountAddress); | |||
} | |||
@Override | |||
public DataAccountKVSetOperationBuilder dataAccount(Bytes accountAddress) { | |||
return opFactory.dataAccount(accountAddress); | |||
} | |||
@Override | |||
public ContractCodeDeployOperationBuilder contracts() { | |||
return opFactory.contracts(); | |||
} | |||
@Override | |||
public ContractEventSendOperationBuilder contractEvents() { | |||
return opFactory.contractEvents(); | |||
} | |||
@Override | |||
public <T> T contract(String address, Class<T> contractIntf) { | |||
// TODO Auto-generated method stub | |||
throw new IllegalStateException("Not implemented."); | |||
} | |||
} |
@@ -1,91 +1,91 @@ | |||
package com.jd.blockchain.transaction; | |||
import java.util.ArrayList; | |||
import java.util.Collection; | |||
import java.util.List; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.Operation; | |||
import com.jd.blockchain.ledger.TransactionContent; | |||
import com.jd.blockchain.utils.io.NumberMask; | |||
/** | |||
* 交易内容的数据块; | |||
* <p> | |||
* | |||
* 包含原始交易请求的数据块; | |||
* | |||
* @author huanghaiquan | |||
* | |||
*/ | |||
public class TxContentBlob implements TransactionContent { | |||
/** | |||
* 操作数量的最大值; | |||
*/ | |||
public static final int MAX_OP_COUNT = NumberMask.SHORT.MAX_BOUNDARY_SIZE; | |||
private List<Operation> operationList = new ArrayList<Operation>(); | |||
private HashDigest hash; | |||
private HashDigest ledgerHash; | |||
public TxContentBlob(HashDigest ledgerHash) { | |||
this.ledgerHash = ledgerHash; | |||
} | |||
/** | |||
* 交易内容的哈希值; | |||
*/ | |||
@Override | |||
public HashDigest getHash() { | |||
return this.hash; | |||
} | |||
/** | |||
* 更新交易内容的哈希值; | |||
* <p> | |||
* 注:当前对象只充当值对象,不校验指定哈希值的完整性,调用者应该在外部实施完整性校验; | |||
* | |||
* @param hash | |||
*/ | |||
public void setHash(HashDigest hash) { | |||
this.hash = hash; | |||
} | |||
/** | |||
* 交易请求链的hash | |||
* | |||
* @return | |||
*/ | |||
@Override | |||
public HashDigest getLedgerHash() { | |||
return ledgerHash; | |||
} | |||
public void setLedgerHash(HashDigest ledgerHash) { | |||
this.ledgerHash = ledgerHash; | |||
} | |||
@Override | |||
public Operation[] getOperations() { | |||
return operationList.toArray(new Operation[operationList.size()]); | |||
} | |||
public void setOperations(Object[] operations) { | |||
// in array's case ,cast will failed! | |||
for (Object operation : operations) { | |||
Operation op = (Operation) operation; | |||
addOperation(op); | |||
} | |||
} | |||
public void addOperation(Operation operation) { | |||
operationList.add(operation); | |||
} | |||
public void addOperations(Collection<Operation> operations) { | |||
operationList.addAll(operations); | |||
} | |||
} | |||
package com.jd.blockchain.transaction; | |||
import java.util.ArrayList; | |||
import java.util.Collection; | |||
import java.util.List; | |||
import com.jd.blockchain.crypto.HashDigest; | |||
import com.jd.blockchain.ledger.Operation; | |||
import com.jd.blockchain.ledger.TransactionContent; | |||
import com.jd.blockchain.utils.io.NumberMask; | |||
/** | |||
* 交易内容的数据块; | |||
* <p> | |||
* | |||
* 包含原始交易请求的数据块; | |||
* | |||
* @author huanghaiquan | |||
* | |||
*/ | |||
public class TxContentBlob implements TransactionContent { | |||
/** | |||
* 操作数量的最大值; | |||
*/ | |||
public static final int MAX_OP_COUNT = NumberMask.SHORT.MAX_BOUNDARY_SIZE; | |||
private List<Operation> operationList = new ArrayList<Operation>(); | |||
private HashDigest hash; | |||
private HashDigest ledgerHash; | |||
public TxContentBlob(HashDigest ledgerHash) { | |||
this.ledgerHash = ledgerHash; | |||
} | |||
/** | |||
* 交易内容的哈希值; | |||
*/ | |||
@Override | |||
public HashDigest getHash() { | |||
return this.hash; | |||
} | |||
/** | |||
* 更新交易内容的哈希值; | |||
* <p> | |||
* 注:当前对象只充当值对象,不校验指定哈希值的完整性,调用者应该在外部实施完整性校验; | |||
* | |||
* @param hash | |||
*/ | |||
public void setHash(HashDigest hash) { | |||
this.hash = hash; | |||
} | |||
/** | |||
* 交易请求链的hash | |||
* | |||
* @return | |||
*/ | |||
@Override | |||
public HashDigest getLedgerHash() { | |||
return ledgerHash; | |||
} | |||
public void setLedgerHash(HashDigest ledgerHash) { | |||
this.ledgerHash = ledgerHash; | |||
} | |||
@Override | |||
public Operation[] getOperations() { | |||
return operationList.toArray(new Operation[operationList.size()]); | |||
} | |||
public void setOperations(Object[] operations) { | |||
// in array's case ,cast will failed! | |||
for (Object operation : operations) { | |||
Operation op = (Operation) operation; | |||
addOperation(op); | |||
} | |||
} | |||
public void addOperation(Operation operation) { | |||
operationList.add(operation); | |||
} | |||
public void addOperations(Collection<Operation> operations) { | |||
operationList.addAll(operations); | |||
} | |||
} |
@@ -1,14 +1,7 @@ | |||
package com.jd.blockchain.utils; | |||
import java.lang.reflect.Array; | |||
import java.util.Collections; | |||
import java.util.HashSet; | |||
import java.util.Iterator; | |||
import java.util.LinkedList; | |||
import java.util.List; | |||
import java.util.Set; | |||
import java.util.SortedSet; | |||
import java.util.TreeSet; | |||
import java.util.*; | |||
/** | |||
* @author haiq | |||
@@ -83,5 +76,4 @@ public abstract class ArrayUtils { | |||
} | |||
return new ReadonlyArrayListWrapper<T>(array, fromIndex, toIndex); | |||
} | |||
} |