Deploy app contracts and rest api on all shards

pull/800/head
Rongjian Lan 6 years ago
parent e9c754a30c
commit ba8cb921b0
  1. 8
      api/service/restclientsupport/service.go
  2. 15
      node/node.go
  3. 6
      node/service_setup.go

@ -36,7 +36,7 @@ type Service struct {
CallFaucetContract func(common.Address) common.Hash CallFaucetContract func(common.Address) common.Hash
GetAccountBalance func(common.Address) (*big.Int, error) GetAccountBalance func(common.Address) (*big.Int, error)
CreateTransactionForPlayMethod func(string) error CreateTransactionForPlayMethod func(string) error
CreateTransactionForPayoutMethod func(string, int) error CreateTransactionForPayoutMethod func(common.Address, uint8) error
} }
// New returns new client support service. // New returns new client support service.
@ -46,7 +46,7 @@ func New(
CreateTransactionForPickWinner func() error, CreateTransactionForPickWinner func() error,
CallFaucetContract func(common.Address) common.Hash, GetAccountBalance func(common.Address) (*big.Int, error), CallFaucetContract func(common.Address) common.Hash, GetAccountBalance func(common.Address) (*big.Int, error),
CreateTransactionForPlayMethod func(string) error, CreateTransactionForPlayMethod func(string) error,
CreateTransactionForPayoutMethod func(string, int) error) *Service { CreateTransactionForPayoutMethod func(common.Address, uint8) error) *Service {
return &Service{ return &Service{
CreateTransactionForEnterMethod: CreateTransactionForEnterMethod, CreateTransactionForEnterMethod: CreateTransactionForEnterMethod,
GetResult: GetResult, GetResult: GetResult,
@ -282,8 +282,8 @@ func (s *Service) Payout(w http.ResponseWriter, r *http.Request) {
return return
} }
if err = s.CreateTransactionForPayoutMethod(key, newLevelInt); err != nil { if err = s.CreateTransactionForPayoutMethod(common.HexToAddress(key), uint8(newLevelInt)); err != nil {
utils.GetLogInstance().Error("error", err) utils.GetLogInstance().Error("Payout error", err)
json.NewEncoder(w).Encode(res) json.NewEncoder(w).Encode(res)
return return
} }

@ -283,16 +283,19 @@ func New(host p2p.Host, consensusObj *consensus.Consensus, db ethdb.Database, is
// Setup one time smart contracts // Setup one time smart contracts
node.CurrentStakes = make(map[common.Address]*structs.StakeInfo) node.CurrentStakes = make(map[common.Address]*structs.StakeInfo)
node.AddStakingContractToPendingTransactions() //This will save the latest information about staked nodes in current staked 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 { } else {
node.AddContractKeyAndAddress(scStaking) 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) node.ContractCaller = contracts.NewContractCaller(&db, node.blockchain, params.TestChainConfig)

@ -25,6 +25,11 @@ func (node *Node) setupForShardLeader() {
// Register networkinfo service. "0" is the beacon shard ID // 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.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. // Register explorer service.
node.serviceManager.RegisterService(service.SupportExplorer, explorer.New(&node.SelfPeer, node.Consensus.GetNodeIDs, node.GetBalanceOfAddress)) node.serviceManager.RegisterService(service.SupportExplorer, explorer.New(&node.SelfPeer, node.Consensus.GetNodeIDs, node.GetBalanceOfAddress))
// Register consensus service. // 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)) 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. // 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. // 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.serviceManager.RegisterService(service.RestClientSupport, restclientsupport.New(
node.CreateTransactionForEnterMethod, node.GetResult, node.CreateTransactionForEnterMethod, node.GetResult,
node.CreateTransactionForPickWinner, node.CallFaucetContract, node.GetBalanceOfAddress, node.CreateTransactionForPickWinner, node.CallFaucetContract, node.GetBalanceOfAddress,

Loading…
Cancel
Save