diff --git a/api/candidate.go b/api/candidate.go index f63dced26..4172e4723 100644 --- a/api/candidate.go +++ b/api/candidate.go @@ -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"` } diff --git a/api/coin_info.go b/api/coin_info.go index 5193f6865..726fc630d 100644 --- a/api/coin_info.go +++ b/api/coin_info.go @@ -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"` diff --git a/api/v2/service/address.go b/api/v2/service/address.go index 9a677f1a1..ba0baa510 100644 --- a/api/v2/service/address.go +++ b/api/v2/service/address.go @@ -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" @@ -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(), @@ -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(), @@ -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(), @@ -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 } diff --git a/api/v2/service/addresses.go b/api/v2/service/addresses.go index f6caa4162..f5f55c1fe 100644 --- a/api/v2/service/addresses.go +++ b/api/v2/service/addresses.go @@ -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(), @@ -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(), @@ -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(), @@ -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 } diff --git a/api/v2/service/block.go b/api/v2/service/block.go index 6dc4cc3d2..3e742f798 100644 --- a/api/v2/service/block.go +++ b/api/v2/service/block.go @@ -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 { @@ -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: @@ -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()), @@ -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 diff --git a/api/v2/service/candidate.go b/api/v2/service/candidate.go index fcb01f04e..3ef961ba0 100644 --- a/api/v2/service/candidate.go +++ b/api/v2/service/candidate.go @@ -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" @@ -56,8 +55,8 @@ 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 { @@ -65,13 +64,13 @@ func makeResponseCandidate(state *state.CheckState, c *candidates.Candidate, inc 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(), @@ -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() } diff --git a/api/v2/service/coin_info.go b/api/v2/service/coin_info.go index c27158c55..0954ac851 100644 --- a/api/v2/service/coin_info.go +++ b/api/v2/service/coin_info.go @@ -2,7 +2,6 @@ package service import ( "context" - "fmt" "strconv" "github.com/MinterTeam/minter-go-node/core/code" @@ -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, @@ -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, diff --git a/api/v2/service/data_encoder.go b/api/v2/service/data_encoder.go index eff64c4e0..efc6f20d8 100644 --- a/api/v2/service/data_encoder.go +++ b/api/v2/service/data_encoder.go @@ -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(), @@ -39,20 +39,20 @@ 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, } @@ -60,9 +60,9 @@ func encode(data transaction.Data, coins coins.RCoins) (*any.Any, error) { 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(), @@ -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(), @@ -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, } @@ -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(), @@ -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: @@ -138,11 +138,11 @@ 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(), @@ -150,12 +150,12 @@ func encode(data transaction.Data, coins coins.RCoins) (*any.Any, error) { 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(), @@ -163,7 +163,7 @@ func encode(data transaction.Data, coins coins.RCoins) (*any.Any, error) { 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(), @@ -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{ @@ -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(), diff --git a/api/v2/service/frozen.go b/api/v2/service/frozen.go index a566e4dc1..cf6eaadf2 100644 --- a/api/v2/service/frozen.go +++ b/api/v2/service/frozen.go @@ -2,7 +2,6 @@ package service import ( "context" - "fmt" "github.com/MinterTeam/minter-go-node/core/code" "github.com/MinterTeam/minter-go-node/core/state/candidates" "github.com/MinterTeam/minter-go-node/core/state/coins" @@ -61,11 +60,11 @@ func (s *Service) Frozen(ctx context.Context, req *pb.FrozenRequest) (*pb.Frozen } } frozen = append(frozen, &pb.FrozenResponse_Frozen{ - Height: fmt.Sprintf("%d", funds.Height()), + Height: funds.Height(), Address: fund.Address.String(), CandidateKey: fund.CandidateKey.String(), Coin: &pb.Coin{ - Id: fund.Coin.String(), + Id: uint64(fund.Coin), Symbol: coin.GetFullSymbol(), }, Value: fund.Value.String(), diff --git a/api/v2/service/gas.go b/api/v2/service/gas.go index e93b5196d..46d6b8325 100644 --- a/api/v2/service/gas.go +++ b/api/v2/service/gas.go @@ -2,7 +2,6 @@ package service import ( "context" - "fmt" pb "github.com/MinterTeam/node-grpc-gateway/api_pb" "github.com/golang/protobuf/ptypes/empty" "google.golang.org/grpc/codes" @@ -12,18 +11,18 @@ import ( // MinGasPrice returns current min gas price. func (s *Service) MinGasPrice(context.Context, *empty.Empty) (*pb.MinGasPriceResponse, error) { return &pb.MinGasPriceResponse{ - MinGasPrice: fmt.Sprintf("%d", s.blockchain.MinGasPrice()), + MinGasPrice: uint64(s.blockchain.MinGasPrice()), }, nil } // MaxGas returns current max gas. -func (s *Service) MaxGas(ctx context.Context, req *pb.MaxGasRequest) (*pb.MaxGasResponse, error) { +func (s *Service) MaxGasPrice(ctx context.Context, req *pb.MaxGasPriceRequest) (*pb.MaxGasPriceResponse, error) { cState, err := s.blockchain.GetStateForHeight(req.Height) if err != nil { - return new(pb.MaxGasResponse), status.Error(codes.NotFound, err.Error()) + return new(pb.MaxGasPriceResponse), status.Error(codes.NotFound, err.Error()) } - return &pb.MaxGasResponse{ - MaxGas: fmt.Sprintf("%d", cState.App().GetMaxGas()), + return &pb.MaxGasPriceResponse{ + MaxGasPrice: cState.App().GetMaxGas(), }, nil } diff --git a/api/v2/service/genesis.go b/api/v2/service/genesis.go index 7fab9fad7..08fe0ff49 100644 --- a/api/v2/service/genesis.go +++ b/api/v2/service/genesis.go @@ -2,11 +2,11 @@ package service import ( "context" - "fmt" pb "github.com/MinterTeam/node-grpc-gateway/api_pb" "github.com/golang/protobuf/ptypes/empty" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "google.golang.org/protobuf/encoding/protojson" "time" ) @@ -21,7 +21,8 @@ func (s *Service) Genesis(ctx context.Context, _ *empty.Empty) (*pb.GenesisRespo return new(pb.GenesisResponse), timeoutStatus.Err() } - appState, err := encodeToStruct(result.Genesis.AppState) + var appState pb.GenesisResponse_AppState + err = protojson.Unmarshal(result.Genesis.AppState, &appState) if err != nil { return new(pb.GenesisResponse), status.Error(codes.Internal, err.Error()) } @@ -35,19 +36,19 @@ func (s *Service) Genesis(ctx context.Context, _ *empty.Empty) (*pb.GenesisRespo ChainId: result.Genesis.ChainID, ConsensusParams: &pb.GenesisResponse_ConsensusParams{ Block: &pb.GenesisResponse_ConsensusParams_Block{ - MaxBytes: fmt.Sprintf("%d", result.Genesis.ConsensusParams.Block.MaxBytes), - MaxGas: fmt.Sprintf("%d", result.Genesis.ConsensusParams.Block.MaxGas), - TimeIotaMs: fmt.Sprintf("%d", result.Genesis.ConsensusParams.Block.TimeIotaMs), + MaxBytes: result.Genesis.ConsensusParams.Block.MaxBytes, + MaxGas: result.Genesis.ConsensusParams.Block.MaxGas, + TimeIotaMs: result.Genesis.ConsensusParams.Block.TimeIotaMs, }, Evidence: &pb.GenesisResponse_ConsensusParams_Evidence{ - MaxAgeNumBlocks: fmt.Sprintf("%d", result.Genesis.ConsensusParams.Evidence.MaxAgeNumBlocks), - MaxAgeDuration: fmt.Sprintf("%d", result.Genesis.ConsensusParams.Evidence.MaxAgeDuration), + MaxAgeNumBlocks: result.Genesis.ConsensusParams.Evidence.MaxAgeNumBlocks, + MaxAgeDuration: int64(result.Genesis.ConsensusParams.Evidence.MaxAgeDuration), }, Validator: &pb.GenesisResponse_ConsensusParams_Validator{ PubKeyTypes: result.Genesis.ConsensusParams.Validator.PubKeyTypes, }, }, AppHash: result.Genesis.AppHash.String(), - AppState: appState, + AppState: &appState, }, nil } diff --git a/api/v2/service/halts.go b/api/v2/service/halts.go index 7045ac916..6ea9b93a7 100644 --- a/api/v2/service/halts.go +++ b/api/v2/service/halts.go @@ -26,6 +26,6 @@ func (s *Service) Halts(_ context.Context, req *pb.HaltsRequest) (*pb.HaltsRespo } return &pb.HaltsResponse{ - Votes: votes, + PublicKeys: votes, }, nil } diff --git a/api/v2/service/missed_blocks.go b/api/v2/service/missed_blocks.go index 505ea240f..a7e52988c 100644 --- a/api/v2/service/missed_blocks.go +++ b/api/v2/service/missed_blocks.go @@ -2,7 +2,6 @@ package service import ( "context" - "fmt" "github.com/MinterTeam/minter-go-node/core/types" pb "github.com/MinterTeam/node-grpc-gateway/api_pb" "google.golang.org/grpc/codes" @@ -37,6 +36,6 @@ func (s *Service) MissedBlocks(ctx context.Context, req *pb.MissedBlocksRequest) return &pb.MissedBlocksResponse{ MissedBlocks: val.AbsentTimes.String(), - MissedBlocksCount: fmt.Sprintf("%d", val.CountAbsentTimes()), + MissedBlocksCount: int64(val.CountAbsentTimes()), }, nil } diff --git a/api/v2/service/net_info.go b/api/v2/service/net_info.go index d46316c2f..122a2d2c3 100644 --- a/api/v2/service/net_info.go +++ b/api/v2/service/net_info.go @@ -2,7 +2,6 @@ package service import ( "context" - "fmt" pb "github.com/MinterTeam/node-grpc-gateway/api_pb" "github.com/golang/protobuf/ptypes/empty" "github.com/golang/protobuf/ptypes/wrappers" @@ -24,10 +23,10 @@ func (s *Service) NetInfo(ctx context.Context, _ *empty.Empty) (*pb.NetInfoRespo var peers []*pb.NetInfoResponse_Peer for _, peer := range result.Peers { - var currentHeight *wrappers.StringValue + var currentHeight *wrappers.UInt64Value peerHeight := peerHeight(s.tmNode.Switch(), peer.NodeInfo.ID()) if peerHeight != 0 { - currentHeight = &wrappers.StringValue{Value: fmt.Sprintf("%d", peerHeight)} + currentHeight = &wrappers.UInt64Value{Value: uint64(peerHeight)} } if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil { @@ -37,11 +36,11 @@ func (s *Service) NetInfo(ctx context.Context, _ *empty.Empty) (*pb.NetInfoRespo var channels []*pb.NetInfoResponse_Peer_ConnectionStatus_Channel for _, channel := range peer.ConnectionStatus.Channels { channels = append(channels, &pb.NetInfoResponse_Peer_ConnectionStatus_Channel{ - Id: fmt.Sprintf("%d", channel.ID), - SendQueueCapacity: fmt.Sprintf("%d", channel.SendQueueCapacity), - SendQueueSize: fmt.Sprintf("%d", channel.SendQueueSize), - Priority: fmt.Sprintf("%d", channel.Priority), - RecentlySent: fmt.Sprintf("%d", channel.RecentlySent), + Id: int64(channel.ID), + SendQueueCapacity: int64(channel.SendQueueCapacity), + SendQueueSize: int64(channel.SendQueueSize), + Priority: int64(channel.Priority), + RecentlySent: channel.RecentlySent, }) } @@ -49,9 +48,9 @@ func (s *Service) NetInfo(ctx context.Context, _ *empty.Empty) (*pb.NetInfoRespo LatestBlockHeight: currentHeight, NodeInfo: &pb.NodeInfo{ ProtocolVersion: &pb.NodeInfo_ProtocolVersion{ - P2P: fmt.Sprintf("%d", peer.NodeInfo.ProtocolVersion.P2P), - Block: fmt.Sprintf("%d", peer.NodeInfo.ProtocolVersion.Block), - App: fmt.Sprintf("%d", peer.NodeInfo.ProtocolVersion.App), + P2P: uint64(peer.NodeInfo.ProtocolVersion.P2P), + Block: uint64(peer.NodeInfo.ProtocolVersion.Block), + App: uint64(peer.NodeInfo.ProtocolVersion.App), }, Id: string(peer.NodeInfo.ID()), ListenAddr: peer.NodeInfo.ListenAddr, @@ -66,24 +65,38 @@ func (s *Service) NetInfo(ctx context.Context, _ *empty.Empty) (*pb.NetInfoRespo }, IsOutbound: peer.IsOutbound, ConnectionStatus: &pb.NetInfoResponse_Peer_ConnectionStatus{ - Duration: fmt.Sprintf("%d", peer.ConnectionStatus.Duration), + Duration: uint64(peer.ConnectionStatus.Duration), SendMonitor: &pb.NetInfoResponse_Peer_ConnectionStatus_Monitor{ - Active: false, + Active: peer.ConnectionStatus.SendMonitor.Active, Start: peer.ConnectionStatus.SendMonitor.Start.Format(time.RFC3339Nano), - Duration: fmt.Sprintf("%d", peer.ConnectionStatus.SendMonitor.Duration.Nanoseconds()), - Idle: fmt.Sprintf("%d", peer.ConnectionStatus.SendMonitor.Idle.Nanoseconds()), - Bytes: fmt.Sprintf("%d", peer.ConnectionStatus.SendMonitor.Bytes), - Samples: fmt.Sprintf("%d", peer.ConnectionStatus.SendMonitor.Samples), - InstRate: fmt.Sprintf("%d", peer.ConnectionStatus.SendMonitor.InstRate), - CurRate: fmt.Sprintf("%d", peer.ConnectionStatus.SendMonitor.CurRate), - AvgRate: fmt.Sprintf("%d", peer.ConnectionStatus.SendMonitor.AvgRate), - PeakRate: fmt.Sprintf("%d", peer.ConnectionStatus.SendMonitor.PeakRate), - BytesRem: fmt.Sprintf("%d", peer.ConnectionStatus.SendMonitor.BytesRem), - TimeRem: fmt.Sprintf("%d", peer.ConnectionStatus.SendMonitor.TimeRem.Nanoseconds()), - Progress: fmt.Sprintf("%d", peer.ConnectionStatus.SendMonitor.Progress), + Duration: peer.ConnectionStatus.SendMonitor.Duration.Nanoseconds(), + Idle: peer.ConnectionStatus.SendMonitor.Idle.Nanoseconds(), + Bytes: peer.ConnectionStatus.SendMonitor.Bytes, + Samples: peer.ConnectionStatus.SendMonitor.Samples, + InstRate: peer.ConnectionStatus.SendMonitor.InstRate, + CurRate: peer.ConnectionStatus.SendMonitor.CurRate, + AvgRate: peer.ConnectionStatus.SendMonitor.AvgRate, + PeakRate: peer.ConnectionStatus.SendMonitor.PeakRate, + BytesRem: peer.ConnectionStatus.SendMonitor.BytesRem, + TimeRem: peer.ConnectionStatus.SendMonitor.TimeRem.Nanoseconds(), + Progress: uint64(peer.ConnectionStatus.SendMonitor.Progress), }, - RecvMonitor: nil, - Channels: channels, + RecvMonitor: &pb.NetInfoResponse_Peer_ConnectionStatus_Monitor{ + Active: peer.ConnectionStatus.RecvMonitor.Active, + Start: peer.ConnectionStatus.RecvMonitor.Start.Format(time.RFC3339Nano), + Duration: peer.ConnectionStatus.RecvMonitor.Duration.Nanoseconds(), + Idle: peer.ConnectionStatus.RecvMonitor.Idle.Nanoseconds(), + Bytes: peer.ConnectionStatus.RecvMonitor.Bytes, + Samples: peer.ConnectionStatus.RecvMonitor.Samples, + InstRate: peer.ConnectionStatus.RecvMonitor.InstRate, + CurRate: peer.ConnectionStatus.RecvMonitor.CurRate, + AvgRate: peer.ConnectionStatus.RecvMonitor.AvgRate, + PeakRate: peer.ConnectionStatus.RecvMonitor.PeakRate, + BytesRem: peer.ConnectionStatus.RecvMonitor.BytesRem, + TimeRem: peer.ConnectionStatus.RecvMonitor.TimeRem.Nanoseconds(), + Progress: uint64(peer.ConnectionStatus.RecvMonitor.Progress), + }, + Channels: channels, }, RemoteIp: peer.RemoteIP, }) @@ -92,7 +105,7 @@ func (s *Service) NetInfo(ctx context.Context, _ *empty.Empty) (*pb.NetInfoRespo return &pb.NetInfoResponse{ Listening: result.Listening, Listeners: result.Listeners, - CountPeers: fmt.Sprintf("%d", result.NPeers), + CountPeers: int64(result.NPeers), Peers: peers, }, nil } diff --git a/api/v2/service/send_transaction.go b/api/v2/service/send_transaction.go index 304259933..1c86a69fc 100644 --- a/api/v2/service/send_transaction.go +++ b/api/v2/service/send_transaction.go @@ -3,7 +3,6 @@ package service import ( "context" "encoding/hex" - "fmt" "github.com/MinterTeam/minter-go-node/core/code" pb "github.com/MinterTeam/node-grpc-gateway/api_pb" abci "github.com/tendermint/tendermint/abci/types" @@ -33,7 +32,7 @@ func (s *Service) SendTransaction(ctx context.Context, req *pb.SendTransactionRe switch result.Code { case code.OK: return &pb.SendTransactionResponse{ - Code: fmt.Sprintf("%d", result.Code), + Code: uint64(result.Code), Log: result.Log, Hash: "Mt" + strings.ToLower(result.Hash.String()), }, nil diff --git a/api/v2/service/status.go b/api/v2/service/status.go index 6e47691f1..bab346c13 100644 --- a/api/v2/service/status.go +++ b/api/v2/service/status.go @@ -25,9 +25,9 @@ func (s *Service) Status(context.Context, *empty.Empty) (*pb.StatusResponse, err Version: s.version, LatestBlockHash: fmt.Sprintf("%X", result.SyncInfo.LatestBlockHash), LatestAppHash: fmt.Sprintf("%X", result.SyncInfo.LatestAppHash), - LatestBlockHeight: fmt.Sprintf("%d", result.SyncInfo.LatestBlockHeight), + LatestBlockHeight: uint64(result.SyncInfo.LatestBlockHeight), LatestBlockTime: result.SyncInfo.LatestBlockTime.Format(time.RFC3339Nano), - KeepLastStates: fmt.Sprintf("%d", s.minterCfg.BaseConfig.KeepLastStates), + KeepLastStates: uint64(s.minterCfg.BaseConfig.KeepLastStates), TotalSlashed: cState.App().GetTotalSlashed().String(), CatchingUp: result.SyncInfo.CatchingUp, PublicKey: fmt.Sprintf("Mp%x", result.ValidatorInfo.PubKey.Bytes()[5:]), diff --git a/api/v2/service/transaction.go b/api/v2/service/transaction.go index 1fd5a9ef2..3f8a6f33b 100644 --- a/api/v2/service/transaction.go +++ b/api/v2/service/transaction.go @@ -53,18 +53,21 @@ func (s *Service) Transaction(ctx context.Context, req *pb.TransactionRequest) ( return &pb.TransactionResponse{ Hash: "Mt" + strings.ToLower(hex.EncodeToString(tx.Tx.Hash())), RawTx: fmt.Sprintf("%x", []byte(tx.Tx)), - Height: fmt.Sprintf("%d", tx.Height), - Index: fmt.Sprintf("%d", tx.Index), + Height: uint64(tx.Height), + Index: uint64(tx.Index), From: sender.String(), - Nonce: fmt.Sprintf("%d", decodedTx.Nonce), - GasPrice: fmt.Sprintf("%d", decodedTx.GasPrice), - GasCoin: decodedTx.GasCoin.String(), - Gas: fmt.Sprintf("%d", decodedTx.Gas()), - Type: fmt.Sprintf("%d", uint8(decodedTx.Type)), - Data: dataStruct, - Payload: decodedTx.Payload, - Tags: tags, - Code: fmt.Sprintf("%d", tx.TxResult.Code), - Log: tx.TxResult.Log, + Nonce: decodedTx.Nonce, + GasPrice: uint64(decodedTx.GasPrice), + GasCoin: &pb.Coin{ + Id: uint64(decodedTx.GasCoin), + Symbol: cState.Coins().GetCoin(decodedTx.GasCoin).GetFullSymbol(), + }, + Gas: uint64(decodedTx.Gas()), + Type: uint64(decodedTx.Type), + Data: dataStruct, + Payload: decodedTx.Payload, + Tags: tags, + Code: uint64(tx.TxResult.Code), + Log: tx.TxResult.Log, }, nil } diff --git a/api/v2/service/transactions.go b/api/v2/service/transactions.go index 85310b306..0ff014eb8 100644 --- a/api/v2/service/transactions.go +++ b/api/v2/service/transactions.go @@ -57,19 +57,22 @@ func (s *Service) Transactions(ctx context.Context, req *pb.TransactionsRequest) result = append(result, &pb.TransactionResponse{ Hash: "Mt" + strings.ToLower(hex.EncodeToString(tx.Tx.Hash())), RawTx: fmt.Sprintf("%x", []byte(tx.Tx)), - Height: fmt.Sprintf("%d", tx.Height), - Index: fmt.Sprintf("%d", tx.Index), + Height: uint64(tx.Height), + Index: uint64(tx.Index), From: sender.String(), - Nonce: fmt.Sprintf("%d", decodedTx.Nonce), - GasPrice: fmt.Sprintf("%d", decodedTx.GasPrice), - GasCoin: decodedTx.GasCoin.String(), - Gas: fmt.Sprintf("%d", decodedTx.Gas()), - Type: fmt.Sprintf("%d", uint8(decodedTx.Type)), - Data: data, - Payload: decodedTx.Payload, - Tags: tags, - Code: fmt.Sprintf("%d", tx.TxResult.Code), - Log: tx.TxResult.Log, + Nonce: uint64(decodedTx.Nonce), + GasPrice: uint64(decodedTx.GasPrice), + GasCoin: &pb.Coin{ + Id: uint64(decodedTx.GasCoin), + Symbol: cState.Coins().GetCoin(decodedTx.GasCoin).GetFullSymbol(), + }, + Gas: uint64(decodedTx.Gas()), + Type: uint64(uint8(decodedTx.Type)), + Data: data, + Payload: decodedTx.Payload, + Tags: tags, + Code: uint64(tx.TxResult.Code), + Log: tx.TxResult.Log, }) } } diff --git a/api/v2/service/unconfirmed_txs.go b/api/v2/service/unconfirmed_txs.go index a0e37d84c..bf7a97b62 100644 --- a/api/v2/service/unconfirmed_txs.go +++ b/api/v2/service/unconfirmed_txs.go @@ -2,7 +2,6 @@ package service import ( "context" - "fmt" pb "github.com/MinterTeam/node-grpc-gateway/api_pb" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -14,9 +13,14 @@ func (s *Service) UnconfirmedTxs(ctx context.Context, req *pb.UnconfirmedTxsRequ if err != nil { return new(pb.UnconfirmedTxsResponse), status.Error(codes.Internal, err.Error()) } + transactions := make([]string, 0, len(txs.Txs)) + for _, tx := range txs.Txs { + transactions = append(transactions, tx.String()) + } return &pb.UnconfirmedTxsResponse{ - TransactionCount: fmt.Sprintf("%d", txs.Count), - TotalTransactions: fmt.Sprintf("%d", txs.Total), - TotalBytes: fmt.Sprintf("%d", txs.TotalBytes), + TransactionCount: uint64(txs.Count), + TotalTransactions: uint64(txs.Total), + TotalBytes: uint64(txs.TotalBytes), + Transactions: transactions, }, nil } diff --git a/api/v2/service/validators.go b/api/v2/service/validators.go index 619128aa5..a2a5a5eaf 100644 --- a/api/v2/service/validators.go +++ b/api/v2/service/validators.go @@ -2,7 +2,6 @@ package service import ( "context" - "fmt" "github.com/MinterTeam/minter-go-node/core/types" pb "github.com/MinterTeam/node-grpc-gateway/api_pb" "google.golang.org/grpc/codes" @@ -31,7 +30,7 @@ func (s *Service) Validators(ctx context.Context, req *pb.ValidatorsRequest) (*p copy(pk[:], val.PubKey.Bytes()[5:]) responseValidators = append(responseValidators, &pb.ValidatorsResponse_Result{ PublicKey: pk.String(), - VotingPower: fmt.Sprintf("%d", val.VotingPower), + VotingPower: uint64(val.VotingPower), }) } return &pb.ValidatorsResponse{Validators: responseValidators}, nil diff --git a/api/v2/service/waitlist.go b/api/v2/service/waitlist.go index 84a7e6a66..bbcf91dba 100644 --- a/api/v2/service/waitlist.go +++ b/api/v2/service/waitlist.go @@ -3,6 +3,7 @@ package service import ( "context" "encoding/hex" + "github.com/MinterTeam/minter-go-node/core/state/waitlist" "github.com/MinterTeam/minter-go-node/core/types" pb "github.com/MinterTeam/node-grpc-gateway/api_pb" "google.golang.org/grpc/codes" @@ -23,12 +24,6 @@ func (s *Service) WaitList(ctx context.Context, req *pb.WaitListRequest) (*pb.Wa address := types.BytesToAddress(decodeString) - if !strings.HasPrefix(req.PublicKey, "Mp") { - return new(pb.WaitListResponse), status.Error(codes.InvalidArgument, "public key don't has prefix 'Mp'") - } - - publickKey := types.HexToPubkey(req.PublicKey) - cState, err := s.blockchain.GetStateForHeight(req.Height) if err != nil { return new(pb.WaitListResponse), status.Error(codes.NotFound, err.Error()) @@ -42,7 +37,20 @@ func (s *Service) WaitList(ctx context.Context, req *pb.WaitListRequest) (*pb.Wa } response := new(pb.WaitListResponse) - items := cState.WaitList().GetByAddressAndPubKey(address, publickKey) + var items []waitlist.Item + publicKey := req.PublicKey + if publicKey != "" { + if !strings.HasPrefix(publicKey, "Mp") { + return new(pb.WaitListResponse), status.Error(codes.InvalidArgument, "public key don't has prefix 'Mp'") + } + items = cState.WaitList().GetByAddressAndPubKey(address, types.HexToPubkey(publicKey)) + } else { + model := cState.WaitList().GetByAddress(address) + if model == nil { + return response, nil + } + items = model.List + } response.List = make([]*pb.WaitListResponse_Wait, 0, len(items)) for _, item := range items { if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil { @@ -50,8 +58,9 @@ func (s *Service) WaitList(ctx context.Context, req *pb.WaitListRequest) (*pb.Wa } response.List = append(response.List, &pb.WaitListResponse_Wait{ + PublicKey: cState.Candidates().PubKey(item.CandidateId).String(), Coin: &pb.Coin{ - Id: item.Coin.String(), + Id: uint64(item.Coin), Symbol: cState.Coins().GetCoin(item.Coin).CSymbol.String(), }, Value: item.Value.String(), diff --git a/cli/service/client.go b/cli/service/client.go index d0ecdb317..66922e273 100644 --- a/cli/service/client.go +++ b/cli/service/client.go @@ -1,12 +1,10 @@ package service import ( - "bytes" "context" "fmt" pb "github.com/MinterTeam/minter-go-node/cli/cli_pb" "github.com/c-bata/go-prompt" - "github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/proto" "github.com/golang/protobuf/ptypes" "github.com/golang/protobuf/ptypes/empty" @@ -14,6 +12,7 @@ import ( "github.com/marcusolsson/tui-go" "github.com/urfave/cli/v2" "google.golang.org/grpc" + "google.golang.org/protobuf/encoding/protojson" "io" "log" "os" @@ -342,12 +341,11 @@ func netInfoCMD(client pb.ManagerServiceClient) func(c *cli.Context) error { return err } if c.Bool("json") { - bb := new(bytes.Buffer) - err := (&jsonpb.Marshaler{EmitDefaults: true}).Marshal(bb, response) + bb, err := protojson.Marshal(response) if err != nil { return err } - fmt.Println(bb.String()) + fmt.Println(string(bb)) return nil } fmt.Println(proto.MarshalTextString(response)) @@ -362,12 +360,11 @@ func statusCMD(client pb.ManagerServiceClient) func(c *cli.Context) error { return err } if c.Bool("json") { - bb := new(bytes.Buffer) - err := (&jsonpb.Marshaler{EmitDefaults: true}).Marshal(bb, response) + bb, err := protojson.Marshal(response) if err != nil { return err } - fmt.Println(bb.String()) + fmt.Println(string(bb)) return nil } fmt.Println(proto.MarshalTextString(response)) diff --git a/core/minter/minter_test.go b/core/minter/minter_test.go index c1f6bff9c..286a420c9 100644 --- a/core/minter/minter_test.go +++ b/core/minter/minter_test.go @@ -66,7 +66,7 @@ func makeTestValidatorsAndCandidates(pubkeys []string, stake *big.Int) ([]types. } cands[i] = types.Candidate{ - ID: uint32(i) + 1, + ID: uint64(i) + 1, RewardAddress: addr, OwnerAddress: crypto.PubkeyToAddress(getPrivateKey().PublicKey), ControlAddress: addr, @@ -76,7 +76,7 @@ func makeTestValidatorsAndCandidates(pubkeys []string, stake *big.Int) ([]types. Stakes: []types.Stake{ { Owner: addr, - Coin: types.GetBaseCoinID(), + Coin: uint64(types.GetBaseCoinID()), Value: stake.String(), BipValue: stake.String(), }, @@ -102,7 +102,7 @@ func getTestGenesis(pv *privval.FilePV) func() (*types2.GenesisDoc, error) { Address: crypto.PubkeyToAddress(getPrivateKey().PublicKey), Balance: []types.Balance{ { - Coin: types.GetBaseCoinID(), + Coin: uint64(types.GetBaseCoinID()), Value: helpers.BipToPip(big.NewInt(1000000)).String(), }, }, diff --git a/core/state/accounts/accounts.go b/core/state/accounts/accounts.go index 9e9aac3f2..5d456da07 100644 --- a/core/state/accounts/accounts.go +++ b/core/state/accounts/accounts.go @@ -190,7 +190,7 @@ func (a *Accounts) ExistsMultisig(msigAddress types.Address) bool { return false } -func (a *Accounts) CreateMultisig(weights []uint, addresses []types.Address, threshold uint, height uint64, address types.Address) types.Address { +func (a *Accounts) CreateMultisig(weights []uint32, addresses []types.Address, threshold uint32, height uint64, address types.Address) types.Address { msig := Multisig{ Weights: weights, Threshold: threshold, @@ -219,7 +219,7 @@ func (a *Accounts) CreateMultisig(weights []uint, addresses []types.Address, thr return address } -func (a *Accounts) EditMultisig(threshold uint, weights []uint, addresses []types.Address, address types.Address) types.Address { +func (a *Accounts) EditMultisig(threshold uint32, weights []uint32, addresses []types.Address, address types.Address) types.Address { account := a.get(address) msig := Multisig{ @@ -333,14 +333,14 @@ func (a *Accounts) Export(state *types.AppState) { var balance []types.Balance for _, b := range a.GetBalances(account.address) { balance = append(balance, types.Balance{ - Coin: b.Coin.ID, + Coin: uint64(b.Coin.ID), Value: b.Value.String(), }) } // sort balances by coin symbol sort.SliceStable(balance, func(i, j int) bool { - return bytes.Compare(balance[i].Coin.Bytes(), balance[j].Coin.Bytes()) == 1 + return bytes.Compare(types.CoinID(balance[i].Coin).Bytes(), types.CoinID(balance[j].Coin).Bytes()) == 1 }) acc := types.Account{ diff --git a/core/state/accounts/accounts_test.go b/core/state/accounts/accounts_test.go index b445adcf6..eefcde863 100644 --- a/core/state/accounts/accounts_test.go +++ b/core/state/accounts/accounts_test.go @@ -15,14 +15,14 @@ import ( ) func TestAccounts_CreateMultisig(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) accounts, err := NewAccounts(b, mutableTree) if err != nil { t.Fatal(err) } - multisigAddr := accounts.CreateMultisig([]uint{1, 1, 2}, []types.Address{[20]byte{1}, [20]byte{2}, [20]byte{3}}, 2, 0, [20]byte{4}) + multisigAddr := accounts.CreateMultisig([]uint32{1, 1, 2}, []types.Address{[20]byte{1}, [20]byte{2}, [20]byte{3}}, 2, 0, [20]byte{4}) account := accounts.GetAccount(multisigAddr) if account == nil { @@ -52,7 +52,7 @@ func TestAccounts_CreateMultisig(t *testing.T) { } func TestAccounts_SetNonce(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) accounts, err := NewAccounts(b, mutableTree) @@ -66,7 +66,7 @@ func TestAccounts_SetNonce(t *testing.T) { } func TestAccounts_SetBalance(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) accounts, err := NewAccounts(b, mutableTree) @@ -84,7 +84,7 @@ func TestAccounts_SetBalance(t *testing.T) { } func TestAccounts_SetBalance_fromDB(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) accounts, err := NewAccounts(b, mutableTree) @@ -107,7 +107,7 @@ func TestAccounts_SetBalance_fromDB(t *testing.T) { } func TestAccounts_SetBalance_0(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) accounts, err := NewAccounts(b, mutableTree) @@ -130,7 +130,7 @@ func TestAccounts_SetBalance_0(t *testing.T) { } func TestAccounts_GetBalances(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) busCoins, err := coins.NewCoins(b, mutableTree) @@ -184,7 +184,7 @@ func TestAccounts_GetBalances(t *testing.T) { } func TestAccounts_ExistsMultisig(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) accounts, err := NewAccounts(b, mutableTree) @@ -209,7 +209,7 @@ func TestAccounts_ExistsMultisig(t *testing.T) { accounts.SetNonce(msigAddress, 0) - _ = accounts.CreateMultisig([]uint{1, 1, 2}, []types.Address{[20]byte{1}, [20]byte{2}, [20]byte{3}}, 2, 0, msigAddress) + _ = accounts.CreateMultisig([]uint32{1, 1, 2}, []types.Address{[20]byte{1}, [20]byte{2}, [20]byte{3}}, 2, 0, msigAddress) if !accounts.ExistsMultisig(msigAddress) { t.Fatal("multisig address is free") @@ -217,7 +217,7 @@ func TestAccounts_ExistsMultisig(t *testing.T) { } func TestAccounts_AddBalance_bus(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) accounts, err := NewAccounts(b, mutableTree) @@ -234,7 +234,7 @@ func TestAccounts_AddBalance_bus(t *testing.T) { } func TestAccounts_SubBalance(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) accounts, err := NewAccounts(b, mutableTree) @@ -255,7 +255,7 @@ func TestAccounts_SubBalance(t *testing.T) { } func TestAccounts_EditMultisig(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) accounts, err := NewAccounts(b, mutableTree) @@ -265,8 +265,8 @@ func TestAccounts_EditMultisig(t *testing.T) { msigAddress := CreateMultisigAddress([20]byte{4}, 12) - _ = accounts.CreateMultisig([]uint{3, 3, 6}, []types.Address{[20]byte{1, 1}, [20]byte{2, 3}, [20]byte{3, 3}}, 6, 0, msigAddress) - _ = accounts.EditMultisig(2, []uint{1, 1, 2}, []types.Address{[20]byte{1}, [20]byte{2}, [20]byte{3}}, msigAddress) + _ = accounts.CreateMultisig([]uint32{3, 3, 6}, []types.Address{[20]byte{1, 1}, [20]byte{2, 3}, [20]byte{3, 3}}, 6, 0, msigAddress) + _ = accounts.EditMultisig(2, []uint32{1, 1, 2}, []types.Address{[20]byte{1}, [20]byte{2}, [20]byte{3}}, msigAddress) account := accounts.GetAccount(msigAddress) if account == nil { @@ -293,7 +293,7 @@ func TestAccounts_EditMultisig(t *testing.T) { } func TestAccounts_Commit(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) accounts, err := NewAccounts(b, mutableTree) @@ -322,7 +322,7 @@ func TestAccounts_Commit(t *testing.T) { } func TestAccounts_Export(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() busCoins, err := coins.NewCoins(b, mutableTree) if err != nil { @@ -361,7 +361,7 @@ func TestAccounts_Export(t *testing.T) { } accounts.SetBalance([20]byte{4}, symbol.ID(), big.NewInt(1001)) - _ = accounts.CreateMultisig([]uint{1, 1, 2}, []types.Address{[20]byte{1}, [20]byte{2}, [20]byte{3}}, 2, 0, [20]byte{4}) + _ = accounts.CreateMultisig([]uint32{1, 1, 2}, []types.Address{[20]byte{1}, [20]byte{2}, [20]byte{3}}, 2, 0, [20]byte{4}) err = accounts.Commit() if err != nil { diff --git a/core/state/accounts/model.go b/core/state/accounts/model.go index 45fd20867..b94585d07 100644 --- a/core/state/accounts/model.go +++ b/core/state/accounts/model.go @@ -27,8 +27,8 @@ type Model struct { } type Multisig struct { - Threshold uint - Weights []uint + Threshold uint32 + Weights []uint32 Addresses []types.Address } @@ -47,7 +47,7 @@ func CreateMultisigAddress(owner types.Address, nonce uint64) types.Address { return addr } -func (m *Multisig) GetWeight(address types.Address) uint { +func (m *Multisig) GetWeight(address types.Address) uint32 { for i, addr := range m.Addresses { if addr == address { return m.Weights[i] diff --git a/core/state/bus/candidates.go b/core/state/bus/candidates.go index f53e0512d..8049c190b 100644 --- a/core/state/bus/candidates.go +++ b/core/state/bus/candidates.go @@ -26,6 +26,6 @@ type Candidate struct { RewardAddress types.Address OwnerAddress types.Address ControlAddress types.Address - Commission uint + Commission uint32 Status byte } diff --git a/core/state/bus/coins.go b/core/state/bus/coins.go index e26c7474b..9c5d9534f 100644 --- a/core/state/bus/coins.go +++ b/core/state/bus/coins.go @@ -15,7 +15,7 @@ type Coins interface { type Coin struct { ID types.CoinID Name string - Crr uint + Crr uint32 Symbol types.CoinSymbol Version types.CoinVersion Volume *big.Int diff --git a/core/state/candidates/candidate_test.go b/core/state/candidates/candidate_test.go index 55d99b5cc..70c61470d 100644 --- a/core/state/candidates/candidate_test.go +++ b/core/state/candidates/candidate_test.go @@ -20,7 +20,7 @@ import ( ) func TestCandidates_Create_oneCandidate(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) candidates, err := NewCandidates(bus.NewBus(), mutableTree) if err != nil { t.Fatal(err) @@ -44,7 +44,7 @@ func TestCandidates_Create_oneCandidate(t *testing.T) { } func TestCandidates_Commit_createThreeCandidates(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) candidates, err := NewCandidates(bus.NewBus(), mutableTree) if err != nil { t.Fatal(err) @@ -93,7 +93,7 @@ func TestCandidates_Commit_createThreeCandidates(t *testing.T) { } func TestCandidates_Commit_changePubKeyAndCheckBlockList(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) candidates, err := NewCandidates(bus.NewBus(), mutableTree) if err != nil { t.Fatal(err) @@ -161,7 +161,7 @@ func TestCandidates_Commit_changePubKeyAndCheckBlockList(t *testing.T) { } func TestCandidates_AddToBlockPubKey(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) candidates, err := NewCandidates(bus.NewBus(), mutableTree) if err != nil { t.Fatal(err) @@ -175,7 +175,7 @@ func TestCandidates_AddToBlockPubKey(t *testing.T) { } func TestCandidates_Commit_withStakeAndUpdate(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) candidates, err := NewCandidates(bus.NewBus(), mutableTree) if err != nil { t.Fatal(err) @@ -236,7 +236,7 @@ func TestCandidates_Commit_withStakeAndUpdate(t *testing.T) { } func TestCandidates_Commit_edit(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) candidates, err := NewCandidates(bus.NewBus(), mutableTree) if err != nil { t.Fatal(err) @@ -293,7 +293,7 @@ func TestCandidates_Commit_edit(t *testing.T) { } func TestCandidates_Commit_createOneCandidateWithID(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) candidates, err := NewCandidates(bus.NewBus(), mutableTree) if err != nil { t.Fatal(err) @@ -326,7 +326,7 @@ func TestCandidates_Commit_createOneCandidateWithID(t *testing.T) { } func TestCandidates_Commit_Delegate(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) candidates, err := NewCandidates(b, mutableTree) @@ -376,7 +376,7 @@ func TestCandidates_Commit_Delegate(t *testing.T) { } func TestCandidates_SetOnlineAndBusSetOffline(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) candidates, err := NewCandidates(b, mutableTree) @@ -407,7 +407,7 @@ func TestCandidates_SetOnlineAndBusSetOffline(t *testing.T) { } func TestCandidates_Count(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) candidates, err := NewCandidates(b, mutableTree) @@ -444,7 +444,7 @@ func TestCandidates_Count(t *testing.T) { } func TestCandidates_GetTotalStake_fromModelAndFromDB(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() wl, err := waitlist.NewWaitList(b, mutableTree) if err != nil { @@ -518,7 +518,7 @@ func TestCandidates_GetTotalStake_fromModelAndFromDB(t *testing.T) { func TestCandidates_GetTotalStake_forCustomCoins(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() wl, err := waitlist.NewWaitList(b, mutableTree) if err != nil { @@ -567,7 +567,7 @@ func TestCandidates_GetTotalStake_forCustomCoins(t *testing.T) { value := strconv.Itoa(i + 2000) stakes = append(stakes, types.Stake{ Owner: types.StringToAddress(strconv.Itoa(i)), - Coin: symbol.ID(), + Coin: uint64(symbol.ID()), Value: value, BipValue: "0", }) @@ -585,7 +585,7 @@ func TestCandidates_GetTotalStake_forCustomCoins(t *testing.T) { } func TestCandidates_Export(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) candidates, err := NewCandidates(bus.NewBus(), mutableTree) if err != nil { t.Fatal(err) @@ -637,7 +637,7 @@ func TestCandidates_Export(t *testing.T) { } func TestCandidates_busGetStakes(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) candidates, err := NewCandidates(bus.NewBus(), mutableTree) if err != nil { t.Fatal(err) @@ -676,7 +676,7 @@ func TestCandidates_busGetStakes(t *testing.T) { } func TestCandidates_GetCandidateByTendermintAddress(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) candidates, err := NewCandidates(bus.NewBus(), mutableTree) if err != nil { t.Fatal(err) @@ -695,7 +695,7 @@ func TestCandidates_GetCandidateByTendermintAddress(t *testing.T) { } } func TestCandidates_busGetCandidateByTendermintAddress(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) candidates, err := NewCandidates(bus.NewBus(), mutableTree) if err != nil { t.Fatal(err) @@ -715,7 +715,7 @@ func TestCandidates_busGetCandidateByTendermintAddress(t *testing.T) { } func TestCandidates_Punish(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() wl, err := waitlist.NewWaitList(b, mutableTree) if err != nil { @@ -773,7 +773,7 @@ func TestCandidates_Punish(t *testing.T) { }, { Owner: [20]byte{1}, - Coin: symbol.ID(), + Coin: uint64(symbol.ID()), Value: "100", BipValue: "0", }, @@ -803,7 +803,7 @@ func (fr *fr) AddFrozenFund(_ uint64, _ types.Address, _ types.Pubkey, _ types.C fr.unbounds = append(fr.unbounds, value) } func TestCandidates_PunishByzantineCandidate(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() frozenfunds := &fr{} b.SetFrozenFunds(frozenfunds) @@ -863,7 +863,7 @@ func TestCandidates_PunishByzantineCandidate(t *testing.T) { }, { Owner: [20]byte{1}, - Coin: symbol.ID(), + Coin: uint64(symbol.ID()), Value: "100", BipValue: "0", }, @@ -897,7 +897,7 @@ func TestCandidates_PunishByzantineCandidate(t *testing.T) { } func TestCandidates_SubStake(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) candidates, err := NewCandidates(b, mutableTree) @@ -931,7 +931,7 @@ func TestCandidates_SubStake(t *testing.T) { } func TestCandidates_IsNewCandidateStakeSufficient(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) candidates, err := NewCandidates(b, mutableTree) @@ -960,7 +960,7 @@ func TestCandidates_IsNewCandidateStakeSufficient(t *testing.T) { } func TestCandidates_IsDelegatorStakeSufficient(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() wl, err := waitlist.NewWaitList(b, mutableTree) if err != nil { @@ -1024,7 +1024,7 @@ func TestCandidates_IsDelegatorStakeSufficient(t *testing.T) { } } func TestCandidates_IsDelegatorStakeSufficient_false(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) candidates, err := NewCandidates(b, mutableTree) @@ -1054,7 +1054,7 @@ func TestCandidates_IsDelegatorStakeSufficient_false(t *testing.T) { } func TestCandidates_GetNewCandidates(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) candidates, err := NewCandidates(b, mutableTree) @@ -1097,7 +1097,7 @@ func TestCandidates_GetNewCandidates(t *testing.T) { } func TestCandidate_GetFilteredUpdates(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) candidates, err := NewCandidates(b, mutableTree) diff --git a/core/state/candidates/candidates.go b/core/state/candidates/candidates.go index 1f96f6914..3cb45e8aa 100644 --- a/core/state/candidates/candidates.go +++ b/core/state/candidates/candidates.go @@ -45,6 +45,7 @@ type RCandidates interface { Export(state *types.AppState) Exists(pubkey types.Pubkey) bool IsBlockedPubKey(pubkey types.Pubkey) bool + PubKey(id uint32) types.Pubkey Count() int IsNewCandidateStakeSufficient(coin types.CoinID, stake *big.Int, limit int) bool IsDelegatorStakeSufficient(address types.Address, pubkey types.Pubkey, coin types.CoinID, amount *big.Int) bool @@ -231,7 +232,7 @@ func (c *Candidates) GetNewCandidates(valCount int) []Candidate { } // Create creates a new candidate with given params and adds it to state -func (c *Candidates) Create(ownerAddress, rewardAddress, controlAddress types.Address, pubkey types.Pubkey, commission uint) { +func (c *Candidates) Create(ownerAddress, rewardAddress, controlAddress types.Address, pubkey types.Pubkey, commission uint32) { candidate := &Candidate{ ID: 0, PubKey: pubkey, @@ -252,7 +253,7 @@ func (c *Candidates) Create(ownerAddress, rewardAddress, controlAddress types.Ad // CreateWithID creates a new candidate with given params and adds it to state // CreateWithID uses given ID to be associated with public key of a candidate -func (c *Candidates) CreateWithID(ownerAddress, rewardAddress, controlAddress types.Address, pubkey types.Pubkey, commission uint, id uint32) { +func (c *Candidates) CreateWithID(ownerAddress, rewardAddress, controlAddress types.Address, pubkey types.Pubkey, commission uint32, id uint32) { c.setPubKeyID(pubkey, id) c.Create(ownerAddress, rewardAddress, controlAddress, pubkey, commission) } @@ -808,7 +809,7 @@ func (c *Candidates) SetStakes(pubkey types.Pubkey, stakes []types.Stake, update for _, u := range updates { candidate.addUpdate(&stake{ Owner: u.Owner, - Coin: u.Coin, + Coin: types.CoinID(u.Coin), Value: helpers.StringToBigInt(u.Value), BipValue: helpers.StringToBigInt(u.BipValue), }) @@ -821,7 +822,7 @@ func (c *Candidates) SetStakes(pubkey types.Pubkey, stakes []types.Stake, update for _, u := range stakes[1000:] { candidate.addUpdate(&stake{ Owner: u.Owner, - Coin: u.Coin, + Coin: types.CoinID(u.Coin), Value: helpers.StringToBigInt(u.Value), BipValue: helpers.StringToBigInt(u.BipValue), }) @@ -831,7 +832,7 @@ func (c *Candidates) SetStakes(pubkey types.Pubkey, stakes []types.Stake, update for i, s := range stakes[:count] { candidate.stakes[i] = &stake{ Owner: s.Owner, - Coin: s.Coin, + Coin: types.CoinID(s.Coin), Value: helpers.StringToBigInt(s.Value), BipValue: helpers.StringToBigInt(s.BipValue), markDirty: func(index int) { @@ -857,7 +858,7 @@ func (c *Candidates) Export(state *types.AppState) { for i, s := range candidateStakes { stakes[i] = types.Stake{ Owner: s.Owner, - Coin: s.Coin, + Coin: uint64(s.Coin), Value: s.Value.String(), BipValue: s.BipValue.String(), } @@ -867,21 +868,21 @@ func (c *Candidates) Export(state *types.AppState) { for i, u := range candidate.updates { updates[i] = types.Stake{ Owner: u.Owner, - Coin: u.Coin, + Coin: uint64(u.Coin), Value: u.Value.String(), BipValue: u.BipValue.String(), } } state.Candidates = append(state.Candidates, types.Candidate{ - ID: candidate.ID, + ID: uint64(candidate.ID), RewardAddress: candidate.RewardAddress, OwnerAddress: candidate.OwnerAddress, ControlAddress: candidate.ControlAddress, TotalBipStake: candidate.GetTotalBipStake().String(), PubKey: candidate.PubKey, - Commission: candidate.Commission, - Status: candidate.Status, + Commission: uint64(candidate.Commission), + Status: uint64(candidate.Status), Updates: updates, Stakes: stakes, }) diff --git a/core/state/candidates/model.go b/core/state/candidates/model.go index ff7f97c82..534dd5690 100644 --- a/core/state/candidates/model.go +++ b/core/state/candidates/model.go @@ -19,7 +19,7 @@ type Candidate struct { RewardAddress types.Address OwnerAddress types.Address ControlAddress types.Address - Commission uint + Commission uint32 Status byte ID uint32 diff --git a/core/state/coins/coins.go b/core/state/coins/coins.go index c8fd05539..dd46710d0 100644 --- a/core/state/coins/coins.go +++ b/core/state/coins/coins.go @@ -185,7 +185,7 @@ func (c *Coins) AddReserve(id types.CoinID, amount *big.Int) { } func (c *Coins) Create(id types.CoinID, symbol types.CoinSymbol, name string, - volume *big.Int, crr uint, reserve *big.Int, maxSupply *big.Int, owner *types.Address, + volume *big.Int, crr uint32, reserve *big.Int, maxSupply *big.Int, owner *types.Address, ) { coin := &Model{ CName: name, @@ -222,7 +222,7 @@ func (c *Coins) Create(id types.CoinID, symbol types.CoinSymbol, name string, } func (c *Coins) Recreate(newID types.CoinID, name string, symbol types.CoinSymbol, - volume *big.Int, crr uint, reserve *big.Int, maxSupply *big.Int, + volume *big.Int, crr uint32, reserve *big.Int, maxSupply *big.Int, ) { recreateCoin := c.GetCoinBySymbol(symbol, 0) if recreateCoin == nil { @@ -371,14 +371,14 @@ func (c *Coins) Export(state *types.AppState) { } state.Coins = append(state.Coins, types.Coin{ - ID: coin.ID(), + ID: uint64(coin.ID()), Name: coin.Name(), Symbol: coin.Symbol(), Volume: coin.Volume().String(), - Crr: coin.Crr(), + Crr: uint64(coin.Crr()), Reserve: coin.Reserve().String(), MaxSupply: coin.MaxSupply().String(), - Version: coin.Version(), + Version: uint64(coin.Version()), OwnerAddress: owner, }) } diff --git a/core/state/coins/model.go b/core/state/coins/model.go index 61e7053a1..0e265716c 100644 --- a/core/state/coins/model.go +++ b/core/state/coins/model.go @@ -11,7 +11,7 @@ var minCoinReserve = helpers.BipToPip(big.NewInt(10000)) type Model struct { CName string - CCrr uint + CCrr uint32 CMaxSupply *big.Int CVersion types.CoinVersion CSymbol types.CoinSymbol @@ -38,7 +38,7 @@ func (m Model) ID() types.CoinID { return m.id } -func (m Model) Crr() uint { +func (m Model) Crr() uint32 { return m.CCrr } diff --git a/core/state/frozenfunds/frozen_funds.go b/core/state/frozenfunds/frozen_funds.go index b0b230e6d..8f9aa6264 100644 --- a/core/state/frozenfunds/frozen_funds.go +++ b/core/state/frozenfunds/frozen_funds.go @@ -212,7 +212,7 @@ func (f *FrozenFunds) Export(state *types.AppState, height uint64) { Height: i, Address: frozenFund.Address, CandidateKey: frozenFund.CandidateKey, - Coin: frozenFund.Coin, + Coin: uint64(frozenFund.Coin), Value: frozenFund.Value.String(), }) } diff --git a/core/state/halts/halts_test.go b/core/state/halts/halts_test.go index 1ef49dd0a..21f0e1394 100644 --- a/core/state/halts/halts_test.go +++ b/core/state/halts/halts_test.go @@ -9,7 +9,7 @@ import ( ) func TestHaltsToDeleteModel(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) h, err := NewHalts(bus.NewBus(), mutableTree) if err != nil { t.Fatal(err) @@ -47,7 +47,7 @@ func TestHaltsToDeleteModel(t *testing.T) { } func TestBusToAddHaltBlock(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) h, err := NewHalts(bus.NewBus(), mutableTree) if err != nil { t.Fatal(err) diff --git a/core/state/state.go b/core/state/state.go index 226d3e514..c3cc9bdf3 100644 --- a/core/state/state.go +++ b/core/state/state.go @@ -168,7 +168,10 @@ type State struct { func (s *State) isValue_State() {} func NewState(height uint64, db db.DB, events eventsdb.IEventsDB, cacheSize int, keepLastStates int64) (*State, error) { - iavlTree := tree.NewMutableTree(height, db, cacheSize) + iavlTree, err := tree.NewMutableTree(height, db, cacheSize) + if err != nil { + return nil, err + } state, err := newStateForTree(iavlTree, events, db, keepLastStates) if err != nil { @@ -219,7 +222,7 @@ func (s *State) Check() error { } if delta.Cmp(volume) != 0 { - return fmt.Errorf("invariants error on coin %s: %s", coin.String(), big.NewInt(0).Sub(volumeDeltas[coin], delta).String()) + return fmt.Errorf("invariants error on coin %s: %s", coin.String(), big.NewInt(0).Sub(volume, delta).String()) } } @@ -297,13 +300,13 @@ func (s *State) Import(state types.AppState) error { s.Accounts.SetNonce(a.Address, a.Nonce) for _, b := range a.Balance { - s.Accounts.SetBalance(a.Address, b.Coin, helpers.StringToBigInt(b.Value)) + s.Accounts.SetBalance(a.Address, types.CoinID(b.Coin), helpers.StringToBigInt(b.Value)) } } for _, c := range state.Coins { - s.Coins.Create(c.ID, c.Symbol, c.Name, helpers.StringToBigInt(c.Volume), - c.Crr, helpers.StringToBigInt(c.Reserve), helpers.StringToBigInt(c.MaxSupply), c.OwnerAddress) + s.Coins.Create(types.CoinID(c.ID), c.Symbol, c.Name, helpers.StringToBigInt(c.Volume), + uint32(c.Crr), helpers.StringToBigInt(c.Reserve), helpers.StringToBigInt(c.MaxSupply), c.OwnerAddress) } var vals []*validators.Validator @@ -325,7 +328,7 @@ func (s *State) Import(state types.AppState) error { } for _, c := range state.Candidates { - s.Candidates.CreateWithID(c.OwnerAddress, c.RewardAddress, c.ControlAddress, c.PubKey, c.Commission, c.ID) + s.Candidates.CreateWithID(c.OwnerAddress, c.RewardAddress, c.ControlAddress, c.PubKey, uint32(c.Commission), uint32(c.ID)) if c.Status == candidates.CandidateStatusOnline { s.Candidates.SetOnline(c.PubKey) } @@ -339,7 +342,7 @@ func (s *State) Import(state types.AppState) error { if !ok { panic(fmt.Sprintf("Cannot decode %s into big.Int", w.Value)) } - s.Waitlist.AddWaitList(w.Owner, s.Candidates.PubKey(w.CandidateID), w.Coin, value) + s.Waitlist.AddWaitList(w.Owner, s.Candidates.PubKey(uint32(w.CandidateID)), types.CoinID(w.Coin), value) } for _, hashString := range state.UsedChecks { @@ -350,7 +353,7 @@ func (s *State) Import(state types.AppState) error { } for _, ff := range state.FrozenFunds { - s.FrozenFunds.AddFund(ff.Height, ff.Address, *ff.CandidateKey, ff.Coin, helpers.StringToBigInt(ff.Value)) + s.FrozenFunds.AddFund(ff.Height, ff.Address, *ff.CandidateKey, types.CoinID(ff.Coin), helpers.StringToBigInt(ff.Value)) } return nil diff --git a/core/state/state_test.go b/core/state/state_test.go index a80fcaaa2..c096fb24b 100644 --- a/core/state/state_test.go +++ b/core/state/state_test.go @@ -155,7 +155,7 @@ func TestStateExport(t *testing.T) { if funds.Height != height || funds.Address != address1 || - funds.Coin != coinTestID || + funds.Coin != uint64(coinTestID) || *funds.CandidateKey != types.Pubkey(candidatePubKey1) || funds.Value != helpers.BipToPip(big.NewInt(100)).String() { t.Fatalf("Wrong new state frozen fund data") @@ -163,7 +163,7 @@ func TestStateExport(t *testing.T) { if funds1.Height != height+10 || funds1.Address != address1 || - funds1.Coin != types.GetBaseCoinID() || + funds1.Coin != uint64(types.GetBaseCoinID()) || *funds1.CandidateKey != types.Pubkey(candidatePubKey1) || funds1.Value != helpers.BipToPip(big.NewInt(3)).String() { t.Fatalf("Wrong new state frozen fund data") @@ -171,7 +171,7 @@ func TestStateExport(t *testing.T) { if funds2.Height != height+100 || funds2.Address != address2 || - funds2.Coin != coinTestID || + funds2.Coin != uint64(coinTestID) || *funds2.CandidateKey != types.Pubkey(candidatePubKey1) || funds2.Value != helpers.BipToPip(big.NewInt(500)).String() { t.Fatalf("Wrong new state frozen fund data") @@ -179,7 +179,7 @@ func TestStateExport(t *testing.T) { if funds3.Height != height+150 || funds3.Address != address2 || - funds3.Coin != coinTest2ID || + funds3.Coin != uint64(coinTest2ID) || *funds3.CandidateKey != types.Pubkey(candidatePubKey1) || funds3.Value != helpers.BipToPip(big.NewInt(1000)).String() { t.Fatalf("Wrong new state frozen fund data") @@ -217,15 +217,15 @@ func TestStateExport(t *testing.T) { t.Fatal("Wrong new state account balances size") } - if account1.Balance[0].Coin != coinTestID || account1.Balance[0].Value != helpers.BipToPip(big.NewInt(1)).String() { + if account1.Balance[0].Coin != uint64(coinTestID) || account1.Balance[0].Value != helpers.BipToPip(big.NewInt(1)).String() { t.Fatal("Wrong new state account balance data") } - if account1.Balance[1].Coin != types.GetBaseCoinID() || account1.Balance[1].Value != helpers.BipToPip(big.NewInt(1)).String() { + if account1.Balance[1].Coin != uint64(types.GetBaseCoinID()) || account1.Balance[1].Value != helpers.BipToPip(big.NewInt(1)).String() { t.Fatal("Wrong new state account balance data") } - if account2.Balance[0].Coin != coinTest2ID || account2.Balance[0].Value != helpers.BipToPip(big.NewInt(2)).String() { + if account2.Balance[0].Coin != uint64(coinTest2ID) || account2.Balance[0].Value != helpers.BipToPip(big.NewInt(2)).String() { t.Fatal("Wrong new state account balance data") } @@ -281,11 +281,11 @@ func TestStateExport(t *testing.T) { t.Fatalf("Invalid amount of waitlist: %d. Expected 2", len(newState.Waitlist)) } - if newState.Waitlist[0].Coin != coinTest2ID || newState.Waitlist[0].Value != big.NewInt(2e18).String() || newState.Waitlist[0].Owner.Compare(wlAddr2) != 0 { + if newState.Waitlist[0].Coin != uint64(coinTest2ID) || newState.Waitlist[0].Value != big.NewInt(2e18).String() || newState.Waitlist[0].Owner.Compare(wlAddr2) != 0 { t.Fatal("Invalid waitlist data") } - if newState.Waitlist[1].Coin != coinTestID || newState.Waitlist[1].Value != big.NewInt(1e18).String() || newState.Waitlist[1].Owner.Compare(wlAddr1) != 0 { + if newState.Waitlist[1].Coin != uint64(coinTestID) || newState.Waitlist[1].Value != big.NewInt(1e18).String() || newState.Waitlist[1].Owner.Compare(wlAddr1) != 0 { t.Fatal("Invalid waitlist data") } } diff --git a/core/state/validators/validators_test.go b/core/state/validators/validators_test.go index 2e00bfc3b..09e6327a5 100644 --- a/core/state/validators/validators_test.go +++ b/core/state/validators/validators_test.go @@ -19,7 +19,7 @@ import ( ) func TestValidators_GetValidators(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() validators, err := NewValidators(b, mutableTree) @@ -48,7 +48,7 @@ func TestValidators_GetValidators(t *testing.T) { } func TestValidators_GetByPublicKey(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() validators, err := NewValidators(b, mutableTree) @@ -70,7 +70,7 @@ func TestValidators_GetByPublicKey(t *testing.T) { } func TestValidators_GetByTmAddress(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() validators, err := NewValidators(b, mutableTree) @@ -94,7 +94,7 @@ func TestValidators_GetByTmAddress(t *testing.T) { } func TestValidators_PunishByzantineValidator(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() validators, err := NewValidators(b, mutableTree) @@ -116,7 +116,7 @@ func TestValidators_PunishByzantineValidator(t *testing.T) { } func TestValidators_LoadValidators(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() b.SetChecker(checker.NewChecker(b)) validators, err := NewValidators(b, mutableTree) @@ -169,7 +169,7 @@ func TestValidators_LoadValidators(t *testing.T) { } func TestValidators_SetValidators(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() validators, err := NewValidators(b, mutableTree) @@ -201,7 +201,7 @@ func TestValidators_SetValidators(t *testing.T) { } func TestValidators_PayRewards(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() accs, err := accounts.NewAccounts(b, mutableTree) if err != nil { @@ -269,7 +269,7 @@ func TestValidators_PayRewards(t *testing.T) { } func TestValidators_SetValidatorAbsent(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() accs, err := accounts.NewAccounts(b, mutableTree) if err != nil { @@ -327,7 +327,7 @@ func TestValidators_SetValidatorAbsent(t *testing.T) { } } func TestValidators_SetValidatorPresent(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() validators, err := NewValidators(b, mutableTree) @@ -356,7 +356,7 @@ func TestValidators_SetValidatorPresent(t *testing.T) { } func TestValidators_SetToDrop(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() validators, err := NewValidators(b, mutableTree) @@ -381,7 +381,7 @@ func TestValidators_SetToDrop(t *testing.T) { } func TestValidators_Export(t *testing.T) { - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) b := bus.NewBus() accs, err := accounts.NewAccounts(b, mutableTree) if err != nil { diff --git a/core/state/waitlist/waitlist.go b/core/state/waitlist/waitlist.go index 55f0b2352..e5fd5f264 100644 --- a/core/state/waitlist/waitlist.go +++ b/core/state/waitlist/waitlist.go @@ -53,9 +53,9 @@ func (wl *WaitList) Export(state *types.AppState) { if model != nil && len(model.List) != 0 { for _, w := range model.List { state.Waitlist = append(state.Waitlist, types.Waitlist{ - CandidateID: w.CandidateId, + CandidateID: uint64(w.CandidateId), Owner: address, - Coin: w.Coin, + Coin: uint64(w.Coin), Value: w.Value.String(), }) } @@ -164,16 +164,20 @@ func (wl *WaitList) Delete(address types.Address, pubkey types.Pubkey, coin type log.Panicf("Candidate not found: %s", pubkey.String()) } + value := big.NewInt(0) items := make([]Item, 0, len(w.List)) for _, item := range w.List { if item.CandidateId != candidate.ID && item.Coin != coin { items = append(items, item) + } else { + value.Add(value, item.Value) } } w.List = items wl.markDirty(address) wl.setToMap(address, w) + wl.bus.Checker().AddCoinVolume(coin, value) } func (wl *WaitList) getOrNew(address types.Address) *Model { diff --git a/core/state/waitlist/waitlist_test.go b/core/state/waitlist/waitlist_test.go index 345dc899f..e5fa3c844 100644 --- a/core/state/waitlist/waitlist_test.go +++ b/core/state/waitlist/waitlist_test.go @@ -12,7 +12,7 @@ import ( func TestWaitListToGetByAddressAndPubKey(t *testing.T) { b := bus.NewBus() - mutableTree := tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) wl, err := NewWaitList(b, mutableTree) if err != nil { diff --git a/core/transaction/buy_coin_test.go b/core/transaction/buy_coin_test.go index f281ec4c0..55979b031 100644 --- a/core/transaction/buy_coin_test.go +++ b/core/transaction/buy_coin_test.go @@ -25,7 +25,6 @@ var ( func getState() *state.State { s, err := state.NewState(0, db.NewMemDB(), nil, 1, 1) - if err != nil { panic(err) } @@ -1341,13 +1340,13 @@ func getAccount() (*ecdsa.PrivateKey, types.Address) { return privateKey, addr } -func createTestCoinWithSymbol(stateDB *state.State, symbol types.CoinSymbol) (types.CoinID, *big.Int, *big.Int, uint) { +func createTestCoinWithSymbol(stateDB *state.State, symbol types.CoinSymbol) (types.CoinID, *big.Int, *big.Int, uint32) { volume := helpers.BipToPip(big.NewInt(100000)) reserve := helpers.BipToPip(big.NewInt(100000)) volume.Mul(volume, big.NewInt(int64(rnd.Intn(9))+1)) reserve.Mul(reserve, big.NewInt(int64(rnd.Intn(9))+1)) - crr := uint(10 + rnd.Intn(90)) + crr := uint32(10 + rnd.Intn(90)) id := stateDB.App.GetNextCoinID() stateDB.Coins.Create(id, symbol, "TEST COIN", volume, crr, reserve, big.NewInt(0).Mul(volume, big.NewInt(10)), nil) diff --git a/core/transaction/create_coin.go b/core/transaction/create_coin.go index 64fc9a437..e483d755f 100644 --- a/core/transaction/create_coin.go +++ b/core/transaction/create_coin.go @@ -30,7 +30,7 @@ type CreateCoinData struct { Symbol types.CoinSymbol InitialAmount *big.Int InitialReserve *big.Int - ConstantReserveRatio uint + ConstantReserveRatio uint32 MaxSupply *big.Int } diff --git a/core/transaction/create_coin_test.go b/core/transaction/create_coin_test.go index 486d147e2..daf0b3ac9 100644 --- a/core/transaction/create_coin_test.go +++ b/core/transaction/create_coin_test.go @@ -25,7 +25,7 @@ func TestCreateCoinTx(t *testing.T) { toCreate := types.StrToCoinSymbol("ABCDEF") reserve := helpers.BipToPip(big.NewInt(10000)) amount := helpers.BipToPip(big.NewInt(100)) - crr := uint(50) + crr := uint32(50) name := "My Test Coin" data := CreateCoinData{ @@ -127,7 +127,7 @@ func TestCreateCoinWithIncorrectName(t *testing.T) { toCreate := types.StrToCoinSymbol("ABCDEF") reserve := helpers.BipToPip(big.NewInt(10000)) amount := helpers.BipToPip(big.NewInt(100)) - crr := uint(50) + crr := uint32(50) var name [65]byte binary.BigEndian.PutUint64(name[:], 0) @@ -185,7 +185,7 @@ func TestCreateCoinWithInvalidSymbol(t *testing.T) { toCreate := types.StrToCoinSymbol("ABC-DEF") reserve := helpers.BipToPip(big.NewInt(10000)) amount := helpers.BipToPip(big.NewInt(100)) - crr := uint(50) + crr := uint32(50) name := "My Test Coin" data := CreateCoinData{ @@ -244,7 +244,7 @@ func TestCreateCoinWithExistingSymbol(t *testing.T) { toCreate := types.StrToCoinSymbol("TEST") reserve := helpers.BipToPip(big.NewInt(10000)) amount := helpers.BipToPip(big.NewInt(100)) - crr := uint(50) + crr := uint32(50) name := "My Test Coin" data := CreateCoinData{ @@ -298,7 +298,7 @@ func TestCreateCoinWithWrongCrr(t *testing.T) { toCreate := types.StrToCoinSymbol("ABCDEF") reserve := helpers.BipToPip(big.NewInt(10000)) amount := helpers.BipToPip(big.NewInt(100)) - crr := uint(9) + crr := uint32(9) name := "My Test Coin" data := CreateCoinData{ @@ -339,7 +339,7 @@ func TestCreateCoinWithWrongCrr(t *testing.T) { t.Fatalf("Response code is not %d. Error %s", code.WrongCrr, response.Log) } - data.ConstantReserveRatio = uint(101) + data.ConstantReserveRatio = uint32(101) encodedData, err = rlp.EncodeToBytes(data) if err != nil { @@ -382,7 +382,7 @@ func TestCreateCoinWithWrongCoinSupply(t *testing.T) { toCreate := types.StrToCoinSymbol("ABCDEF") reserve := helpers.BipToPip(big.NewInt(10000)) - crr := uint(50) + crr := uint32(50) name := "My Test Coin" data := CreateCoinData{ @@ -535,7 +535,7 @@ func TestCreateCoinWithInsufficientFundsForGas(t *testing.T) { toCreate := types.StrToCoinSymbol("ABCDEF") reserve := helpers.BipToPip(big.NewInt(10000)) - crr := uint(50) + crr := uint32(50) name := "My Test Coin" data := CreateCoinData{ @@ -587,7 +587,7 @@ func TestCreateCoinTxToGasCoinReserveUnderflow(t *testing.T) { toCreate := types.StrToCoinSymbol("ABCDEF") reserve := helpers.BipToPip(big.NewInt(10000)) - crr := uint(50) + crr := uint32(50) name := "My Test Coin" addr := crypto.PubkeyToAddress(privateKey.PublicKey) @@ -641,7 +641,7 @@ func TestCreateCoinToInsufficientFundsForGasCoin(t *testing.T) { toCreate := types.StrToCoinSymbol("ABCDEF") reserve := helpers.BipToPip(big.NewInt(10000)) - crr := uint(50) + crr := uint32(50) name := "My Test Coin" addr := crypto.PubkeyToAddress(privateKey.PublicKey) @@ -693,7 +693,7 @@ func TestCreateCoinToInsufficientFundsForInitialReserve(t *testing.T) { toCreate := types.StrToCoinSymbol("ABCDEF") reserve := helpers.BipToPip(big.NewInt(11000)) - crr := uint(50) + crr := uint32(50) name := "My Test Coin" addr := crypto.PubkeyToAddress(privateKey.PublicKey) diff --git a/core/transaction/create_multisig.go b/core/transaction/create_multisig.go index e1412feeb..08c79c360 100644 --- a/core/transaction/create_multisig.go +++ b/core/transaction/create_multisig.go @@ -16,8 +16,8 @@ import ( ) type CreateMultisigData struct { - Threshold uint - Weights []uint + Threshold uint32 + Weights []uint32 Addresses []types.Address } diff --git a/core/transaction/create_multisig_test.go b/core/transaction/create_multisig_test.go index 396e19099..1eddad884 100644 --- a/core/transaction/create_multisig_test.go +++ b/core/transaction/create_multisig_test.go @@ -33,7 +33,7 @@ func TestCreateMultisigTx(t *testing.T) { addr2, } - weights := []uint{1, 1} + weights := []uint32{1, 1} data := CreateMultisigData{ Threshold: 1, @@ -126,7 +126,7 @@ func TestCreateMultisigFromExistingAccountTx(t *testing.T) { addr2, } - weights := []uint{1, 1} + weights := []uint32{1, 1} data := CreateMultisigData{ Threshold: 1, @@ -224,7 +224,7 @@ func TestCreateExistingMultisigTx(t *testing.T) { data := CreateMultisigData{ Threshold: 1, - Weights: []uint{1, 1}, + Weights: []uint32{1, 1}, Addresses: []types.Address{ addr, addr2, @@ -278,7 +278,7 @@ func TestCreateMultisigOwnersTxToNonExistenAddress(t *testing.T) { data := EditMultisigData{ Threshold: 3, - Weights: []uint{2, 1, 2}, + Weights: []uint32{2, 1, 2}, Addresses: []types.Address{addr1, addr2, addr3}, } @@ -322,8 +322,8 @@ func TestCreateMultisigOwnersTxToTooLargeOwnersList(t *testing.T) { coin := types.GetBaseCoinID() - weights := make([]uint, 33) - for i := uint(0); i <= 32; i++ { + weights := make([]uint32, 33) + for i := uint32(0); i <= 32; i++ { weights[i] = i } @@ -375,7 +375,7 @@ func TestCreateMultisigOwnersTxIncorrectWeights(t *testing.T) { data := CreateMultisigData{ Threshold: 3, - Weights: []uint{1, 2, 3, 4}, + Weights: []uint32{1, 2, 3, 4}, Addresses: []types.Address{addr1, addr2, addr3}, } @@ -408,7 +408,7 @@ func TestCreateMultisigOwnersTxIncorrectWeights(t *testing.T) { t.Fatalf("Response code is not %d. Error %s", code.DifferentCountAddressesAndWeights, response.Log) } - data.Weights = []uint{1, 2, 1024} + data.Weights = []uint32{1, 2, 1024} encodedData, err = rlp.EncodeToBytes(data) if err != nil { t.Fatal(err) @@ -440,7 +440,7 @@ func TestCreateMultisigOwnersTxToAddressDuplication(t *testing.T) { data := CreateMultisigData{ Threshold: 3, - Weights: []uint{1, 2, 3}, + Weights: []uint32{1, 2, 3}, Addresses: []types.Address{addr1, addr1, addr3}, } @@ -486,7 +486,7 @@ func TestCreateMultisigOwnersTxToInsufficientFunds(t *testing.T) { data := CreateMultisigData{ Threshold: 3, - Weights: []uint{1, 2, 3}, + Weights: []uint32{1, 2, 3}, Addresses: []types.Address{addr1, addr2, addr3}, } @@ -537,7 +537,7 @@ func TestCreateMultisigTxToGasCoinReserveUnderflow(t *testing.T) { data := CreateMultisigData{ Threshold: 3, - Weights: []uint{1, 2, 3}, + Weights: []uint32{1, 2, 3}, Addresses: []types.Address{addr1, addr2, addr3}, } diff --git a/core/transaction/declare_candidacy.go b/core/transaction/declare_candidacy.go index b04cd65c3..bdbbde914 100644 --- a/core/transaction/declare_candidacy.go +++ b/core/transaction/declare_candidacy.go @@ -19,7 +19,7 @@ const maxCommission = 100 type DeclareCandidacyData struct { Address types.Address PubKey types.Pubkey - Commission uint + Commission uint32 Coin types.CoinID Stake *big.Int } diff --git a/core/transaction/declare_candidacy_test.go b/core/transaction/declare_candidacy_test.go index 37068d3f0..1b0fd623c 100644 --- a/core/transaction/declare_candidacy_test.go +++ b/core/transaction/declare_candidacy_test.go @@ -30,7 +30,7 @@ func TestDeclareCandidacyTx(t *testing.T) { var publicKey types.Pubkey copy(publicKey[:], publicKeyBytes) - commission := uint(10) + commission := uint32(10) data := DeclareCandidacyData{ Address: addr, @@ -136,7 +136,7 @@ func TestDeclareCandidacyTxOverflow(t *testing.T) { data := DeclareCandidacyData{ Address: addr, PubKey: publicKey, - Commission: uint(10), + Commission: uint32(10), Coin: coin, Stake: helpers.BipToPip(big.NewInt(10)), } @@ -197,7 +197,7 @@ func TestDeclareCandidacyTxWithBlockPybKey(t *testing.T) { cState.Accounts.AddBalance(addr, coin, helpers.BipToPip(big.NewInt(1000000))) - commission := uint(10) + commission := uint32(10) data := DeclareCandidacyData{ Address: addr, @@ -277,7 +277,7 @@ func TestDeclareCandidacyToNonExistenCoin(t *testing.T) { var publicKey types.Pubkey copy(publicKey[:], publicKeyBytes) - commission := uint(10) + commission := uint32(10) data := DeclareCandidacyData{ Address: addr, @@ -332,9 +332,9 @@ func TestDeclareCandidacyToExistenCandidate(t *testing.T) { var publicKey types.Pubkey copy(publicKey[:], publicKeyBytes) - cState.Candidates.Create(addr, addr, addr, publicKey, uint(10)) + cState.Candidates.Create(addr, addr, addr, publicKey, uint32(10)) - commission := uint(10) + commission := uint32(10) data := DeclareCandidacyData{ Address: addr, @@ -389,7 +389,7 @@ func TestDeclareCandidacyToDecodeError(t *testing.T) { var publicKey types.Pubkey copy(publicKey[:], publicKeyBytes) - commission := uint(10) + commission := uint32(10) data := DeclareCandidacyData{ Address: addr, @@ -492,7 +492,7 @@ func TestDeclareCandidacyToInsufficientFunds(t *testing.T) { data := DeclareCandidacyData{ Address: addr, PubKey: publicKey, - Commission: uint(10), + Commission: uint32(10), Coin: coin, Stake: stake, } @@ -592,7 +592,7 @@ func TestDeclareCandidacyTxToGasCoinReserveUnderflow(t *testing.T) { data := DeclareCandidacyData{ Address: addr, PubKey: publicKey, - Commission: uint(10), + Commission: uint32(10), Coin: coin, Stake: stake, } diff --git a/core/transaction/delegate_test.go b/core/transaction/delegate_test.go index b462514a4..881804a61 100644 --- a/core/transaction/delegate_test.go +++ b/core/transaction/delegate_test.go @@ -2,7 +2,6 @@ package transaction import ( "encoding/binary" - "github.com/MinterTeam/minter-go-node/core/code" "github.com/MinterTeam/minter-go-node/core/state" "github.com/MinterTeam/minter-go-node/core/types" @@ -493,3 +492,58 @@ func TestDelegateTxToGasCoinReserveUnderflow(t *testing.T) { t.Fatalf("Response code is not %d. Error %s", code.CoinReserveUnderflow, response.Log) } } + +func TestDelegateData_addFromWaitlist(t *testing.T) { + cState := getState() + + pubkey := createTestCandidate(cState) + + privateKey, _ := crypto.GenerateKey() + addr := crypto.PubkeyToAddress(privateKey.PublicKey) + cState.Waitlist.AddWaitList(addr, pubkey, 0, big.NewInt(100)) + cState.Accounts.AddBalance(addr, 0, helpers.BipToPip(big.NewInt(1000000))) + cState.Checker.AddCoinVolume(0, helpers.BipToPip(big.NewInt(1000000))) + + value := big.NewInt(10000000000) + data := DelegateData{ + PubKey: pubkey, + Coin: 0, + Value: value, + } + + encodedData, err := rlp.EncodeToBytes(data) + if err != nil { + t.Fatal(err) + } + + tx := Transaction{ + Nonce: 1, + GasPrice: 1, + ChainID: types.CurrentChainID, + GasCoin: 0, + Type: TypeDelegate, + Data: encodedData, + SignatureType: SigTypeSingle, + } + + if err := tx.Sign(privateKey); err != nil { + t.Fatal(err) + } + + encodedTx, err := rlp.EncodeToBytes(tx) + if err != nil { + t.Fatal(err) + } + + rewards := big.NewInt(0) + response := RunTx(cState, encodedTx, rewards, 0, &sync.Map{}, 0) + if response.Code != 0 { + t.Fatalf("Response code is not %d. Error %s", code.OK, response.Log) + } + cState.Checker.AddCoin(0, rewards) + + err = cState.Check() + if err != nil { + t.Fatal(err) + } +} diff --git a/core/transaction/edit_multisig.go b/core/transaction/edit_multisig.go index 88adaa2c1..a07229729 100644 --- a/core/transaction/edit_multisig.go +++ b/core/transaction/edit_multisig.go @@ -15,8 +15,8 @@ import ( ) type EditMultisigData struct { - Threshold uint - Weights []uint + Threshold uint32 + Weights []uint32 Addresses []types.Address } @@ -72,7 +72,7 @@ func (data EditMultisigData) BasicCheck(tx *Transaction, context *state.CheckSta usedAddresses[address] = true } - var totalWeight uint + var totalWeight uint32 for _, weight := range data.Weights { totalWeight += weight } diff --git a/core/transaction/edit_multisig_test.go b/core/transaction/edit_multisig_test.go index 85f78541f..028722600 100644 --- a/core/transaction/edit_multisig_test.go +++ b/core/transaction/edit_multisig_test.go @@ -31,7 +31,7 @@ func TestEditMultisigTx(t *testing.T) { privateKey4, _ := crypto.GenerateKey() addr4 := crypto.PubkeyToAddress(privateKey4.PublicKey) - cState.Accounts.CreateMultisig([]uint{1, 2, 3}, []types.Address{addr1, addr2, addr3}, 3, 1, addr) + cState.Accounts.CreateMultisig([]uint32{1, 2, 3}, []types.Address{addr1, addr2, addr3}, 3, 1, addr) coin := types.GetBaseCoinID() initialBalance := big.NewInt(1) @@ -39,7 +39,7 @@ func TestEditMultisigTx(t *testing.T) { data := EditMultisigData{ Threshold: 3, - Weights: []uint{2, 1, 2}, + Weights: []uint32{2, 1, 2}, Addresses: []types.Address{addr1, addr2, addr4}, } @@ -111,7 +111,7 @@ func TestEditMultisigTxToNonExistenAddress(t *testing.T) { data := EditMultisigData{ Threshold: 3, - Weights: []uint{2, 1, 2}, + Weights: []uint32{2, 1, 2}, Addresses: []types.Address{addr1, addr2, addr3}, } @@ -156,10 +156,10 @@ func TestEditMultisigTxToTooLargeOwnersList(t *testing.T) { coin := types.GetBaseCoinID() - cState.Accounts.CreateMultisig([]uint{1, 2, 3}, []types.Address{addr1, addr2, addr3}, 3, 1, addr) + cState.Accounts.CreateMultisig([]uint32{1, 2, 3}, []types.Address{addr1, addr2, addr3}, 3, 1, addr) - weights := make([]uint, 33) - for i := uint(0); i <= 32; i++ { + weights := make([]uint32, 33) + for i := uint32(0); i <= 32; i++ { weights[i] = i } @@ -214,11 +214,11 @@ func TestEditMultisigTxIncorrectWeights(t *testing.T) { coin := types.GetBaseCoinID() - cState.Accounts.CreateMultisig([]uint{1, 2, 3}, []types.Address{addr1, addr2, addr3}, 3, 1, addr) + cState.Accounts.CreateMultisig([]uint32{1, 2, 3}, []types.Address{addr1, addr2, addr3}, 3, 1, addr) data := EditMultisigData{ Threshold: 3, - Weights: []uint{1, 2, 3, 4}, + Weights: []uint32{1, 2, 3, 4}, Addresses: []types.Address{addr1, addr2, addr3}, } @@ -253,7 +253,7 @@ func TestEditMultisigTxIncorrectWeights(t *testing.T) { t.Fatalf("Response code is not %d. Error %s", code.DifferentCountAddressesAndWeights, response.Log) } - data.Weights = []uint{1, 2, 1024} + data.Weights = []uint32{1, 2, 1024} encodedData, err = rlp.EncodeToBytes(data) if err != nil { t.Fatal(err) @@ -274,7 +274,7 @@ func TestEditMultisigTxIncorrectWeights(t *testing.T) { t.Fatalf("Response code is not %d. Error %s", code.IncorrectWeights, response.Log) } - data.Weights = []uint{1, 2, 3} + data.Weights = []uint32{1, 2, 3} data.Threshold = 7 encodedData, err = rlp.EncodeToBytes(data) if err != nil { @@ -310,11 +310,11 @@ func TestEditMultisigTxToAddressDuplication(t *testing.T) { coin := types.GetBaseCoinID() - cState.Accounts.CreateMultisig([]uint{1, 2, 3}, []types.Address{addr1, addr2, addr3}, 3, 1, addr) + cState.Accounts.CreateMultisig([]uint32{1, 2, 3}, []types.Address{addr1, addr2, addr3}, 3, 1, addr) data := EditMultisigData{ Threshold: 3, - Weights: []uint{1, 2, 3}, + Weights: []uint32{1, 2, 3}, Addresses: []types.Address{addr1, addr1, addr3}, } @@ -363,11 +363,11 @@ func TestEditMultisigTxToInsufficientFunds(t *testing.T) { coin := types.GetBaseCoinID() - cState.Accounts.CreateMultisig([]uint{1, 2, 3}, []types.Address{addr1, addr2, addr3}, 3, 1, addr) + cState.Accounts.CreateMultisig([]uint32{1, 2, 3}, []types.Address{addr1, addr2, addr3}, 3, 1, addr) data := EditMultisigData{ Threshold: 3, - Weights: []uint{1, 2, 3}, + Weights: []uint32{1, 2, 3}, Addresses: []types.Address{addr1, addr2, addr3}, } @@ -417,11 +417,11 @@ func TestEditMultisigTxToGasCoinReserveUnderflow(t *testing.T) { coin := createTestCoin(cState) cState.Coins.SubReserve(coin, helpers.BipToPip(big.NewInt(90000))) - cState.Accounts.CreateMultisig([]uint{1, 2, 3}, []types.Address{addr1, addr2, addr3}, 3, 1, addr) + cState.Accounts.CreateMultisig([]uint32{1, 2, 3}, []types.Address{addr1, addr2, addr3}, 3, 1, addr) data := EditMultisigData{ Threshold: 3, - Weights: []uint{1, 2, 3}, + Weights: []uint32{1, 2, 3}, Addresses: []types.Address{addr1, addr2, addr3}, } diff --git a/core/transaction/executor.go b/core/transaction/executor.go index c5000b9d3..148f119a6 100644 --- a/core/transaction/executor.go +++ b/core/transaction/executor.go @@ -150,7 +150,7 @@ func RunTx(context state.Interface, } txHash := tx.Hash() - var totalWeight uint + var totalWeight uint32 var usedAccounts = map[types.Address]bool{} for _, sig := range tx.multisig.Signatures { diff --git a/core/transaction/executor_test.go b/core/transaction/executor_test.go index 798230f6d..f376284a6 100644 --- a/core/transaction/executor_test.go +++ b/core/transaction/executor_test.go @@ -232,7 +232,7 @@ func TestMultiSigTx(t *testing.T) { addr := crypto.PubkeyToAddress(privateKey.PublicKey) coin := types.GetBaseCoinID() - msigAddress := cState.Accounts.CreateMultisig([]uint{1}, []types.Address{addr}, 1, 1, accounts.CreateMultisigAddress(addr, 1)) + msigAddress := cState.Accounts.CreateMultisig([]uint32{1}, []types.Address{addr}, 1, 1, accounts.CreateMultisigAddress(addr, 1)) cState.Accounts.AddBalance(msigAddress, coin, helpers.BipToPip(big.NewInt(1000000))) txData := SendData{ @@ -276,7 +276,7 @@ func TestMultiSigDoubleSignTx(t *testing.T) { addr := crypto.PubkeyToAddress(privateKey.PublicKey) coin := types.GetBaseCoinID() - msigAddress := cState.Accounts.CreateMultisig([]uint{1, 1}, []types.Address{addr, {}}, 2, 1, accounts.CreateMultisigAddress(addr, 1)) + msigAddress := cState.Accounts.CreateMultisig([]uint32{1, 1}, []types.Address{addr, {}}, 2, 1, accounts.CreateMultisigAddress(addr, 1)) cState.Accounts.AddBalance(msigAddress, coin, helpers.BipToPip(big.NewInt(1000000))) txData := SendData{ @@ -324,7 +324,7 @@ func TestMultiSigTooManySignsTx(t *testing.T) { addr := crypto.PubkeyToAddress(privateKey.PublicKey) coin := types.GetBaseCoinID() - msigAddress := cState.Accounts.CreateMultisig([]uint{1, 1}, []types.Address{addr, {}}, 2, 1, accounts.CreateMultisigAddress(addr, 1)) + msigAddress := cState.Accounts.CreateMultisig([]uint32{1, 1}, []types.Address{addr, {}}, 2, 1, accounts.CreateMultisigAddress(addr, 1)) cState.Accounts.AddBalance(msigAddress, coin, helpers.BipToPip(big.NewInt(1000000))) txData := SendData{ @@ -375,7 +375,7 @@ func TestMultiSigNotEnoughTx(t *testing.T) { addr := crypto.PubkeyToAddress(privateKey.PublicKey) coin := types.GetBaseCoinID() - msigAddress := cState.Accounts.CreateMultisig([]uint{1}, []types.Address{addr}, 2, 1, accounts.CreateMultisigAddress(addr, 1)) + msigAddress := cState.Accounts.CreateMultisig([]uint32{1}, []types.Address{addr}, 2, 1, accounts.CreateMultisigAddress(addr, 1)) cState.Accounts.AddBalance(msigAddress, coin, helpers.BipToPip(big.NewInt(1000000))) txData := SendData{ @@ -419,7 +419,7 @@ func TestMultiSigIncorrectSignsTx(t *testing.T) { addr := crypto.PubkeyToAddress(privateKey.PublicKey) coin := types.GetBaseCoinID() - msigAddress := cState.Accounts.CreateMultisig([]uint{1}, []types.Address{addr}, 1, 1, accounts.CreateMultisigAddress(addr, 1)) + msigAddress := cState.Accounts.CreateMultisig([]uint32{1}, []types.Address{addr}, 1, 1, accounts.CreateMultisigAddress(addr, 1)) cState.Accounts.AddBalance(msigAddress, coin, helpers.BipToPip(big.NewInt(1000000))) txData := SendData{ diff --git a/core/transaction/recreate_coin.go b/core/transaction/recreate_coin.go index c5fbf57b6..355a4359b 100644 --- a/core/transaction/recreate_coin.go +++ b/core/transaction/recreate_coin.go @@ -19,7 +19,7 @@ type RecreateCoinData struct { Symbol types.CoinSymbol InitialAmount *big.Int InitialReserve *big.Int - ConstantReserveRatio uint + ConstantReserveRatio uint32 MaxSupply *big.Int } diff --git a/core/transaction/recreate_coin_test.go b/core/transaction/recreate_coin_test.go index 34f971e98..b5f6eac2c 100644 --- a/core/transaction/recreate_coin_test.go +++ b/core/transaction/recreate_coin_test.go @@ -27,7 +27,7 @@ func TestRecreateCoinTx(t *testing.T) { reserve := helpers.BipToPip(big.NewInt(10000)) amount := helpers.BipToPip(big.NewInt(100)) - crr := uint(50) + crr := uint32(50) data := RecreateCoinData{ Name: "TEST", @@ -118,7 +118,7 @@ func TestRecreateCoinTxWithWrongOwner(t *testing.T) { reserve := helpers.BipToPip(big.NewInt(10000)) amount := helpers.BipToPip(big.NewInt(100)) - crr := uint(50) + crr := uint32(50) data := RecreateCoinData{ Symbol: getTestCoinSymbol(), @@ -152,7 +152,7 @@ func TestRecreateCoinTxWithWrongSymbol(t *testing.T) { reserve := helpers.BipToPip(big.NewInt(10000)) amount := helpers.BipToPip(big.NewInt(100)) - crr := uint(50) + crr := uint32(50) data := RecreateCoinData{ Symbol: types.StrToCoinSymbol("UNKNOWN"), @@ -185,7 +185,7 @@ func TestRecreateCoinWithIncorrectName(t *testing.T) { toCreate := types.StrToCoinSymbol("ABCDEF") reserve := helpers.BipToPip(big.NewInt(10000)) amount := helpers.BipToPip(big.NewInt(100)) - crr := uint(50) + crr := uint32(50) var name [65]byte binary.BigEndian.PutUint64(name[:], 0) @@ -243,7 +243,7 @@ func TestRecreateCoinWithWrongCrr(t *testing.T) { toCreate := types.StrToCoinSymbol("ABCDEF") reserve := helpers.BipToPip(big.NewInt(10000)) amount := helpers.BipToPip(big.NewInt(100)) - crr := uint(9) + crr := uint32(9) name := "My Test Coin" data := RecreateCoinData{ @@ -284,7 +284,7 @@ func TestRecreateCoinWithWrongCrr(t *testing.T) { t.Fatalf("Response code is not %d. Error %s", code.WrongCrr, response.Log) } - data.ConstantReserveRatio = uint(101) + data.ConstantReserveRatio = uint32(101) encodedData, err = rlp.EncodeToBytes(data) if err != nil { t.Fatal(err) @@ -326,7 +326,7 @@ func TestRecreateCoinWithWrongCoinSupply(t *testing.T) { toCreate := types.StrToCoinSymbol("ABCDEF") reserve := helpers.BipToPip(big.NewInt(10000)) - crr := uint(50) + crr := uint32(50) name := "My Test Coin" data := RecreateCoinData{ @@ -452,7 +452,7 @@ func TestRecreateCoinWithInsufficientFundsForGas(t *testing.T) { toCreate := types.StrToCoinSymbol("TEST") reserve := helpers.BipToPip(big.NewInt(10000)) - crr := uint(50) + crr := uint32(50) name := "My Test Coin" data := RecreateCoinData{ @@ -525,7 +525,7 @@ func TestRecreateCoinToInsufficientFundsForInitialReserve(t *testing.T) { toCreate := types.StrToCoinSymbol("TEST") reserve := helpers.BipToPip(big.NewInt(100000)) - crr := uint(50) + crr := uint32(50) name := "My Test Coin" data := RecreateCoinData{ @@ -563,7 +563,7 @@ func TestRecreateCoinToGasCoinReserveUnderflow(t *testing.T) { toCreate := types.StrToCoinSymbol("TEST") reserve := helpers.BipToPip(big.NewInt(100000)) - crr := uint(50) + crr := uint32(50) name := "My Test Coin" data := RecreateCoinData{ diff --git a/core/transaction/send_test.go b/core/transaction/send_test.go index 1dee5da2c..5d9538813 100644 --- a/core/transaction/send_test.go +++ b/core/transaction/send_test.go @@ -84,7 +84,7 @@ func TestSendMultisigTx(t *testing.T) { coin := types.GetBaseCoinID() - msig := cState.Accounts.CreateMultisig([]uint{1, 1}, []types.Address{addr1, addr2}, 1, 1, accounts.CreateMultisigAddress(addr1, 1)) + msig := cState.Accounts.CreateMultisig([]uint32{1, 1}, []types.Address{addr1, addr2}, 1, 1, accounts.CreateMultisigAddress(addr1, 1)) cState.Accounts.AddBalance(msig, coin, helpers.BipToPip(big.NewInt(1000000))) @@ -152,7 +152,7 @@ func TestSendFailedMultisigTx(t *testing.T) { coin := types.GetBaseCoinID() - msig := cState.Accounts.CreateMultisig([]uint{1, 3}, []types.Address{addr1, addr2}, 3, 1, accounts.CreateMultisigAddress(addr1, 1)) + msig := cState.Accounts.CreateMultisig([]uint32{1, 3}, []types.Address{addr1, addr2}, 3, 1, accounts.CreateMultisigAddress(addr1, 1)) cState.Accounts.AddBalance(msig, coin, helpers.BipToPip(big.NewInt(1000000))) diff --git a/core/types/appstate.go b/core/types/appstate.go index 8ef627ca1..3c50250a7 100644 --- a/core/types/appstate.go +++ b/core/types/appstate.go @@ -82,18 +82,20 @@ func (s *AppState) Verify() error { return fmt.Errorf("not valid balance for account %s", acc.Address.String()) } - if !bal.Coin.IsBaseCoin() { + coinID := CoinID(bal.Coin) + if !coinID.IsBaseCoin() { // check not existing coins foundCoin := false for _, coin := range s.Coins { - if coin.ID == bal.Coin { + id := CoinID(coin.ID) + if id == coinID { foundCoin = true break } } if !foundCoin { - return fmt.Errorf("coin %s not found", bal.Coin) + return fmt.Errorf("coin %s not found", coinID) } } } @@ -103,24 +105,26 @@ func (s *AppState) Verify() error { stakes := map[string]struct{}{} for _, stake := range candidate.Stakes { // check duplicated stakes - key := fmt.Sprintf("%s:%s", stake.Owner.String(), stake.Coin.String()) + coinID := CoinID(stake.Coin) + key := fmt.Sprintf("%s:%s", stake.Owner.String(), coinID.String()) if _, exists := stakes[key]; exists { return fmt.Errorf("duplicated stake %s", key) } stakes[key] = struct{}{} // check not existing coins - if !stake.Coin.IsBaseCoin() { + if !coinID.IsBaseCoin() { foundCoin := false for _, coin := range s.Coins { - if coin.ID == stake.Coin { + id := CoinID(coin.ID) + if id == coinID { foundCoin = true break } } if !foundCoin { - return fmt.Errorf("coin %s not found", stake.Coin) + return fmt.Errorf("coin %s not found", coinID) } } } @@ -173,17 +177,19 @@ func (s *AppState) Verify() error { } // check not existing coins - if !ff.Coin.IsBaseCoin() { + coinID := CoinID(ff.Coin) + if !coinID.IsBaseCoin() { foundCoin := false for _, coin := range s.Coins { - if coin.ID == ff.Coin { + id := CoinID(coin.ID) + if id == coinID { foundCoin = true break } } if !foundCoin { - return fmt.Errorf("coin %s not found", ff.Coin) + return fmt.Errorf("coin %s not found", coinID) } } } @@ -211,49 +217,49 @@ type Validator struct { } type Candidate struct { - ID uint32 `json:"id"` + ID uint64 `json:"id"` RewardAddress Address `json:"reward_address"` OwnerAddress Address `json:"owner_address"` ControlAddress Address `json:"control_address"` TotalBipStake string `json:"total_bip_stake"` PubKey Pubkey `json:"public_key"` - Commission uint `json:"commission"` + Commission uint64 `json:"commission"` Stakes []Stake `json:"stakes"` Updates []Stake `json:"updates"` - Status byte `json:"status"` + Status uint64 `json:"status"` } type Stake struct { Owner Address `json:"owner"` - Coin CoinID `json:"coin"` + Coin uint64 `json:"coin"` Value string `json:"value"` BipValue string `json:"bip_value"` } type Waitlist struct { - CandidateID uint32 `json:"candidate_id"` + CandidateID uint64 `json:"candidate_id"` Owner Address `json:"owner"` - Coin CoinID `json:"coin"` + Coin uint64 `json:"coin"` Value string `json:"value"` } type Coin struct { - ID CoinID `json:"id"` - Name string `json:"name"` - Symbol CoinSymbol `json:"symbol"` - Volume string `json:"volume"` - Crr uint `json:"crr"` - Reserve string `json:"reserve"` - MaxSupply string `json:"max_supply"` - Version CoinVersion `json:"version"` - OwnerAddress *Address `json:"owner_address"` + ID uint64 `json:"id"` + Name string `json:"name"` + Symbol CoinSymbol `json:"symbol"` + Volume string `json:"volume"` + Crr uint64 `json:"crr"` + Reserve string `json:"reserve"` + MaxSupply string `json:"max_supply"` + Version uint64 `json:"version"` + OwnerAddress *Address `json:"owner_address"` } type FrozenFund struct { Height uint64 `json:"height"` Address Address `json:"address"` CandidateKey *Pubkey `json:"candidate_key,omitempty"` - Coin CoinID `json:"coin"` + Coin uint64 `json:"coin"` Value string `json:"value"` } @@ -267,13 +273,13 @@ type Account struct { } type Balance struct { - Coin CoinID `json:"coin"` + Coin uint64 `json:"coin"` Value string `json:"value"` } type Multisig struct { - Weights []uint `json:"weights"` - Threshold uint `json:"threshold"` + Weights []uint32 `json:"weights"` + Threshold uint32 `json:"threshold"` Addresses []Address `json:"addresses"` } diff --git a/core/types/types_test.go b/core/types/types_test.go index 72e25e40b..d1c074ed4 100644 --- a/core/types/types_test.go +++ b/core/types/types_test.go @@ -154,7 +154,7 @@ func TestAppState(t *testing.T) { Stakes: []Stake{ { Owner: testAddr, - Coin: GetBaseCoinID(), + Coin: uint64(GetBaseCoinID()), Value: big.NewInt(1).String(), BipValue: big.NewInt(1).String(), }, @@ -167,17 +167,17 @@ func TestAppState(t *testing.T) { Address: testAddr, Balance: []Balance{ { - Coin: GetBaseCoinID(), + Coin: uint64(GetBaseCoinID()), Value: big.NewInt(1).String(), }, { - Coin: GetBaseCoinID() + 1, + Coin: uint64(GetBaseCoinID() + 1), Value: big.NewInt(1).String(), }, }, Nonce: 1, MultisigData: &Multisig{ - Weights: []uint{1, 2, 3}, + Weights: []uint32{1, 2, 3}, Threshold: 1, Addresses: []Address{testAddr, testAddr}, }, @@ -185,7 +185,7 @@ func TestAppState(t *testing.T) { }, Coins: []Coin{ { - ID: GetBaseCoinID() + 1, + ID: uint64(GetBaseCoinID() + 1), Name: "ASD", Symbol: StrToCoinSymbol("TEST"), Volume: big.NewInt(2).String(), @@ -199,7 +199,7 @@ func TestAppState(t *testing.T) { Height: 1, Address: testAddr, CandidateKey: &pubkey, - Coin: GetBaseCoinID() + 1, + Coin: uint64(GetBaseCoinID() + 1), Value: big.NewInt(1).String(), }, }, @@ -281,7 +281,7 @@ func TestAppStateToInvalidState(t *testing.T) { Stakes: []Stake{ { Owner: testAddr, - Coin: GetBaseCoinID(), + Coin: uint64(GetBaseCoinID()), Value: big.NewInt(1).String(), BipValue: big.NewInt(1).String(), }, @@ -331,7 +331,7 @@ func TestAppStateToInvalidState(t *testing.T) { Stakes: []Stake{ { Owner: testAddr, - Coin: GetBaseCoinID(), + Coin: uint64(GetBaseCoinID()), Value: big.NewInt(1).String(), BipValue: big.NewInt(1).String(), }, @@ -362,7 +362,7 @@ func TestAppStateToInvalidState(t *testing.T) { Address: testAddr, Balance: []Balance{ { - Coin: GetBaseCoinID(), + Coin: uint64(GetBaseCoinID()), Value: big.NewInt(1).String(), }, }, @@ -371,7 +371,7 @@ func TestAppStateToInvalidState(t *testing.T) { Address: testAddr, Balance: []Balance{ { - Coin: GetBaseCoinID(), + Coin: uint64(GetBaseCoinID()), Value: big.NewInt(1).String(), }, }, @@ -389,7 +389,7 @@ func TestAppStateToInvalidState(t *testing.T) { Address: testAddr, Balance: []Balance{ { - Coin: GetBaseCoinID(), + Coin: uint64(GetBaseCoinID()), Value: "", }, }, @@ -406,7 +406,7 @@ func TestAppStateToInvalidState(t *testing.T) { Address: testAddr, Balance: []Balance{ { - Coin: GetBaseCoinID() + 1, + Coin: uint64(GetBaseCoinID() + 1), Value: big.NewInt(1).String(), }, }, @@ -423,7 +423,7 @@ func TestAppStateToInvalidState(t *testing.T) { Address: testAddr, Balance: []Balance{ { - Coin: GetBaseCoinID(), + Coin: uint64(GetBaseCoinID()), Value: big.NewInt(1).String(), }, }, @@ -434,13 +434,13 @@ func TestAppStateToInvalidState(t *testing.T) { appState.Candidates[0].Stakes = []Stake{ { Owner: testAddr, - Coin: GetBaseCoinID(), + Coin: uint64(GetBaseCoinID()), Value: big.NewInt(1).String(), BipValue: big.NewInt(1).String(), }, { Owner: testAddr, - Coin: GetBaseCoinID(), + Coin: uint64(GetBaseCoinID()), Value: big.NewInt(1).String(), BipValue: big.NewInt(1).String(), }, @@ -453,7 +453,7 @@ func TestAppStateToInvalidState(t *testing.T) { appState.Candidates[0].Stakes = []Stake{ { Owner: testAddr, - Coin: GetBaseCoinID() + 1, + Coin: uint64(GetBaseCoinID() + 1), Value: big.NewInt(1).String(), BipValue: big.NewInt(1).String(), }, @@ -461,7 +461,7 @@ func TestAppStateToInvalidState(t *testing.T) { appState.Coins = []Coin{ { - ID: GetBaseCoinID() + 2, + ID: uint64(GetBaseCoinID() + 2), }, } @@ -472,7 +472,7 @@ func TestAppStateToInvalidState(t *testing.T) { appState.Candidates[0].Stakes = []Stake{ { Owner: testAddr, - Coin: GetBaseCoinID() + 1, + Coin: uint64(GetBaseCoinID() + 1), Value: big.NewInt(1).String(), BipValue: big.NewInt(1).String(), }, @@ -480,7 +480,7 @@ func TestAppStateToInvalidState(t *testing.T) { appState.Coins = []Coin{ { - ID: GetBaseCoinID() + 1, + ID: uint64(GetBaseCoinID() + 1), Name: "ASD", Symbol: StrToCoinSymbol("TEST"), Volume: big.NewInt(1).String(), @@ -489,7 +489,7 @@ func TestAppStateToInvalidState(t *testing.T) { MaxSupply: helpers.BipToPip(big.NewInt(100000)).String(), }, { - ID: GetBaseCoinID(), + ID: uint64(GetBaseCoinID()), Symbol: GetBaseCoin(), }, } @@ -500,7 +500,7 @@ func TestAppStateToInvalidState(t *testing.T) { appState.Coins = []Coin{ { - ID: GetBaseCoinID() + 1, + ID: uint64(GetBaseCoinID() + 1), Name: "ASD", Symbol: StrToCoinSymbol("TEST"), Volume: big.NewInt(1).String(), @@ -509,7 +509,7 @@ func TestAppStateToInvalidState(t *testing.T) { MaxSupply: helpers.BipToPip(big.NewInt(100000)).String(), }, { - ID: GetBaseCoinID() + 1, + ID: uint64(GetBaseCoinID() + 1), Name: "ASD", Symbol: StrToCoinSymbol("TEST"), Volume: big.NewInt(1).String(), @@ -518,7 +518,7 @@ func TestAppStateToInvalidState(t *testing.T) { MaxSupply: helpers.BipToPip(big.NewInt(100000)).String(), }, { - ID: GetBaseCoinID(), + ID: uint64(GetBaseCoinID()), Symbol: GetBaseCoin(), }, } @@ -529,7 +529,7 @@ func TestAppStateToInvalidState(t *testing.T) { appState.Coins = []Coin{ { - ID: GetBaseCoinID() + 1, + ID: uint64(GetBaseCoinID() + 1), Name: "ASD", Symbol: StrToCoinSymbol("TEST"), Volume: big.NewInt(1).String(), @@ -544,7 +544,7 @@ func TestAppStateToInvalidState(t *testing.T) { Height: 1, Address: testAddr, CandidateKey: &pubkey, - Coin: GetBaseCoinID() + 1, + Coin: uint64(GetBaseCoinID() + 1), Value: big.NewInt(1e18).String(), }, } @@ -558,7 +558,7 @@ func TestAppStateToInvalidState(t *testing.T) { Height: 1, Address: testAddr, CandidateKey: &pubkey, - Coin: GetBaseCoinID(), + Coin: uint64(GetBaseCoinID()), Value: "", }, } @@ -572,7 +572,7 @@ func TestAppStateToInvalidState(t *testing.T) { Height: 1, Address: testAddr, CandidateKey: &pubkey, - Coin: GetBaseCoinID() + 3, + Coin: uint64(GetBaseCoinID() + 3), Value: big.NewInt(1e18).String(), }, } @@ -586,7 +586,7 @@ func TestAppStateToInvalidState(t *testing.T) { Height: 1, Address: testAddr, CandidateKey: &pubkey, - Coin: GetBaseCoinID(), + Coin: uint64(GetBaseCoinID()), Value: big.NewInt(1e18).String(), }, } diff --git a/formula/formula.go b/formula/formula.go index a703e1dd3..bd8769a72 100644 --- a/formula/formula.go +++ b/formula/formula.go @@ -12,7 +12,7 @@ const ( // CalculatePurchaseReturn calculates amount of coin that user will receive by depositing given amount of BIP // Return = supply * ((1 + deposit / reserve) ^ (crr / 100) - 1) -func CalculatePurchaseReturn(supply *big.Int, reserve *big.Int, crr uint, deposit *big.Int) *big.Int { +func CalculatePurchaseReturn(supply *big.Int, reserve *big.Int, crr uint32, deposit *big.Int) *big.Int { if deposit.Cmp(types.Big0) == 0 { return big.NewInt(0) } @@ -40,7 +40,7 @@ func CalculatePurchaseReturn(supply *big.Int, reserve *big.Int, crr uint, deposi // CalculatePurchaseAmount is the reversed version of function CalculatePurchaseReturn // Deposit = reserve * (((wantReceive + supply) / supply)^(100/c) - 1) -func CalculatePurchaseAmount(supply *big.Int, reserve *big.Int, crr uint, wantReceive *big.Int) *big.Int { +func CalculatePurchaseAmount(supply *big.Int, reserve *big.Int, crr uint32, wantReceive *big.Int) *big.Int { if wantReceive.Cmp(types.Big0) == 0 { return big.NewInt(0) } @@ -68,7 +68,7 @@ func CalculatePurchaseAmount(supply *big.Int, reserve *big.Int, crr uint, wantRe // CalculateSaleReturn returns amount of BIP user will receive by depositing given amount of coins // Return = reserve * (1 - (1 - sellAmount / supply) ^ (100 / crr)) -func CalculateSaleReturn(supply *big.Int, reserve *big.Int, crr uint, sellAmount *big.Int) *big.Int { +func CalculateSaleReturn(supply *big.Int, reserve *big.Int, crr uint32, sellAmount *big.Int) *big.Int { // special case for 0 sell amount if sellAmount.Cmp(types.Big0) == 0 { return big.NewInt(0) @@ -103,7 +103,7 @@ func CalculateSaleReturn(supply *big.Int, reserve *big.Int, crr uint, sellAmount // CalculateSaleAmount is the reversed version of function CalculateSaleReturn // Deposit = -(-1 + (-(wantReceive - reserve)/reserve)^(1/crr)) * supply -func CalculateSaleAmount(supply *big.Int, reserve *big.Int, crr uint, wantReceive *big.Int) *big.Int { +func CalculateSaleAmount(supply *big.Int, reserve *big.Int, crr uint32, wantReceive *big.Int) *big.Int { if wantReceive.Cmp(types.Big0) == 0 { return big.NewInt(0) } diff --git a/formula/formula_test.go b/formula/formula_test.go index 8407c3793..f56f4aaf6 100644 --- a/formula/formula_test.go +++ b/formula/formula_test.go @@ -8,7 +8,7 @@ import ( type PurchaseReturnData struct { Supply *big.Int Reserve *big.Int - Crr uint + Crr uint32 Deposit *big.Int Result *big.Int } @@ -50,7 +50,7 @@ func TestCalculatePurchaseReturn(t *testing.T) { type PurchaseAmountData struct { Supply *big.Int Reserve *big.Int - Crr uint + Crr uint32 WantReceive *big.Int Deposit *big.Int } @@ -92,7 +92,7 @@ func TestCalculatePurchaseAmount(t *testing.T) { type CalculateSaleReturnData struct { Supply *big.Int Reserve *big.Int - Crr uint + Crr uint32 SellAmount *big.Int Result *big.Int } @@ -141,7 +141,7 @@ func TestCalculateSaleReturn(t *testing.T) { type CalculateBuyDepositData struct { Supply *big.Int Reserve *big.Int - Crr uint + Crr uint32 WantReceive *big.Int Result *big.Int } diff --git a/go.mod b/go.mod index 1169f8d56..c5565a6ea 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/MinterTeam/minter-go-node go 1.15 require ( - github.com/MinterTeam/node-grpc-gateway v1.1.3-0.20200922114348-418a230208a8 + github.com/MinterTeam/node-grpc-gateway v1.1.3-0.20200925002945-15b5cde8e354 github.com/btcsuite/btcd v0.20.1-beta github.com/c-bata/go-prompt v0.2.3 github.com/go-kit/kit v0.10.0 diff --git a/go.sum b/go.sum index a6c7efc71..fadd8b7a3 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,10 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= -github.com/MinterTeam/node-grpc-gateway v1.1.3-0.20200922114348-418a230208a8 h1:3C/50f/+Vhc+7/GlofHgsWYr8PmItWM1bTk3TlRnUPE= -github.com/MinterTeam/node-grpc-gateway v1.1.3-0.20200922114348-418a230208a8/go.mod h1:LZ+Y8IYfSBx0IQZY+a9pHLjztMwmlaCQX2ncTejoE2o= +github.com/MinterTeam/node-grpc-gateway v1.1.3-0.20200924215921-1e86f38ac67c h1:90nbZ96AfzYL8lvHLSPob8zNRFEFOa8LWsJ//0Bcj/s= +github.com/MinterTeam/node-grpc-gateway v1.1.3-0.20200924215921-1e86f38ac67c/go.mod h1:LZ+Y8IYfSBx0IQZY+a9pHLjztMwmlaCQX2ncTejoE2o= +github.com/MinterTeam/node-grpc-gateway v1.1.3-0.20200925002945-15b5cde8e354 h1:HpjApkir3UtOL4WzGzkgQcdT9SyqwiZ/wbGrahzIlLQ= +github.com/MinterTeam/node-grpc-gateway v1.1.3-0.20200925002945-15b5cde8e354/go.mod h1:LZ+Y8IYfSBx0IQZY+a9pHLjztMwmlaCQX2ncTejoE2o= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= diff --git a/legacy/accounts/model.go b/legacy/accounts/model.go index 307773997..ef67c6fb4 100644 --- a/legacy/accounts/model.go +++ b/legacy/accounts/model.go @@ -27,8 +27,8 @@ type Model struct { } type Multisig struct { - Threshold uint - Weights []uint + Threshold uint32 + Weights []uint32 Addresses []types.Address } @@ -44,7 +44,7 @@ func (m *Multisig) Address() types.Address { return addr } -func (m *Multisig) GetWeight(address types.Address) uint { +func (m *Multisig) GetWeight(address types.Address) uint32 { for i, addr := range m.Addresses { if addr == address { return m.Weights[i] diff --git a/legacy/candidates/candidates.go b/legacy/candidates/candidates.go index 5c1eb7bd1..edfe8d3d9 100644 --- a/legacy/candidates/candidates.go +++ b/legacy/candidates/candidates.go @@ -68,7 +68,7 @@ func (c *Candidates) GetNewCandidates(valCount int) []Candidate { return result } -func (c *Candidates) Create(ownerAddress types.Address, rewardAddress types.Address, pubkey types.Pubkey, commission uint) { +func (c *Candidates) Create(ownerAddress types.Address, rewardAddress types.Address, pubkey types.Pubkey, commission uint32) { candidate := &Candidate{ PubKey: pubkey, RewardAddress: rewardAddress, @@ -259,14 +259,14 @@ func (c *Candidates) Export(state *types.AppState, coinsMap map[types.CoinSymbol } state.Candidates = append(state.Candidates, types.Candidate{ - ID: maxID, + ID: uint64(maxID), RewardAddress: candidate.RewardAddress, OwnerAddress: candidate.OwnerAddress, ControlAddress: candidate.OwnerAddress, TotalBipStake: candidate.GetTotalBipStake().String(), PubKey: candidate.PubKey, - Commission: candidate.Commission, - Status: candidate.Status, + Commission: uint64(candidate.Commission), + Status: uint64(candidate.Status), Updates: updates, Stakes: stakes, }) diff --git a/legacy/candidates/model.go b/legacy/candidates/model.go index 6b6830b09..10c4395bf 100644 --- a/legacy/candidates/model.go +++ b/legacy/candidates/model.go @@ -11,7 +11,7 @@ type Candidate struct { PubKey types.Pubkey RewardAddress types.Address OwnerAddress types.Address - Commission uint + Commission uint32 Status byte totalBipStake *big.Int diff --git a/legacy/coins/coins.go b/legacy/coins/coins.go index e3fe6b590..08f1b2b4d 100644 --- a/legacy/coins/coins.go +++ b/legacy/coins/coins.go @@ -117,7 +117,7 @@ func (c *Coins) Export(state *types.AppState) map[types.CoinSymbol]types.Coin { Name: coin.Name(), Symbol: coin.Symbol(), Volume: coin.Volume().String(), - Crr: coin.Crr(), + Crr: uint64(coin.Crr()), Reserve: coin.Reserve().String(), MaxSupply: coin.MaxSupply().String(), Version: 0, @@ -134,10 +134,10 @@ func (c *Coins) Export(state *types.AppState) map[types.CoinSymbol]types.Coin { }) coinsMap := make(map[types.CoinSymbol]types.Coin, len(coins)) - coinsMap[types.GetBaseCoin()] = types.Coin{ID: types.GetBaseCoinID()} + coinsMap[types.GetBaseCoin()] = types.Coin{ID: uint64(types.GetBaseCoinID())} - for i, _ := range coins { - coins[i].ID = types.CoinID(i + 1) + for i := range coins { + coins[i].ID = uint64(i + 1) coinsMap[coins[i].Symbol] = coins[i] } diff --git a/tests/send_test.go b/tests/send_test.go index 9abd9ea70..3726475a4 100644 --- a/tests/send_test.go +++ b/tests/send_test.go @@ -19,7 +19,7 @@ func TestSend(t *testing.T) { Address: address, Balance: []types.Balance{ { - Coin: types.GetBaseCoinID(), + Coin: uint64(types.GetBaseCoinID()), Value: helpers.BipToPip(big.NewInt(1)).String(), }, }, diff --git a/tree/tree.go b/tree/tree.go index c5e1af1b0..82954ad33 100644 --- a/tree/tree.go +++ b/tree/tree.go @@ -34,25 +34,25 @@ type MTree interface { // NewMutableTree creates and returns new MutableTree using given db. Panics on error. // If you want to get read-only state, you should use height = 0 and LazyLoadVersion (version), see NewImmutableTree -func NewMutableTree(height uint64, db dbm.DB, cacheSize int) MTree { +func NewMutableTree(height uint64, db dbm.DB, cacheSize int) (MTree, error) { tree, err := iavl.NewMutableTree(db, cacheSize) if err != nil { - panic(err) + return nil, err } if height == 0 { return &mutableTree{ tree: tree, - } + }, nil } if _, err := tree.LoadVersionForOverwriting(int64(height)); err != nil { - panic(err) + return nil, err } return &mutableTree{ tree: tree, - } + }, nil } type mutableTree struct { @@ -212,7 +212,7 @@ type ImmutableTree struct { // NewImmutableTree returns MTree from given db at given height // Warning: returns the MTree interface, but you should only use ReadOnlyTree func NewImmutableTree(height uint64, db dbm.DB) (MTree, error) { - tree := NewMutableTree(0, db, 1024) + tree, _ := NewMutableTree(0, db, 1024) _, err := tree.LazyLoadVersion(int64(height)) if err != nil { return nil, err