-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #225 from m-Peter/use-evm-dry-run-method
Use `EVM.dryRun` method
- Loading branch information
Showing
8 changed files
with
105 additions
and
120 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package api | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/onflow/go-ethereum/core/types" | ||
) | ||
|
||
const defaultGasLimit uint64 = 15_000_000 | ||
|
||
// encodeTxFromArgs will create a transaction from the given arguments. | ||
// The resulting unsigned transaction is only supposed to be used through | ||
// `EVM.dryRun` inside Cadence scripts, meaning that no state change | ||
// will occur. | ||
// This is only useful for `eth_estimateGas` and `eth_call` endpoints. | ||
func encodeTxFromArgs(args TransactionArgs) ([]byte, error) { | ||
var data []byte | ||
if args.Data != nil { | ||
data = *args.Data | ||
} else if args.Input != nil { | ||
data = *args.Input | ||
} | ||
|
||
// provide a high enough gas for the tx to be able to execute, | ||
// capped by the gas set in transaction args. | ||
gasLimit := defaultGasLimit | ||
if args.Gas != nil { | ||
gasLimit = uint64(*args.Gas) | ||
} | ||
|
||
value := big.NewInt(0) | ||
if args.Value != nil { | ||
value = args.Value.ToInt() | ||
} | ||
|
||
tx := types.NewTx( | ||
&types.LegacyTx{ | ||
Nonce: 0, | ||
To: args.To, | ||
Value: value, | ||
Gas: gasLimit, | ||
GasPrice: big.NewInt(0), | ||
Data: data, | ||
}, | ||
) | ||
|
||
return tx.MarshalBinary() | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
import EVM | ||
|
||
access(all) | ||
fun main(hexEncodedTx: String, hexEncodedAddress: String): EVM.Result { | ||
let addressBytes = hexEncodedAddress.decodeHex().toConstantSized<[UInt8; 20]>()! | ||
let address = EVM.EVMAddress(bytes: addressBytes) | ||
|
||
return EVM.dryRun(tx: hexEncodedTx.decodeHex(), from: address) | ||
} |
This file was deleted.
Oops, something went wrong.
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