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

Propagate block number to eth_call #109

Merged
merged 5 commits into from
Feb 15, 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
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ module github.com/hyperledger/firefly-evmconnect

go 1.21

toolchain go1.21.6

require (
github.com/hashicorp/golang-lru v1.0.2
github.com/hyperledger/firefly-common v1.4.5
github.com/hyperledger/firefly-common v1.4.6-0.20240131185020-80d20a173401
github.com/hyperledger/firefly-signer v1.1.12
github.com/hyperledger/firefly-transaction-manager v1.3.6
github.com/hyperledger/firefly-transaction-manager v1.3.7
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.8.4
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU=
github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/hyperledger/firefly-common v1.4.5 h1:tvuO2IiET8Jhp/T0yVvL0k3hPnUXe2clEXB3l6fs+BA=
github.com/hyperledger/firefly-common v1.4.5/go.mod h1:jkErZdQmC9fsAJZQO427tURdwB9iiW+NMUZSqS3eBIE=
github.com/hyperledger/firefly-common v1.4.6-0.20240131185020-80d20a173401 h1:bcIg8zUalHyjxPmhIggwg/VK/IVDvpH2XJwCkfAYrSU=
github.com/hyperledger/firefly-common v1.4.6-0.20240131185020-80d20a173401/go.mod h1:jkErZdQmC9fsAJZQO427tURdwB9iiW+NMUZSqS3eBIE=
github.com/hyperledger/firefly-signer v1.1.12 h1:wv1cq4HV60G2MQdmIEkYkywoxUSkaH0ss95Nn3ohdEk=
github.com/hyperledger/firefly-signer v1.1.12/go.mod h1:4MW7bcTqPsS7SKwANJZRL030cJRsHcpB/a+06wUROvc=
github.com/hyperledger/firefly-transaction-manager v1.3.6 h1:gz6ZXiGQuZWKlQTS6FI2NWyp62J11SF0PXmWz44jEkI=
github.com/hyperledger/firefly-transaction-manager v1.3.6/go.mod h1:gGNTdxNRyK9+rsyVnT7uP7S2kW8MHCXSDL/v8vuxARg=
github.com/hyperledger/firefly-transaction-manager v1.3.7 h1:rHQw0UopJMl4s6RigW6As+VkjGYuV+oTp+jLOATOptw=
github.com/hyperledger/firefly-transaction-manager v1.3.7/go.mod h1:kwhCuzcFwhmj2+LYsE5dEzI7NqA+l0SYexsCMj06xXg=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
Expand Down
4 changes: 2 additions & 2 deletions internal/ethereum/estimate_gas.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -76,7 +76,7 @@ func (c *ethConnector) gasEstimate(ctx context.Context, tx *ethsigner.Transactio
}

// If it fails, fall back to an eth_call to see if we get a reverted reason
_, reason, errCall := c.callTransaction(ctx, tx, method, errors)
_, reason, errCall := c.callTransaction(ctx, tx, method, errors, nil)
if reason == ffcapi.ErrorReasonTransactionReverted {
return nil, reason, errCall
}
Expand Down
12 changes: 8 additions & 4 deletions internal/ethereum/exec_query.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -68,7 +68,7 @@ func (c *ethConnector) QueryInvoke(ctx context.Context, req *ffcapi.QueryInvokeR
}

// Do the call, with processing of revert reasons
outputs, reason, err := c.callTransaction(ctx, tx, method, errors)
outputs, reason, err := c.callTransaction(ctx, tx, method, errors, req.BlockNumber)
if err != nil {
return nil, reason, err
}
Expand Down Expand Up @@ -99,11 +99,15 @@ func (c *ethConnector) attemptProcessingRevertData(ctx context.Context, errors [
return "", nil
}

func (c *ethConnector) callTransaction(ctx context.Context, tx *ethsigner.Transaction, method *abi.Entry, errors []*abi.Entry) (*fftypes.JSONAny, ffcapi.ErrorReason, error) {
func (c *ethConnector) callTransaction(ctx context.Context, tx *ethsigner.Transaction, method *abi.Entry, errors []*abi.Entry, blockNumber *string) (*fftypes.JSONAny, ffcapi.ErrorReason, error) {

// Do the raw call
var outputData ethtypes.HexBytes0xPrefix
rpcErr := c.backend.CallRPC(ctx, &outputData, "eth_call", tx, "latest")
blockNumberStr := "latest"
if blockNumber != nil {
blockNumberStr = *blockNumber
}
rpcErr := c.backend.CallRPC(ctx, &outputData, "eth_call", tx, blockNumberStr)
if rpcErr != nil {
if reason, revertErr := c.attemptProcessingRevertData(ctx, errors, rpcErr); revertErr != nil {
return nil, reason, revertErr
Expand Down
3 changes: 2 additions & 1 deletion internal/ethereum/exec_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,15 @@ func TestExecQueryOKResponse(t *testing.T) {
assert.Equal(t, "0x60fe47b100000000000000000000000000000000000000000000000000000000feedbeef", tx.Data.String())
return true
}),
"latest").
"0x12345").
Run(func(args mock.Arguments) {
*(args[1].(*ethtypes.HexBytes0xPrefix)) = ethtypes.MustNewHexBytes0xPrefix("0x00000000000000000000000000000000000000000000000000000000baadf00d0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000b68656c6c6f20776f726c64000000000000000000000000000000000000000000")
}).
Return(nil)

var req ffcapi.QueryInvokeRequest
err := json.Unmarshal([]byte(sampleExecQuery), &req)
req.BlockNumber = strPtr("0x12345")
assert.NoError(t, err)

res, reason, err := c.QueryInvoke(ctx, &req)
Expand Down
Loading