|
|
|
@ -43,6 +43,7 @@ func (node *Node) AddLotteryContract() { |
|
|
|
|
types.HomesteadSigner{}, |
|
|
|
|
priKey) |
|
|
|
|
node.DemoContractAddress = crypto.CreateAddress(crypto.PubkeyToAddress(priKey.PublicKey), uint64(0)) |
|
|
|
|
node.DemoContractPrivateKey = priKey |
|
|
|
|
node.addPendingTransactions(types.Transactions{demoContract}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -64,11 +65,13 @@ func (node *Node) CreateTransactionForEnterMethod(amount int64, priKey string) e |
|
|
|
|
|
|
|
|
|
key, err := crypto.HexToECDSA(priKey) |
|
|
|
|
nonce := node.GetNonceOfAddress(crypto.PubkeyToAddress(key.PublicKey)) |
|
|
|
|
Amount := big.NewInt(amount) |
|
|
|
|
Amount = Amount.Mul(Amount, big.NewInt(params.Ether)) |
|
|
|
|
tx := types.NewTransaction( |
|
|
|
|
nonce, |
|
|
|
|
toAddress, |
|
|
|
|
0, |
|
|
|
|
big.NewInt(amount), |
|
|
|
|
Amount, |
|
|
|
|
params.TxGas*10, |
|
|
|
|
nil, |
|
|
|
|
bytesData, |
|
|
|
@ -86,7 +89,62 @@ func (node *Node) CreateTransactionForEnterMethod(amount int64, priKey string) e |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetResult2 get current players and their balances.
|
|
|
|
|
func (node *Node) GetResult2() (players []string, balances []uint64) { |
|
|
|
|
for _, account := range contract_constants.DemoAccounts { |
|
|
|
|
players = append(players, account.Address) |
|
|
|
|
key, err := crypto.HexToECDSA(account.Private) |
|
|
|
|
if err != nil { |
|
|
|
|
utils.GetLogInstance().Error("Error when HexToECDSA") |
|
|
|
|
} |
|
|
|
|
address := crypto.PubkeyToAddress(key.PublicKey) |
|
|
|
|
balances = append(balances, node.GetBalanceOfAddress(address)) |
|
|
|
|
} |
|
|
|
|
return players, balances |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetResult get current players and their balances.
|
|
|
|
|
func (node *Node) GetResult() (players []string, balances []uint64) { |
|
|
|
|
return []string{}, []uint64{} |
|
|
|
|
return node.GetResult2() |
|
|
|
|
// abi, err := abi.JSON(strings.NewReader(contracts.LotteryABI))
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// utils.GetLogInstance().Error("Failed to generate staking contract's ABI", "error", err)
|
|
|
|
|
// }
|
|
|
|
|
// bytesData, err := abi.Pack("getPlayers")
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// utils.GetLogInstance().Error("Failed to generate ABI function bytes data", "error", err)
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// demoContractAddress := node.DemoContractAddress
|
|
|
|
|
// demoContractPrivateKey := node.DemoContractPrivateKey
|
|
|
|
|
|
|
|
|
|
// tx := types.NewTransaction(
|
|
|
|
|
// node.GetNonceOfAddress(demoContractAddress),
|
|
|
|
|
// demoContractAddress,
|
|
|
|
|
// 0,
|
|
|
|
|
// nil,
|
|
|
|
|
// math.MaxUint64,
|
|
|
|
|
// nil,
|
|
|
|
|
// bytesData,
|
|
|
|
|
// )
|
|
|
|
|
// signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, demoContractPrivateKey)
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// utils.GetLogInstance().Error("Failed to sign contract call tx", "error", err)
|
|
|
|
|
// return nil
|
|
|
|
|
// }
|
|
|
|
|
// output, err := node.ContractCaller.CallContract(signedTx)
|
|
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// utils.GetLogInstance().Error("Failed to call staking contract", "error", err)
|
|
|
|
|
// return nil
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// ret := &structs.PlayersInfo{}
|
|
|
|
|
// err = abi.Unpack(ret, "getPlayers", output)
|
|
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// utils.GetLogInstance().Error("Failed to unpack stake info", "error", err)
|
|
|
|
|
// return nil
|
|
|
|
|
// }
|
|
|
|
|
// return ret
|
|
|
|
|
} |
|
|
|
|