Skip to content

Commit

Permalink
fix invalid txs resource
Browse files Browse the repository at this point in the history
  • Loading branch information
grkamil committed May 16, 2022
1 parent afa36d5 commit 3ef030e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
20 changes: 17 additions & 3 deletions invalid_transaction/data_resources/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package data_resources
import (
"github.com/MinterTeam/minter-explorer-api/v2/coins"
"github.com/MinterTeam/minter-explorer-api/v2/helpers"
"github.com/MinterTeam/minter-explorer-extender/v2/models"
"github.com/MinterTeam/node-grpc-gateway/api_pb"
)

Expand All @@ -24,13 +25,26 @@ func (Coin) Transform(data *api_pb.Coin) Coin {
type PoolCoin struct {
ID uint64 `json:"id"`
Symbol string `json:"symbol"`
Amount string `json:"amount"`
}

func (PoolCoin) Transform(data *api_pb.Coin, pipAmount string) PoolCoin {
func (PoolCoin) Transform(data *api_pb.Coin) PoolCoin {
return PoolCoin{
ID: data.GetId(),
Symbol: data.GetSymbol(),
Amount: helpers.PipStr2Bip(pipAmount),
}
}


func (PoolCoin) TransformCollection(data []*api_pb.Coin, model models.InvalidTransaction) []PoolCoin {
poolCoins := make([]PoolCoin, len(data))

for i, coin := range data {
// todo: refactor
coinModel, err := coins.GlobalRepository.FindByID(uint(coin.Id))
helpers.CheckErr(err)
coin.Symbol = coinModel.GetSymbol()
poolCoins[i] = new(PoolCoin).Transform(coin)
}

return poolCoins
}
35 changes: 21 additions & 14 deletions invalid_transaction/data_resources/swap_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ package data_resources
import (
"github.com/MinterTeam/minter-explorer-api/v2/helpers"
"github.com/MinterTeam/minter-explorer-api/v2/resource"
"github.com/MinterTeam/minter-explorer-extender/v2/models"
"github.com/MinterTeam/node-grpc-gateway/api_pb"
)

type BuySwapPool struct {
CoinToBuy Coin `json:"coin_to_buy"`
CoinToSell Coin `json:"coin_to_sell"`
ValueToBuy string `json:"value_to_buy"`
MaximumValueToSell string `json:"maximum_value_to_sell"`
Coins []PoolCoin `json:"coins"`
CoinToBuy Coin `json:"coin_to_buy"`
CoinToSell Coin `json:"coin_to_sell"`
ValueToBuy string `json:"value_to_buy"`
MaximumValueToSell string `json:"maximum_value_to_sell"`
}

func (BuySwapPool) Transform(txData resource.ItemInterface, params ...resource.ParamInterface) resource.Interface {
data := txData.(*api_pb.BuySwapPoolData)
data, model := txData.(*api_pb.BuySwapPoolData), params[0].(models.InvalidTransaction)

return BuySwapPool{
Coins: new(PoolCoin).TransformCollection(data.Coins, model),
CoinToBuy: new(Coin).Transform(data.Coins[len(data.Coins)-1]),
CoinToSell: new(Coin).Transform(data.Coins[0]),
ValueToBuy: helpers.PipStr2Bip(data.ValueToBuy),
Expand All @@ -25,10 +28,11 @@ func (BuySwapPool) Transform(txData resource.ItemInterface, params ...resource.P
}

type SellSwapPool struct {
CoinToBuy Coin `json:"coin_to_buy"`
CoinToSell Coin `json:"coin_to_sell"`
ValueToSell string `json:"value_to_sell"`
MinimumValueToBuy string `json:"minimum_value_to_buy"`
Coins []PoolCoin `json:"coins"`
CoinToBuy Coin `json:"coin_to_buy"`
CoinToSell Coin `json:"coin_to_sell"`
ValueToSell string `json:"value_to_sell"`
MinimumValueToBuy string `json:"minimum_value_to_buy"`
}

type LimitOrderData struct {
Expand All @@ -39,9 +43,10 @@ type LimitOrderData struct {
}

func (SellSwapPool) Transform(txData resource.ItemInterface, params ...resource.ParamInterface) resource.Interface {
data := txData.(*api_pb.SellSwapPoolData)
data, model := txData.(*api_pb.SellSwapPoolData), params[0].(models.InvalidTransaction)

return SellSwapPool{
Coins: new(PoolCoin).TransformCollection(data.Coins, model),
CoinToSell: new(Coin).Transform(data.Coins[0]),
CoinToBuy: new(Coin).Transform(data.Coins[len(data.Coins)-1]),
ValueToSell: helpers.PipStr2Bip(data.ValueToSell),
Expand All @@ -50,15 +55,17 @@ func (SellSwapPool) Transform(txData resource.ItemInterface, params ...resource.
}

type SellAllSwapPool struct {
CoinToBuy Coin `json:"coin_to_buy"`
CoinToSell Coin `json:"coin_to_sell"`
MinimumValueToBuy string `json:"minimum_value_to_buy"`
Coins []PoolCoin `json:"coins"`
CoinToBuy Coin `json:"coin_to_buy"`
CoinToSell Coin `json:"coin_to_sell"`
MinimumValueToBuy string `json:"minimum_value_to_buy"`
}

func (SellAllSwapPool) Transform(txData resource.ItemInterface, params ...resource.ParamInterface) resource.Interface {
data := txData.(*api_pb.SellAllSwapPoolData)
data, model := txData.(*api_pb.SellAllSwapPoolData), params[0].(models.InvalidTransaction)

return SellAllSwapPool{
Coins: new(PoolCoin).TransformCollection(data.Coins, model),
CoinToSell: new(Coin).Transform(data.Coins[0]),
CoinToBuy: new(Coin).Transform(data.Coins[len(data.Coins)-1]),
MinimumValueToBuy: helpers.PipStr2Bip(data.MinimumValueToBuy),
Expand Down

0 comments on commit 3ef030e

Please sign in to comment.