From ba8cb921b00391f5e169ed03d6da8c227aeaca78 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Wed, 1 May 2019 12:26:06 -0700 Subject: [PATCH] Deploy app contracts and rest api on all shards --- api/service/restclientsupport/service.go | 8 ++++---- node/node.go | 15 +++++++++------ node/service_setup.go | 6 +++++- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/api/service/restclientsupport/service.go b/api/service/restclientsupport/service.go index a30b4bb55..693b4d760 100644 --- a/api/service/restclientsupport/service.go +++ b/api/service/restclientsupport/service.go @@ -36,7 +36,7 @@ type Service struct { CallFaucetContract func(common.Address) common.Hash GetAccountBalance func(common.Address) (*big.Int, error) CreateTransactionForPlayMethod func(string) error - CreateTransactionForPayoutMethod func(string, int) error + CreateTransactionForPayoutMethod func(common.Address, uint8) error } // New returns new client support service. @@ -46,7 +46,7 @@ func New( CreateTransactionForPickWinner func() error, CallFaucetContract func(common.Address) common.Hash, GetAccountBalance func(common.Address) (*big.Int, error), CreateTransactionForPlayMethod func(string) error, - CreateTransactionForPayoutMethod func(string, int) error) *Service { + CreateTransactionForPayoutMethod func(common.Address, uint8) error) *Service { return &Service{ CreateTransactionForEnterMethod: CreateTransactionForEnterMethod, GetResult: GetResult, @@ -282,8 +282,8 @@ func (s *Service) Payout(w http.ResponseWriter, r *http.Request) { return } - if err = s.CreateTransactionForPayoutMethod(key, newLevelInt); err != nil { - utils.GetLogInstance().Error("error", err) + if err = s.CreateTransactionForPayoutMethod(common.HexToAddress(key), uint8(newLevelInt)); err != nil { + utils.GetLogInstance().Error("Payout error", err) json.NewEncoder(w).Encode(res) return } diff --git a/node/node.go b/node/node.go index b2ce4b5ef..9f04f8b9b 100644 --- a/node/node.go +++ b/node/node.go @@ -283,16 +283,19 @@ func New(host p2p.Host, consensusObj *consensus.Consensus, db ethdb.Database, is // Setup one time smart contracts node.CurrentStakes = make(map[common.Address]*structs.StakeInfo) node.AddStakingContractToPendingTransactions() //This will save the latest information about staked nodes in current staked - // TODO(minhdoan): Think of a better approach to deploy smart contract. - // This is temporary for demo purpose. - node.AddLotteryContract() - node.AddPuzzleContract() } else { node.AddContractKeyAndAddress(scStaking) - node.AddContractKeyAndAddress(scLottery) - node.AddContractKeyAndAddress(scPuzzle) } } + if isFirstTime { + // TODO(minhdoan): Think of a better approach to deploy smart contract. + // This is temporary for demo purpose. + node.AddLotteryContract() + node.AddPuzzleContract() + } else { + node.AddContractKeyAndAddress(scLottery) + node.AddContractKeyAndAddress(scPuzzle) + } } node.ContractCaller = contracts.NewContractCaller(&db, node.blockchain, params.TestChainConfig) diff --git a/node/service_setup.go b/node/service_setup.go index 5621e1752..ccf7523e5 100644 --- a/node/service_setup.go +++ b/node/service_setup.go @@ -25,6 +25,11 @@ func (node *Node) setupForShardLeader() { // Register networkinfo service. "0" is the beacon shard ID node.serviceManager.RegisterService(service.NetworkInfo, networkinfo.New(node.host, node.NodeConfig.GetShardGroupID(), chanPeer, nil)) + node.serviceManager.RegisterService(service.RestClientSupport, restclientsupport.New( + node.CreateTransactionForEnterMethod, node.GetResult, + node.CreateTransactionForPickWinner, node.CallFaucetContract, node.GetBalanceOfAddress, + node.CreateTransactionForPlayMethod, node.CreateTransactionForPayoutMethod)) + // Register explorer service. node.serviceManager.RegisterService(service.SupportExplorer, explorer.New(&node.SelfPeer, node.Consensus.GetNodeIDs, node.GetBalanceOfAddress)) // Register consensus service. @@ -62,7 +67,6 @@ func (node *Node) setupForBeaconLeader() { node.serviceManager.RegisterService(service.ClientSupport, clientsupport.New(node.blockchain.State, node.CallFaucetContract, node.getDeployedStakingContract, node.SelfPeer.IP, node.SelfPeer.Port)) // TODO(minhdoan): We will remove the old client support and use the new client support which uses new message protocol. // Register client new support service. - // TODO(minhdoan): Also consider provide clientsupport/restclientsupport for other shards in the future. node.serviceManager.RegisterService(service.RestClientSupport, restclientsupport.New( node.CreateTransactionForEnterMethod, node.GetResult, node.CreateTransactionForPickWinner, node.CallFaucetContract, node.GetBalanceOfAddress,