Skip to content

Commit

Permalink
imp(outposts): common function to read ABI (#1973)
Browse files Browse the repository at this point in the history
* use common function to read abi in precompiles

* fix copypasta docstring

* update CHANGELOG
  • Loading branch information
0xstepit committed Oct 31, 2023
1 parent f497fd3 commit b3844fe
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (distribution) [#1949](https://github.com/evmos/evmos/pull/1949) Add `ClaimRewards` custom transaction.
- (distribution) [#1954](https://github.com/evmos/evmos/pull/1954) Add `ClaimRewards` unit and event tests.
- (osmosis-outpost) [#1944](https://github.com/evmos/evmos/pull/1921) Add more validation to Osmosis outpost.
- (precompiles) [[#1973](https://github.com/evmos/evmos/pull/1973) Use `LoadABI` from precompiles common package in outposts.

### Bug Fixes

Expand Down
1 change: 1 addition & 0 deletions precompiles/common/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func PackNum(value reflect.Value) []byte {
}
}

// LoadABI read the ABI file described by the path and parse it as JSON.
func LoadABI(fs embed.FS, path string) (abi.ABI, error) {
abiBz, err := fs.ReadFile(path)
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions precompiles/outposts/osmosis/osmosis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package osmosis

import (
"bytes"
"embed"
"fmt"

Expand Down Expand Up @@ -63,19 +62,14 @@ func NewPrecompile(
transferKeeper transferkeeper.Keeper,
erc20Keeper erc20keeper.Keeper,
) (*Precompile, error) {
abiBz, err := f.ReadFile("abi.json")
if err != nil {
return nil, err
}

newAbi, err := abi.JSON(bytes.NewReader(abiBz))
abi, err := LoadABI()
if err != nil {
return nil, err
}

return &Precompile{
Precompile: cmn.Precompile{
ABI: newAbi,
ABI: abi,
KvGasConfig: storetypes.KVGasConfig(),
TransientKVGasConfig: storetypes.TransientGasConfig(),
ApprovalExpiration: cmn.DefaultExpirationDuration, // should be configurable in the future.
Expand All @@ -90,6 +84,12 @@ func NewPrecompile(
}, nil
}

// LoadABI loads the Osmosis outpost ABI from the embedded abi.json file
// for the Osmosis outpost precompile.
func LoadABI() (abi.ABI, error) {
return cmn.LoadABI(f, "abi.json")
}

// Address defines the address of the Osmosis outpost precompile contract.
func (Precompile) Address() common.Address {
return common.HexToAddress(OsmosisOutpostAddress)
Expand Down
16 changes: 8 additions & 8 deletions precompiles/outposts/stride/stride.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package stride

import (
"bytes"
"embed"
"fmt"

Expand Down Expand Up @@ -48,19 +47,14 @@ func NewPrecompile(
authzKeeper authzkeeper.Keeper,
stakingKeeper stakingkeeper.Keeper,
) (*Precompile, error) {
abiBz, err := f.ReadFile("abi.json")
if err != nil {
return nil, err
}

newAbi, err := abi.JSON(bytes.NewReader(abiBz))
abi, err := LoadABI()
if err != nil {
return nil, err
}

return &Precompile{
Precompile: cmn.Precompile{
ABI: newAbi,
ABI: abi,
AuthzKeeper: authzKeeper,
KvGasConfig: storetypes.KVGasConfig(),
TransientKVGasConfig: storetypes.TransientGasConfig(),
Expand All @@ -75,6 +69,12 @@ func NewPrecompile(
}, nil
}

// LoadABI loads the Stride outpost ABI from the embedded abi.json file
// for the Stride outpost precompile.
func LoadABI() (abi.ABI, error) {
return cmn.LoadABI(f, "abi.json")
}

// Address defines the address of the Stride Outpost precompile contract.
func (Precompile) Address() common.Address {
return common.HexToAddress("0x0000000000000000000000000000000000000900")
Expand Down

0 comments on commit b3844fe

Please sign in to comment.