Skip to content

Commit

Permalink
Merge pull request #407 from klim0v/v1.2
Browse files Browse the repository at this point in the history
V1.2
  • Loading branch information
danil-lashin authored Sep 25, 2020
2 parents a6b5a94 + 81d8f5a commit d76332e
Show file tree
Hide file tree
Showing 67 changed files with 519 additions and 425 deletions.
2 changes: 1 addition & 1 deletion api/candidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type CandidateResponse struct {
OwnerAddress string `json:"owner_address"`
TotalStake string `json:"total_stake"`
PubKey string `json:"pub_key"`
Commission uint `json:"commission"`
Commission uint32 `json:"commission"`
Stakes []Stake `json:"stakes,omitempty"`
Status byte `json:"status"`
}
Expand Down
2 changes: 1 addition & 1 deletion api/coin_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type CoinInfoResponse struct {
Name string `json:"name"`
Symbol string `json:"symbol"`
Volume string `json:"volume"`
Crr uint `json:"crr"`
Crr uint32 `json:"crr"`
ReserveBalance string `json:"reserve_balance"`
MaxSupply string `json:"max_supply"`
OwnerAddress *string `json:"owner_address"`
Expand Down
9 changes: 4 additions & 5 deletions api/v2/service/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package service
import (
"context"
"encoding/hex"
"fmt"
"github.com/MinterTeam/minter-go-node/core/state"
"github.com/MinterTeam/minter-go-node/core/types"
"github.com/MinterTeam/minter-go-node/formula"
Expand Down Expand Up @@ -57,7 +56,7 @@ func (s *Service) Address(ctx context.Context, req *pb.AddressRequest) (*pb.Addr
totalStakesGroupByCoin[coin.Coin.ID] = coin.Value
res.Balance = append(res.Balance, &pb.AddressBalance{
Coin: &pb.Coin{
Id: coin.Coin.ID.String(),
Id: uint64(coin.Coin.ID),
Symbol: cState.Coins().GetCoin(coin.Coin.ID).Symbol().String(),
},
Value: coin.Value.String(),
Expand Down Expand Up @@ -96,7 +95,7 @@ func (s *Service) Address(ctx context.Context, req *pb.AddressRequest) (*pb.Addr
for coinID, delegatedStake := range userDelegatedStakesGroupByCoin {
res.Delegated = append(res.Delegated, &pb.AddressDelegatedBalance{
Coin: &pb.Coin{
Id: coinID.String(),
Id: uint64(coinID),
Symbol: cState.Coins().GetCoin(coinID).Symbol().String(),
},
Value: delegatedStake.Value.String(),
Expand Down Expand Up @@ -124,7 +123,7 @@ func (s *Service) Address(ctx context.Context, req *pb.AddressRequest) (*pb.Addr
if req.Delegated {
res.Total = append(res.Total, &pb.AddressBalance{
Coin: &pb.Coin{
Id: coinID.String(),
Id: uint64(coinID),
Symbol: cState.Coins().GetCoin(coinID).Symbol().String(),
},
Value: stake.String(),
Expand All @@ -134,7 +133,7 @@ func (s *Service) Address(ctx context.Context, req *pb.AddressRequest) (*pb.Addr
coinsBipValue.Add(coinsBipValue, balance)
}
res.BipValue = coinsBipValue.String()
res.TransactionCount = fmt.Sprintf("%d", cState.Accounts().GetNonce(address))
res.TransactionCount = cState.Accounts().GetNonce(address)
return &res, nil
}

Expand Down
8 changes: 4 additions & 4 deletions api/v2/service/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *Service) Addresses(ctx context.Context, req *pb.AddressesRequest) (*pb.
totalStakesGroupByCoin[coin.Coin.ID] = coin.Value
res.Balance = append(res.Balance, &pb.AddressBalance{
Coin: &pb.Coin{
Id: coin.Coin.ID.String(),
Id: uint64(coin.Coin.ID),
Symbol: cState.Coins().GetCoin(coin.Coin.ID).Symbol().String(),
},
Value: coin.Value.String(),
Expand Down Expand Up @@ -97,7 +97,7 @@ func (s *Service) Addresses(ctx context.Context, req *pb.AddressesRequest) (*pb.
for coinID, delegatedStake := range userDelegatedStakesGroupByCoin {
res.Delegated = append(res.Delegated, &pb.AddressDelegatedBalance{
Coin: &pb.Coin{
Id: coinID.String(),
Id: uint64(coinID),
Symbol: cState.Coins().GetCoin(coinID).Symbol().String(),
},
Value: delegatedStake.Value.String(),
Expand Down Expand Up @@ -125,7 +125,7 @@ func (s *Service) Addresses(ctx context.Context, req *pb.AddressesRequest) (*pb.
if req.Delegated {
res.Total = append(res.Total, &pb.AddressBalance{
Coin: &pb.Coin{
Id: coinID.String(),
Id: uint64(coinID),
Symbol: cState.Coins().GetCoin(coinID).Symbol().String(),
},
Value: stake.String(),
Expand All @@ -135,7 +135,7 @@ func (s *Service) Addresses(ctx context.Context, req *pb.AddressesRequest) (*pb.
coinsBipValue.Add(coinsBipValue, balance)
}
res.BipValue = coinsBipValue.String()
res.TransactionCount = fmt.Sprintf("%d", cState.Accounts().GetNonce(address))
res.TransactionCount = uint64(cState.Accounts().GetNonce(address))

response.Addresses[addr] = &res
}
Expand Down
29 changes: 16 additions & 13 deletions api/v2/service/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ func (s *Service) Block(ctx context.Context, req *pb.BlockRequest) (*pb.BlockRes

response := &pb.BlockResponse{
Hash: hex.EncodeToString(block.Block.Hash()),
Height: fmt.Sprintf("%d", block.Block.Height),
Height: uint64(block.Block.Height),
Time: block.Block.Time.Format(time.RFC3339Nano),
TransactionCount: fmt.Sprintf("%d", len(block.Block.Txs)),
TransactionCount: uint64(len(block.Block.Txs)),
}

var totalValidators []*tmTypes.Validator
var cState *state.CheckState

if len(req.Fields) == 0 {
response.Size = fmt.Sprintf("%d", len(s.cdc.MustMarshalBinaryLengthPrefixed(block)))
response.Size = uint64(len(s.cdc.MustMarshalBinaryLengthPrefixed(block)))
response.BlockReward = rewards.GetRewardForBlock(uint64(height)).String()

if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil {
Expand Down Expand Up @@ -111,7 +111,7 @@ func (s *Service) Block(ctx context.Context, req *pb.BlockRequest) (*pb.BlockRes
}
switch field {
case pb.BlockRequest_size:
response.Size = fmt.Sprintf("%d", len(s.cdc.MustMarshalBinaryLengthPrefixed(block)))
response.Size = uint64(len(s.cdc.MustMarshalBinaryLengthPrefixed(block)))
case pb.BlockRequest_block_reward:
response.BlockReward = rewards.GetRewardForBlock(uint64(height)).String()
case pb.BlockRequest_transactions, pb.BlockRequest_missed:
Expand Down Expand Up @@ -163,7 +163,7 @@ func blockEvidence(block *core_types.ResultBlock) *pb.BlockResponse_Evidence {
evidences := make([]*pb.BlockResponse_Evidence_Evidence, 0, len(block.Block.Evidence.Evidence))
for _, evidence := range block.Block.Evidence.Evidence {
evidences = append(evidences, &pb.BlockResponse_Evidence_Evidence{
Height: fmt.Sprintf("%d", evidence.Height()),
Height: uint64(evidence.Height()),
Time: evidence.Time().Format(time.RFC3339Nano),
Address: fmt.Sprintf("%s", evidence.Address()),
Hash: fmt.Sprintf("%s", evidence.Hash()),
Expand Down Expand Up @@ -233,17 +233,20 @@ func (s *Service) blockTransaction(block *core_types.ResultBlock, blockResults *
Hash: strings.Title(fmt.Sprintf("Mt%x", rawTx.Hash())),
RawTx: fmt.Sprintf("%x", []byte(rawTx)),
From: sender.String(),
Nonce: fmt.Sprintf("%d", tx.Nonce),
GasPrice: fmt.Sprintf("%d", tx.GasPrice),
Type: fmt.Sprintf("%d", tx.Type),
Nonce: uint64(tx.Nonce),
GasPrice: uint64(tx.GasPrice),
Type: uint64(tx.Type),
Data: data,
Payload: tx.Payload,
ServiceData: tx.ServiceData,
Gas: fmt.Sprintf("%d", tx.Gas()),
GasCoin: tx.GasCoin.String(),
Tags: tags,
Code: fmt.Sprintf("%d", blockResults.TxsResults[i].Code),
Log: blockResults.TxsResults[i].Log,
Gas: uint64(tx.Gas()),
GasCoin: &pb.Coin{
Id: uint64(tx.GasCoin),
Symbol: coins.GetCoin(tx.GasCoin).GetFullSymbol(),
},
Tags: tags,
Code: uint64(blockResults.TxsResults[i].Code),
Log: blockResults.TxsResults[i].Log,
})
}
return txs, nil
Expand Down
11 changes: 5 additions & 6 deletions api/v2/service/candidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package service
import (
"context"
"encoding/hex"
"fmt"
"github.com/MinterTeam/minter-go-node/core/state"
"github.com/MinterTeam/minter-go-node/core/state/candidates"
"github.com/MinterTeam/minter-go-node/core/types"
Expand Down Expand Up @@ -56,22 +55,22 @@ func makeResponseCandidate(state *state.CheckState, c *candidates.Candidate, inc
ControlAddress: c.ControlAddress.String(),
TotalStake: state.Candidates().GetTotalStake(c.PubKey).String(),
PublicKey: c.PubKey.String(),
Commission: fmt.Sprintf("%d", c.Commission),
Status: fmt.Sprintf("%d", c.Status),
Commission: uint64(c.Commission),
Status: uint64(c.Status),
}

if includeStakes {
addresses := map[types.Address]struct{}{}
minStake := big.NewInt(0)
stakes := state.Candidates().GetStakes(c.PubKey)
usedSlots := len(stakes)
candidate.UsedSlots = fmt.Sprintf("%d", usedSlots)
candidate.UsedSlots = uint64(usedSlots)
candidate.Stakes = make([]*pb.CandidateResponse_Stake, 0, usedSlots)
for i, stake := range stakes {
candidate.Stakes = append(candidate.Stakes, &pb.CandidateResponse_Stake{
Owner: stake.Owner.String(),
Coin: &pb.Coin{
Id: stake.Coin.String(),
Id: uint64(stake.Coin),
Symbol: state.Coins().GetCoin(stake.Coin).Symbol().String(),
},
Value: stake.Value.String(),
Expand All @@ -85,7 +84,7 @@ func makeResponseCandidate(state *state.CheckState, c *candidates.Candidate, inc
minStake = stake.BipValue
}
}
candidate.UniqUsers = fmt.Sprintf("%d", len(addresses))
candidate.UniqUsers = uint64(len(addresses))
candidate.MinStake = minStake.String()
}

Expand Down
9 changes: 4 additions & 5 deletions api/v2/service/coin_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package service

import (
"context"
"fmt"
"strconv"

"github.com/MinterTeam/minter-go-node/core/code"
Expand Down Expand Up @@ -42,11 +41,11 @@ func (s *Service) CoinInfo(ctx context.Context, req *pb.CoinInfoRequest) (*pb.Co
}

return &pb.CoinInfoResponse{
Id: coin.ID().String(),
Id: uint64(coin.ID()),
Name: coin.Name(),
Symbol: coin.GetFullSymbol(),
Volume: coin.Volume().String(),
Crr: fmt.Sprintf("%d", coin.Crr()),
Crr: uint64(coin.Crr()),
ReserveBalance: coin.Reserve().String(),
MaxSupply: coin.MaxSupply().String(),
OwnerAddress: ownerAddress,
Expand Down Expand Up @@ -81,11 +80,11 @@ func (s *Service) CoinInfoById(ctx context.Context, req *pb.CoinIdRequest) (*pb.
}

return &pb.CoinInfoResponse{
Id: coin.ID().String(),
Id: uint64(coin.ID()),
Name: coin.Name(),
Symbol: coin.GetFullSymbol(),
Volume: coin.Volume().String(),
Crr: fmt.Sprintf("%d", coin.Crr()),
Crr: uint64(coin.Crr()),
ReserveBalance: coin.Reserve().String(),
MaxSupply: coin.MaxSupply().String(),
OwnerAddress: ownerAddress,
Expand Down
42 changes: 21 additions & 21 deletions api/v2/service/data_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ func encode(data transaction.Data, coins coins.RCoins) (*any.Any, error) {
case *transaction.BuyCoinData:
m = &pb.BuyCoinData{
CoinToBuy: &pb.Coin{
Id: d.CoinToBuy.String(),
Id: uint64(d.CoinToBuy),
Symbol: coins.GetCoin(d.CoinToBuy).Symbol().String(),
},
ValueToBuy: d.ValueToBuy.String(),
CoinToSell: &pb.Coin{
Id: d.CoinToSell.String(),
Id: uint64(d.CoinToSell),
Symbol: coins.GetCoin(d.CoinToSell).Symbol().String(),
},
MaximumValueToSell: d.MaximumValueToSell.String(),
Expand All @@ -39,30 +39,30 @@ func encode(data transaction.Data, coins coins.RCoins) (*any.Any, error) {
Symbol: d.Symbol.String(),
InitialAmount: d.InitialAmount.String(),
InitialReserve: d.InitialReserve.String(),
ConstantReserveRatio: strconv.Itoa(int(d.ConstantReserveRatio)),
ConstantReserveRatio: uint64(d.ConstantReserveRatio),
MaxSupply: d.MaxSupply.String(),
}
case *transaction.CreateMultisigData:
weights := make([]string, 0, len(d.Weights))
weights := make([]uint64, 0, len(d.Weights))
for _, weight := range d.Weights {
weights = append(weights, strconv.Itoa(int(weight)))
weights = append(weights, uint64(weight))
}
addresses := make([]string, 0, len(d.Addresses))
for _, address := range d.Addresses {
addresses = append(addresses, address.String())
}
m = &pb.CreateMultisigData{
Threshold: strconv.Itoa(int(d.Threshold)),
Threshold: uint64(d.Threshold),
Weights: weights,
Addresses: addresses,
}
case *transaction.DeclareCandidacyData:
m = &pb.DeclareCandidacyData{
Address: d.Address.String(),
PubKey: d.PubKey.String(),
Commission: strconv.Itoa(int(d.Commission)),
Commission: uint64(d.Commission),
Coin: &pb.Coin{
Id: d.Coin.String(),
Id: uint64(d.Coin),
Symbol: coins.GetCoin(d.Coin).Symbol().String(),
},
Stake: d.Stake.String(),
Expand All @@ -71,7 +71,7 @@ func encode(data transaction.Data, coins coins.RCoins) (*any.Any, error) {
m = &pb.DelegateData{
PubKey: d.PubKey.String(),
Coin: &pb.Coin{
Id: d.Coin.String(),
Id: uint64(d.Coin),
Symbol: coins.GetCoin(d.Coin).Symbol().String(),
},
Value: d.Value.String(),
Expand All @@ -89,16 +89,16 @@ func encode(data transaction.Data, coins coins.RCoins) (*any.Any, error) {
NewPubKey: d.NewPubKey.String(),
}
case *transaction.EditMultisigData:
weights := make([]string, 0, len(d.Weights))
weights := make([]uint64, 0, len(d.Weights))
for _, weight := range d.Weights {
weights = append(weights, strconv.Itoa(int(weight)))
weights = append(weights, uint64(weight))
}
addresses := make([]string, 0, len(d.Addresses))
for _, address := range d.Addresses {
addresses = append(addresses, address.String())
}
m = &pb.EditMultisigData{
Threshold: strconv.Itoa(int(d.Threshold)),
Threshold: uint64(d.Threshold),
Weights: weights,
Addresses: addresses,
}
Expand All @@ -107,7 +107,7 @@ func encode(data transaction.Data, coins coins.RCoins) (*any.Any, error) {
for _, item := range d.List {
list = append(list, &pb.SendData{
Coin: &pb.Coin{
Id: item.Coin.String(),
Id: uint64(item.Coin),
Symbol: coins.GetCoin(item.Coin).Symbol().String(),
},
To: item.To.String(),
Expand All @@ -127,7 +127,7 @@ func encode(data transaction.Data, coins coins.RCoins) (*any.Any, error) {
Symbol: d.Symbol.String(),
InitialAmount: d.InitialAmount.String(),
InitialReserve: d.InitialReserve.String(),
ConstantReserveRatio: strconv.Itoa(int(d.ConstantReserveRatio)),
ConstantReserveRatio: uint64(d.ConstantReserveRatio),
MaxSupply: d.MaxSupply.String(),
}
case *transaction.RedeemCheckData:
Expand All @@ -138,32 +138,32 @@ func encode(data transaction.Data, coins coins.RCoins) (*any.Any, error) {
case *transaction.SellAllCoinData:
m = &pb.SellAllCoinData{
CoinToSell: &pb.Coin{
Id: d.CoinToSell.String(),
Id: uint64(d.CoinToSell),
Symbol: coins.GetCoin(d.CoinToSell).Symbol().String(),
},
CoinToBuy: &pb.Coin{
Id: d.CoinToBuy.String(),
Id: uint64(d.CoinToBuy),
Symbol: coins.GetCoin(d.CoinToBuy).Symbol().String(),
},
MinimumValueToBuy: d.MinimumValueToBuy.String(),
}
case *transaction.SellCoinData:
m = &pb.SellCoinData{
CoinToSell: &pb.Coin{
Id: d.CoinToSell.String(),
Id: uint64(d.CoinToSell),
Symbol: coins.GetCoin(d.CoinToSell).Symbol().String(),
},
ValueToSell: d.ValueToSell.String(),
CoinToBuy: &pb.Coin{
Id: d.CoinToBuy.String(),
Id: uint64(d.CoinToBuy),
Symbol: coins.GetCoin(d.CoinToBuy).Symbol().String(),
},
MinimumValueToBuy: d.MinimumValueToBuy.String(),
}
case *transaction.SendData:
m = &pb.SendData{
Coin: &pb.Coin{
Id: d.Coin.String(),
Id: uint64(d.Coin),
Symbol: coins.GetCoin(d.Coin).Symbol().String(),
},
To: d.To.String(),
Expand All @@ -172,7 +172,7 @@ func encode(data transaction.Data, coins coins.RCoins) (*any.Any, error) {
case *transaction.SetHaltBlockData:
m = &pb.SetHaltBlockData{
PubKey: d.PubKey.String(),
Height: strconv.Itoa(int(d.Height)),
Height: uint64(d.Height),
}
case *transaction.SetCandidateOnData:
m = &pb.SetCandidateOnData{
Expand All @@ -186,7 +186,7 @@ func encode(data transaction.Data, coins coins.RCoins) (*any.Any, error) {
m = &pb.UnbondData{
PubKey: d.PubKey.String(),
Coin: &pb.Coin{
Id: d.Coin.String(),
Id: uint64(d.Coin),
Symbol: coins.GetCoin(d.Coin).Symbol().String(),
},
Value: d.Value.String(),
Expand Down
Loading

0 comments on commit d76332e

Please sign in to comment.