Skip to content

Commit

Permalink
Merge pull request #161 from MinterTeam/dev
Browse files Browse the repository at this point in the history
v0.7.3
  • Loading branch information
danil-lashin authored Nov 18, 2018
2 parents 426a380 + 131f6e0 commit 2019a3f
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 0.7.3
*Nov 18th, 2018*

BUG FIXES

- [core] More fixes on issue with negative coin reserve

## 0.7.2
*Nov 18th, 2018*

Expand Down
18 changes: 18 additions & 0 deletions core/transaction/buy_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ func (data BuyCoinData) Run(sender types.Address, tx *Transaction, context *stat
}

commission = formula.CalculateSaleAmount(coin.Volume(), coin.ReserveBalance(), coin.Data().Crr, commissionInBaseCoin)

if commission == nil {
return Response{
Code: 999,
Log: "Unknown error"}
}
}

if context.GetBalance(sender, tx.GasCoin).Cmp(commission) < 0 {
Expand Down Expand Up @@ -122,6 +128,12 @@ func (data BuyCoinData) Run(sender types.Address, tx *Transaction, context *stat

value = formula.CalculateSaleAmount(coin.Volume, coin.ReserveBalance, coin.Crr, data.ValueToBuy)

if value == nil {
return Response{
Code: 999,
Log: "Unknown error"}
}

if context.GetBalance(sender, data.CoinToSell).Cmp(value) < 0 {
return Response{
Code: code.InsufficientFunds,
Expand Down Expand Up @@ -159,6 +171,12 @@ func (data BuyCoinData) Run(sender types.Address, tx *Transaction, context *stat

value = formula.CalculateSaleAmount(coinFrom.Volume, coinFrom.ReserveBalance, coinFrom.Crr, baseCoinNeeded)

if value == nil {
return Response{
Code: 999,
Log: "Unknown error"}
}

if context.GetBalance(sender, data.CoinToSell).Cmp(value) < 0 {
return Response{
Code: code.InsufficientFunds,
Expand Down
6 changes: 6 additions & 0 deletions core/transaction/create_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ func (data CreateCoinData) Run(sender types.Address, tx *Transaction, context *s
}

commission = formula.CalculateSaleAmount(coin.Volume(), coin.ReserveBalance(), coin.Data().Crr, commissionInBaseCoin)

if commission == nil {
return Response{
Code: 999,
Log: "Unknown error"}
}
}

if context.GetBalance(sender, tx.GasCoin).Cmp(commission) < 0 {
Expand Down
6 changes: 6 additions & 0 deletions core/transaction/create_multisig.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ func (data CreateMultisigData) Run(sender types.Address, tx *Transaction, contex
}

commission = formula.CalculateSaleAmount(coin.Volume(), coin.ReserveBalance(), coin.Data().Crr, commissionInBaseCoin)

if commission == nil {
return Response{
Code: 999,
Log: "Unknown error"}
}
}

if context.GetBalance(sender, tx.GasCoin).Cmp(commission) < 0 {
Expand Down
6 changes: 6 additions & 0 deletions core/transaction/declare_candidacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ func (data DeclareCandidacyData) Run(sender types.Address, tx *Transaction, cont
}

commission = formula.CalculateSaleAmount(coin.Volume(), coin.ReserveBalance(), coin.Data().Crr, commissionInBaseCoin)

if commission == nil {
return Response{
Code: 999,
Log: "Unknown error"}
}
}

if context.GetBalance(sender, data.Coin).Cmp(data.Stake) < 0 {
Expand Down
6 changes: 6 additions & 0 deletions core/transaction/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ func (data DelegateData) Run(sender types.Address, tx *Transaction, context *sta
}

commission = formula.CalculateSaleAmount(coin.Volume(), coin.ReserveBalance(), coin.Data().Crr, commissionInBaseCoin)

if commission == nil {
return Response{
Code: 999,
Log: "Unknown error"}
}
}

if context.GetBalance(sender, tx.GasCoin).Cmp(commission) < 0 {
Expand Down
6 changes: 6 additions & 0 deletions core/transaction/multisend.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ func (data MultisendData) Run(sender types.Address, tx *Transaction, context *st
}

commission = formula.CalculateSaleAmount(coin.Volume(), coin.ReserveBalance(), coin.Data().Crr, commissionInBaseCoin)

if commission == nil {
return Response{
Code: 999,
Log: "Unknown error"}
}
}

if err := checkBalances(context, sender, data.List, commission, tx.GasCoin); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions core/transaction/redeem_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ func (data RedeemCheckData) Run(sender types.Address, tx *Transaction, context *
if !decodedCheck.Coin.IsBaseCoin() {
coin := context.GetStateCoin(decodedCheck.Coin)
commission = formula.CalculateSaleAmount(coin.Volume(), coin.ReserveBalance(), coin.Data().Crr, commissionInBaseCoin)

if commission == nil {
return Response{
Code: 999,
Log: "Unknown error"}
}
}

totalTxCost := big.NewInt(0).Add(decodedCheck.Value, commission)
Expand Down
6 changes: 6 additions & 0 deletions core/transaction/sell_all_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func (data SellAllCoinData) Run(sender types.Address, tx *Transaction, context *
}

commission = formula.CalculateSaleAmount(coin.Volume(), coin.ReserveBalance(), coin.Data().Crr, commissionInBaseCoin)

if commission == nil {
return Response{
Code: 999,
Log: "Unknown error"}
}
}

if context.GetBalance(sender, data.CoinToSell).Cmp(commission) < 0 {
Expand Down
6 changes: 6 additions & 0 deletions core/transaction/sell_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ func (data SellCoinData) Run(sender types.Address, tx *Transaction, context *sta
}

commission = formula.CalculateSaleAmount(coin.Volume(), coin.ReserveBalance(), coin.Data().Crr, commissionInBaseCoin)

if commission == nil {
return Response{
Code: 999,
Log: "Unknown error"}
}
}

if context.GetBalance(sender, data.CoinToSell).Cmp(data.ValueToSell) < 0 {
Expand Down
6 changes: 6 additions & 0 deletions core/transaction/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ func (data SendData) Run(sender types.Address, tx *Transaction, context *state.S
}

commission = formula.CalculateSaleAmount(coin.Volume(), coin.ReserveBalance(), coin.Data().Crr, commissionInBaseCoin)

if commission == nil {
return Response{
Code: 999,
Log: "Unknown error"}
}
}

if context.GetBalance(sender, data.Coin).Cmp(data.Value) < 0 {
Expand Down
12 changes: 12 additions & 0 deletions core/transaction/switch_candidate_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ func (data SetCandidateOnData) Run(sender types.Address, tx *Transaction, contex
}

commission = formula.CalculateSaleAmount(coin.Volume(), coin.ReserveBalance(), coin.Data().Crr, commissionInBaseCoin)

if commission == nil {
return Response{
Code: 999,
Log: "Unknown error"}
}
}

if context.GetBalance(sender, tx.GasCoin).Cmp(commission) < 0 {
Expand Down Expand Up @@ -133,6 +139,12 @@ func (data SetCandidateOffData) Run(sender types.Address, tx *Transaction, conte
}

commission = formula.CalculateSaleAmount(coin.Volume(), coin.ReserveBalance(), coin.Data().Crr, commissionInBaseCoin)

if commission == nil {
return Response{
Code: 999,
Log: "Unknown error"}
}
}

if context.GetBalance(sender, tx.GasCoin).Cmp(commission) < 0 {
Expand Down
6 changes: 6 additions & 0 deletions core/transaction/unbond.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ func (data UnbondData) Run(sender types.Address, tx *Transaction, context *state
}

commission = formula.CalculateSaleAmount(coin.Volume(), coin.ReserveBalance(), coin.Data().Crr, commissionInBaseCoin)

if commission == nil {
return Response{
Code: 999,
Log: "Unknown error"}
}
}

if context.GetBalance(sender, tx.GasCoin).Cmp(commission) < 0 {
Expand Down
9 changes: 9 additions & 0 deletions formula/formula.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func CalculatePurchaseReturn(supply *big.Int, reserve *big.Int, crr uint, deposi

result, _ := res.Int(nil)

// TODO: delete
if result == nil {
return big.NewInt(0)
}

return result
}

Expand Down Expand Up @@ -117,6 +122,10 @@ func CalculateSaleAmount(supply *big.Int, reserve *big.Int, crr uint, wantReceiv
return ret
}

if reserve.Cmp(wantReceive) == -1 {
return nil
}

tSupply := newFloat(0).SetInt(supply)
tReserve := newFloat(0).SetInt(reserve)
tWantReceive := newFloat(0).SetInt(wantReceive)
Expand Down
4 changes: 2 additions & 2 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ package version
const (
Maj = "0"
Min = "7"
Fix = "2"
Fix = "3"
)

var (
// Must be a string because scripts like dist.sh read this file.
Version = "0.7.2"
Version = "0.7.3"

// GitCommit is the current HEAD set using ldflags.
GitCommit string
Expand Down

0 comments on commit 2019a3f

Please sign in to comment.