Skip to content

Commit

Permalink
Client: Rename "permit" operation to "publish" (closes #128)
Browse files Browse the repository at this point in the history
"Permit" button is now labeled "publish" because local jobs may always
start, even if the button is not pressed.
  • Loading branch information
indyjo committed Feb 6, 2017
1 parent 9b0bb44 commit 9aabaee
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion share/bitwrk-client/htroot/js/activity.js
Expand Up @@ -73,7 +73,7 @@ function setActivities(node, activitiesjson, serverUrl) {
+ '_phase_dummy_' + '<div class="info"></div>';
} else {
item.innerHTML = '<div class="type"></div>'
+ '<button class="closebtn btn btn-primary btn-xs">Permit</button>'
+ '<button class="closebtn btn btn-primary btn-xs">Publish</button>'
+ '<div class="article"></div>' + '_phase_dummy_'
+ '<div class="info"></div>';
}
Expand Down
8 changes: 4 additions & 4 deletions src/github.com/indyjo/bitwrk-client/activity.go
Expand Up @@ -43,9 +43,9 @@ type Activity interface {
GetKey() ActivityKey
GetState() *ActivityState

// Permit the activity.
// Returns true if the call caused the activity to be accepted.
Permit(identity *bitcoin.KeyPair, price money.Money) bool
// Publish the activity.
// Returns true if the call caused the activity to be published.
Publish(identity *bitcoin.KeyPair, price money.Money) bool

// Forbid the activity.
// Returns true if the call caused the activity to be rejected.
Expand All @@ -59,7 +59,7 @@ type ActivityState struct {
Type string
Article bitwrk.ArticleId
Alive bool // Whether the activity is still alive
Accepted bool // Whether the activity was permitted
Accepted bool // true iff the activity can no longer be published
Rejected bool
Amount money.Money
BidId, TxId string
Expand Down
Expand Up @@ -194,7 +194,6 @@ func handleRevokeMandate(r *http.Request) error {
return nil
}


// Simply forward the request to the BitWrk service
func handleRequestDepositAddress(r *http.Request) error {
if nonce, err := protocol.GetNonce(); err != nil {
Expand Down
24 changes: 13 additions & 11 deletions src/github.com/indyjo/bitwrk-client/mandate.go
Expand Up @@ -24,17 +24,18 @@ import (
"time"
)

// Automates granting permission to (or publishing of, as it is now called) a trade.
type Mandate struct {
mutex sync.Mutex
expired bool
Identity *bitcoin.KeyPair
BidType bitwrk.BidType // Buy or Sell
Article bitwrk.ArticleId
Price money.Money
UseTradesLeft bool
TradesLeft int
UseUntil bool
Until time.Time
mutex sync.Mutex // Protects every access to the mandate's state
expired bool // Initially false
Identity *bitcoin.KeyPair // Which identity to pass to the publish operation
BidType bitwrk.BidType // Buy or Sell
Article bitwrk.ArticleId // Which article to buy or sell
Price money.Money // Which price to bid/ask for
UseTradesLeft bool // Whether TradesLeft should be regarded
TradesLeft int // Remaining number of trades until expiration
UseUntil bool // Whether Until should be regarded
Until time.Time // Time at which mandate should expire
}

// Shown to user
Expand All @@ -48,6 +49,7 @@ type MandateInfo struct {
Until time.Time
}

// Returns true if the mandate has expired
func (m *Mandate) Expired() bool {
m.mutex.Lock()
defer m.mutex.Unlock()
Expand Down Expand Up @@ -109,7 +111,7 @@ func (m *Mandate) Apply(activity Activity, now time.Time) bool {
return false
}

result := t.Permit(m.Identity, m.Price)
result := t.Publish(m.Identity, m.Price)
if result {
m.TradesLeft--
}
Expand Down
12 changes: 6 additions & 6 deletions src/github.com/indyjo/bitwrk-client/trade.go
Expand Up @@ -40,11 +40,11 @@ type Trade struct {

alive bool // Set to false on end of life
clearanceDenied bool // Set to true on Forbid
clearedForTrade bool // Set to true on Permit
published bool // Set to true on Publish
localMatch *Trade // Set to a matching trade on local match
awaitingClearance bool // Set to false on local match, Forbid and Permit
awaitingClearance bool // Set to false on local match, Forbid and Publish

// Information stored on Permit(...)
// Information stored on Publish(...)
identity *bitcoin.KeyPair
price money.Money

Expand Down Expand Up @@ -129,7 +129,7 @@ func (t *Trade) awaitClearance(log bitwrk.Logger, interrupt <-chan bool) error {
fmt.Errorf("Clearance denied")
return ErrNoPermission
} else {
if t.clearedForTrade {
if t.published {
log.Printf("Got trade clearance. Price: %v", t.price)
} else if t.localMatch != nil {
log.Printf("Got local clearance. Matched with #%v.", t.localMatch.key)
Expand Down Expand Up @@ -426,15 +426,15 @@ func (t *Trade) GetState() *ActivityState {
return result
}

func (t *Trade) Permit(identity *bitcoin.KeyPair, price money.Money) bool {
func (t *Trade) Publish(identity *bitcoin.KeyPair, price money.Money) bool {
t.condition.L.Lock()
defer t.condition.L.Unlock()
if !t.awaitingClearance {
return false
}
t.identity = identity
t.price = price
t.clearedForTrade = true
t.published = true
t.awaitingClearance = false
t.condition.Broadcast()
return true
Expand Down

0 comments on commit 9aabaee

Please sign in to comment.