Skip to content

Commit

Permalink
scaffolds an ethereum address from orchestrator address in staking si…
Browse files Browse the repository at this point in the history
…mulation to have a deterministic way of creating it
  • Loading branch information
rach-id committed May 9, 2022
1 parent 03e8b0c commit fd79550
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions x/staking/simulation/operations.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package simulation

import (
"crypto/ecdsa"
"fmt"
"github.com/ethereum/go-ethereum/crypto"
"math/rand"

"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -148,10 +146,12 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k
simtypes.RandomDecAmount(r, maxCommission),
)

ethPrivateKey, _ := crypto.GenerateKey()
orchEthPublicKey := ethPrivateKey.Public().(*ecdsa.PublicKey)
ethAddr, _ := types.NewEthAddress(crypto.PubkeyToAddress(*orchEthPublicKey).Hex())
orchAddr := simAccount.Address
// create an Ethereum address from the orchestrator address
// this is mainly to have a deterministic way of generating an Ethereum address on every run
bytesOrchAddressWithoutPrefix := simAccount.Address.Bytes()[len([]byte(sdk.Bech32MainPrefix)):]
doubleOrchAddressBytes := append(bytesOrchAddressWithoutPrefix, bytesOrchAddressWithoutPrefix...) // to have a long enough bytes array
ethAddr, _ := types.NewEthAddress("0x" + fmt.Sprintf("%X", doubleOrchAddressBytes[:(types.ETHContractAddressLen/2)-2]))

msg, err := types.NewMsgCreateValidator(address, simAccount.ConsKey.PubKey(), selfDelegation, description, commission, sdk.OneInt(), orchAddr, *ethAddr)
if err != nil {
Expand Down

0 comments on commit fd79550

Please sign in to comment.