From fa2db31edce2a2e859635eeeb9f9fb1be1393027 Mon Sep 17 00:00:00 2001 From: ak Date: Mon, 10 Dec 2018 17:35:26 -0800 Subject: [PATCH] responding to RJ's changes --- node/node.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/node/node.go b/node/node.go index ee7ad8278..38fc7ee81 100644 --- a/node/node.go +++ b/node/node.go @@ -106,6 +106,7 @@ type Node struct { // Test only TestBankKeys []*ecdsa.PrivateKey + ContractKeys []*ecdsa.PrivateKey // The p2p host used to send/receive p2p messages host host.Host @@ -228,18 +229,15 @@ func DeserializeNode(d []byte) *NetworkNode { return &wn } +//AddSmartContractsToPendingTransactions adds the faucet contract the genesis block. func (node *Node) AddSmartContractsToPendingTransactions() { // Add a contract deployment transactionv - priKey := node.TestBankKeys[0] - txs := make([]*types.Transaction, 0) - var nonce uint64 - nonce = 0 + priKey := node.ContractKeys[0] contractData := "0x608060405234801561001057600080fd5b506040516020806104c08339810180604052602081101561003057600080fd5b505160008054600160a060020a0319163317808255600160a060020a031681526001602081905260409091205560ff811661006c600282610073565b50506100bd565b8154818355818111156100975760008381526020902061009791810190830161009c565b505050565b6100ba91905b808211156100b657600081556001016100a2565b5090565b90565b6103f4806100cc6000396000f3fe60806040526004361061005b577c010000000000000000000000000000000000000000000000000000000060003504635c19a95c8114610060578063609ff1bd146100955780639e7b8d61146100c0578063b3f98adc146100f3575b600080fd5b34801561006c57600080fd5b506100936004803603602081101561008357600080fd5b5035600160a060020a0316610120565b005b3480156100a157600080fd5b506100aa610280565b6040805160ff9092168252519081900360200190f35b3480156100cc57600080fd5b50610093600480360360208110156100e357600080fd5b5035600160a060020a03166102eb565b3480156100ff57600080fd5b506100936004803603602081101561011657600080fd5b503560ff16610348565b3360009081526001602081905260409091209081015460ff1615610144575061027d565b5b600160a060020a0382811660009081526001602081905260409091200154620100009004161580159061019c5750600160a060020a0382811660009081526001602081905260409091200154620100009004163314155b156101ce57600160a060020a039182166000908152600160208190526040909120015462010000900490911690610145565b600160a060020a0382163314156101e5575061027d565b6001818101805460ff1916821775ffffffffffffffffffffffffffffffffffffffff0000191662010000600160a060020a0386169081029190911790915560009081526020829052604090209081015460ff16156102725781546001820154600280549091610100900460ff1690811061025b57fe5b60009182526020909120018054909101905561027a565b815481540181555b50505b50565b600080805b60025460ff821610156102e6578160028260ff168154811015156102a557fe5b906000526020600020016000015411156102de576002805460ff83169081106102ca57fe5b906000526020600020016000015491508092505b600101610285565b505090565b600054600160a060020a0316331415806103215750600160a060020a0381166000908152600160208190526040909120015460ff165b1561032b5761027d565b600160a060020a0316600090815260016020819052604090912055565b3360009081526001602081905260409091209081015460ff1680610371575060025460ff831610155b1561037c575061027d565b6001818101805460ff191690911761ff00191661010060ff8516908102919091179091558154600280549192909181106103b257fe5b600091825260209091200180549091019055505056fea165627a7a72305820164189ef302b4648e01e22456b0a725191604cb63ee472f230ef6a2d17d702f900290000000000000000000000000000000000000000000000000000000000000002" dataEnc := common.FromHex(contractData) // Unsigned transaction to avoid the case of transaction address. - mycontracttx, _ := types.SignTx(types.NewContractCreation(nonce, 0, big.NewInt(1000000), params.TxGasContractCreation*10, nil, dataEnc), types.HomesteadSigner{}, priKey) - txs = append(txs, mycontracttx) - node.pendingTransactionsAccount = txs + mycontracttx, _ := types.SignTx(types.NewContractCreation(uint64(0), 0, big.NewInt(1000000), params.TxGasContractCreation*10, nil, dataEnc), types.HomesteadSigner{}, priKey) + node.pendingTransactionsAccount = append(node.pendingTransactionsAccount, mycontracttx) } // New creates a new node. @@ -288,6 +286,12 @@ func New(host host.Host, consensus *bft.Consensus, db *hdb.LDBDatabase) *Node { node.TestBankKeys = append(node.TestBankKeys, testBankKey) } + contractKey, _ := ecdsa.GenerateKey(crypto.S256(), reader) + contractAddress := crypto.PubkeyToAddress(contractKey.PublicKey) + contractFunds := big.NewInt(8000000000000000000) + genesisAloc[contractAddress] = core.GenesisAccount{Balance: contractFunds} + node.ContractKeys = append(node.ContractKeys, contractKey) + database := hdb.NewMemDatabase() chainConfig := params.TestChainConfig chainConfig.ChainID = big.NewInt(int64(node.Consensus.ShardID)) // Use ChainID as piggybacked ShardID