Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hash field in Transaction plugin interface. #111

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public TransactionResult transaction(
when(transaction.getV()).thenReturn(bigInteger(v));
when(transaction.getR()).thenReturn(bigInteger(r));
when(transaction.getS()).thenReturn(bigInteger(s));
when(transaction.hash()).thenReturn(hash(hash));
when(transaction.getHash()).thenReturn(hash(hash));
when(transaction.getTo()).thenReturn(Optional.ofNullable(address(toAddress)));
when(transaction.getSender()).thenReturn(address(fromAddress));
when(transaction.getPayload()).thenReturn(bytes(input));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public void shouldReturnHashesIfNewPendingTransactions() {

// We've added one transaction, so there should be one new hash.
expected =
new JsonRpcSuccessResponse(null, Lists.newArrayList(String.valueOf(transaction.hash())));
new JsonRpcSuccessResponse(null, Lists.newArrayList(String.valueOf(transaction.getHash())));
actual = method.response(request);
assertThat(actual).isEqualToComparingFieldByField(expected);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ DataFetcher<Optional<Bytes32>> getSendRawTransactionDataFetcher() {
final ValidationResult<TransactionInvalidReason> validationResult =
transactionPool.addLocalTransaction(transaction);
if (validationResult.isValid()) {
return Optional.of(transaction.hash());
return Optional.of(transaction.getHash());
} else {
throw new GraphQLException(GraphQLError.of(validationResult.getInvalidReason()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public TransactionAdapter(final TransactionWithMetadata transactionWithMetadata)
}

public Optional<Hash> getHash() {
return Optional.of(transactionWithMetadata.getTransaction().hash());
return Optional.of(transactionWithMetadata.getTransaction().getHash());
}

public Optional<Long> getNonce() {
Expand Down Expand Up @@ -111,7 +111,7 @@ public Optional<NormalBlockAdapter> getBlock(final DataFetchingEnvironment envir

public Optional<Long> getStatus(final DataFetchingEnvironment environment) {
return Optional.ofNullable(transactionWithMetadata.getTransaction())
.map(Transaction::hash)
.map(Transaction::getHash)
.flatMap(rpt -> getBlockchainQueries(environment).transactionReceiptByTransactionHash(rpt))
.map(TransactionReceiptWithMetadata::getReceipt)
.flatMap(
Expand All @@ -124,14 +124,16 @@ public Optional<Long> getStatus(final DataFetchingEnvironment environment) {
public Optional<Long> getGasUsed(final DataFetchingEnvironment environment) {
final BlockchainQueries query = getBlockchainQueries(environment);
final Optional<TransactionReceiptWithMetadata> rpt =
query.transactionReceiptByTransactionHash(transactionWithMetadata.getTransaction().hash());
query.transactionReceiptByTransactionHash(
transactionWithMetadata.getTransaction().getHash());
return rpt.map(TransactionReceiptWithMetadata::getGasUsed);
}

public Optional<Long> getCumulativeGasUsed(final DataFetchingEnvironment environment) {
final BlockchainQueries query = getBlockchainQueries(environment);
final Optional<TransactionReceiptWithMetadata> rpt =
query.transactionReceiptByTransactionHash(transactionWithMetadata.getTransaction().hash());
query.transactionReceiptByTransactionHash(
transactionWithMetadata.getTransaction().getHash());
if (rpt.isPresent()) {
final TransactionReceipt receipt = rpt.get().getReceipt();
return Optional.of(receipt.getCumulativeGasUsed());
Expand Down Expand Up @@ -164,7 +166,7 @@ public Optional<AccountAdapter> getCreatedContract(final DataFetchingEnvironment

public List<LogAdapter> getLogs(final DataFetchingEnvironment environment) {
final BlockchainQueries query = getBlockchainQueries(environment);
final Hash hash = transactionWithMetadata.getTransaction().hash();
final Hash hash = transactionWithMetadata.getTransaction().getHash();
final Optional<TransactionReceiptWithMetadata> tranRpt =
query.transactionReceiptByTransactionHash(hash);
final List<LogAdapter> results = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void recordPendingTransactionEvent(final Transaction transaction) {
pendingTransactionFilters.forEach(
(filter) -> {
synchronized (filter) {
filter.addTransactionHash(transaction.hash());
filter.addTransactionHash(transaction.getHash());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public JsonRpcResponse response(final JsonRpcRequest request) {
.get()
.afterTransactionInBlock(
blockHash,
transactionWithMetadata.getTransaction().hash(),
transactionWithMetadata.getTransaction().getHash(),
(transaction, blockHeader, blockchain, worldState, transactionProcessor) ->
extractStorageAt(request, accountAddress, startKey, limit, worldState))
.orElseGet(() -> emptyResponse(request))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public JsonRpcResponse response(final JsonRpcRequest request) {
final ValidationResult<TransactionInvalidReason> validationResult =
transactionPool.get().addLocalTransaction(transaction);
return validationResult.either(
() -> new JsonRpcSuccessResponse(request.getId(), transaction.hash().toString()),
() -> new JsonRpcSuccessResponse(request.getId(), transaction.getHash().toString()),
errorReason ->
sendEmptyHashOnInvalidBlock
? new JsonRpcSuccessResponse(request.getId(), Hash.EMPTY.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private JsonNode formatTraces(
.ifPresent(
transactionTrace -> {
resultNode.put(
"transactionHash", transactionTrace.getTransaction().hash().getHexString());
"transactionHash", transactionTrace.getTransaction().getHash().getHexString());
resultNode.put("output", transactionTrace.getResult().getOutput().toString());
});
resultNode.put("stateDiff", (String) null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public JsonRpcResponse response(final JsonRpcRequest request) {
.either(
() ->
new JsonRpcSuccessResponse(
request.getId(), privacyMarkerTransaction.hash().toString()),
request.getId(), privacyMarkerTransaction.getHash().toString()),
errorReason ->
new JsonRpcErrorResponse(
request.getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public <T> Optional<T> beforeTransactionInBlock(
(body, header, blockchain, mutableWorldState, transactionProcessor) -> {
final BlockHashLookup blockHashLookup = new BlockHashLookup(header, blockchain);
for (final Transaction transaction : body.getTransactions()) {
if (transaction.hash().equals(transactionHash)) {
if (transaction.getHash().equals(transactionHash)) {
return Optional.of(
action.performAction(
transaction, header, blockchain, mutableWorldState, transactionProcessor));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public TransactionCompleteResult(final TransactionWithMetadata tx) {
this.from = transaction.getSender().toString();
this.gas = Quantity.create(transaction.getGasLimit());
this.gasPrice = Quantity.create(transaction.getGasPrice());
this.hash = transaction.hash().toString();
this.hash = transaction.getHash().toString();
this.input = transaction.getPayload().toString();
this.nonce = Quantity.create(transaction.getNonce());
this.to = transaction.getTo().map(BytesValue::toString).orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public TransactionPendingResult(final Transaction transaction) {
this.from = transaction.getSender().toString();
this.gas = Quantity.create(transaction.getGasLimit());
this.gasPrice = Quantity.create(transaction.getGasPrice());
this.hash = transaction.hash().toString();
this.hash = transaction.getHash().toString();
this.input = transaction.getPayload().toString();
this.nonce = Quantity.create(transaction.getNonce());
this.to = transaction.getTo().map(BytesValue::toString).orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ public TransactionReceiptResult(final TransactionReceiptWithMetadata receiptWith
logReceipts(
receipt.getLogs(),
receiptWithMetadata.getBlockNumber(),
receiptWithMetadata.getTransaction().hash(),
receiptWithMetadata.getTransaction().getHash(),
receiptWithMetadata.getBlockHash(),
receiptWithMetadata.getTransactionIndex());
this.logsBloom = receipt.getBloomFilter().toString();
this.to = receiptWithMetadata.getTransaction().getTo().map(BytesValue::toString).orElse(null);
this.transactionHash = receiptWithMetadata.getTransaction().hash().toString();
this.transactionHash = receiptWithMetadata.getTransaction().getHash().toString();
this.transactionIndex = Quantity.create(receiptWithMetadata.getTransactionIndex());
this.revertReason = receipt.getRevertReason().map(BytesValue::toString).orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void onBlockAdded(final BlockAddedEvent event, final Blockchain blockchai
}

event.getAddedTransactions().stream()
.map(tx -> blockchainQueries.transactionReceiptByTransactionHash(tx.hash()))
.map(tx -> blockchainQueries.transactionReceiptByTransactionHash(tx.getHash()))
.filter(Optional::isPresent)
.map(Optional::get)
.forEachOrdered(
Expand All @@ -59,7 +59,7 @@ public void onBlockAdded(final BlockAddedEvent event, final Blockchain blockchai
});

event.getRemovedTransactions().stream()
.map(tx -> blockchainQueries.transactionReceiptByTransactionHash(tx.hash()))
.map(tx -> blockchainQueries.transactionReceiptByTransactionHash(tx.getHash()))
.filter(Optional::isPresent)
.map(Optional::get)
.forEachOrdered(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public PendingTransactionDetailResult(final Transaction tx) {
this.from = tx.getSender().toString();
this.gas = Quantity.create(tx.getGasLimit());
this.gasPrice = Quantity.create(tx.getGasPrice());
this.hash = tx.hash().toString();
this.hash = tx.getHash().toString();
this.input = tx.getPayload().toString();
this.nonce = Quantity.create(tx.getNonce());
this.to = tx.getTo().map(BytesValue::toString).orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public PendingTransactionDroppedSubscriptionService(

@Override
public void onTransactionDropped(final Transaction transaction) {
notifySubscribers(transaction.hash());
notifySubscribers(transaction.getHash());
}

private void notifySubscribers(final Hash pendingTransaction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private void notifySubscribers(final Transaction pendingTransaction) {
final List<Subscription> subscriptions = pendingTransactionSubscriptions();

final PendingTransactionResult hashResult =
new PendingTransactionResult(pendingTransaction.hash());
new PendingTransactionResult(pendingTransaction.getHash());
final PendingTransactionDetailResult detailResult =
new PendingTransactionDetailResult(pendingTransaction);
for (final Subscription subscription : subscriptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public Optional<BlockWithMetadata<Hash, Hash>> blockByHashWithTxHashes(
(td) -> {
final List<Hash> txs =
body.getTransactions().stream()
.map(Transaction::hash)
.map(Transaction::getHash)
.collect(Collectors.toList());
final List<Hash> ommers =
body.getOmmers().stream()
Expand Down Expand Up @@ -566,7 +566,7 @@ private List<LogWithMetadata> generateLogWithMetadata(
logIndex,
number,
blockhash,
transaction.get(transactionIndex).hash(),
transaction.get(transactionIndex).getHash(),
transactionIndex,
receipts.get(transactionIndex).getLogs().get(logIndex).getLogger(),
receipts.get(transactionIndex).getLogs().get(logIndex).getData(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,7 @@ private void verifyBlockResult(
final Transaction transaction = block.getBody().getTransactions().get(i);
if (shouldTransactionsBeHashed) {
assertThat(Hash.fromHexString(transactionsResult.getString(i)))
.isEqualTo(transaction.hash());
.isEqualTo(transaction.getHash());
} else {
final JsonObject transactionResult = transactionsResult.getJsonObject(i);
final Integer expectedIndex = i;
Expand All @@ -1768,7 +1768,7 @@ private void assertTransactionResultMatchesTransaction(
final Integer index,
final Hash blockHash,
final Long blockNumber) {
assertThat(Hash.fromHexString(result.getString("hash"))).isEqualTo(transaction.hash());
assertThat(Hash.fromHexString(result.getString("hash"))).isEqualTo(transaction.getHash());
assertThat(Long.decode(result.getString("nonce"))).isEqualByComparingTo(transaction.getNonce());
if (blockHash != null) {
assertThat(Hash.fromHexString(result.getString("blockHash"))).isEqualTo(blockHash);
Expand Down Expand Up @@ -1899,7 +1899,7 @@ public BlockWithMetadata<Hash, Hash> blockWithMetadataAndTxHashes(final Block bl

final List<Hash> txs =
block.getBody().getTransactions().stream()
.map(Transaction::hash)
.map(Transaction::getHash)
.collect(Collectors.toList());
final List<Hash> ommers =
block.getBody().getOmmers().stream().map(BlockHeader::getHash).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static Transaction transaction(
final String s) {

final Transaction transaction = mock(Transaction.class);
when(transaction.hash()).thenReturn(blockHash);
when(transaction.getHash()).thenReturn(blockHash);
when(transaction.getGasPrice()).thenReturn(Wei.fromHexString(gasPrice));
when(transaction.getNonce()).thenReturn(unsignedLong(nonce));
when(transaction.getV()).thenReturn(bigInteger(v));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private Hash recordPendingTransaction(final int blockNumber, final int transacti
final Block block = blockchainSetupUtil.getBlock(blockNumber);
final Transaction transaction = block.getBody().getTransactions().get(transactionIndex);
filterManager.recordPendingTransactionEvent(transaction);
return transaction.hash();
return transaction.getHash();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,6 @@ private Hash appendBlockToBlockchain() {
private Hash receivePendingTransaction() {
final Transaction transaction = blockGenerator.transaction();
filterManager.recordPendingTransactionEvent(transaction);
return transaction.hash();
return transaction.getHash();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class DebugStorageRangeAtTest {

@Before
public void setUp() {
when(transaction.hash()).thenReturn(transactionHash);
when(transaction.getHash()).thenReturn(transactionHash);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void setUp() {
public void returnReceiptIfTransactionExists() {
final PrivGetTransactionReceipt privGetTransactionReceipt =
new PrivGetTransactionReceipt(blockchainQueries, enclave, parameters, privacyParameters);
final Object[] params = new Object[] {transaction.hash()};
final Object[] params = new Object[] {transaction.getHash()};
final JsonRpcRequest request = new JsonRpcRequest("1", "priv_getTransactionReceipt", params);

final JsonRpcSuccessResponse response =
Expand All @@ -183,7 +183,7 @@ public void enclavePayloadNotFoundResultsInSuccessButNullResponse() {
final PrivGetTransactionReceipt privGetTransactionReceipt =
new PrivGetTransactionReceipt(
blockchainQueries, failingEnclave, parameters, privacyParameters);
final Object[] params = new Object[] {transaction.hash()};
final Object[] params = new Object[] {transaction.getHash()};
final JsonRpcRequest request = new JsonRpcRequest("1", "priv_getTransactionReceipt", params);

final JsonRpcSuccessResponse response =
Expand All @@ -200,7 +200,7 @@ public void markerTransactionNotAvailableResultsInNullResponse() {

final PrivGetTransactionReceipt privGetTransactionReceipt =
new PrivGetTransactionReceipt(blockchainQueries, enclave, parameters, privacyParameters);
final Object[] params = new Object[] {transaction.hash()};
final Object[] params = new Object[] {transaction.getHash()};
final JsonRpcRequest request = new JsonRpcRequest("1", "priv_getTransactionReceipt", params);

final JsonRpcSuccessResponse response =
Expand All @@ -216,7 +216,7 @@ public void enclaveConnectionIssueThrowsRuntimeException() {
final PrivGetTransactionReceipt privGetTransactionReceipt =
new PrivGetTransactionReceipt(
blockchainQueries, failingEnclave, parameters, privacyParameters);
final Object[] params = new Object[] {transaction.hash()};
final Object[] params = new Object[] {transaction.getHash()};
final JsonRpcRequest request = new JsonRpcRequest("1", "priv_getTransactionReceipt", params);

final Throwable t = catchThrowable(() -> privGetTransactionReceipt.response(request));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public class TransactionTracerTest {
public void setUp() throws Exception {
transactionTracer =
new TransactionTracer(new BlockReplay(protocolSchedule, blockchain, worldStateArchive));
when(transaction.hash()).thenReturn(transactionHash);
when(otherTransaction.hash()).thenReturn(otherTransactionHash);
when(transaction.getHash()).thenReturn(transactionHash);
when(otherTransaction.getHash()).thenReturn(otherTransactionHash);
when(blockHeader.getNumber()).thenReturn(12L);
when(blockHeader.getHash()).thenReturn(blockHash);
when(blockHeader.getParentHash()).thenReturn(previousBlockHash);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private List<TransactionWithMetadata> transactionsWithMetadata() {
private List<Hash> transactionsWithHashOnly() {
final List<Hash> hashes = new ArrayList<>();
for (final TransactionWithMetadata transactionWithMetadata : transactionsWithMetadata()) {
hashes.add(transactionWithMetadata.getTransaction().hash());
hashes.add(transactionWithMetadata.getTransaction().getHash());
}
return hashes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ private TransactionReceiptWithMetadata createTransactionWithLog(
TransactionReceiptWithMetadata.create(
transactionReceipt,
transaction,
transaction.hash(),
transaction.getHash(),
0,
1L,
blockHeader.getHash(),
blockHeader.getNumber());

when(blockchainQueries.transactionReceiptByTransactionHash(eq(transaction.hash())))
when(blockchainQueries.transactionReceiptByTransactionHash(eq(transaction.getHash())))
.thenReturn(Optional.of(transactionReceiptWithMetadata));

return transactionReceiptWithMetadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private Map<Long, Hash> messages(final Hash result, final long... subscriptionId

private Transaction transaction(final Hash hash) {
final Transaction tx = mock(Transaction.class);
when(tx.hash()).thenReturn(hash);
when(tx.getHash()).thenReturn(hash);
return tx;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ private void assertBlockMatchesResultWithTxHashes(
for (int i = 0; i < result.getTransactions().size(); i++) {
final Hash txResult = result.getTransactions().get(i);
final Transaction actualTx = targetBlock.getBody().getTransactions().get(i);
assertThat(txResult).isEqualByComparingTo(actualTx.hash());
assertThat(txResult).isEqualByComparingTo(actualTx.getHash());
}
}

Expand Down
Loading