use of org.fisco.bcos.web3j.protocol.core.methods.response.Transaction in project web3sdk by FISCO-BCOS.
the class Web3jApITest method getTransactionByBlockHashAndIndex.
@Test
public void getTransactionByBlockHashAndIndex() throws IOException {
BcosTransaction bcosTransaction = web3j.getTransactionByBlockHashAndIndex(blockHash, new BigInteger("0")).send();
Transaction transaction = bcosTransaction.getTransaction().get();
assertNotNull(transaction);
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.Transaction in project web3sdk by FISCO-BCOS.
the class Web3jApITest method getTransactionByBlockNumberAndIndex.
@Test
public void getTransactionByBlockNumberAndIndex() throws IOException {
BcosTransaction bcosTransaction = web3j.getTransactionByBlockNumberAndIndex(DefaultBlockParameter.valueOf(blockNumber), new BigInteger("0")).send();
Transaction transaction = bcosTransaction.getTransaction().get();
assertNotNull(transaction);
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.Transaction in project web3sdk by FISCO-BCOS.
the class TransactionResource method getTransactionWithProof.
public TransactionWithProof getTransactionWithProof(String transactionHash, String rootHash) throws IOException {
TransactionWithProof transactionWithProof = web3j.getTransactionByHashWithProof(transactionHash).send();
if (transactionWithProof.getTransactionWithProof() == null) {
return null;
}
Transaction transaction = transactionWithProof.getTransactionWithProof().getTransaction();
logger.debug("Transaction:{}", transaction);
// transaction index
String index = transaction.getTransactionIndexRaw();
BigInteger indexValue = Numeric.toBigInt(index);
byte[] byteIndex = RlpEncoder.encode(RlpString.create(indexValue));
String input = Numeric.toHexString(byteIndex) + transactionHash.substring(2);
logger.info("TransWithIndex:{}", input);
String proof = Merkle.calculateMerkleRoot(transactionWithProof.getTransactionWithProof().getTxProof(), input);
if (!proof.equals(rootHash)) {
logger.debug("MerkleRoot:{}", proof);
logger.debug("TransRoot :{}", rootHash);
return null;
}
return transactionWithProof;
}
use of org.fisco.bcos.web3j.protocol.core.methods.response.Transaction in project web3sdk by FISCO-BCOS.
the class MerkleProofUtility method verifyTransaction.
/**
* Verify transaction merkle proof
*
* @param transactionRoot
* @param transAndProof
* @return
*/
public static boolean verifyTransaction(String transactionRoot, TransactionWithProof.TransAndProof transAndProof) {
// transaction index
Transaction transaction = transAndProof.getTransaction();
BigInteger index = transaction.getTransactionIndex();
String input = Numeric.toHexString(RlpEncoder.encode(RlpString.create(index))) + transaction.getHash().substring(2);
String proof = Merkle.calculateMerkleRoot(transAndProof.getTxProof(), input);
logger.debug(" transaction hash: {}, transaction index: {}, root: {}, proof: {}", transaction.getHash(), transaction.getTransactionIndex(), transactionRoot, proof);
return proof.equals(transactionRoot);
}
Aggregations