From 269e4f61194a435abab8e19f0321eb095dd23dd0 Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Mon, 25 Feb 2019 15:15:49 -0800 Subject: [PATCH] fix private key constant --- internal/utils/contract/constants.go | 23 ++++++++++++++++------- node/contract.go | 3 ++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/internal/utils/contract/constants.go b/internal/utils/contract/constants.go index 27f234b84..aa5617508 100644 --- a/internal/utils/contract/constants.go +++ b/internal/utils/contract/constants.go @@ -1,7 +1,9 @@ package contract import ( - "github.com/ethereum/go-ethereum/common" + "crypto/ecdsa" + "strings" + "github.com/ethereum/go-ethereum/crypto" ) @@ -12,15 +14,22 @@ type DeployAccount struct { Public string } -// GenesisBeaconAccount is the account which creates contract account. -var GenesisBeaconAccount = DeployAccount{ - Address: "0x4e464afF0aB44780fC9A008AC890047BcbDf376f", - Private: "b167c74da42202fc2093f8e2ed8171b4ad67d095595ac655fc56df236cad9714", - Public: "0x4e464afF0aB44780fC9A008AC890047BcbDf376f", +// // GenesisBeaconAccount is the account which creates contract account. +// var GenesisBeaconAccount = DeployAccount{ +// Address: "0x4e464afF0aB44780fC9A008AC890047BcbDf376f", +// Private: "b167c74da42202fc2093f8e2ed8171b4ad67d095595ac655fc56df236cad9714", +// Public: "0x4e464afF0aB44780fC9A008AC890047BcbDf376f", +// } + +func BeaconAccountPriKey() *ecdsa.PrivateKey { + prikey, _ := ecdsa.GenerateKey(crypto.S256(), strings.NewReader("Deposit Smart Contract Key")) + return prikey } +var GenesisBeaconAccountPriKey = BeaconAccountPriKey() + // DeployedContractAddress is the deployed contract address of the staking smart contract in beacon chain. -var DeployedContractAddress = crypto.CreateAddress(common.HexToAddress(GenesisBeaconAccount.Address), uint64(0)) +var DeployedContractAddress = crypto.CreateAddress(crypto.PubkeyToAddress(GenesisBeaconAccountPriKey.PublicKey), uint64(0)) // FakeAccounts is the accounts only used for development purpose. var FakeAccounts = [...]DeployAccount{ diff --git a/node/contract.go b/node/contract.go index e754ec655..6f45c4250 100644 --- a/node/contract.go +++ b/node/contract.go @@ -12,6 +12,7 @@ import ( "github.com/ethereum/go-ethereum/params" "github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/internal/utils/contract" + contract_constants "github.com/harmony-one/harmony/internal/utils/contract" "golang.org/x/crypto/sha3" ) @@ -27,7 +28,7 @@ const ( func (node *Node) AddStakingContractToPendingTransactions() { // Add a contract deployment transaction //Generate contract key and associate funds with the smart contract - priKey, _ := ecdsa.GenerateKey(crypto.S256(), strings.NewReader("Deposit Smart Contract Key")) + priKey := contract_constants.GenesisBeaconAccountPriKey contractAddress := crypto.PubkeyToAddress(priKey.PublicKey) //Initially the smart contract should have minimal funds. contractFunds := big.NewInt(0)