Skip to content

Commit

Permalink
Merge pull request #71 from MinterTeam/dev
Browse files Browse the repository at this point in the history
v0.1.6
  • Loading branch information
danil-lashin authored Jul 30, 2018
2 parents 14c0945 + 1855e9f commit 45cc444
Show file tree
Hide file tree
Showing 19 changed files with 81 additions and 61 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@

- [api] Add validators rewards to block api

## 0.1.6
*Jule 30th, 2018*

BREAKING CHANGES

- [testnet] New testnet id

BUG FIXES

- [core] Fixed critical bug

## 0.1.5
*Jule 28th, 2018*

BUG FIXES

- [tendermint] Update tendermint to 0.22.8
- [core] Temporary critical fix

## 0.1.4
*Jule 25th, 2018*

Expand Down
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

[[constraint]]
name = "github.com/tendermint/tendermint"
version = "=v0.22.6"
version = "=v0.22.8"

[[constraint]]
branch = "v1"
Expand Down
1 change: 1 addition & 0 deletions api/estimate_coin_sell.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func EstimateCoinSell(w http.ResponseWriter, r *http.Request) {
Code: 1,
Log: fmt.Sprintf("Coin reserve balance is not sufficient for transaction. Has: %s, required %s", coin.ReserveBalance().String(), commissionInBaseCoin.String()),
})
return
}

commission = formula.CalculateSaleAmount(coin.Volume(), coin.ReserveBalance(), coin.Data().Crr, commissionInBaseCoin)
Expand Down
19 changes: 9 additions & 10 deletions core/transaction/buy_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (data BuyCoinData) Gas() int64 {
return commissions.ConvertTx
}

func (data BuyCoinData) Run(sender types.Address, tx *Transaction, context *state.StateDB, isCheck bool, rewardPull *big.Int, currentBlock uint64) Response {
func (data BuyCoinData) Run(sender types.Address, tx *Transaction, context *state.StateDB, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response {
if data.CoinToSell == data.CoinToBuy {
return Response{
Code: code.CrossConvert,
Expand Down Expand Up @@ -69,7 +69,7 @@ func (data BuyCoinData) Run(sender types.Address, tx *Transaction, context *stat
commissionInBaseCoin.Mul(commissionInBaseCoin, CommissionMultiplier)
commission := big.NewInt(0).Set(commissionInBaseCoin)

if tx.GasCoin != types.GetBaseCoin() {
if !tx.GasCoin.IsBaseCoin() {
coin := context.GetStateCoin(tx.GasCoin)

if coin.ReserveBalance().Cmp(commissionInBaseCoin) < 0 {
Expand All @@ -89,7 +89,7 @@ func (data BuyCoinData) Run(sender types.Address, tx *Transaction, context *stat

var value *big.Int

if data.CoinToSell == types.GetBaseCoin() {
if data.CoinToSell.IsBaseCoin() {
coin := context.GetStateCoin(data.CoinToBuy).Data()

value = formula.CalculatePurchaseAmount(coin.Volume, coin.ReserveBalance, coin.Crr, data.ValueToBuy)
Expand Down Expand Up @@ -117,16 +117,15 @@ func (data BuyCoinData) Run(sender types.Address, tx *Transaction, context *stat
context.AddCoinVolume(data.CoinToBuy, data.ValueToBuy)
context.AddCoinReserve(data.CoinToBuy, value)
}
} else if data.CoinToBuy == types.GetBaseCoin() {
} else if data.CoinToBuy.IsBaseCoin() {
coin := context.GetStateCoin(data.CoinToSell).Data()

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

totalTxCost := big.NewInt(0).Add(value, commission)
if context.GetBalance(sender, data.CoinToSell).Cmp(totalTxCost) < 0 {
if context.GetBalance(sender, data.CoinToSell).Cmp(value) < 0 {
return Response{
Code: code.InsufficientFunds,
Log: fmt.Sprintf("Insufficient funds for sender account: %s. Wanted %s %s", sender.String(), totalTxCost.String(), data.CoinToSell)}
Log: fmt.Sprintf("Insufficient funds for sender account: %s. Wanted %s %s", sender.String(), value.String(), data.CoinToSell)}
}

if data.CoinToSell == tx.GasCoin {
Expand Down Expand Up @@ -183,16 +182,16 @@ func (data BuyCoinData) Run(sender types.Address, tx *Transaction, context *stat
}

if !isCheck {
rewardPull.Add(rewardPull, commissionInBaseCoin)
rewardPool.Add(rewardPool, commissionInBaseCoin)

context.SubBalance(sender, tx.GasCoin, commission)

if tx.GasCoin != types.GetBaseCoin() {
if !tx.GasCoin.IsBaseCoin() {
context.SubCoinVolume(tx.GasCoin, commission)
context.SubCoinReserve(tx.GasCoin, commissionInBaseCoin)
}

context.AddBalance(sender, data.CoinToBuy, value)
context.AddBalance(sender, data.CoinToBuy, data.ValueToBuy)
context.SetNonce(sender, tx.Nonce)
}

Expand Down
4 changes: 2 additions & 2 deletions core/transaction/create_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (data CreateCoinData) Gas() int64 {
return commissions.CreateTx
}

func (data CreateCoinData) Run(sender types.Address, tx *Transaction, context *state.StateDB, isCheck bool, rewardPull *big.Int, currentBlock uint64) Response {
func (data CreateCoinData) Run(sender types.Address, tx *Transaction, context *state.StateDB, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response {

if !context.CoinExists(tx.GasCoin) {
return Response{
Expand Down Expand Up @@ -145,7 +145,7 @@ func (data CreateCoinData) Run(sender types.Address, tx *Transaction, context *s
}

if !isCheck {
rewardPull.Add(rewardPull, commissionInBaseCoin)
rewardPool.Add(rewardPool, commissionInBaseCoin)

context.SubBalance(sender, types.GetBaseCoin(), data.InitialReserve)
context.SubBalance(sender, tx.GasCoin, commission)
Expand Down
4 changes: 2 additions & 2 deletions core/transaction/declare_candidacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (data DeclareCandidacyData) Gas() int64 {
return commissions.DeclareCandidacyTx
}

func (data DeclareCandidacyData) Run(sender types.Address, tx *Transaction, context *state.StateDB, isCheck bool, rewardPull *big.Int, currentBlock uint64) Response {
func (data DeclareCandidacyData) Run(sender types.Address, tx *Transaction, context *state.StateDB, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response {

if !context.CoinExists(tx.GasCoin) {
return Response{
Expand Down Expand Up @@ -117,7 +117,7 @@ func (data DeclareCandidacyData) Run(sender types.Address, tx *Transaction, cont
// TODO: limit number of candidates to prevent flooding

if !isCheck {
rewardPull.Add(rewardPull, commissionInBaseCoin)
rewardPool.Add(rewardPool, commissionInBaseCoin)

context.SubBalance(sender, data.Coin, data.Stake)
context.SubBalance(sender, tx.GasCoin, commission)
Expand Down
6 changes: 3 additions & 3 deletions core/transaction/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ func (data DelegateData) MarshalJSON() ([]byte, error) {
}

func (data DelegateData) String() string {
return fmt.Sprintf("DELEGATE ubkey:%s ",
return fmt.Sprintf("DELEGATE pubkey:%s ",
hexutil.Encode(data.PubKey[:]))
}

func (data DelegateData) Gas() int64 {
return commissions.DelegateTx
}

func (data DelegateData) Run(sender types.Address, tx *Transaction, context *state.StateDB, isCheck bool, rewardPull *big.Int, currentBlock uint64) Response {
func (data DelegateData) Run(sender types.Address, tx *Transaction, context *state.StateDB, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response {

if !context.CoinExists(tx.GasCoin) {
return Response{
Expand Down Expand Up @@ -94,7 +94,7 @@ func (data DelegateData) Run(sender types.Address, tx *Transaction, context *sta
}

if !isCheck {
rewardPull.Add(rewardPull, commissionInBaseCoin)
rewardPool.Add(rewardPool, commissionInBaseCoin)

context.SubBalance(sender, tx.GasCoin, commission)
context.SubBalance(sender, data.Coin, data.Stake)
Expand Down
4 changes: 2 additions & 2 deletions core/transaction/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Response struct {
Fee common.KI64Pair `protobuf:"bytes,8,opt,name=fee" json:"fee"`
}

func RunTx(context *state.StateDB, isCheck bool, rawTx []byte, rewardPull *big.Int, currentBlock uint64) Response {
func RunTx(context *state.StateDB, isCheck bool, rawTx []byte, rewardPool *big.Int, currentBlock uint64) Response {

if len(rawTx) > maxTxLength {
return Response{
Expand Down Expand Up @@ -77,5 +77,5 @@ func RunTx(context *state.StateDB, isCheck bool, rawTx []byte, rewardPull *big.I
Log: fmt.Sprintf("Unexpected nonce. Expected: %d, got %d.", expectedNonce, tx.Nonce)}
}

return tx.decodedData.Run(sender, tx, context, isCheck, rewardPull, currentBlock)
return tx.decodedData.Run(sender, tx, context, isCheck, rewardPool, currentBlock)
}
8 changes: 4 additions & 4 deletions core/transaction/redeem_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (data RedeemCheckData) Gas() int64 {
return commissions.SendTx
}

func (data RedeemCheckData) Run(sender types.Address, tx *Transaction, context *state.StateDB, isCheck bool, rewardPull *big.Int, currentBlock uint64) Response {
func (data RedeemCheckData) Run(sender types.Address, tx *Transaction, context *state.StateDB, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response {
decodedCheck, err := check.DecodeFromBytes(data.RawCheck)

if err != nil {
Expand Down Expand Up @@ -122,7 +122,7 @@ func (data RedeemCheckData) Run(sender types.Address, tx *Transaction, context *
commissionInBaseCoin.Mul(commissionInBaseCoin, CommissionMultiplier)
commission := big.NewInt(0).Set(commissionInBaseCoin)

if decodedCheck.Coin != types.GetBaseCoin() {
if !decodedCheck.Coin.IsBaseCoin() {
coin := context.GetStateCoin(decodedCheck.Coin)
commission = formula.CalculateSaleAmount(coin.Volume(), coin.ReserveBalance(), coin.Data().Crr, commissionInBaseCoin)
}
Expand All @@ -137,9 +137,9 @@ func (data RedeemCheckData) Run(sender types.Address, tx *Transaction, context *

if !isCheck {
context.UseCheck(decodedCheck)
rewardPull.Add(rewardPull, commissionInBaseCoin)
rewardPool.Add(rewardPool, commissionInBaseCoin)

if decodedCheck.Coin != types.GetBaseCoin() {
if !decodedCheck.Coin.IsBaseCoin() {
context.SubCoinVolume(decodedCheck.Coin, commission)
context.SubCoinReserve(decodedCheck.Coin, commissionInBaseCoin)
}
Expand Down
14 changes: 7 additions & 7 deletions core/transaction/sell_all_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ func (data SellAllCoinData) MarshalJSON() ([]byte, error) {

func (data SellAllCoinData) String() string {
return fmt.Sprintf("SELL ALL COIN sell:%s buy:%s",
data.CoinToBuy.String(), data.CoinToSell.String())
data.CoinToSell.String(), data.CoinToBuy.String())
}

func (data SellAllCoinData) Gas() int64 {
return commissions.ConvertTx
}

func (data SellAllCoinData) Run(sender types.Address, tx *Transaction, context *state.StateDB, isCheck bool, rewardPull *big.Int, currentBlock uint64) Response {
func (data SellAllCoinData) Run(sender types.Address, tx *Transaction, context *state.StateDB, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response {
if data.CoinToSell == data.CoinToBuy {
return Response{
Code: code.CrossConvert,
Expand All @@ -62,7 +62,7 @@ func (data SellAllCoinData) Run(sender types.Address, tx *Transaction, context *
commissionInBaseCoin.Mul(commissionInBaseCoin, CommissionMultiplier)
commission := big.NewInt(0).Set(commissionInBaseCoin)

if data.CoinToSell != types.GetBaseCoin() {
if !data.CoinToSell.IsBaseCoin() {
coin := context.GetStateCoin(data.CoinToSell)

if coin.ReserveBalance().Cmp(commissionInBaseCoin) < 0 {
Expand All @@ -84,19 +84,19 @@ func (data SellAllCoinData) Run(sender types.Address, tx *Transaction, context *
amountToSell.Sub(amountToSell, commission)

if !isCheck {
rewardPull.Add(rewardPull, commissionInBaseCoin)
rewardPool.Add(rewardPool, commissionInBaseCoin)

context.SubBalance(sender, data.CoinToSell, available)

if data.CoinToSell != types.GetBaseCoin() {
if !data.CoinToSell.IsBaseCoin() {
context.SubCoinVolume(data.CoinToSell, commission)
context.SubCoinReserve(data.CoinToSell, commissionInBaseCoin)
}
}

var value *big.Int

if data.CoinToSell == types.GetBaseCoin() {
if data.CoinToSell.IsBaseCoin() {
coin := context.GetStateCoin(data.CoinToBuy).Data()

value = formula.CalculatePurchaseReturn(coin.Volume, coin.ReserveBalance, coin.Crr, amountToSell)
Expand All @@ -105,7 +105,7 @@ func (data SellAllCoinData) Run(sender types.Address, tx *Transaction, context *
context.AddCoinVolume(data.CoinToBuy, value)
context.AddCoinReserve(data.CoinToBuy, amountToSell)
}
} else if data.CoinToBuy == types.GetBaseCoin() {
} else if data.CoinToBuy.IsBaseCoin() {
coin := context.GetStateCoin(data.CoinToSell).Data()

value = formula.CalculateSaleReturn(coin.Volume, coin.ReserveBalance, coin.Crr, amountToSell)
Expand Down
12 changes: 6 additions & 6 deletions core/transaction/sell_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (data SellCoinData) Gas() int64 {
return commissions.ConvertTx
}

func (data SellCoinData) Run(sender types.Address, tx *Transaction, context *state.StateDB, isCheck bool, rewardPull *big.Int, currentBlock uint64) Response {
func (data SellCoinData) Run(sender types.Address, tx *Transaction, context *state.StateDB, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response {
if data.CoinToSell == data.CoinToBuy {
return Response{
Code: code.CrossConvert,
Expand Down Expand Up @@ -69,7 +69,7 @@ func (data SellCoinData) Run(sender types.Address, tx *Transaction, context *sta
commissionInBaseCoin.Mul(commissionInBaseCoin, CommissionMultiplier)
commission := big.NewInt(0).Set(commissionInBaseCoin)

if tx.GasCoin != types.GetBaseCoin() {
if !tx.GasCoin.IsBaseCoin() {
coin := context.GetStateCoin(tx.GasCoin)

if coin.ReserveBalance().Cmp(commissionInBaseCoin) < 0 {
Expand Down Expand Up @@ -100,20 +100,20 @@ func (data SellCoinData) Run(sender types.Address, tx *Transaction, context *sta
}

if !isCheck {
rewardPull.Add(rewardPull, commissionInBaseCoin)
rewardPool.Add(rewardPool, commissionInBaseCoin)

context.SubBalance(sender, data.CoinToSell, data.ValueToSell)
context.SubBalance(sender, tx.GasCoin, commission)

if tx.GasCoin != types.GetBaseCoin() {
if !tx.GasCoin.IsBaseCoin() {
context.SubCoinVolume(tx.GasCoin, commission)
context.SubCoinReserve(tx.GasCoin, commissionInBaseCoin)
}
}

var value *big.Int

if data.CoinToSell == types.GetBaseCoin() {
if data.CoinToSell.IsBaseCoin() {
coin := context.GetStateCoin(data.CoinToBuy).Data()

value = formula.CalculatePurchaseReturn(coin.Volume, coin.ReserveBalance, coin.Crr, data.ValueToSell)
Expand All @@ -122,7 +122,7 @@ func (data SellCoinData) Run(sender types.Address, tx *Transaction, context *sta
context.AddCoinVolume(data.CoinToBuy, value)
context.AddCoinReserve(data.CoinToBuy, data.ValueToSell)
}
} else if data.CoinToBuy == types.GetBaseCoin() {
} else if data.CoinToBuy.IsBaseCoin() {
coin := context.GetStateCoin(data.CoinToSell).Data()

value = formula.CalculateSaleReturn(coin.Volume, coin.ReserveBalance, coin.Crr, data.ValueToSell)
Expand Down
8 changes: 4 additions & 4 deletions core/transaction/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (data SendData) Gas() int64 {
return commissions.SendTx
}

func (data SendData) Run(sender types.Address, tx *Transaction, context *state.StateDB, isCheck bool, rewardPull *big.Int, currentBlock uint64) Response {
func (data SendData) Run(sender types.Address, tx *Transaction, context *state.StateDB, isCheck bool, rewardPool *big.Int, currentBlock uint64) Response {
if !context.CoinExists(data.Coin) {
return Response{
Code: code.CoinNotExists,
Expand All @@ -57,7 +57,7 @@ func (data SendData) Run(sender types.Address, tx *Transaction, context *state.S
commissionInBaseCoin.Mul(commissionInBaseCoin, CommissionMultiplier)
commission := big.NewInt(0).Set(commissionInBaseCoin)

if tx.GasCoin != types.GetBaseCoin() {
if !tx.GasCoin.IsBaseCoin() {
coin := context.GetStateCoin(tx.GasCoin)

if coin.ReserveBalance().Cmp(commissionInBaseCoin) < 0 {
Expand Down Expand Up @@ -94,9 +94,9 @@ func (data SendData) Run(sender types.Address, tx *Transaction, context *state.S
}

if !isCheck {
rewardPull.Add(rewardPull, commissionInBaseCoin)
rewardPool.Add(rewardPool, commissionInBaseCoin)

if tx.GasCoin != types.GetBaseCoin() {
if !tx.GasCoin.IsBaseCoin() {
context.SubCoinVolume(tx.GasCoin, commission)
context.SubCoinReserve(tx.GasCoin, commissionInBaseCoin)
}
Expand Down
Loading

0 comments on commit 45cc444

Please sign in to comment.