Skip to content

Commit

Permalink
Merge pull request #428 from MinterTeam/dev
Browse files Browse the repository at this point in the history
v1.2
  • Loading branch information
danil-lashin authored Oct 19, 2020
2 parents 8778031 + 055e0c1 commit 2e6614d
Show file tree
Hide file tree
Showing 235 changed files with 27,245 additions and 7,815 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
echo ::set-env name=DOCKER_REPO::$(if [[ "$SECRET_DOCKER_HUB_REPO" == "" ]]; then if [[ "$SECRET_DOCKER_HUB_USER" == "" ]]; then echo "testbuild"; else echo "$SECRET_DOCKER_HUB_USER"; fi; else echo "$SECRET_DOCKER_HUB_REPO"; fi)
- name: Docker build
run: docker build -t $DOCKER_REPO/$DOCKER_IMAGE:$VERSION .
run: docker build -t $DOCKER_REPO/$DOCKER_IMAGE:$VERSION . -f ./Dockerfile-ci

- name: Start docker container
run: docker run -d --name $CONTAINER_NAME -p $API_RUN_PORT:8841 $DOCKER_REPO/$DOCKER_IMAGE:$VERSION
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## 1.2.0

- [core] Added ControlAddress for Candidate
- [core] Added changing candidate’s public key functionality
- [core] Coins now identified by ID, not by symbols
- [core] Added RecreateCoin tx
- [core] Added ChangeCoinOwner tx
- [core] Limit validators slots to 64
- [core] Add EditMultisigData tx
- [core] Add PriceVoteData tx
- [core] Stake value calculation changes
- [console] Added PruneBlocks command
- [api] Marked as deprecated version of API v1
- [api] Added Swagger UI for API v2

## 1.1.8

BUG FIXES
Expand Down
22 changes: 22 additions & 0 deletions Dockerfile-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM tazhate/dockerfile-gox as builder

COPY . /gopath/src/github.com/MinterTeam/minter-go-node
WORKDIR /gopath/src/github.com/MinterTeam/minter-go-node
RUN apt-get update && apt-get install libleveldb-dev -y --no-install-recommends -q
RUN make build

FROM ubuntu:bionic

COPY --from=builder /gopath/src/github.com/MinterTeam/minter-go-node/build/minter/ /usr/bin/minter
RUN apt update && apt install libleveldb1v5 ca-certificates -y --no-install-recommends -q && \
addgroup minteruser && \
useradd --no-log-init -r -m -d /minter -g minteruser minteruser && \
chown -R minteruser:minteruser /minter && \
rm -rf /var/lib/apt/lists/*

USER minteruser
WORKDIR /minter
RUN mkdir /minter/data
EXPOSE 8841
ENTRYPOINT ["/usr/bin/minter"]
CMD ["node", "--home-dir", "/minter", "--genesis", "https://github.com/MinterTeam/minter-go-node/releases/download/v1.2-testnet-9/genesis.json"]
6 changes: 0 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ update_tools:
@echo "--> Updating tools"
@go get -u $(GOTOOLS)

#Run this from CI
get_vendor_deps:
@rm -rf vendor/
@echo "--> Running dep"
@go mod vendor

#Run this locally.
ensure_deps:
@rm -rf vendor/
Expand Down
44 changes: 34 additions & 10 deletions api/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@ import (
)

type AddressResponse struct {
Balance map[string]string `json:"balance"`
TransactionCount uint64 `json:"transaction_count"`
Balance []BalanceItem `json:"balances"`
TransactionCount uint64 `json:"transaction_count"`
}

type BalanceItem struct {
CoinID uint32 `json:"coin_id"`
Symbol string `json:"symbol"`
Value string `json:"value"`
}

type Coin struct {
ID uint32 `json:"id"`
Symbol string `json:"symbol"`
}

func Address(address types.Address, height int) (*AddressResponse, error) {
Expand All @@ -18,19 +29,32 @@ func Address(address types.Address, height int) (*AddressResponse, error) {
cState.RLock()
defer cState.RUnlock()

balances := cState.Accounts().GetBalances(address)

response := AddressResponse{
Balance: make(map[string]string),
TransactionCount: cState.Accounts.GetNonce(address),
Balance: make([]BalanceItem, len(balances)),
TransactionCount: cState.Accounts().GetNonce(address),
}

balances := cState.Accounts.GetBalances(address)

for k, v := range balances {
response.Balance[k.String()] = v.String()
isBaseCoinExists := false
for k, b := range balances {
response.Balance[k] = BalanceItem{
CoinID: b.Coin.ID.Uint32(),
Symbol: b.Coin.GetFullSymbol(),
Value: b.Value.String(),
}

if b.Coin.ID.IsBaseCoin() {
isBaseCoinExists = true
}
}

if _, exists := response.Balance[types.GetBaseCoin().String()]; !exists {
response.Balance[types.GetBaseCoin().String()] = "0"
if !isBaseCoinExists {
response.Balance = append(response.Balance, BalanceItem{
CoinID: types.GetBaseCoinID().Uint32(),
Symbol: types.GetBaseCoin().String(),
Value: "0",
})
}

return &response, nil
Expand Down
34 changes: 24 additions & 10 deletions api/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
)

type AddressesResponse struct {
Address string `json:"address"`
Balance map[string]string `json:"balance"`
TransactionCount uint64 `json:"transaction_count"`
Address string `json:"address"`
Balance []BalanceItem `json:"balance"`
TransactionCount uint64 `json:"transaction_count"`
}

func Addresses(addresses []types.Address, height int) (*[]AddressesResponse, error) {
Expand All @@ -22,19 +22,33 @@ func Addresses(addresses []types.Address, height int) (*[]AddressesResponse, err
response := make([]AddressesResponse, len(addresses))

for i, address := range addresses {
balances := cState.Accounts().GetBalances(address)

data := AddressesResponse{
Address: address.String(),
Balance: make(map[string]string),
TransactionCount: cState.Accounts.GetNonce(address),
Balance: make([]BalanceItem, len(balances)),
TransactionCount: cState.Accounts().GetNonce(address),
}

balances := cState.Accounts.GetBalances(address)
for k, v := range balances {
data.Balance[k.String()] = v.String()
isBaseCoinExists := false
for k, b := range balances {
data.Balance[k] = BalanceItem{
CoinID: b.Coin.ID.Uint32(),
Symbol: b.Coin.GetFullSymbol(),
Value: b.Value.String(),
}

if b.Coin.ID.IsBaseCoin() {
isBaseCoinExists = true
}
}

if _, exists := data.Balance[types.GetBaseCoin().String()]; !exists {
data.Balance[types.GetBaseCoin().String()] = "0"
if !isBaseCoinExists {
data.Balance = append(data.Balance, BalanceItem{
CoinID: types.GetBaseCoinID().Uint32(),
Symbol: types.GetBaseCoin().String(),
Value: "0",
})
}

response[i] = data
Expand Down
54 changes: 10 additions & 44 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@ package api

import (
"fmt"
eventsdb "github.com/MinterTeam/events-db"
"github.com/MinterTeam/minter-go-node/config"
"github.com/MinterTeam/minter-go-node/core/minter"
"github.com/MinterTeam/minter-go-node/core/state"
"github.com/MinterTeam/minter-go-node/rpc/lib/server"
"github.com/rs/cors"
"github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/multisig"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/tendermint/tendermint/evidence"
"github.com/tendermint/tendermint/libs/log"
rpc "github.com/tendermint/tendermint/rpc/client"
"github.com/tendermint/tendermint/types"
rpc "github.com/tendermint/tendermint/rpc/client/local"
"net/http"
"net/url"
"strings"
Expand All @@ -34,7 +27,7 @@ var Routes = map[string]*rpcserver.RPCFunc{
"status": rpcserver.NewRPCFunc(Status, ""),
"candidates": rpcserver.NewRPCFunc(Candidates, "height,include_stakes"),
"candidate": rpcserver.NewRPCFunc(Candidate, "pub_key,height"),
"validators": rpcserver.NewRPCFunc(Validators, "height,page,perPage"),
"validators": rpcserver.NewRPCFunc(Validators, "height"),
"address": rpcserver.NewRPCFunc(Address, "address,height"),
"addresses": rpcserver.NewRPCFunc(Addresses, "addresses,height"),
"send_transaction": rpcserver.NewRPCFunc(SendTransaction, "tx"),
Expand All @@ -43,34 +36,33 @@ var Routes = map[string]*rpcserver.RPCFunc{
"block": rpcserver.NewRPCFunc(Block, "height"),
"events": rpcserver.NewRPCFunc(Events, "height"),
"net_info": rpcserver.NewRPCFunc(NetInfo, ""),
"coin_info": rpcserver.NewRPCFunc(CoinInfo, "symbol,height"),
"coin_info": rpcserver.NewRPCFunc(CoinInfo, "symbol,id,height"),
"estimate_coin_sell": rpcserver.NewRPCFunc(EstimateCoinSell, "coin_to_sell,coin_to_buy,value_to_sell,height"),
"estimate_coin_sell_all": rpcserver.NewRPCFunc(EstimateCoinSellAll, "coin_to_sell,coin_to_buy,value_to_sell,gas_price,height"),
"estimate_coin_sell_all": rpcserver.NewRPCFunc(EstimateCoinSellAll, "coin_to_sell,coin_to_buy,value_to_sell,height"),
"estimate_coin_buy": rpcserver.NewRPCFunc(EstimateCoinBuy, "coin_to_sell,coin_to_buy,value_to_buy,height"),
"estimate_tx_commission": rpcserver.NewRPCFunc(EstimateTxCommission, "tx,height"),
"unconfirmed_txs": rpcserver.NewRPCFunc(UnconfirmedTxs, "limit"),
"max_gas": rpcserver.NewRPCFunc(MaxGas, "height"),
"min_gas_price": rpcserver.NewRPCFunc(MinGasPrice, ""),
"genesis": rpcserver.NewRPCFunc(Genesis, ""),
"missed_blocks": rpcserver.NewRPCFunc(MissedBlocks, "pub_key,height"),
"waitlist": rpcserver.NewRPCFunc(Waitlist, "pub_key,address,height"),
}

func responseTime(b *minter.Blockchain) func(f func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) {
return func(f func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
f(w, r)
go b.StatisticData().SetApiTime(time.Now().Sub(start), r.URL.Path)
go b.StatisticData().SetApiTime(time.Since(start), r.URL.Path)
}
}
}

func RunAPI(b *minter.Blockchain, tmRPC *rpc.Local, cfg *config.Config, logger log.Logger) {
// RunAPI start
func RunAPI(codec *amino.Codec, b *minter.Blockchain, tmRPC *rpc.Local, cfg *config.Config, logger log.Logger) {
cdc = codec
minterCfg = cfg
RegisterCryptoAmino(cdc)
eventsdb.RegisterAminoEvents(cdc)
RegisterEvidenceMessages(cdc)

client = tmRPC
blockchain = b
waitForTendermint()
Expand Down Expand Up @@ -138,7 +130,7 @@ type Response struct {
Log string `json:"log,omitempty"`
}

func GetStateForHeight(height int) (*state.State, error) {
func GetStateForHeight(height int) (*state.CheckState, error) {
if height > 0 {
cState, err := blockchain.GetStateForHeight(uint64(height))

Expand All @@ -147,29 +139,3 @@ func GetStateForHeight(height int) (*state.State, error) {

return blockchain.CurrentState(), nil
}

// RegisterAmino registers all crypto related types in the given (amino) codec.
func RegisterCryptoAmino(cdc *amino.Codec) {
// These are all written here instead of
cdc.RegisterInterface((*crypto.PubKey)(nil), nil)
cdc.RegisterConcrete(ed25519.PubKeyEd25519{},
ed25519.PubKeyAminoName, nil)
cdc.RegisterConcrete(secp256k1.PubKeySecp256k1{},
secp256k1.PubKeyAminoName, nil)
cdc.RegisterConcrete(multisig.PubKeyMultisigThreshold{},
multisig.PubKeyMultisigThresholdAminoRoute, nil)

cdc.RegisterInterface((*crypto.PrivKey)(nil), nil)
cdc.RegisterConcrete(ed25519.PrivKeyEd25519{},
ed25519.PrivKeyAminoName, nil)
cdc.RegisterConcrete(secp256k1.PrivKeySecp256k1{},
secp256k1.PrivKeyAminoName, nil)
}

func RegisterEvidenceMessages(cdc *amino.Codec) {
cdc.RegisterInterface((*evidence.Message)(nil), nil)
cdc.RegisterConcrete(&evidence.ListMessage{},
"tendermint/evidence/EvidenceListMessage", nil)
cdc.RegisterInterface((*types.Evidence)(nil), nil)
cdc.RegisterConcrete(&types.DuplicateVoteEvidence{}, "tendermint/DuplicateVoteEvidence", nil)
}
26 changes: 16 additions & 10 deletions api/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"time"

"github.com/MinterTeam/minter-go-node/core/rewards"
"github.com/MinterTeam/minter-go-node/core/transaction"
"github.com/MinterTeam/minter-go-node/core/transaction/encoder"
"github.com/MinterTeam/minter-go-node/core/types"
"github.com/MinterTeam/minter-go-node/rpc/lib/types"
rpctypes "github.com/MinterTeam/minter-go-node/rpc/lib/types"
core_types "github.com/tendermint/tendermint/rpc/core/types"
tmTypes "github.com/tendermint/tendermint/types"
"time"
)

type BlockResponse struct {
Expand Down Expand Up @@ -65,14 +67,18 @@ func Block(height int64) (*BlockResponse, error) {
valHeight = 1
}

var totalValidators []*tmTypes.Validator
for i := 0; i < (((len(block.Block.LastCommit.Signatures) - 1) / 100) + 1); i++ {
tmValidators, err := client.Validators(&valHeight, i+1, 100)
if err != nil {
return nil, rpctypes.RPCError{Code: 500, Message: err.Error()}
}
totalValidators = append(totalValidators, tmValidators.Validators...)
tmValidators, err := client.Validators(&valHeight, 1, 100)
if err != nil {
return nil, rpctypes.RPCError{Code: 500, Message: err.Error()}
}
totalValidators := tmValidators.Validators

cState, err := GetStateForHeight(0)
if err != nil {
return nil, err
}

txJsonEncoder := encoder.NewTxEncoderJSON(cState)

txs := make([]BlockTransactionResponse, len(block.Block.Data.Txs))
for i, rawTx := range block.Block.Data.Txs {
Expand All @@ -88,7 +94,7 @@ func Block(height int64) (*BlockResponse, error) {
tags[string(tag.Key)] = string(tag.Value)
}

data, err := encodeTxData(tx)
data, err := txJsonEncoder.EncodeData(tx)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 2e6614d

Please sign in to comment.