Skip to content

Commit

Permalink
server/auth: postbond, tiers, bond tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
chappjc committed Mar 18, 2022
1 parent 04c72a8 commit 083200d
Show file tree
Hide file tree
Showing 8 changed files with 1,114 additions and 420 deletions.
31 changes: 8 additions & 23 deletions server/account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"time"

"decred.org/dcrdex/server/account/pki"
"github.com/decred/dcrd/crypto/blake256"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
)

var (
HashFunc = blake256.Sum256
century = time.Hour * 24 * 365 * 100
)
type PrivateKey = secp256k1.PrivateKey

const (
HashSize = blake256.Size
PrivKeySize = secp256k1.PrivKeyBytesLen
PubKeySize = secp256k1.PubKeyBytesLenCompressed
HashSize = blake256.Size
)

var HashFunc = blake256.Sum256

type AccountID [HashSize]byte

// NewID generates a unique account id with the provided public key bytes.
Expand Down Expand Up @@ -74,9 +73,9 @@ type Account struct {
// NewAccountFromPubKey creates a dex client account from the provided public
// key bytes.
func NewAccountFromPubKey(pk []byte) (*Account, error) {
if len(pk) != pki.PubKeySize {
if len(pk) != PubKeySize {
return nil, fmt.Errorf("invalid pubkey length, "+
"expected %d, got %d", pki.PubKeySize, len(pk))
"expected %d, got %d", PubKeySize, len(pk))
}

pubKey, err := secp256k1.ParsePubKey(pk)
Expand Down Expand Up @@ -118,35 +117,29 @@ const (
// details holds rule specific details.
type details struct {
name, description string
duration time.Duration
}

// ruleDetails maps rules to rule details.
var ruleDetails = map[Rule]details{
NoRule: {
name: "NoRule",
description: "no rules have been broken",
duration: 0,
},
PreimageReveal: {
name: "PreimageReveal",
description: "failed to respond with a valid preimage for an order during epoch processing",
duration: century,
},
FailureToAct: {
name: "FailureToAct",
description: "did not follow through on a swap negotiation step",
duration: century,
},
CancellationRate: {
name: "CancellationRate",
description: "cancellation rate dropped below the acceptable level",
duration: century,
},
LowFees: {
name: "LowFees",
description: "did not pay transaction mining fees at the requisite level",
duration: century,
},
}

Expand All @@ -166,14 +159,6 @@ func (r Rule) Description() string {
return "description not specified"
}

// Duration returns the penalty duration of the rule being broken.
func (r Rule) Duration() time.Duration {
if d, ok := ruleDetails[r]; ok {
return d.duration
}
return century
}

// Punishable returns whether breaking this rule incurs a penalty.
func (r Rule) Punishable() bool {
return r > NoRule && r < MaxRule
Expand Down
13 changes: 0 additions & 13 deletions server/account/pki/pki.go

This file was deleted.

Loading

0 comments on commit 083200d

Please sign in to comment.