Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add per-ticket API authentication scheme #514

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4c6992b
setup ticket ownership validation/authentication middleware
itswisdomagain Aug 1, 2019
ae81af2
implement v3 auth middleware
itswisdomagain Aug 1, 2019
cf0f138
add v3 api support
itswisdomagain Aug 1, 2019
3769865
use ticket validity age from config
itswisdomagain Aug 1, 2019
375f20e
track timestamp usage in ticket auth routine
itswisdomagain Aug 1, 2019
f4c9c26
cache ticket auth signature instead of timestamp
itswisdomagain Aug 9, 2019
136e908
return more descriptive error messages on ticket auth failure
itswisdomagain Aug 9, 2019
3fc6f04
support new ticketauth api auth scheme on /v1 and /v2 api endpoints
itswisdomagain Aug 21, 2019
2940a31
allow timestamps value 5mins into future
itswisdomagain Aug 30, 2019
14fce14
allow access to some /api routes without valid auth header
itswisdomagain Aug 31, 2019
9b529a6
remove maxticketchallengeage config option, use constant value
itswisdomagain Sep 4, 2019
1970e45
return proper error for invalid ticket signature cases
itswisdomagain Sep 11, 2019
4b0145c
ctx.WalletConnection -> ctx.WalletConnection.RPCClient()
itswisdomagain Sep 19, 2019
8a7cf8f
Joe's review
itswisdomagain Sep 21, 2019
5ccd341
rename OwnerRewardAddress to UserRewardAddress
itswisdomagain Sep 22, 2019
4ac97e5
gitignore vendor
itswisdomagain Oct 2, 2019
a892cf7
use dcrutil/v2, wallet/v3 and txscript/v2
itswisdomagain Nov 7, 2019
64558ac
bump dcrwallet/wallet mod version
itswisdomagain Nov 7, 2019
b8db13e
go fmt
itswisdomagain Nov 7, 2019
a9cf03c
post rebase fixes and cleanup
itswisdomagain Mar 11, 2020
2f0c03d
refactor application.Init
itswisdomagain Mar 11, 2020
10e8b82
unexport some types and properties, fix panics
itswisdomagain Mar 12, 2020
dcd59fc
validate tx hash supplied for ticket ownership validation
itswisdomagain Mar 12, 2020
be5e840
fix panic on api request without acceptable auth header
itswisdomagain Mar 19, 2020
f5bbac5
use passed context for GetTicketInfo stakepoold rpc call
itswisdomagain Mar 19, 2020
8384d53
bump stakepoold minor version
itswisdomagain Mar 21, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ testing/
*.orig
debug
public/**/*.gz
vendor
10 changes: 10 additions & 0 deletions backend/stakepoold/rpc/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ service StakepooldService {
rpc ValidateAddress (ValidateAddressRequest) returns (ValidateAddressResponse);
rpc AddMissingTicket (AddMissingTicketRequest) returns (AddMissingTicketResponse);
rpc GetTickets (GetTicketsRequest) returns (GetTicketsResponse);
rpc GetTicketInfo (GetTicketInfoRequest) returns (GetTicketInfoResponse);
rpc ListScripts (ListScriptsRequest) returns (ListScriptsResponse);
rpc AccountSyncAddressIndex (AccountSyncAddressIndexRequest) returns (AccountSyncAddressIndexResponse);
rpc CreateMultisig (CreateMultisigRequest) returns (CreateMultisigResponse);
Expand All @@ -41,6 +42,15 @@ message GetLiveTicketsResponse {
repeated Ticket tickets = 1;
}

message GetTicketInfoRequest {
string Hash = 1;
}
message GetTicketInfoResponse {
string MultiSigAddress = 1;
string VspRewardAddress = 2;
string UserRewardAddress = 3;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to start tracking txids in the db, as we want to become more self-sufficient. Although I am aware that you want to reduce the communication between the db and stakepoold, because it is on another machine. A centralized area to track tickets is needed, imo. What do you think? It should be discussed somewhere... I'll make an issue after a little more thought.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we can totally remove reliance on dcrwallet; unless that's possible and is something we're working towards, I'd prefer that where possible, we not store information that we can deduce by making 1 or 2 RPC calls. But you can open an issue for this and we can discuss it more and see what we can come up with.

Copy link
Member Author

@itswisdomagain itswisdomagain Sep 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I later commented below, this may be a good idea after all. I can proceed to implement in this PR if that's agreed.


message SetAddedLowFeeTicketsRequest {
repeated Ticket tickets = 1;
}
Expand Down
19 changes: 16 additions & 3 deletions backend/stakepoold/rpc/server/server.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2015-2016 The btcsuite developers
// Copyright (c) 2016-2017 The Decred developers
// Copyright (c) 2016-2020 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -34,9 +34,9 @@ const (
// collection cycle to also trigger a timeout but the current allocation
// pattern of stakepoold is not known to cause such conditions at this time.
GRPCCommandTimeout = time.Millisecond * 100
semverString = "9.0.0"
semverString = "9.1.0"
semverMajor = 9
semverMinor = 0
semverMinor = 1
semverPatch = 0
)

Expand Down Expand Up @@ -203,6 +203,19 @@ func (s *stakepooldServer) GetTickets(ctx context.Context, req *pb.GetTicketsReq
return &pb.GetTicketsResponse{Tickets: ticketBytes}, nil
}

func (s *stakepooldServer) GetTicketInfo(ctx context.Context, req *pb.GetTicketInfoRequest) (*pb.GetTicketInfoResponse, error) {
ticketInfo, err := s.stakepoold.GetTicketInfo(req.Hash)
if err != nil {
return nil, err
}

return &pb.GetTicketInfoResponse{
MultiSigAddress: ticketInfo.MultiSigAddress,
VspRewardAddress: ticketInfo.VspRewardAddress,
UserRewardAddress: ticketInfo.UserRewardAddress,
}, nil
}

func (s *stakepooldServer) AddMissingTicket(ctx context.Context, req *pb.AddMissingTicketRequest) (*pb.AddMissingTicketResponse, error) {

err := s.stakepoold.AddMissingTicket(req.Hash)
Expand Down
395 changes: 265 additions & 130 deletions backend/stakepoold/rpc/stakepoolrpc/api.pb.go

Large diffs are not rendered by default.

79 changes: 79 additions & 0 deletions backend/stakepoold/stakepool/stakepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
wallettypes "github.com/decred/dcrwallet/rpc/jsonrpc/types"

"github.com/decred/dcrd/rpcclient/v4"
"github.com/decred/dcrd/txscript/v2"
"github.com/decred/dcrd/wire"
"github.com/decred/dcrstakepool/backend/stakepoold/userdata"
"github.com/decred/dcrwallet/wallet/v3/txrules"
Expand Down Expand Up @@ -109,6 +110,12 @@ type ticketMetadata struct {
err error // log errors along the way
}

type ticketInfo struct {
MultiSigAddress string
VspRewardAddress string
UserRewardAddress string
}

// EvaluateStakePoolTicket evaluates a voting service ticket to see if it's
// acceptable to the voting service. The ticket must pay out to the voting
// service cold wallet, and must have a sufficient fee.
Expand Down Expand Up @@ -414,6 +421,78 @@ func (spd *Stakepoold) GetTickets(includeImmature bool) ([]*chainhash.Hash, erro
return tickets, nil
}

// GetTicketInfo pulls the transaction information for a ticket from dcrwallet,
// returning the voting address and reward addresses for the ticket.
func (spd *Stakepoold) GetTicketInfo(ticketHash string) (*ticketInfo, error) {
hash, err := chainhash.NewHashFromStr(ticketHash)
if err != nil {
log.Errorf("GetTicketInfo: Failed to parse ticket hash: %v", err)
return nil, err
}

res, err := spd.WalletConnection.RPCClient().GetTransaction(hash)
if err != nil {
log.Errorf("GetTicketInfo: GetTransaction rpc failed: %v", err)
return nil, err
}

msgTx, err := MsgTxFromHex(res.Hex)
if err != nil {
log.Errorf("GetTicketInfo: MsgTxFromHex failed for %v: %v", res.Hex, err)
return nil, err
}

if !stake.IsSStx(msgTx) {
log.Errorf("GetTicketInfo: %s not a ticket purchase transaction", ticketHash)
return nil, fmt.Errorf("%s not a ticket purchase transaction", ticketHash)
}

ticketBlockHash, err := chainhash.NewHashFromStr(res.BlockHash)
if err != nil {
log.Warnf("GetTicketInfo: NewHashFromStr failed for %v: %v", res.BlockHash, err)
return nil, err
}

ticketBlockHeader, err := spd.NodeConnection.GetBlockHeader(ticketBlockHash)
if err != nil {
log.Warnf("GetTicketInfo: GetBlockHeader failed for %v: %v", ticketBlockHash, err)
return nil, err
}

if knownByVsp, _ := spd.EvaluateStakePoolTicket(msgTx, int32(ticketBlockHeader.Height)); !knownByVsp {
log.Errorf("GetTicketInfo: ticket (%s) not watched by this VSP", ticketHash)
return nil, fmt.Errorf("ticket (%s) not watched by this VSP", ticketHash)
}

p2shOut := msgTx.TxOut[0]
_, p2shOutAddresses, _, err := txscript.ExtractPkScriptAddrs(p2shOut.Version, p2shOut.PkScript, spd.Params)
if err != nil {
log.Errorf("GetTicketInfo: Failed to parse p2sh out addr: %v", err)
return nil, err
}
multiSigAddress := p2shOutAddresses[0]

vspCommitmentOut := msgTx.TxOut[1]
vspCommitAddr, err := stake.AddrFromSStxPkScrCommitment(vspCommitmentOut.PkScript, spd.Params)
if err != nil {
log.Errorf("GetTicketInfo: Failed to parse commit out addr: %v", err)
return nil, err
}

ownerCommitmentOut := msgTx.TxOut[3]
ownerCommitAddr, err := stake.AddrFromSStxPkScrCommitment(ownerCommitmentOut.PkScript, spd.Params)
if err != nil {
log.Errorf("GetTicketInfo: Failed to parse commit out addr: %v", err)
return nil, err
}

return &ticketInfo{
MultiSigAddress: multiSigAddress.Address(),
VspRewardAddress: vspCommitAddr.Address(),
UserRewardAddress: ownerCommitAddr.Address(),
}, nil
}

itswisdomagain marked this conversation as resolved.
Show resolved Hide resolved
// StakePoolUserInfo performs the rpc command stakepooluserinfo on dcrwallet and
// returns the result.
func (spd *Stakepoold) StakePoolUserInfo(multisigAddress string) (*wallettypes.StakePoolUserInfoResult, error) {
Expand Down
4 changes: 4 additions & 0 deletions controllers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ func (controller *MainController) API(c web.C, r *http.Request) *system.APIRespo
}
}

if invalidAuthMessage := c.Env["AuthErrorMessage"]; invalidAuthMessage != "" && code == codes.Unauthenticated {
err = fmt.Errorf("invalid api authorization: %s", invalidAuthMessage)
}

if err != nil {
status = "error"
response = response + " - " + err.Error()
Expand Down
5 changes: 5 additions & 0 deletions controllers/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ type tStakepooldManager struct {
qItem func() queueItem
}

func (m *tStakepooldManager) GetTicketInfo(_ context.Context, hash string) (*pb.GetTicketInfoResponse, error) {
item := m.qItem()
thing, _ := item.thing.(*pb.GetTicketInfoResponse)
return thing, item.err
}
func (m *tStakepooldManager) GetAddedLowFeeTickets(_ context.Context) (map[chainhash.Hash]string, error) {
item := m.qItem()
thing, _ := item.thing.(map[chainhash.Hash]string)
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ require (
github.com/decred/dcrd/dcrutil/v2 v2.0.1
github.com/decred/dcrd/hdkeychain/v2 v2.1.0
github.com/decred/dcrd/rpcclient/v4 v4.0.0
github.com/decred/dcrd/txscript/v2 v2.1.0
github.com/decred/dcrd/wire v1.3.0
github.com/decred/dcrdata/api/types/v4 v4.0.4
github.com/decred/dcrdata/txhelpers/v3 v3.0.5 // indirect
github.com/decred/dcrwallet/rpc/jsonrpc/types v1.4.0
github.com/decred/dcrwallet/wallet/v3 v3.2.1
github.com/decred/slog v1.0.0
Expand Down
32 changes: 32 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
decred.org/cspp v0.2.0 h1:SdwdoGT2wZenkczeDxzcKwoAA55Y0Ti3aZslabBORvA=
decred.org/cspp v0.2.0/go.mod h1:KVnB49sueBFCldRa/ivZCaWZbrPNEiXWwxHCf1jTYKI=
decred.org/cspp v0.2.0/go.mod h1:KVnB49sueBFCldRa/ivZCaWZbrPNEiXWwxHCf1jTYKI=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DATA-DOG/go-sqlmock v1.4.1 h1:ThlnYciV1iM/V0OSF/dtkqWb6xo5qITT1TJBG1MRDJM=
github.com/DATA-DOG/go-sqlmock v1.4.1/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
Expand Down Expand Up @@ -36,6 +39,8 @@ github.com/decred/dcrd/blockchain/standalone v1.0.0 h1:bPkFgSV7/NeZI+ZEGhaOP+Xcc
github.com/decred/dcrd/blockchain/standalone v1.0.0/go.mod h1:U5lOleFSi1nL7heSdLgEtuvg0udS1p3cvHxvLJbihfE=
github.com/decred/dcrd/blockchain/standalone v1.1.0 h1:yclvVGEY09Gf8A4GSAo+NCtL1dW2TYJ4OKp4+g0ICI0=
github.com/decred/dcrd/blockchain/standalone v1.1.0/go.mod h1:6K8ZgzlWM1Kz2TwXbrtiAvfvIwfAmlzrtpA7CVPCUPE=
github.com/decred/dcrd/blockchain/v2 v2.1.0 h1:IOzw2ckSabvmnLrhYJLUH9bD9x7wScqlJ5jY3ke5/Us=
github.com/decred/dcrd/blockchain/v2 v2.1.0/go.mod h1:DBmX26fUDTQocIozF44Ydo5+m+QzaC6aMYMBFFsCOJs=
github.com/decred/dcrd/blockchain/v2 v2.1.0/go.mod h1:DBmX26fUDTQocIozF44Ydo5+m+QzaC6aMYMBFFsCOJs=
github.com/decred/dcrd/certgen v1.1.0 h1:lAPE2OLYdYeXDCaji/+KC53j7/s7wF7RVGeQbXK//XA=
github.com/decred/dcrd/certgen v1.1.0/go.mod h1:ivkPLChfjdAgFh7ZQOtl6kJRqVkfrCq67dlq3AbZBQE=
Expand Down Expand Up @@ -83,6 +88,11 @@ github.com/decred/dcrd/hdkeychain/v2 v2.0.1/go.mod h1:qPv+vTla19liVHFuXVnQ70dMI4
github.com/decred/dcrd/hdkeychain/v2 v2.1.0 h1:NVNIz36HPukOnaysBDsLO+2kWqijLM4tvLUsLLyLfME=
github.com/decred/dcrd/hdkeychain/v2 v2.1.0/go.mod h1:DR+lD4uV8G0i3c9qnUJwjiGaaEWK+nSrbWCz1BRHBL8=
github.com/decred/dcrd/rpc/jsonrpc/types v1.0.0 h1:d5ptnjuSADTQMa3i83VpeJNoMRTOJZZBqk7P+E41VXM=
github.com/decred/dcrd/rpc/jsonrpc/types v1.0.0 h1:d5ptnjuSADTQMa3i83VpeJNoMRTOJZZBqk7P+E41VXM=
github.com/decred/dcrd/rpc/jsonrpc/types v1.0.0 h1:d5ptnjuSADTQMa3i83VpeJNoMRTOJZZBqk7P+E41VXM=
github.com/decred/dcrd/rpc/jsonrpc/types v1.0.0 h1:d5ptnjuSADTQMa3i83VpeJNoMRTOJZZBqk7P+E41VXM=
github.com/decred/dcrd/rpc/jsonrpc/types v1.0.0/go.mod h1:0dwmpIP21tJxjg/UuUHWIFMbfoLv2ifCBMokNKlOxpo=
github.com/decred/dcrd/rpc/jsonrpc/types v1.0.0/go.mod h1:0dwmpIP21tJxjg/UuUHWIFMbfoLv2ifCBMokNKlOxpo=
github.com/decred/dcrd/rpc/jsonrpc/types v1.0.0/go.mod h1:0dwmpIP21tJxjg/UuUHWIFMbfoLv2ifCBMokNKlOxpo=
github.com/decred/dcrd/rpc/jsonrpc/types v1.0.1 h1:sWsGtWzdmrna6aysDCHwjANTJh+Lxt2xp6S10ahP79Y=
github.com/decred/dcrd/rpc/jsonrpc/types v1.0.1/go.mod h1:dJUp9PoyFYklzmlImpVkVLOr6j4zKuUv66YgemP2sd8=
Expand All @@ -104,15 +114,29 @@ github.com/decred/dcrdata/semver v1.0.0 h1:DBqYU/x+4LqHq/3r4xKdF6xG5ewktG2KDC+g/
github.com/decred/dcrdata/semver v1.0.0/go.mod h1:z+nQqiAd9fYkHhBLbejysZ2FPHtgkrErWDgMf+JlZWE=
github.com/decred/dcrdata/txhelpers/v3 v3.0.4 h1:kjvzHU6Tf4//7FJVn+BuwGHskjjrRt4Ps88104Y1vbA=
github.com/decred/dcrdata/txhelpers/v3 v3.0.4/go.mod h1:tKEDhoO+TbYrFrx+5qKZDxcla8ELQFYs4f5+8gL4cuY=
github.com/decred/dcrdata/txhelpers/v3 v3.0.4/go.mod h1:tKEDhoO+TbYrFrx+5qKZDxcla8ELQFYs4f5+8gL4cuY=
github.com/decred/dcrdata/txhelpers/v3 v3.0.5 h1:UhzuJgw9cPIC8h2HUnFXQhIZVWlseumFnoiKYbvZxKE=
github.com/decred/dcrdata/txhelpers/v3 v3.0.5/go.mod h1:tKEDhoO+TbYrFrx+5qKZDxcla8ELQFYs4f5+8gL4cuY=
github.com/decred/dcrwallet/deployments/v2 v2.0.0 h1:sSjkc87hcDFGoLMTIwNt5ze+rCHbholqyM8Z3H9k5CE=
github.com/decred/dcrwallet/deployments/v2 v2.0.0/go.mod h1:fY1HV1vIeeY5bHjrMknUhB/ZOVIfthBiUlSgRqFFKrg=
github.com/decred/dcrwallet/deployments/v2 v2.0.0/go.mod h1:fY1HV1vIeeY5bHjrMknUhB/ZOVIfthBiUlSgRqFFKrg=
github.com/decred/dcrwallet/errors/v2 v2.0.0 h1:b3QHoQNjKkrcO0GSpueeHvFKp5eqtRv9aw649MDyejA=
github.com/decred/dcrwallet/errors/v2 v2.0.0 h1:b3QHoQNjKkrcO0GSpueeHvFKp5eqtRv9aw649MDyejA=
github.com/decred/dcrwallet/errors/v2 v2.0.0/go.mod h1:2HYvtRuCE9XqDNCWhKmBuzLG364xUgcUIsJu02r0F5Q=
github.com/decred/dcrwallet/errors/v2 v2.0.0/go.mod h1:2HYvtRuCE9XqDNCWhKmBuzLG364xUgcUIsJu02r0F5Q=
github.com/decred/dcrwallet/rpc/client/dcrd v1.0.0 h1:xRx6XdG3IFWDVL4XMBzy41dz6Gtff/suzQggSR6uKyw=
github.com/decred/dcrwallet/rpc/client/dcrd v1.0.0/go.mod h1:qrJri+p+cn+obQ8nkW5hTtagPcOnCqKPGBq1t02gBc0=
github.com/decred/dcrwallet/rpc/client/dcrd v1.0.0/go.mod h1:qrJri+p+cn+obQ8nkW5hTtagPcOnCqKPGBq1t02gBc0=
github.com/decred/dcrwallet/rpc/jsonrpc/types v1.1.0/go.mod h1:xUT7XXATLOzE0pwwmvgfRWtZdrB+PsWFilo+jkH5/Ig=
github.com/decred/dcrwallet/rpc/jsonrpc/types v1.1.0/go.mod h1:xUT7XXATLOzE0pwwmvgfRWtZdrB+PsWFilo+jkH5/Ig=
github.com/decred/dcrwallet/rpc/jsonrpc/types v1.3.0 h1:yCxtFqK7X6GvZWQzHXjCwoGCy9YVe3tGEwxCjW5rYQk=
github.com/decred/dcrwallet/rpc/jsonrpc/types v1.3.0 h1:yCxtFqK7X6GvZWQzHXjCwoGCy9YVe3tGEwxCjW5rYQk=
github.com/decred/dcrwallet/rpc/jsonrpc/types v1.3.0/go.mod h1:Xvekb43GtfMiRbyIY4ZJ9Uhd9HRIAcnp46f3q2eIExU=
github.com/decred/dcrwallet/rpc/jsonrpc/types v1.3.0/go.mod h1:Xvekb43GtfMiRbyIY4ZJ9Uhd9HRIAcnp46f3q2eIExU=
github.com/decred/dcrwallet/rpc/jsonrpc/types v1.4.0 h1:dg5wAleAQ6shYL1xIBZjN6bK34FU/S1C0ugc+R/GEqY=
github.com/decred/dcrwallet/rpc/jsonrpc/types v1.4.0/go.mod h1:Xvekb43GtfMiRbyIY4ZJ9Uhd9HRIAcnp46f3q2eIExU=
github.com/decred/dcrwallet/validate v1.1.1 h1:hoHrHaJTQoANN/ZW37HbeTQSJ+N4rMFFLz6LT/FACJQ=
github.com/decred/dcrwallet/validate v1.1.1/go.mod h1:T++tlVcCOh2oSrEq4r5CKCvmftaQdq9uZwO7jSNYZaw=
github.com/decred/dcrwallet/validate v1.1.1/go.mod h1:T++tlVcCOh2oSrEq4r5CKCvmftaQdq9uZwO7jSNYZaw=
github.com/decred/dcrwallet/wallet/v3 v3.2.1 h1:oPm/xauyMJPt4TBkhRWEO+j18FP/fMbtJM74eQR5/bg=
github.com/decred/dcrwallet/wallet/v3 v3.2.1/go.mod h1:SJ+++gtMdcUeqMv6iIO3gVGlGJfM+4iY2QSaAakhbUw=
Expand Down Expand Up @@ -149,15 +173,19 @@ github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+
github.com/gorilla/sessions v1.2.0 h1:S7P+1Hm5V/AT9cjEcUD5uDaQSX0OE577aCXgoaKpYbQ=
github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jrick/bitset v1.0.0 h1:Ws0PXV3PwXqWK2n7Vz6idCdrV/9OrBXgHEJi27ZB9Dw=
github.com/jrick/bitset v1.0.0/go.mod h1:ZOYB5Uvkla7wIEY4FEssPVi3IQXa02arznRaYaAEPe4=
github.com/jrick/logrotate v1.0.0 h1:lQ1bL/n9mBNeIXoTUoYRlK4dHuNJVofX9oWqBtPnSzI=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/jrick/wsrpc/v2 v2.0.0 h1:f0ACoYeSG0fUNpA42gPpDdZ/xzYLUxZjT1F4L+HLTgY=
github.com/jrick/wsrpc/v2 v2.0.0/go.mod h1:naH/fojac6vQWYgAA0e7b9TX/bShsWoVL7CwrdvFmUk=
github.com/jrick/wsrpc/v2 v2.2.0 h1:6/vdMn8DhCg2gYedvZL2C44cyWv9JCw62tK3+9popMU=
github.com/jrick/wsrpc/v2 v2.2.0/go.mod h1:naH/fojac6vQWYgAA0e7b9TX/bShsWoVL7CwrdvFmUk=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down Expand Up @@ -201,6 +229,8 @@ golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand All @@ -211,9 +241,11 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 h1:fHDIZ2oxGnUZRN6WgWFCbYBjH9uqVPRCUVUDhs0wnbA=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
11 changes: 11 additions & 0 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ func GetUserByID(dbMap *gorp.DbMap, id int64) (user *User, err error) {
return user, nil
}

// GetUserByMSA returns user info from db for user with the provided multisig address.
func GetUserByMSA(dbMap *gorp.DbMap, msa string) (user *User, err error) {
itswisdomagain marked this conversation as resolved.
Show resolved Hide resolved
JoeGruffins marked this conversation as resolved.
Show resolved Hide resolved
err = dbMap.SelectOne(&user, "SELECT * FROM Users WHERE MultiSigAddress = ?", msa)

if err != nil {
return nil, err
}

return user, nil
}

// GetUserCount gives a count of all users.
func GetUserCount(dbMap *gorp.DbMap) int64 {
userCount, err := dbMap.SelectInt("SELECT COUNT(*) FROM Users")
Expand Down
33 changes: 22 additions & 11 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/decred/dcrd/rpcclient/v4"
"github.com/decred/dcrstakepool/controllers"
"github.com/decred/dcrstakepool/email"
"github.com/decred/dcrstakepool/models"
"github.com/decred/dcrstakepool/signal"
"github.com/decred/dcrstakepool/stakepooldclient"
"github.com/decred/dcrstakepool/system"
Expand Down Expand Up @@ -66,14 +67,30 @@ func runMain(ctx context.Context) error {
}
}()

var application = &system.Application{}
dbMap := models.GetDbMap(
cfg.APISecret,
cfg.BaseURL,
cfg.DBUser,
cfg.DBPassword,
cfg.DBHost,
cfg.DBPort,
cfg.DBName)

application.Init(ctx, wg, cfg.APISecret, cfg.BaseURL, cfg.CookieSecret,
cfg.CookieSecure, cfg.DBHost, cfg.DBName, cfg.DBPassword, cfg.DBPort,
cfg.DBUser)
if application.DbMap == nil {
if dbMap == nil {
return fmt.Errorf("failed to open database")
}

stakepooldConnMan, err := stakepooldclient.ConnectStakepooldGRPC(ctx, cfg.StakepooldHosts,
cfg.StakepooldCerts)
if err != nil {
return fmt.Errorf("failed to connect to stakepoold host: %v", err)
}

var application = &system.Application{}

application.Init(ctx, dbMap, stakepooldConnMan, wg, cfg.APISecret, cfg.CookieSecret,
cfg.CookieSecure, activeNetParams)

if err = application.LoadTemplates(cfg.TemplatePath); err != nil {
return fmt.Errorf("failed to load templates: %v", err)
}
Expand All @@ -87,12 +104,6 @@ func runMain(ctx context.Context) error {
// Supported API versions are advertised in the API stats result
APIVersionsSupported := []int{1, 2}

stakepooldConnMan, err := stakepooldclient.ConnectStakepooldGRPC(ctx, cfg.StakepooldHosts,
cfg.StakepooldCerts)
if err != nil {
return fmt.Errorf("failed to connect to stakepoold host: %v", err)
}

var sender email.Sender
if cfg.SMTPHost != "" {
sender, err = email.NewSender(cfg.SMTPHost, cfg.SMTPUsername, cfg.SMTPPassword,
Expand Down
Loading