Skip to content

Commit

Permalink
Merge pull request #51 from MinterTeam/dev
Browse files Browse the repository at this point in the history
v0.0.5
  • Loading branch information
danil-lashin authored Jul 4, 2018
2 parents c2296bb + bcf9bb7 commit 01f1482
Show file tree
Hide file tree
Showing 29 changed files with 517 additions and 125 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## 0.0.5
*Jule 4rd, 2018*

BREAKING CHANGES

- [core] Remove Reserve Coin from coin object. All coins should be reserved with base coin
- [core] Limit tx payload and service data to 128 bytes
- [core] Fix critical issue with instant convert of 2 custom coins
- [testnet] New testnet chain id (minter-test-network-8)
- [tendermint] Switched to v0.22.0

IMPROVEMENT

- [api] Fix issue with not found coins

BUG FIXES

- [api] Fix transaction endpoint

## 0.0.4

*June 24th, 2018*
Expand Down
106 changes: 76 additions & 30 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 @@ -59,7 +59,7 @@

[[constraint]]
name = "github.com/tendermint/tendermint"
version = "0.21.0"
version = "0.22.0"

[[constraint]]
branch = "v2"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $ docker-compose up
You'll need **go** [installed](https://golang.org/doc/install) and the required
[environment variables set](https://github.com/tendermint/tendermint/wiki/Setting-GOPATH)

1. Install [Tendermint 0.21.0](https://github.com/tendermint/tendermint/blob/master/docs/install.rst)
1. Install [Tendermint 0.22.0](https://github.com/tendermint/tendermint/blob/master/docs/install.rst)

2. Clone Minter to your machine
```bash
Expand Down
2 changes: 1 addition & 1 deletion api/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"github.com/MinterTeam/minter-go-node/core/transaction"
"github.com/gorilla/mux"
"github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
"github.com/tendermint/tmlibs/common"
"math/big"
"net/http"
"strconv"
Expand Down
27 changes: 18 additions & 9 deletions api/coin_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type CoinInfoResponse struct {
Symbol types.CoinSymbol `json:"symbol"`
Volume string `json:"volume"`
Crr uint `json:"crr"`
ReserveCoin types.CoinSymbol `json:"reserve_coin"`
ReserveBalance string `json:"reserve_balance"`
Creator types.Address `json:"creator"`
}
Expand All @@ -28,21 +27,31 @@ func GetCoinInfo(w http.ResponseWriter, r *http.Request) {

copy(coinSymbol[:], []byte(symbol))

coin := cState.GetStateCoin(coinSymbol).Data()
coin := cState.GetStateCoin(coinSymbol)

w.Header().Set("Content-Type", "application/json; charset=UTF-8")

if coin == nil {
w.WriteHeader(http.StatusNotFound)
json.NewEncoder(w).Encode(Response{
Code: 404,
Result: nil,
Log: "Coin not found",
})
return
}

w.WriteHeader(http.StatusOK)

json.NewEncoder(w).Encode(Response{
Code: 0,
Result: CoinInfoResponse{
Name: coin.Name,
Symbol: coin.Symbol,
Volume: coin.Volume.String(),
Crr: coin.Crr,
ReserveCoin: coin.ReserveCoin,
ReserveBalance: coin.ReserveBalance.String(),
Creator: coin.Creator,
Name: coin.Data().Name,
Symbol: coin.Data().Symbol,
Volume: coin.Data().Volume.String(),
Crr: coin.Data().Crr,
ReserveBalance: coin.Data().ReserveBalance.String(),
Creator: coin.Data().Creator,
},
})
}
54 changes: 46 additions & 8 deletions api/estimate_coin_exchange_return.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,55 @@ func EstimateCoinExchangeReturn(w http.ResponseWriter, r *http.Request) {
var result *big.Int

if fromCoinSymbol == blockchain.BaseCoin {
coin := cState.GetStateCoin(toCoinSymbol).Data()
result = formula.CalculatePurchaseReturn(coin.Volume, coin.ReserveBalance, coin.Crr, value)
coin := cState.GetStateCoin(toCoinSymbol)
if coin == nil {
w.WriteHeader(http.StatusNotFound)
json.NewEncoder(w).Encode(Response{
Code: 404,
Result: nil,
Log: "Coin not found",
})
return
}
result = formula.CalculatePurchaseReturn(coin.Data().Volume, coin.Data().ReserveBalance, coin.Data().Crr, value)
} else if toCoinSymbol == blockchain.BaseCoin {
coin := cState.GetStateCoin(fromCoinSymbol).Data()
result = formula.CalculateSaleReturn(coin.Volume, coin.ReserveBalance, coin.Crr, value)
coin := cState.GetStateCoin(fromCoinSymbol)
if coin == nil {
w.WriteHeader(http.StatusNotFound)
json.NewEncoder(w).Encode(Response{
Code: 404,
Result: nil,
Log: "Coin not found",
})
return
}
result = formula.CalculateSaleReturn(coin.Data().Volume, coin.Data().ReserveBalance, coin.Data().Crr, value)
} else {
coinFrom := cState.GetStateCoin(fromCoinSymbol).Data()
coinTo := cState.GetStateCoin(toCoinSymbol).Data()
coinFrom := cState.GetStateCoin(fromCoinSymbol)
coinTo := cState.GetStateCoin(toCoinSymbol)

val := formula.CalculateSaleReturn(coinFrom.Volume, coinFrom.ReserveBalance, coinFrom.Crr, value)
result = formula.CalculatePurchaseReturn(coinTo.Volume, coinTo.ReserveBalance, coinTo.Crr, val)
if coinFrom == nil {
w.WriteHeader(http.StatusNotFound)
json.NewEncoder(w).Encode(Response{
Code: 404,
Result: nil,
Log: "Coin not found",
})
return
}

if coinTo == nil {
w.WriteHeader(http.StatusNotFound)
json.NewEncoder(w).Encode(Response{
Code: 404,
Result: nil,
Log: "Coin not found",
})
return
}

val := formula.CalculateSaleReturn(coinFrom.Data().Volume, coinFrom.Data().ReserveBalance, coinFrom.Data().Crr, value)
result = formula.CalculatePurchaseReturn(coinTo.Data().Volume, coinTo.Data().ReserveBalance, coinTo.Data().Crr, val)
}

w.Header().Set("Content-Type", "application/json; charset=UTF-8")
Expand Down
2 changes: 1 addition & 1 deletion api/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package api

import (
"encoding/json"
"github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tmlibs/common"
"net/http"
"time"
)
Expand Down
2 changes: 1 addition & 1 deletion api/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func Transaction(w http.ResponseWriter, r *http.Request) {

vars := mux.Vars(r)
hash := strings.TrimRight(vars["hash"], "Mt")
hash := strings.TrimLeft(vars["hash"], "Mt")
decoded, err := hex.DecodeString(hash)

result := new(types.TxResult)
Expand Down
2 changes: 1 addition & 1 deletion api/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package api
import (
"encoding/json"
"github.com/MinterTeam/minter-go-node/core/transaction"
"github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tmlibs/common"
"math/big"
"net/http"
)
Expand Down
Loading

0 comments on commit 01f1482

Please sign in to comment.