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

Fixed block ref param handling in eth_call #2278

Merged
merged 1 commit into from
Apr 8, 2024
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
9 changes: 6 additions & 3 deletions rskj-core/src/main/java/co/rsk/rpc/Web3EthModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ default String eth_sign(HexAddressParam addr, HexDataParam data) {
return getEthModule().sign(addr.getAddress().toHexString(), data.getAsHexString());
}

default String eth_call(CallArgumentsParam args, BlockIdentifierParam bnOrId) {
return getEthModule().call(args, bnOrId);
default String eth_call(CallArgumentsParam args, BlockRefParam blockRefParam) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we are updating this method, is there a reason to implement this logic into the interface using default? our could we move the method implementation to the implementation class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea was to make it as minimalistic as possible. But yeah, in future we may want to refactor this a bit and move all implementations of default methods to appropriate impl classes

if (blockRefParam.getIdentifier() != null) {
return getEthModule().call(args, new BlockIdentifierParam(blockRefParam.getIdentifier()));
}
return eth_call(args, blockRefParam.getInputs());
}

default Map<String, Object> eth_bridgeState() throws Exception {
Expand Down Expand Up @@ -78,7 +81,7 @@ default String eth_chainId() {

String eth_blockNumber();

String eth_call(CallArgumentsParam args, Map<String, String> blockRef) throws Exception; // NOSONAR
String eth_call(CallArgumentsParam args, Map<String, String> blockRef); // NOSONAR

String eth_getBalance(HexAddressParam address, BlockRefParam blockRefParam) throws Exception;

Expand Down
2 changes: 1 addition & 1 deletion rskj-core/src/main/java/org/ethereum/rpc/Web3Impl.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public String eth_blockNumber() {

@Override
public String eth_call(CallArgumentsParam args, Map<String, String> inputs) {
return invokeByBlockRef(inputs, blockNumber -> this.eth_call(args, new BlockIdentifierParam(blockNumber)));
return invokeByBlockRef(inputs, blockNumber -> getEthModule().call(args, new BlockIdentifierParam(blockNumber)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@ public byte[] execute(byte[] data) {
int expLen = parseLen(data, EXPONENT);
int modLen = parseLen(data, MODULUS);

if (baseLen == 0 && modLen == 0) {
return ByteUtil.leftPadBytes(ByteUtil.EMPTY_BYTE_ARRAY, modLen);
}

int expOffset = Math.addExact(ARGS_OFFSET, baseLen);
int modOffset = Math.addExact(expOffset, expLen);

Expand Down
8 changes: 4 additions & 4 deletions rskj-core/src/test/java/org/ethereum/rpc/Web3ImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@ function greet(string memory param) public pure returns (string memory) {
argsForCall.setTo(HexUtils.toJsonHex(tx.getContractAddress().getBytes()));
argsForCall.setData("0xead710c40000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000");

String result = web3.eth_call(TransactionFactoryHelper.toCallArgumentsParam(argsForCall), new BlockIdentifierParam("latest"));
String result = web3.eth_call(TransactionFactoryHelper.toCallArgumentsParam(argsForCall), new BlockRefParam("latest"));

assertEquals("0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000", result);
}
Expand Down Expand Up @@ -1997,7 +1997,7 @@ function greet(string memory param) public pure returns (string memory) {
argsForCall.setTo(HexUtils.toJsonHex(tx.getContractAddress().getBytes()));
argsForCall.setData("0xead710c40000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000");

String result = web3.eth_call(TransactionFactoryHelper.toCallArgumentsParam(argsForCall), new BlockIdentifierParam("latest"));
String result = web3.eth_call(TransactionFactoryHelper.toCallArgumentsParam(argsForCall), new BlockRefParam("latest"));

assertEquals("0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000", result);
}
Expand Down Expand Up @@ -2030,7 +2030,7 @@ void callNoneContractReturn() {
argsForCall.setTo(HexUtils.toUnformattedJsonHex(tx.getContractAddress().getBytes()));
argsForCall.setData(HexUtils.toUnformattedJsonHex(func.encode()));

String result = web3.eth_call(TransactionFactoryHelper.toCallArgumentsParam(argsForCall), new BlockIdentifierParam("latest"));
String result = web3.eth_call(TransactionFactoryHelper.toCallArgumentsParam(argsForCall), new BlockRefParam("latest"));

assertEquals("0x", result);
}
Expand Down Expand Up @@ -2612,7 +2612,7 @@ void callWithoutReturn() {
argsForCall.setTo(HexUtils.toJsonHex(tx.getContractAddress().getBytes()));
argsForCall.setData(HexUtils.toJsonHex(noreturn.functions.get("noreturn").encodeSignature()));

String result = web3.eth_call(TransactionFactoryHelper.toCallArgumentsParam(argsForCall), new BlockIdentifierParam("latest"));
String result = web3.eth_call(TransactionFactoryHelper.toCallArgumentsParam(argsForCall), new BlockRefParam("latest"));

Assertions.assertEquals("0x", result);
}
Expand Down
Loading