diff --git a/controllers/main.go b/controllers/main.go index d89a5e4c..3a12ca95 100644 --- a/controllers/main.go +++ b/controllers/main.go @@ -353,7 +353,7 @@ func (controller *MainController) APIAddress(c web.C, r *http.Request) ([]string createMultiSig.RedeemScript, poolPubKeyAddr, userPubKeyAddr, userFeeAddr.EncodeAddress(), importedHeight) - log.Infof("successfully create multisigaddress for user %d", c.Env["APIUserID"]) + log.Infof("successfully create multisigaddress for user %d", int(user.Id)) err = controller.StakepooldUpdateUsers(dbMap) if err != nil { @@ -367,8 +367,7 @@ func (controller *MainController) APIAddress(c web.C, r *http.Request) ([]string func (controller *MainController) APIPurchaseTicket(c web.C, r *http.Request) (*poolapi.PurchaseInfo, codes.Code, string, error) { userPubKeyAddr := r.FormValue("UserPubKeyAddr") - u, err := validateUserPubKeyAddr(userPubKeyAddr) - if err != nil { + if _, err := validateUserPubKeyAddr(userPubKeyAddr); err != nil { return nil, codes.InvalidArgument, "address error", err } @@ -387,21 +386,18 @@ func (controller *MainController) APIPurchaseTicket(c web.C, r *http.Request) (* return purchaseInfo, codes.OK, "APIPurchaseTicket: purchaseinfo retrieved for existing userPubKeyAddr", nil } - //token := models.NewUserToken() user = &models.User{ Username: userPubKeyAddr, Email: userPubKeyAddr, - //EmailToken: token.String(), EmailVerified: 0, VoteBits: 1, VoteBitsVersion: int64(controller.voteVersion), } - //user.HashPassword(password) remoteIP := getClientIP(r, controller.realIPHeader) log.Infof("APIPurchaseTicket POST from %v, created new user account %v. Inserting.", remoteIP, user.Email) - err = models.InsertUser(dbMap, user) + err := models.InsertUser(dbMap, user) if err != nil { log.Errorf("Error while creating new user account for ticket purchase: %v", err) return nil, codes.Unavailable, "system error", errors.New("unable to setup db entry for purchase") @@ -409,10 +405,10 @@ func (controller *MainController) APIPurchaseTicket(c web.C, r *http.Request) (* // load saved user info from db to get the user id user = models.GetUserByEmail(dbMap, userPubKeyAddr) - userId := user.Id + userId := int(user.Id) // Get the ticket address for this user - pooladdress, err := controller.TicketAddressForUserID(int(userId)) + pooladdress, err := controller.TicketAddressForUserID(int(user.Id)) if err != nil { log.Errorf("unable to derive ticket address: %v", err) return nil, codes.Unavailable, "system error", errors.New("unable to process wallet commands") @@ -431,29 +427,22 @@ func (controller *MainController) APIPurchaseTicket(c web.C, r *http.Request) (* poolPubKeyAddr := poolValidateAddress.PubKeyAddr - p, err := dcrutil.DecodeAddress(poolPubKeyAddr) - if err != nil { - controller.handlePotentialFatalError("DecodeAddress poolPubKeyAddr", err) + if _, err = dcrutil.DecodeAddress(poolPubKeyAddr); err != nil { return nil, codes.Unavailable, "system error", errors.New("unable to process wallet commands") } - if controller.RPCIsStopped() { - return nil, codes.Unavailable, "system error", errors.New("unable to process wallet commands") - } - createMultiSig, err := controller.rpcServers.CreateMultisig(1, []dcrutil.Address{p, u}) + createMultiSig, err := controller.StakepooldServers.CreateMultisig([]string{poolPubKeyAddr, userPubKeyAddr}) if err != nil { - controller.handlePotentialFatalError("CreateMultisig", err) return nil, codes.Unavailable, "system error", errors.New("unable to process wallet commands") } - // Serialize the RedeemScript (hex string -> []byte) + // Serialize the redeem script (hex string -> []byte) serializedScript, err := hex.DecodeString(createMultiSig.RedeemScript) if err != nil { - controller.handlePotentialFatalError("CreateMultisig DecodeString", err) return nil, codes.Unavailable, "system error", errors.New("unable to process wallet commands") } - // Import the RedeemScript + // Import the redeem script var importedHeight int64 importedHeight, err = controller.StakepooldServers.ImportScript(serializedScript) if err != nil { @@ -471,7 +460,7 @@ func (controller *MainController) APIPurchaseTicket(c web.C, r *http.Request) (* createMultiSig.RedeemScript, poolPubKeyAddr, userPubKeyAddr, userFeeAddr.EncodeAddress(), importedHeight) - log.Infof("successfully create multisigaddress for user %d", c.Env["APIUserID"]) + log.Infof("successfully create multisigaddress for user %d", userId) err = controller.StakepooldUpdateUsers(dbMap) if err != nil { @@ -479,10 +468,10 @@ func (controller *MainController) APIPurchaseTicket(c web.C, r *http.Request) (* } purchaseInfo := &poolapi.PurchaseInfo{ - PoolAddress: user.UserFeeAddr, + PoolAddress: userFeeAddr.EncodeAddress(), PoolFees: controller.poolFees, - Script: user.MultiSigScript, - TicketAddress: user.MultiSigAddress, + Script: createMultiSig.RedeemScript, + TicketAddress: createMultiSig.Address, VoteBits: uint16(user.VoteBits), } return purchaseInfo, codes.OK, "APIPurchaseTicket: purchaseinfo generated for userPubKeyAddr", nil