Skip to content

Commit

Permalink
reorder methods
Browse files Browse the repository at this point in the history
  • Loading branch information
esaulpaugh committed Aug 30, 2024
1 parent 7ea36cd commit b13150a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 68 deletions.
20 changes: 10 additions & 10 deletions src/main/java/com/esaulpaugh/headlong/abi/ContractError.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public Function function() {
return Function.parse(getCanonicalSignature());
}

@Override
public boolean isContractError() {
return true;
}

@Override
public int hashCode() {
return Objects.hash(name, inputs);
Expand All @@ -68,6 +73,11 @@ public boolean equals(Object o) {
return false;
}

@Override
public String toString() {
return toJson(true);
}

public static <X extends Tuple> ContractError<X> fromJson(String errorJson) {
return fromJsonObject(ABIType.FLAGS_NONE, ABIJSON.parseObject(errorJson));
}
Expand All @@ -81,14 +91,4 @@ public static <X extends Tuple> ContractError<X> fromJson(int flags, String erro
public static <X extends Tuple> ContractError<X> fromJsonObject(int flags, JsonObject error) {
return ABIJSON.parseError(error, flags);
}

@Override
public String toString() {
return toJson(true);
}

@Override
public boolean isContractError() {
return true;
}
}
38 changes: 19 additions & 19 deletions src/main/java/com/esaulpaugh/headlong/abi/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public <X extends Tuple> TupleType<X> getNonIndexedParams() {
return (TupleType<X>) nonIndexedParams;
}

@Override
public boolean isEvent() {
return true;
}

@Override
public int hashCode() {
return 31 * (31 * (31 * name.hashCode() + inputs.hashCode()) + Arrays.hashCode(indexManifest)) + Boolean.hashCode(anonymous);
Expand All @@ -118,30 +123,11 @@ public boolean equals(Object o) {
&& Arrays.equals(other.indexManifest, this.indexManifest);
}

public static <X extends Tuple> Event<X> fromJson(String eventJson) {
return fromJsonObject(ABIType.FLAGS_NONE, ABIJSON.parseObject(eventJson));
}

/** @see ABIObject#fromJson(int, String) */
public static <X extends Tuple> Event<X> fromJson(int flags, String eventJson) {
return fromJsonObject(flags, ABIJSON.parseObject(eventJson));
}

/** @see ABIObject#fromJsonObject(int, JsonObject) */
public static <X extends Tuple> Event<X> fromJsonObject(int flags, JsonObject event) {
return ABIJSON.parseEvent(event, flags);
}

@Override
public String toString() {
return toJson(true);
}

@Override
public boolean isEvent() {
return true;
}

public <X extends Tuple> X decodeTopics(byte[][] topics) {
return Tuple.create(decodeTopicsArray(topics));
}
Expand Down Expand Up @@ -217,4 +203,18 @@ private void checkTopics(byte[][] topics) {
throw new IllegalArgumentException("expected topics.length " + expectedTopics + " but found length " + topics.length);
}
}

public static <X extends Tuple> Event<X> fromJson(String eventJson) {
return fromJsonObject(ABIType.FLAGS_NONE, ABIJSON.parseObject(eventJson));
}

/** @see ABIObject#fromJson(int, String) */
public static <X extends Tuple> Event<X> fromJson(int flags, String eventJson) {
return fromJsonObject(flags, ABIJSON.parseObject(eventJson));
}

/** @see ABIObject#fromJsonObject(int, JsonObject) */
public static <X extends Tuple> Event<X> fromJsonObject(int flags, JsonObject event) {
return ABIJSON.parseEvent(event, flags);
}
}
78 changes: 39 additions & 39 deletions src/main/java/com/esaulpaugh/headlong/abi/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ public <J> J decodeSingletonReturn(ByteBuffer buf) {
throw new IllegalArgumentException("return type not a singleton: " + outputTypes.canonicalType);
}

@Override
public boolean isFunction() {
return true;
}

@Override
public int hashCode() {
return 31 * Objects.hash(type, name, inputTypes, outputTypes, stateMutability, hashAlgorithm)
Expand All @@ -323,11 +328,6 @@ public String toString() {
return toJson(true);
}

@Override
public boolean isFunction() {
return true;
}

private static String validateName(String input) {
final int len = input.length();
if (len > MAX_NAME_CHARS) {
Expand All @@ -341,6 +341,26 @@ private static String validateName(String input) {
}
return input;
}

/**
* Experimental. Annotates the given function call and returns an informational formatted String. This method is
* subject to change or removal in a future release.
*/
public String annotateCall(byte[] call) {
return annotateCall(decodeCall(call));
}

/**
* Experimental. Annotates the function call given the {@code args} and returns an informational formatted String. This
* method is subject to change or removal in a future release.
*/
public String annotateCall(Tuple args) {
return inputTypes.annotate(
args,
new StringBuilder(768).append(name).append(":\n")
.append(ID_LABEL_PADDED).append(selectorHex())
);
}
// ---------------------------------------------------------------------------------------------------------------------
public static Function parse(String signature) {
return new Function(signature);
Expand All @@ -354,24 +374,6 @@ public static Function parse(int flags, String signature, String outputs) {
return new Function(flags, signature, outputs);
}

public static Function fromJson(String objectJson) {
return fromJsonObject(ABIType.FLAGS_NONE, ABIJSON.parseObject(objectJson));
}

/** @see ABIObject#fromJson(int, String) */
public static Function fromJson(int flags, String objectJson) {
return fromJsonObject(flags, ABIJSON.parseObject(objectJson));
}

/** @see ABIObject#fromJsonObject(int, JsonObject) */
public static Function fromJsonObject(int flags, JsonObject function) {
return fromJsonObject(flags, function, Function.newDefaultDigest());
}

public static Function fromJsonObject(int flags, JsonObject function, MessageDigest digest) {
return ABIJSON.parseFunction(function, digest, flags);
}

/**
* @return a {@link MessageDigest}
*/
Expand Down Expand Up @@ -405,23 +407,21 @@ public static String formatCall(byte[] buffer, IntFunction<String> labeler) {
);
}

/**
* Experimental. Annotates the given function call and returns an informational formatted String. This method is
* subject to change or removal in a future release.
*/
public String annotateCall(byte[] call) {
return annotateCall(decodeCall(call));
public static Function fromJson(String objectJson) {
return fromJsonObject(ABIType.FLAGS_NONE, ABIJSON.parseObject(objectJson));
}

/**
* Experimental. Annotates the function call given the {@code args} and returns an informational formatted String. This
* method is subject to change or removal in a future release.
*/
public String annotateCall(Tuple args) {
return inputTypes.annotate(
args,
new StringBuilder(768).append(name).append(":\n")
.append(ID_LABEL_PADDED).append(selectorHex())
);
/** @see ABIObject#fromJson(int, String) */
public static Function fromJson(int flags, String objectJson) {
return fromJsonObject(flags, ABIJSON.parseObject(objectJson));
}

/** @see ABIObject#fromJsonObject(int, JsonObject) */
public static Function fromJsonObject(int flags, JsonObject function) {
return fromJsonObject(flags, function, Function.newDefaultDigest());
}

public static Function fromJsonObject(int flags, JsonObject function, MessageDigest digest) {
return ABIJSON.parseFunction(function, digest, flags);
}
}

0 comments on commit b13150a

Please sign in to comment.