forked from hyperledger/besu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TraceService: return results for transactions in block
Signed-off-by: Daniel Lehrner <[email protected]>
- Loading branch information
1 parent
03a8335
commit 596fba5
Showing
7 changed files
with
263 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
plugin-api/src/main/java/org/hyperledger/besu/plugin/data/BlockTraceResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright Hyperledger Besu Contributors. | ||
* | ||
* 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 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.plugin.data; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class BlockTraceResult { | ||
final List<TransactionTraceResult> transactionTraceResults; | ||
|
||
public BlockTraceResult(final List<TransactionTraceResult> transactionTraceResults) { | ||
this.transactionTraceResults = transactionTraceResults; | ||
} | ||
|
||
public static BlockTraceResult empty() { | ||
return new BlockTraceResult(new ArrayList<>()); | ||
} | ||
|
||
public List<TransactionTraceResult> transactionTraceResults() { | ||
return transactionTraceResults; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final BlockTraceResult that = (BlockTraceResult) o; | ||
return transactionTraceResults.equals(that.transactionTraceResults()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(transactionTraceResults); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final StringBuilder builder = new StringBuilder(); | ||
builder.append("BlockTraceResult{transactionTraceResults=["); | ||
|
||
final Iterator<TransactionTraceResult> iterator = transactionTraceResults.iterator(); | ||
while (iterator.hasNext()) { | ||
builder.append(iterator.next().toString()); | ||
|
||
if (iterator.hasNext()) { | ||
builder.append(","); | ||
} | ||
} | ||
builder.append("]}"); | ||
return builder.toString(); | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder { | ||
List<TransactionTraceResult> transactionTraceResults = new ArrayList<>(); | ||
|
||
public Builder addTransactionTraceResult(final TransactionTraceResult transactionTraceResult) { | ||
transactionTraceResults.add(transactionTraceResult); | ||
|
||
return this; | ||
} | ||
|
||
public BlockTraceResult build() { | ||
return new BlockTraceResult(transactionTraceResults); | ||
} | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
plugin-api/src/main/java/org/hyperledger/besu/plugin/data/TransactionTraceResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright Hyperledger Besu Contributors. | ||
* | ||
* 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 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.plugin.data; | ||
|
||
import org.hyperledger.besu.datatypes.Hash; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
public class TransactionTraceResult { | ||
public enum Status { | ||
/* the transaction was traced successfully. This might include transactions that have been reverted */ | ||
SUCCESS, | ||
/* there was an internal error while generating the trace */ | ||
ERROR | ||
} | ||
|
||
private final Hash txHash; | ||
private final Status status; | ||
private final String errorMessage; | ||
|
||
private TransactionTraceResult( | ||
final Hash txHash, final Status status, final String errorMessage) { | ||
this.txHash = txHash; | ||
this.status = status; | ||
this.errorMessage = errorMessage; | ||
} | ||
|
||
public static TransactionTraceResult success(final Hash txHash) { | ||
return new TransactionTraceResult(txHash, Status.SUCCESS, null); | ||
} | ||
|
||
public static TransactionTraceResult error(final Hash txHash, final String errorMessage) { | ||
return new TransactionTraceResult(txHash, Status.ERROR, errorMessage); | ||
} | ||
|
||
public Hash getTxHash() { | ||
return txHash; | ||
} | ||
|
||
public Status getStatus() { | ||
return status; | ||
} | ||
|
||
public Optional<String> errorMessage() { | ||
return Optional.ofNullable(errorMessage); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final TransactionTraceResult that = (TransactionTraceResult) o; | ||
return Objects.equals(txHash, that.txHash) | ||
&& status == that.status | ||
&& Objects.equals(errorMessage, that.errorMessage); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(txHash, status, errorMessage); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "TransactionTraceResult{" | ||
+ "txHash=" | ||
+ txHash | ||
+ ", status=" | ||
+ status | ||
+ ", errorMessage='" | ||
+ errorMessage | ||
+ '\'' | ||
+ '}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters