Skip to content

Commit

Permalink
Merge pull request #766 from MinterTeam/dev
Browse files Browse the repository at this point in the history
v3
  • Loading branch information
danil-lashin authored Apr 6, 2022
2 parents 38a6ddb + 5548517 commit 4761e73
Show file tree
Hide file tree
Showing 155 changed files with 9,416 additions and 809 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
asset_name: darwin_amd64
steps:

- name: Set up Go 1.16
- name: Set up Go 1.18
uses: actions/setup-go@v2
with:
go-version: ^1.16
go-version: ^1.18

- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand All @@ -39,7 +39,7 @@ jobs:
- name: Packaging in zip archive
run: |
zip -j "./assets/minter_${{ steps.get-version.outputs.VERSION }}_${{ steps.get-version.outputs.GIT_COMMIT }}_${{ matrix.asset_name }}.zip" ./build/minter
shasum -a256 ./assets/minter_${{ steps.get-version.outputs.VERSION }}_${{ steps.get-version.outputs.GIT_COMMIT }}_${{ matrix.asset_name }}.zip > "./assets/minter_${{ steps.get-version.outputs.VERSION }}_${{ steps.get-version.outputs.GIT_COMMIT }}_${{ matrix.asset_name }}_SHA256SUMS"
shasum -a256 ./assets/minter_${{ steps.get-version.outputs.VERSION }}_${{ steps.get-version.outputs.GIT_COMMIT }}_${{ matrix.asset_name }}.zip > "./assets/minter_${{ steps.get-version.outputs.VERSION }}_${{ steps.get-version.outputs.GIT_COMMIT }}_${{ matrix.asset_name }}_SHA256SUMS.txt"
- name: Upload binary to release
uses: svenstaro/upload-release-action@v2
Expand All @@ -54,7 +54,7 @@ jobs:
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./assets/minter_${{ steps.get-version.outputs.VERSION }}_${{ steps.get-version.outputs.GIT_COMMIT }}_${{ matrix.asset_name }}_SHA256SUMS
file: ./assets/minter_${{ steps.get-version.outputs.VERSION }}_${{ steps.get-version.outputs.GIT_COMMIT }}_${{ matrix.asset_name }}_SHA256SUMS.txt
tag: ${{ github.ref }}
file_glob: true
overwrite: true
4 changes: 2 additions & 2 deletions .github/workflows/taconet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
name: Build & Deploy
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.16
- name: Set up Go 1.18
uses: actions/setup-go@v2
with:
go-version: ^1.16
go-version: ^1.18

- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.17'
go-version: '1.18'
- run: go mod tidy && go build ./...
- name: Test
run: go test -cover ./...
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## [v3.0.0](https://github.com/MinterTeam/minter-go-node/tree/v3.0.0)

[Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v2.6.1...v3.0.0)

### Added

- Dynamic Mining
- Auto-Redelegation
- Burning by Balancer
- Burning of Ticker Fees
- BIP Buyback
- 3-Year BIP Lock
- Stake Transfer

### Fixed

- Limit order caching error

## [v2.6.1](https://github.com/MinterTeam/minter-go-node/tree/v2.6.1)

[Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v2.6.0...v2.6.1)
Expand Down
1 change: 1 addition & 0 deletions api/v2/service/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func (s *Service) Address(ctx context.Context, req *pb.AddressRequest) (*pb.Addr
res.TransactionCount = cState.Accounts().GetNonce(address)

res.Multisig = s.getMultisig(cState.Accounts().GetAccount(address))
res.LockedStakeUntilBlock = cState.Accounts().GetLockStakeUntilBlock(address)

return &res, nil
}
Expand Down
1 change: 1 addition & 0 deletions api/v2/service/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func (s *Service) Addresses(ctx context.Context, req *pb.AddressesRequest) (*pb.
res.BipValue = coinsBipValue.String()
res.TransactionCount = cState.Accounts().GetNonce(address)
res.Multisig = s.getMultisig(cState.Accounts().GetAccount(address))
res.LockedStakeUntilBlock = cState.Accounts().GetLockStakeUntilBlock(address)
response.Addresses[addr] = &res
}

Expand Down
37 changes: 36 additions & 1 deletion api/v2/service/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"context"
"encoding/hex"
"fmt"
"github.com/MinterTeam/minter-go-node/coreV2/minter"
"google.golang.org/protobuf/types/known/wrapperspb"
"math/big"
"strings"
"time"

Expand Down Expand Up @@ -122,6 +125,20 @@ func (s *Service) Block(ctx context.Context, req *pb.BlockRequest) (*pb.BlockRes
Coin: e.Coin,
ValidatorPubKey: e.ValidatorPubKeyString(),
}
case *events.UnlockEvent:
m = &pb.UnlockEvent{
Address: e.AddressString(),
Amount: e.Amount,
Coin: e.Coin,
}
case *events.StakeMoveEvent:
m = &pb.StakeMoveEvent{
Address: e.AddressString(),
Amount: e.Amount,
Coin: e.Coin,
CandidatePubKey: e.CandidatePubKey.String(),
ToCandidatePubKey: e.ToCandidatePubKey.String(),
}
case *events.RemoveCandidateEvent:
m = &pb.RemoveCandidateEvent{
CandidatePubKey: e.CandidatePubKeyString(),
Expand All @@ -130,6 +147,11 @@ func (s *Service) Block(ctx context.Context, req *pb.BlockRequest) (*pb.BlockRes
m = &pb.UpdateNetworkEvent{
Version: e.Version,
}
case *events.UpdatedBlockRewardEvent:
m = &pb.UpdatedBlockRewardEvent{
Value: e.Value,
ValueLockedStakeRewards: e.ValueLockedStakeRewards,
}
case *events.UpdateCommissionsEvent:
m = &pb.UpdateCommissionsEvent{
Coin: e.Coin,
Expand Down Expand Up @@ -199,7 +221,20 @@ func (s *Service) Block(ctx context.Context, req *pb.BlockRequest) (*pb.BlockRes
case pb.BlockField_size:
response.Size = uint64(block.Block.Size())
case pb.BlockField_block_reward:
response.BlockReward = s.rewards.GetRewardForBlock(uint64(height)).String()
if h := s.blockchain.GetVersionHeight(minter.V3); req.Height < h {
response.BlockReward = wrapperspb.String(s.rewards.GetRewardForBlock(uint64(height)).String())
continue
}

state, err := s.blockchain.GetStateForHeight(req.Height)
if err != nil { // is ok
//return nil, status.Error(codes.NotFound, err.Error())
continue
}

reward, rewardWithLock := state.App().Reward()
response.BlockReward = wrapperspb.String(reward.String())
response.LockedStakeRewards = wrapperspb.String(new(big.Int).Mul(rewardWithLock, big.NewInt(3)).String())
case pb.BlockField_transactions:
response.Transactions, err = s.blockTransaction(block, blockResults, s.blockchain.CurrentState().Coins(), req.FailedTxs)
if err != nil {
Expand Down
33 changes: 30 additions & 3 deletions api/v2/service/data_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func encode(data transaction.Data, txType transaction.TxType, rCoins coins.RCoin
PubKey: d.PubKey.String(),
}
case transaction.TypeUnbond:
d := data.(*transaction.UnbondDataV260)
d := data.(*transaction.UnbondDataV3)
m = &pb.UnbondData{
PubKey: d.PubKey.String(),
Coin: &pb.Coin{
Expand Down Expand Up @@ -323,7 +323,7 @@ func encode(data transaction.Data, txType transaction.TxType, rCoins coins.RCoin
Commission: uint64(d.Commission),
}
case transaction.TypeVoteCommission:
d := data.(*transaction.VoteCommissionDataV250)
d := data.(*transaction.VoteCommissionDataV3)
m = priceCommissionData(d, rCoins.GetCoin(d.Coin))
case transaction.TypeVoteUpdate:
d := data.(*transaction.VoteUpdateDataV230)
Expand Down Expand Up @@ -365,6 +365,30 @@ func encode(data transaction.Data, txType transaction.TxType, rCoins coins.RCoin
m = &pb.RemoveLimitOrderData{
Id: uint64(d.ID),
}
case transaction.TypeMoveStake:
d := data.(*transaction.MoveStakeData)
m = &pb.MoveStakeData{
FromPubKey: d.FromPubKey.String(),
ToPubKey: d.ToPubKey.String(),
Coin: &pb.Coin{
Id: uint64(d.Coin),
Symbol: rCoins.GetCoin(d.Coin).GetFullSymbol(),
},
Value: d.Value.String(),
}
case transaction.TypeLockStake:
//d := data.(*transaction.LockStakeData)
m = &pb.LockStakeData{}
case transaction.TypeLock:
d := data.(*transaction.LockData)
m = &pb.LockData{
DueBlock: uint64(d.DueBlock),
Coin: &pb.Coin{
Id: uint64(d.Coin),
Symbol: rCoins.GetCoin(d.Coin).GetFullSymbol(),
},
Value: d.Value.String(),
}
default:
return nil, errors.New("unknown tx type")
}
Expand All @@ -377,7 +401,7 @@ func encode(data transaction.Data, txType transaction.TxType, rCoins coins.RCoin
return a, nil
}

func priceCommissionData(d *transaction.VoteCommissionDataV250, coin *coins.Model) proto.Message {
func priceCommissionData(d *transaction.VoteCommissionDataV3, coin *coins.Model) proto.Message {
return &pb.VoteCommissionData{
PubKey: d.PubKey.String(),
Height: d.Height,
Expand Down Expand Up @@ -430,6 +454,9 @@ func priceCommissionData(d *transaction.VoteCommissionDataV250, coin *coins.Mode
FailedTx: d.FailedTxPrice().String(),
AddLimitOrder: d.AddLimitOrderPrice().String(),
RemoveLimitOrder: d.RemoveLimitOrderPrice().String(),
MoveStake: d.MoveStakePrice().String(),
LockStake: d.LockStakePrice().String(),
Lock: d.LockPrice().String(),
}
}

Expand Down
20 changes: 11 additions & 9 deletions api/v2/service/estimate_coin_buy.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ func (s *Service) EstimateCoinBuy(ctx context.Context, req *pb.EstimateCoinBuyRe
var resultCommission *big.Int
swapFrom := req.SwapFrom

reverseCoinIds(req.Route)
route := req.Route
reverseCoinIds(route)

switch req.SwapFrom {
case pb.SwapFrom_bancor:
Expand All @@ -105,15 +106,15 @@ func (s *Service) EstimateCoinBuy(ctx context.Context, req *pb.EstimateCoinBuyRe
value = valueBancor
resultCommission = commissionBancor
case pb.SwapFrom_pool:
commissionPool, valuePool, err := s.calcBuyPoolWithCommission(ctx, commissions, cState, requestCoinCommissionID, valueToBuy, coinFrom, coinTo, req.Route)
commissionPool, valuePool, err := s.calcBuyPoolWithCommission(ctx, commissions, cState, requestCoinCommissionID, valueToBuy, coinFrom, coinTo, route)
if err != nil {
return nil, err
}
value = valuePool
resultCommission = commissionPool
default:
commissionBancor, valueBancor, errBancor := s.calcBuyBancorWithCommission(commissions, cState, requestCoinCommissionID, coinTo, coinFrom, valueToBuy)
commissionPool, valuePool, errPool := s.calcBuyPoolWithCommission(ctx, commissions, cState, requestCoinCommissionID, valueToBuy, coinFrom, coinTo, req.Route)
commissionPool, valuePool, errPool := s.calcBuyPoolWithCommission(ctx, commissions, cState, requestCoinCommissionID, valueToBuy, coinFrom, coinTo, route)

if valueBancor != nil && valuePool != nil {
if valueBancor.Cmp(valuePool) == 1 {
Expand Down Expand Up @@ -166,10 +167,16 @@ func (s *Service) calcBuyFromPool(ctx context.Context, value *big.Int, cState *s
}

sellCoinID := types.CoinID(sellCoinInt)

coinSell := cState.Coins().GetCoin(sellCoinID)
if coinSell == nil {
return nil, s.createError(status.New(codes.NotFound, "Coin to sell not exists"), transaction.EncodeError(code.NewCoinNotExists("", sellCoinID.String())))
}

swapChecker := cState.Swap().GetSwapper(sellCoinID, buyCoinID)

if !swapChecker.Exists() {
return nil, s.createError(status.New(codes.NotFound, fmt.Sprintf("swap pool between coins %s and %s not exists", coinFrom.GetFullSymbol(), coinBuy.GetFullSymbol())), transaction.EncodeError(code.NewPairNotExists(coinFrom.ID().String(), coinBuy.ID().String())))
return nil, s.createError(status.New(codes.NotFound, fmt.Sprintf("swap pool between coins %s and %s not exists", coinSell.GetFullSymbol(), coinBuy.GetFullSymbol())), transaction.EncodeError(code.NewPairNotExists(sellCoinID.String(), coinBuy.ID().String())))
}

if _, ok := dup[swapChecker.GetID()]; ok {
Expand All @@ -185,11 +192,6 @@ func (s *Service) calcBuyFromPool(ctx context.Context, value *big.Int, cState *s
}
}

coinSell := coinFrom
if sellCoinID != coinSell.ID() {
coinSell = cState.Coins().GetCoin(sellCoinID)
}

errResp, sellValue, _ := transaction.CheckSwap(swapChecker, coinSell, coinBuy, coins.MaxCoinSupply(), buyValue, true)
if errResp != nil {
return nil, s.createError(status.New(codes.FailedPrecondition, errResp.Log), errResp.Info)
Expand Down
7 changes: 4 additions & 3 deletions api/v2/service/estimate_coin_sell.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,11 @@ func (s *Service) calcSellFromPool(ctx context.Context, value *big.Int, cState *
buyCoinID := types.CoinID(buyCoinInt)
swapChecker := cState.Swap().GetSwapper(sellCoinID, buyCoinID)

coinBuy := coinTo
if buyCoinID != coinBuy.ID() {
coinBuy = cState.Coins().GetCoin(buyCoinID)
coinBuy := cState.Coins().GetCoin(buyCoinID)
if coinBuy == nil {
return nil, s.createError(status.New(codes.NotFound, "Coin to sell not exists"), transaction.EncodeError(code.NewCoinNotExists("", buyCoinID.String())))
}

if !swapChecker.Exists() {
return nil, s.createError(status.New(codes.NotFound, fmt.Sprintf("swap pool between coins %s and %s not exists", coinSell.GetFullSymbol(), coinBuy.GetFullSymbol())), transaction.EncodeError(code.NewPairNotExists(coinSell.ID().String(), coinBuy.ID().String())))
}
Expand Down
Loading

0 comments on commit 4761e73

Please sign in to comment.