Skip to content

Commit

Permalink
Merge pull request #189 from MinterTeam/dev
Browse files Browse the repository at this point in the history
v0.9.0
  • Loading branch information
danil-lashin authored Dec 24, 2018
2 parents 2cccfc3 + 827fc77 commit 6fd49c9
Show file tree
Hide file tree
Showing 62 changed files with 1,052 additions and 572 deletions.
24 changes: 23 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
# Changelog

## 0.8.5
## 0.9.0
*Dec 10th, 2018*

IMPROVEMENT

- [events] Refactor events
- [api] #183 Report if node has full state history in /status
- [api] #164 Add /unconfirmed_txs endpoint
- [api] Add /max_gas endpoint
- [core] Do not accept 2 transactions from same address in mempool at once
- [core] Add missing tags to transactions
- [core] Dynamically adjust max gas in blocks
- [core] Update commissions
- [tendermint] Update to v0.27.4

BUG FIXES

- [core] Fix issue with `SellAll` tx
- [core] Fix issue #182 with candidate owner's address
- [core] Fix max coin supply
- [api] Fix tx tags

## 0.8.5
*Dec 11th, 2018*

BUG FIXES

- [api] Fix estimate coin buy empty response
Expand Down
11 changes: 5 additions & 6 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 @@ -43,7 +43,7 @@

[[constraint]]
name = "github.com/tendermint/tendermint"
version = "0.27.0"
version = "0.27.4"

[[constraint]]
name = "github.com/MinterTeam/go-amino"
Expand Down
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var Routes = map[string]*rpcserver.RPCFunc{
"estimate_coin_buy": rpcserver.NewRPCFunc(EstimateCoinBuy, "coin_to_sell,coin_to_buy,value_to_buy,height"),
"estimate_tx_commission": rpcserver.NewRPCFunc(EstimateTxCommission, "tx,height"),
"unconfirmed_txs": rpcserver.NewRPCFunc(UnconfirmedTxs, "limit"),
"max_gas": rpcserver.NewRPCFunc(MaxGas, "height"),
}

func RunApi(b *minter.Blockchain, tmRPC *rpc.Local) {
Expand Down
46 changes: 22 additions & 24 deletions api/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,20 @@ type BlockResponse struct {
}

type BlockTransactionResponse struct {
Hash string `json:"hash"`
RawTx string `json:"raw_tx"`
From string `json:"from"`
Nonce uint64 `json:"nonce"`
GasPrice *big.Int `json:"gas_price"`
Type byte `json:"type"`
Data json.RawMessage `json:"data"`
Payload []byte `json:"payload"`
ServiceData []byte `json:"service_data"`
Gas int64 `json:"gas"`
GasCoin types.CoinSymbol `json:"gas_coin"`
GasUsed int64 `json:"gas_used"`
Tags map[string]string `json:"tags"`
Code uint32 `json:"code,omitempty"`
Log string `json:"log,omitempty"`
Hash string `json:"hash"`
RawTx string `json:"raw_tx"`
From string `json:"from"`
Nonce uint64 `json:"nonce"`
GasPrice *big.Int `json:"gas_price"`
Type transaction.TxType `json:"type"`
Data json.RawMessage `json:"data"`
Payload []byte `json:"payload"`
ServiceData []byte `json:"service_data"`
Gas int64 `json:"gas"`
GasCoin types.CoinSymbol `json:"gas_coin"`
Tags map[string]string `json:"tags"`
Code uint32 `json:"code,omitempty"`
Log string `json:"log,omitempty"`
}

type BlockValidatorResponse struct {
Expand All @@ -58,25 +57,25 @@ func Block(height int64) (*BlockResponse, error) {

txs := make([]BlockTransactionResponse, len(block.Block.Data.Txs))
for i, rawTx := range block.Block.Data.Txs {
tx, _ := transaction.DecodeFromBytes(rawTx)
tx, _ := transaction.TxDecoder.DecodeFromBytes(rawTx)
sender, _ := tx.Sender()

tags := make(map[string]string)

for _, tag := range blockResults.Results.DeliverTx[i].Tags {
switch string(tag.Key) {
case "tx.type":
tags[string(tag.Key)] = fmt.Sprintf("%X", tag.Value)
default:
tags[string(tag.Key)] = string(tag.Value)
}
tags[string(tag.Key)] = string(tag.Value)
}

data, err := encodeTxData(tx)
if err != nil {
return nil, err
}

gas := tx.Gas()
if tx.Type == transaction.TypeCreateCoin {
gas += tx.GetDecodedData().(transaction.CreateCoinData).Commission()
}

txs[i] = BlockTransactionResponse{
Hash: fmt.Sprintf("Mt%x", rawTx.Hash()),
RawTx: fmt.Sprintf("%x", []byte(rawTx)),
Expand All @@ -87,9 +86,8 @@ func Block(height int64) (*BlockResponse, error) {
Data: data,
Payload: tx.Payload,
ServiceData: tx.ServiceData,
Gas: tx.Gas(),
Gas: gas,
GasCoin: tx.GasCoin,
GasUsed: blockResults.Results.DeliverTx[i].GasUsed,
Tags: tags,
Code: blockResults.Results.DeliverTx[i].Code,
Log: blockResults.Results.DeliverTx[i].Log,
Expand Down
28 changes: 15 additions & 13 deletions api/candidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,25 @@ type Stake struct {
}

type CandidateResponse struct {
CandidateAddress types.Address `json:"candidate_address"`
TotalStake *big.Int `json:"total_stake"`
PubKey types.Pubkey `json:"pubkey"`
Commission uint `json:"commission"`
Stakes []Stake `json:"stakes,omitempty"`
CreatedAtBlock uint `json:"created_at_block"`
Status byte `json:"status"`
RewardAddress types.Address `json:"reward_address"`
OwnerAddress types.Address `json:"owner_address"`
TotalStake *big.Int `json:"total_stake"`
PubKey types.Pubkey `json:"pubkey"`
Commission uint `json:"commission"`
Stakes []Stake `json:"stakes,omitempty"`
CreatedAtBlock uint `json:"created_at_block"`
Status byte `json:"status"`
}

func makeResponseCandidate(c state.Candidate, includeStakes bool) CandidateResponse {
candidate := CandidateResponse{
CandidateAddress: c.CandidateAddress,
TotalStake: c.TotalBipStake,
PubKey: c.PubKey,
Commission: c.Commission,
CreatedAtBlock: c.CreatedAtBlock,
Status: c.Status,
RewardAddress: c.RewardAddress,
OwnerAddress: c.OwnerAddress,
TotalStake: c.TotalBipStake,
PubKey: c.PubKey,
Commission: c.Commission,
CreatedAtBlock: c.CreatedAtBlock,
Status: c.Status,
}

if includeStakes {
Expand Down
2 changes: 1 addition & 1 deletion api/estimate_tx_commission.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func EstimateTxCommission(tx []byte, height int) (*TxCommissionResponse, error)
return nil, err
}

decodedTx, err := transaction.DecodeFromBytes(tx)
decodedTx, err := transaction.TxDecoder.DecodeFromBytes(tx)
if err != nil {
return nil, err
}
Expand Down
15 changes: 15 additions & 0 deletions api/maxgas.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package api

import (
"github.com/MinterTeam/minter-go-node/rpc/lib/types"
)

func MaxGas(height int) (*uint64, error) {
cState, err := GetStateForHeight(height)
if err != nil {
return nil, &rpctypes.RPCError{Code: 404, Message: "State at given height not found", Data: err.Error()}
}

maxGas := cState.GetCurrentMaxGas()
return &maxGas, nil
}
7 changes: 7 additions & 0 deletions api/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type StatusResponse struct {
LatestAppHash string `json:"latest_app_hash"`
LatestBlockHeight int64 `json:"latest_block_height"`
LatestBlockTime time.Time `json:"latest_block_time"`
StateHistory string `json:"state_history"`
TmStatus *core_types.ResultStatus `json:"tm_status"`
}

Expand All @@ -23,12 +24,18 @@ func Status() (*StatusResponse, error) {
return nil, err
}

stateHistory := "off"
if cfg.BaseConfig.KeepStateHistory {
stateHistory = "on"
}

return &StatusResponse{
MinterVersion: version.Version,
LatestBlockHash: fmt.Sprintf("%X", result.SyncInfo.LatestBlockHash),
LatestAppHash: fmt.Sprintf("%X", result.SyncInfo.LatestAppHash),
LatestBlockHeight: result.SyncInfo.LatestBlockHeight,
LatestBlockTime: result.SyncInfo.LatestBlockTime,
StateHistory: stateHistory,
TmStatus: result,
}, nil
}
42 changes: 21 additions & 21 deletions api/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ func Transaction(hash []byte) (*TransactionResponse, error) {
return nil, errors.New("Tx not found")
}

decodedTx, _ := transaction.DecodeFromBytes(tx.Tx)
decodedTx, _ := transaction.TxDecoder.DecodeFromBytes(tx.Tx)
sender, _ := decodedTx.Sender()

tags := make(map[string]string)

for _, tag := range tx.TxResult.Tags {
switch string(tag.Key) {
case "tx.type":
tags[string(tag.Key)] = fmt.Sprintf("%X", tag.Value)
default:
tags[string(tag.Key)] = string(tag.Value)
}
tags[string(tag.Key)] = string(tag.Value)
}

data, err := encodeTxData(decodedTx)
if err != nil {
return nil, err
}

gas := decodedTx.Gas()
if decodedTx.Type == transaction.TypeCreateCoin {
gas += decodedTx.GetDecodedData().(transaction.CreateCoinData).Commission()
}

return &TransactionResponse{
Hash: common.HexBytes(tx.Tx.Hash()),
RawTx: fmt.Sprintf("%x", []byte(tx.Tx)),
Expand All @@ -45,7 +45,7 @@ func Transaction(hash []byte) (*TransactionResponse, error) {
Nonce: decodedTx.Nonce,
GasPrice: decodedTx.GasPrice,
GasCoin: decodedTx.GasCoin,
GasUsed: tx.TxResult.GasUsed,
Gas: gas,
Type: decodedTx.Type,
Data: data,
Payload: decodedTx.Payload,
Expand All @@ -58,31 +58,31 @@ func Transaction(hash []byte) (*TransactionResponse, error) {
func encodeTxData(decodedTx *transaction.Transaction) ([]byte, error) {
switch decodedTx.Type {
case transaction.TypeSend:
return cdc.MarshalJSON(decodedTx.GetDecodedData().(transaction.SendData))
return cdc.MarshalJSON(decodedTx.GetDecodedData().(*transaction.SendData))
case transaction.TypeRedeemCheck:
return cdc.MarshalJSON(decodedTx.GetDecodedData().(transaction.RedeemCheckData))
return cdc.MarshalJSON(decodedTx.GetDecodedData().(*transaction.RedeemCheckData))
case transaction.TypeSellCoin:
return cdc.MarshalJSON(decodedTx.GetDecodedData().(transaction.SellCoinData))
return cdc.MarshalJSON(decodedTx.GetDecodedData().(*transaction.SellCoinData))
case transaction.TypeSellAllCoin:
return cdc.MarshalJSON(decodedTx.GetDecodedData().(transaction.SellAllCoinData))
return cdc.MarshalJSON(decodedTx.GetDecodedData().(*transaction.SellAllCoinData))
case transaction.TypeBuyCoin:
return cdc.MarshalJSON(decodedTx.GetDecodedData().(transaction.BuyCoinData))
return cdc.MarshalJSON(decodedTx.GetDecodedData().(*transaction.BuyCoinData))
case transaction.TypeCreateCoin:
return cdc.MarshalJSON(decodedTx.GetDecodedData().(transaction.CreateCoinData))
return cdc.MarshalJSON(decodedTx.GetDecodedData().(*transaction.CreateCoinData))
case transaction.TypeDeclareCandidacy:
return cdc.MarshalJSON(decodedTx.GetDecodedData().(transaction.DeclareCandidacyData))
return cdc.MarshalJSON(decodedTx.GetDecodedData().(*transaction.DeclareCandidacyData))
case transaction.TypeDelegate:
return cdc.MarshalJSON(decodedTx.GetDecodedData().(transaction.DelegateData))
return cdc.MarshalJSON(decodedTx.GetDecodedData().(*transaction.DelegateData))
case transaction.TypeSetCandidateOnline:
return cdc.MarshalJSON(decodedTx.GetDecodedData().(transaction.SetCandidateOnData))
return cdc.MarshalJSON(decodedTx.GetDecodedData().(*transaction.SetCandidateOnData))
case transaction.TypeSetCandidateOffline:
return cdc.MarshalJSON(decodedTx.GetDecodedData().(transaction.SetCandidateOffData))
return cdc.MarshalJSON(decodedTx.GetDecodedData().(*transaction.SetCandidateOffData))
case transaction.TypeUnbond:
return cdc.MarshalJSON(decodedTx.GetDecodedData().(transaction.UnbondData))
return cdc.MarshalJSON(decodedTx.GetDecodedData().(*transaction.UnbondData))
case transaction.TypeCreateMultisig:
return cdc.MarshalJSON(decodedTx.GetDecodedData().(transaction.CreateMultisigData))
return cdc.MarshalJSON(decodedTx.GetDecodedData().(*transaction.CreateMultisigData))
case transaction.TypeMultisend:
return cdc.MarshalJSON(decodedTx.GetDecodedData().(transaction.MultisendData))
return cdc.MarshalJSON(decodedTx.GetDecodedData().(*transaction.MultisendData))
}

return nil, errors.New("unknown tx type")
Expand Down
Loading

0 comments on commit 6fd49c9

Please sign in to comment.