Skip to content

Commit

Permalink
Merge pull request #24 from skip-mev/fix-account-retrieval
Browse files Browse the repository at this point in the history
- Fixes a bug in which the account derivation was resulting in an error when sending bundles by updating the method of retrieving account
  • Loading branch information
NotJeremyLiu authored Apr 13, 2023
2 parents af73db9 + a93edba commit 10ae188
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
2 changes: 0 additions & 2 deletions skipper-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ func startCommand() {
tx := <-txChan

go backrunner.OnTransaction(tx)
//
// backrunner.OnTransaction(tx)
}
}

Expand Down
40 changes: 28 additions & 12 deletions skipper-go/skip/skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
evmosEthsecp256k1 "github.com/evmos/ethermint/crypto/ethsecp256k1"
evmostypes "github.com/tharsis/evmos/v5/types"
)

type SkipClient struct {
Expand Down Expand Up @@ -54,13 +53,6 @@ func NewSkipClient(
panic(err)
}

ethAddressBytes, err := evmostypes.GetEvmosAddressFromBech32(bech32Address)
if err != nil {
panic(err)
}

ethAddress := fmt.Sprintf("0x%x", ethAddressBytes)

client := &SkipClient{
SignerAddress: bech32Address,

Expand All @@ -73,7 +65,7 @@ func NewSkipClient(

go func() {
for {
account, err := client.getAccount(ethAddress)
account, err := client.getAccount(bech32Address)
if err != nil {
fmt.Println(err)
time.Sleep(5 * time.Second)
Expand Down Expand Up @@ -209,19 +201,43 @@ type Account struct {
}

func (client *SkipClient) getAccount(accountAddress string) (*Account, error) {
resp, err := http.Get(fmt.Sprintf("%s/ethermint/evm/v1/cosmos_account/%s", client.restURL, accountAddress))
type responseType struct {
Account struct {
Type string `json:"@type"`
BaseAccount struct {
Address string `json:"address"`
PubKey struct {
Type string `json:"@type"`
Key string `json:"key"`
} `json:"pub_key"`
AccountNumber string `json:"account_number"`
Sequence string `json:"sequence"`
} `json:"base_account"`
CodeHash string `json:"code_hash"`
} `json:"account"`
}

resp, err := http.Get(fmt.Sprintf("%s/cosmos/auth/v1beta1/accounts/%s", client.restURL, accountAddress))
if err != nil {
return nil, err
}

result := Account{}
defer resp.Body.Close()

result := responseType{}

err = json.NewDecoder(resp.Body).Decode(&result)
if err != nil {
return nil, err
}

return &result, nil
account := &Account{
AccountNumber: result.Account.BaseAccount.AccountNumber,
Sequence: result.Account.BaseAccount.Sequence,
CosmosAddress: result.Account.BaseAccount.Address,
}

return account, nil
}

type SendBundleResult struct {
Expand Down

0 comments on commit 10ae188

Please sign in to comment.