Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.4.x #796

Open
wants to merge 51 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
43f4f18
Merge pull request #789 from MinterTeam/dev
Apr 18, 2022
de768df
Merge pull request #792 from MinterTeam/dev
Apr 27, 2022
235a4a2
Merge pull request #794 from MinterTeam/dev
Apr 29, 2022
3baae6a
optimization bestTrade
May 2, 2022
ce1b9b8
update sync peers
May 7, 2022
85a796e
update sync peers
May 7, 2022
70b8d45
waitlists
May 11, 2022
49a8ae3
testnet fix
May 13, 2022
abb86e1
tx tags
May 16, 2022
46c5905
testnet
May 16, 2022
7bb33c5
version
May 16, 2022
5247d99
Subscribe
May 16, 2022
bb042fe
load_last_events cmd
May 20, 2022
38328ce
only-api-mode
May 20, 2022
43555c7
only-api-mode
May 20, 2022
0ff550e
only-api-mode
May 20, 2022
6b2cd56
fix deletedCandidates
May 21, 2022
8ff9f94
fix emission
May 21, 2022
469adce
fix emission
May 21, 2022
b18196b
update
May 21, 2022
42fd2a8
fix message sell MinimumValueToBuyReached error
May 24, 2022
ba0f324
wip: tests
May 30, 2022
eba7cac
wip: tests
May 31, 2022
d1ad22d
wip: tests
May 31, 2022
3c1f886
wip: test balance
Jun 2, 2022
e9b080f
wip: test validators
Jun 2, 2022
6f209da
add net message for edit archived tokens
Jun 2, 2022
e84ae58
fix x3 rewards and tests
Jun 2, 2022
73d225f
update version and CHANGELOG.md
Jun 2, 2022
32bccc2
update gateway
Jun 2, 2022
6dd2b5b
update old tests
Jun 3, 2022
1edb55f
update old tests
Jun 3, 2022
b648658
refactor for ChainTestnet and filter for invalidIDCandidate
Jun 3, 2022
9901403
backward compatibility
Jun 7, 2022
41fd221
remove account coins mutex
Jun 12, 2022
e23580e
remove account coins mutex
Jun 13, 2022
acd364e
fix rwmu
Jul 5, 2022
03b5fd5
fix rwmu
Jul 5, 2022
2f67886
add todo
Jul 12, 2022
85e3d66
fix rw mutex
Jul 23, 2022
8f4cbf3
add endpoint changeSwapPoolAmountsForPrice
Jul 23, 2022
889edd5
mark v340 as beta
Jul 23, 2022
f976d80
fix Transaction endpoint response 404
Jul 23, 2022
3a76eda
update docs
Jul 23, 2022
8b0e9a5
update docs^ add endpoint LimitOrdersByOwner
Jul 23, 2022
2932fc6
refactor
Jul 23, 2022
87ede60
refactor
Jul 23, 2022
408e5ac
endpoint GetOrdersAll
Jul 24, 2022
c26b9db
refactor
Jul 24, 2022
3e2218f
fix estimate_coin_sell_all with route
Sep 8, 2022
e81dc31
enable V340
Sep 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

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

[Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v3.3.0...v3.4.0)

### Added

- API methods: `waitlist_all`, `limit_orders_by_owner`
- Indexed tags to search for transactions by order
- Starting a node without processing new states with tag `--only-api-mode`

### Fixed

- API Balance deadlock
- Calculation of x3 rewards

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

[Full Changelog](https://github.com/MinterTeam/minter-go-node/compare/v3.2.0...v3.3.0)
Expand Down
248 changes: 128 additions & 120 deletions api/v2/service/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,126 +82,8 @@ func (s *Service) Block(ctx context.Context, req *pb.BlockRequest) (*pb.BlockRes
if req.Events {
loadEvents := s.blockchain.GetEventsDB().LoadEvents(uint32(req.Height))
for _, event := range loadEvents {
var m proto.Message
switch e := event.(type) {
case *events.JailEvent:
m = &pb.JailEvent{
ValidatorPubKey: e.ValidatorPubKeyString(),
JailedUntil: e.JailedUntil,
}
case *events.OrderExpiredEvent:
m = &pb.OrderExpiredEvent{
Id: e.ID,
Address: e.AddressString(),
Coin: e.Coin,
Amount: e.Amount,
}
case *events.RewardEvent:
m = &pb.RewardEvent{
Role: pb.RewardEvent_Role(pb.RewardEvent_Role_value[e.Role]),
Address: e.AddressString(),
Amount: e.Amount,
ForCoin: e.ForCoin,
ValidatorPubKey: e.ValidatorPubKeyString(),
}
case *events.SlashEvent:
m = &pb.SlashEvent{
Address: e.AddressString(),
Amount: e.Amount,
Coin: e.Coin,
ValidatorPubKey: e.ValidatorPubKeyString(),
}
case *events.StakeKickEvent:
m = &pb.StakeKickEvent{
Address: e.AddressString(),
Amount: e.Amount,
Coin: e.Coin,
ValidatorPubKey: e.ValidatorPubKeyString(),
}
case *events.UnbondEvent:
m = &pb.UnbondEvent{
Address: e.AddressString(),
Amount: e.Amount,
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(),
}
case *events.UpdateNetworkEvent:
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,
PayloadByte: e.PayloadByte,
Send: e.Send,
BuyBancor: e.BuyBancor,
SellBancor: e.SellBancor,
SellAllBancor: e.SellAllBancor,
BuyPoolBase: e.BuyPoolBase,
BuyPoolDelta: e.BuyPoolDelta,
SellPoolBase: e.SellPoolBase,
SellPoolDelta: e.SellPoolDelta,
SellAllPoolBase: e.SellAllPoolBase,
SellAllPoolDelta: e.SellAllPoolDelta,
CreateTicker3: e.CreateTicker3,
CreateTicker4: e.CreateTicker4,
CreateTicker5: e.CreateTicker5,
CreateTicker6: e.CreateTicker6,
CreateTicker7_10: e.CreateTicker7_10,
CreateCoin: e.CreateCoin,
CreateToken: e.CreateToken,
RecreateCoin: e.RecreateCoin,
RecreateToken: e.RecreateToken,
DeclareCandidacy: e.DeclareCandidacy,
Delegate: e.Delegate,
Unbond: e.Unbond,
RedeemCheck: e.RedeemCheck,
SetCandidateOn: e.SetCandidateOn,
SetCandidateOff: e.SetCandidateOff,
CreateMultisig: e.CreateMultisig,
MultisendBase: e.MultisendBase,
MultisendDelta: e.MultisendDelta,
EditCandidate: e.EditCandidate,
SetHaltBlock: e.SetHaltBlock,
EditTickerOwner: e.EditTickerOwner,
EditMultisig: e.EditMultisig,
EditCandidatePublicKey: e.EditCandidatePublicKey,
CreateSwapPool: e.CreateSwapPool,
AddLiquidity: e.AddLiquidity,
RemoveLiquidity: e.RemoveLiquidity,
EditCandidateCommission: e.EditCandidateCommission,
MintToken: e.MintToken,
BurnToken: e.BurnToken,
VoteCommission: e.VoteCommission,
VoteUpdate: e.VoteUpdate,
FailedTx: e.FailedTx,
AddLimitOrder: e.AddLimitOrder,
RemoveLimitOrder: e.RemoveLimitOrder,
}
default:
m := DecodeEvent(event)
if m == nil {
return nil, status.Error(codes.Internal, "unknown event type")
}

Expand Down Expand Up @@ -258,6 +140,132 @@ func (s *Service) Block(ctx context.Context, req *pb.BlockRequest) (*pb.BlockRes
return response, nil
}

func DecodeEvent(event events.Event) proto.Message {
var m proto.Message
switch e := event.(type) {
case *events.JailEvent:
m = &pb.JailEvent{
ValidatorPubKey: e.ValidatorPubKeyString(),
JailedUntil: e.JailedUntil,
}
case *events.OrderExpiredEvent:
m = &pb.OrderExpiredEvent{
Id: e.ID,
Address: e.AddressString(),
Coin: e.Coin,
Amount: e.Amount,
}
case *events.RewardEvent:
m = &pb.RewardEvent{
Role: pb.RewardEvent_Role(pb.RewardEvent_Role_value[e.Role]),
Address: e.AddressString(),
Amount: e.Amount,
ForCoin: e.ForCoin,
ValidatorPubKey: e.ValidatorPubKeyString(),
}
case *events.SlashEvent:
m = &pb.SlashEvent{
Address: e.AddressString(),
Amount: e.Amount,
Coin: e.Coin,
ValidatorPubKey: e.ValidatorPubKeyString(),
}
case *events.StakeKickEvent:
m = &pb.StakeKickEvent{
Address: e.AddressString(),
Amount: e.Amount,
Coin: e.Coin,
ValidatorPubKey: e.ValidatorPubKeyString(),
}
case *events.UnbondEvent:
m = &pb.UnbondEvent{
Address: e.AddressString(),
Amount: e.Amount,
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(),
}
case *events.UpdateNetworkEvent:
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,
PayloadByte: e.PayloadByte,
Send: e.Send,
BuyBancor: e.BuyBancor,
SellBancor: e.SellBancor,
SellAllBancor: e.SellAllBancor,
BuyPoolBase: e.BuyPoolBase,
BuyPoolDelta: e.BuyPoolDelta,
SellPoolBase: e.SellPoolBase,
SellPoolDelta: e.SellPoolDelta,
SellAllPoolBase: e.SellAllPoolBase,
SellAllPoolDelta: e.SellAllPoolDelta,
CreateTicker3: e.CreateTicker3,
CreateTicker4: e.CreateTicker4,
CreateTicker5: e.CreateTicker5,
CreateTicker6: e.CreateTicker6,
CreateTicker7_10: e.CreateTicker7_10,
CreateCoin: e.CreateCoin,
CreateToken: e.CreateToken,
RecreateCoin: e.RecreateCoin,
RecreateToken: e.RecreateToken,
DeclareCandidacy: e.DeclareCandidacy,
Delegate: e.Delegate,
Unbond: e.Unbond,
RedeemCheck: e.RedeemCheck,
SetCandidateOn: e.SetCandidateOn,
SetCandidateOff: e.SetCandidateOff,
CreateMultisig: e.CreateMultisig,
MultisendBase: e.MultisendBase,
MultisendDelta: e.MultisendDelta,
EditCandidate: e.EditCandidate,
SetHaltBlock: e.SetHaltBlock,
EditTickerOwner: e.EditTickerOwner,
EditMultisig: e.EditMultisig,
EditCandidatePublicKey: e.EditCandidatePublicKey,
CreateSwapPool: e.CreateSwapPool,
AddLiquidity: e.AddLiquidity,
RemoveLiquidity: e.RemoveLiquidity,
EditCandidateCommission: e.EditCandidateCommission,
MintToken: e.MintToken,
BurnToken: e.BurnToken,
VoteCommission: e.VoteCommission,
VoteUpdate: e.VoteUpdate,
FailedTx: e.FailedTx,
AddLimitOrder: e.AddLimitOrder,
RemoveLimitOrder: e.RemoveLimitOrder,
}
default:
return nil
}
return m
}

func blockEvidence(block *core_types.ResultBlock) (*pb.BlockResponse_Evidence, error) {
evidences := make([]*_struct.Struct, 0, len(block.Block.Evidence.Evidence))
for _, evidence := range block.Block.Evidence.Evidence {
Expand Down
11 changes: 11 additions & 0 deletions api/v2/service/candidates.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ func (s *Service) Candidates(ctx context.Context, req *pb.CandidatesRequest) (*p
candidates := cState.Candidates().GetCandidates()

response := &pb.CandidatesResponse{}
if req.Status == pb.CandidatesRequest_all || req.Status == pb.CandidatesRequest_deleted {
for _, dc := range cState.Candidates().DeletedCandidates() {
response.Deleted = append(response.Deleted, &pb.CandidatesResponse_Deleted{
Id: uint64(dc.ID),
PublicKey: dc.PubKey.String(),
})
}
}
if req.Status == pb.CandidatesRequest_deleted {
return response, nil
}
for _, candidate := range candidates {

if timeoutStatus := s.checkTimeout(ctx); timeoutStatus != nil {
Expand Down
57 changes: 57 additions & 0 deletions api/v2/service/custom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package service

import (
"math/big"
"net/http"
"strconv"

"github.com/MinterTeam/minter-go-node/coreV2/types"
"github.com/gin-gonic/gin"
)

func (s *Service) changeAmountsForPrice(c *gin.Context) {
coin0S := c.Param("coin0")
coin1S := c.Param("coin1")
priceS := c.Param("price")
coin0I, err := strconv.Atoi(coin0S)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"error": map[string]string{
"message": err.Error(),
},
})
return
}
coin1I, err := strconv.Atoi(coin1S)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"error": map[string]string{
"message": err.Error(),
},
})
return
}
priceF, err := strconv.ParseFloat(priceS, 10)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"error": map[string]string{
"message": err.Error(),
},
})
return
}
amount0, amount1 := s.blockchain.CurrentState().Swap().GetSwapper(types.CoinID(coin0I), types.CoinID(coin1I)).CalculateAddAmountsForPrice(big.NewFloat(1 / priceF))
c.JSON(200, gin.H{
"amount0In": amount0,
"amount1Out": amount1,
// todo: reverse price if amounts nil
})
}

// CustomHandlers return custom http methods
func (s *Service) CustomHandlers() http.Handler {
gin.SetMode(gin.ReleaseMode)
r := gin.Default()
r.GET("/change_amounts_for_price/:coin0/:coin1/:price", s.changeAmountsForPrice)
return r
}
2 changes: 1 addition & 1 deletion api/v2/service/estimate_coin_sell_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (s *Service) EstimateCoinSellAll(ctx context.Context, req *pb.EstimateCoinS
valueBancor, errBancor = s.calcSellAllFromBancor(valueToSell, coinTo, coinFrom, commissionInBaseCoin)
}
if req.SwapFrom == pb.SwapFrom_pool || req.SwapFrom == pb.SwapFrom_optimal {
commissionInBaseCoin := new(big.Int).Set(commissions.SellAllPoolBase)
commissionInBaseCoin := new(big.Int).Add(commissions.SellAllPoolBase, new(big.Int).Mul(commissions.SellAllPoolDelta, big.NewInt(int64(len(req.Route)))))
if !commissions.Coin.IsBaseCoin() {
commissionInBaseCoin, _ = cState.Swap().GetSwapper(types.GetBaseCoinID(), commissions.Coin).CalculateSellForBuyWithOrders(commissionInBaseCoin)
}
Expand Down
3 changes: 2 additions & 1 deletion api/v2/service/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func (s *Service) Subscribe(request *pb.SubscribeRequest, stream pb.ApiService_S
}
}()

ctxSubscribeConnection, _ := context.WithTimeout(stream.Context(), s.minterCfg.WSConnectionDuration)
ctxSubscribeConnection, cancel2 := context.WithTimeout(stream.Context(), s.minterCfg.WSConnectionDuration)
defer cancel2()

for {
select {
Expand Down
Loading