Exemplo n.º 1
0
func (dao *gaeAccountingDao) GetAccount(participant string) (account ParticipantAccount, err error) {
	key := AccountKey(dao.c, participant)
	err = datastore.Get(dao.c, key, accountCodec{&account})
	if err == datastore.ErrNoSuchEntity {
		dao.c.Infof("Pulling account out of thin air: %v", participant)
		account.Participant = participant
		account.Available = money.MustParse("BTC 1")
		account.Blocked = money.MustParse("BTC 0")
		err = nil
	}

	return
}
Exemplo n.º 2
0
}

type RawBid struct {
	Type    BidType
	Article ArticleId
	Price   money.Money
}

func (bid *Bid) Verify() error {
	if err := bitcoin.VerifySignatureBase64(bid.Document, bid.Participant, bid.Signature); err != nil {
		return fmt.Errorf("Could not validate signature: %v", err)
	}
	return nil
}

var MinimumPrice = money.MustParse("uBTC 10")

func NewBid(bidType BidType, article ArticleId, price money.Money, participant, document, signature string) (*Bid, error) {
	if bidType != Buy && bidType != Sell {
		return nil, fmt.Errorf("Illegal bid type")
	}
	if price.Currency != MinimumPrice.Currency || price.Amount < MinimumPrice.Amount {
		return nil, fmt.Errorf("Invalid price %v, must be >= %v", price, MinimumPrice)
	}

	now := time.Now()
	result := &Bid{Type: bidType,
		State:       InQueue,
		Article:     article,
		Price:       price,
		Fee:         money.Money{Currency: price.Currency, Amount: (3*price.Amount + 99) / 100},