Skip to content

Commit

Permalink
add decodeCall method to Function which accepts indices
Browse files Browse the repository at this point in the history
  • Loading branch information
esaulpaugh committed Mar 24, 2022
1 parent 9ecff58 commit 15ce979
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/main/java/com/esaulpaugh/headlong/abi/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,20 @@ public Tuple decodeCall(byte[] call) {
* @return the decoded arguments
*/
public Tuple decodeCall(ByteBuffer abiBuffer) {
return inputTypes.decode(abiBuffer, checkSelector(abiBuffer));
}

public <T> T decodeCall(byte[] call, int... indices) {
ByteBuffer bb = ByteBuffer.wrap(call);
checkSelector(bb);
return inputTypes.decode(bb, indices);
}

private byte[] checkSelector(ByteBuffer bb) {
final byte[] unitBuffer = ABIType.newUnitBuffer();
abiBuffer.get(unitBuffer, 0, SELECTOR_LEN);
bb.get(unitBuffer, 0, SELECTOR_LEN);
checkSelector(unitBuffer);
return inputTypes.decode(abiBuffer, unitBuffer); // unitBuffer contents are ignored, overwritten during decode
return unitBuffer; // unitBuffer contents are ignored, overwritten during decode
}

private void checkSelector(byte[] buffer) {
Expand Down

0 comments on commit 15ce979

Please sign in to comment.