Skip to content

Commit

Permalink
MN-439: add new transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
grkamil committed Aug 19, 2020
1 parent d428911 commit caaf81d
Show file tree
Hide file tree
Showing 26 changed files with 447 additions and 89 deletions.
9 changes: 5 additions & 4 deletions balance/resource.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package balance

import (
"github.com/MinterTeam/minter-explorer-api/coins"
"github.com/MinterTeam/minter-explorer-api/helpers"
"github.com/MinterTeam/minter-explorer-api/resource"
"github.com/MinterTeam/minter-explorer-tools/v4/models"
Expand All @@ -9,16 +10,16 @@ import (
)

type Resource struct {
Coin string `json:"coin"`
Amount string `json:"amount"`
BipAmount string `json:"bip_amount"`
Coin resource.Interface `json:"coin"`
Amount string `json:"amount"`
BipAmount string `json:"bip_amount"`
}

func (Resource) Transform(model resource.ItemInterface, params ...resource.ParamInterface) resource.Interface {
balance := model.(models.Balance)

return Resource{
Coin: balance.Coin.Symbol,
Coin: new(coins.IdResource).Transform(*balance.Coin),
Amount: helpers.PipStr2Bip(balance.Value),
BipAmount: helpers.PipStr2Bip(getCoinBalanceInBaseValue(balance).String()),
}
Expand Down
13 changes: 13 additions & 0 deletions coins/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,16 @@ func (Resource) Transform(model resource.ItemInterface, params ...resource.Param
Symbol: coin.Symbol,
}
}

type IdResource struct {
ID uint64 `json:"id"`
Symbol string `json:"symbol"`
}

func (IdResource) Transform(model resource.ItemInterface, params ...resource.ParamInterface) resource.Interface {
coin := model.(models.Coin)
return IdResource{
ID: coin.ID,
Symbol: coin.Symbol,
}
}
5 changes: 3 additions & 2 deletions delegation/resource.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package delegation

import (
"github.com/MinterTeam/minter-explorer-api/coins"
"github.com/MinterTeam/minter-explorer-api/helpers"
"github.com/MinterTeam/minter-explorer-api/resource"
"github.com/MinterTeam/minter-explorer-api/validator"
"github.com/MinterTeam/minter-explorer-tools/v4/models"
)

type Resource struct {
Coin string `json:"coin"`
Coin resource.Interface `json:"coin"`
Value string `json:"value"`
BipValue string `json:"bip_value"`
Validator resource.Interface `json:"validator"`
Expand All @@ -18,7 +19,7 @@ func (resource Resource) Transform(model resource.ItemInterface, params ...resou
stake := model.(models.Stake)

return Resource{
Coin: stake.Coin.Symbol,
Coin: new(coins.IdResource).Transform(*stake.Coin),
Value: helpers.PipStr2Bip(stake.Value),
BipValue: helpers.PipStr2Bip(stake.BipValue),
Validator: new(validator.Resource).Transform(*stake.Validator),
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ go 1.13

require (
github.com/MinterTeam/go-amino v0.14.1 // indirect
github.com/MinterTeam/minter-explorer-tools v1.5.2
github.com/MinterTeam/minter-explorer-tools/v4 v4.1.3
github.com/MinterTeam/minter-explorer-tools/v4 v4.2.3
github.com/MinterTeam/minter-go-node v1.0.5
github.com/MinterTeam/minter-go-sdk v1.1.6
github.com/MinterTeam/minter-go-sdk/v2 v2.0.0-20200818114839-c812cbadacaa
github.com/MinterTeam/node-grpc-gateway v1.1.3-0.20200818113440-fe9f21434b29
github.com/btcsuite/btcd v0.20.1-beta // indirect
github.com/centrifugal/centrifuge-go v0.3.0
github.com/gin-contrib/cors v1.3.0
Expand Down
230 changes: 222 additions & 8 deletions go.sum

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions slash/resource.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package slash

import (
"github.com/MinterTeam/minter-explorer-api/coins"
"github.com/MinterTeam/minter-explorer-api/helpers"
"github.com/MinterTeam/minter-explorer-api/resource"
"github.com/MinterTeam/minter-explorer-api/validator"
Expand All @@ -10,7 +11,7 @@ import (

type Resource struct {
BlockID uint64 `json:"height"`
Coin string `json:"coin"`
Coin resource.Interface `json:"coin"`
Amount string `json:"amount"`
Address string `json:"address"`
Timestamp string `json:"timestamp"`
Expand All @@ -22,7 +23,7 @@ func (Resource) Transform(model resource.ItemInterface, params ...resource.Param

slashResource := Resource{
BlockID: slash.BlockID,
Coin: slash.Coin.Symbol,
Coin: new(coins.IdResource).Transform(*slash.Coin),
Amount: helpers.PipStr2Bip(slash.Amount),
Address: slash.Address.GetAddress(),
Timestamp: slash.Block.CreatedAt.Format(time.RFC3339),
Expand Down
11 changes: 6 additions & 5 deletions stake/resource.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package stake

import (
"github.com/MinterTeam/minter-explorer-api/coins"
"github.com/MinterTeam/minter-explorer-api/helpers"
"github.com/MinterTeam/minter-explorer-api/resource"
"github.com/MinterTeam/minter-explorer-tools/v4/models"
)

type Resource struct {
Coin string `json:"coin"`
Address string `json:"address"`
Value string `json:"value"`
BipValue string `json:"bip_value"`
Coin resource.Interface `json:"coin"`
Address string `json:"address"`
Value string `json:"value"`
BipValue string `json:"bip_value"`
}

func (Resource) Transform(model resource.ItemInterface, params ...resource.ParamInterface) resource.Interface {
stake := model.(models.Stake)

return Resource{
Coin: stake.Coin.Symbol,
Coin: new(coins.IdResource).Transform(*stake.Coin),
Address: stake.OwnerAddress.GetAddress(),
Value: helpers.PipStr2Bip(stake.Value),
BipValue: helpers.PipStr2Bip(stake.BipValue),
Expand Down
11 changes: 6 additions & 5 deletions transaction/data_resources/buy_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@ import (
"github.com/MinterTeam/minter-explorer-api/helpers"
"github.com/MinterTeam/minter-explorer-api/resource"
"github.com/MinterTeam/minter-explorer-tools/v4/models"
"github.com/MinterTeam/node-grpc-gateway/api_pb"
)

type BuyCoin struct {
CoinToBuy string `json:"coin_to_buy"`
CoinToSell string `json:"coin_to_sell"`
CoinToBuy Coin `json:"coin_to_buy"`
CoinToSell Coin `json:"coin_to_sell"`
ValueToBuy string `json:"value_to_buy"`
ValueToSell string `json:"value_to_sell"`
MaximumValueToSell string `json:"maximum_value_to_sell"`
}

func (BuyCoin) Transform(txData resource.ItemInterface, params ...resource.ParamInterface) resource.Interface {
data := txData.(*models.BuyCoinTxData)
data := txData.(*api_pb.BuyCoin)
model := params[0].(models.Transaction)

return BuyCoin{
CoinToBuy: data.CoinToBuy,
CoinToSell: data.CoinToSell,
CoinToBuy: new(Coin).Transform(data.CoinToBuy),
CoinToSell: new(Coin).Transform(data.CoinToSell),
ValueToBuy: helpers.PipStr2Bip(data.ValueToBuy),
ValueToSell: helpers.PipStr2Bip(model.Tags["tx.return"]),
MaximumValueToSell: helpers.PipStr2Bip(data.MaximumValueToSell),
Expand Down
20 changes: 20 additions & 0 deletions transaction/data_resources/change_coin_owner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package data_resources

import (
"github.com/MinterTeam/minter-explorer-api/resource"
"github.com/MinterTeam/node-grpc-gateway/api_pb"
)

type ChangeCoinOwner struct {
Symbol string `json:"symbol"`
NewOwner string `json:"new_owner"`
}

func (ChangeCoinOwner) Transform(txData resource.ItemInterface, params ...resource.ParamInterface) resource.Interface {
data := txData.(*api_pb.ChangeCoinOwnerData)

return ChangeCoinOwner{
Symbol: data.GetSymbol(),
NewOwner: data.GetNewOwner(),
}
}
19 changes: 19 additions & 0 deletions transaction/data_resources/coin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package data_resources

import (
"github.com/MinterTeam/node-grpc-gateway/api_pb"
"strconv"
)

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

func (Coin) Transform(data *api_pb.Coin) Coin {
id, _ := strconv.ParseUint(data.GetId(), 10, 32)
return Coin{
ID: uint32(id),
Symbol: data.GetSymbol(),
}
}
4 changes: 2 additions & 2 deletions transaction/data_resources/create_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package data_resources
import (
"github.com/MinterTeam/minter-explorer-api/helpers"
"github.com/MinterTeam/minter-explorer-api/resource"
"github.com/MinterTeam/minter-explorer-tools/v4/models"
"github.com/MinterTeam/node-grpc-gateway/api_pb"
)

type CreateCoin struct {
Expand All @@ -16,7 +16,7 @@ type CreateCoin struct {
}

func (CreateCoin) Transform(txData resource.ItemInterface, params ...resource.ParamInterface) resource.Interface {
data := txData.(*models.CreateCoinTxData)
data := txData.(*api_pb.CreateCoinData)

return CreateCoin{
Name: data.Name,
Expand Down
3 changes: 2 additions & 1 deletion transaction/data_resources/create_multisig.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/resource"
"github.com/MinterTeam/minter-explorer-tools/v4/models"
"github.com/MinterTeam/node-grpc-gateway/api_pb"
)

type CreateMultisig struct {
Expand All @@ -13,7 +14,7 @@ type CreateMultisig struct {
}

func (CreateMultisig) Transform(txData resource.ItemInterface, params ...resource.ParamInterface) resource.Interface {
data := txData.(*models.CreateMultisigTxData)
data := txData.(*api_pb.CreateMultisigData)
model := params[0].(models.Transaction)

return CreateMultisig{
Expand Down
8 changes: 4 additions & 4 deletions transaction/data_resources/declare_candidacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ package data_resources
import (
"github.com/MinterTeam/minter-explorer-api/helpers"
"github.com/MinterTeam/minter-explorer-api/resource"
"github.com/MinterTeam/minter-explorer-tools/v4/models"
"github.com/MinterTeam/node-grpc-gateway/api_pb"
)

type DeclareCandidacy struct {
Address string `json:"address"`
PubKey string `json:"pub_key"`
Commission string `json:"commission"`
Coin string `json:"coin"`
Coin Coin `json:"coin"`
Stake string `json:"stake"`
}

func (DeclareCandidacy) Transform(txData resource.ItemInterface, params ...resource.ParamInterface) resource.Interface {
data := txData.(*models.DeclareCandidacyTxData)
data := txData.(*api_pb.DeclareCandidacyData)

return DeclareCandidacy{
Address: data.Address,
PubKey: data.PubKey,
Commission: data.Commission,
Coin: data.Coin,
Coin: new(Coin).Transform(data.Coin),
Stake: helpers.PipStr2Bip(data.Stake),
}
}
8 changes: 4 additions & 4 deletions transaction/data_resources/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ package data_resources
import (
"github.com/MinterTeam/minter-explorer-api/helpers"
"github.com/MinterTeam/minter-explorer-api/resource"
"github.com/MinterTeam/minter-explorer-tools/v4/models"
"github.com/MinterTeam/node-grpc-gateway/api_pb"
)

type Delegate struct {
PubKey string `json:"pub_key"`
Coin string `json:"coin"`
Coin Coin `json:"coin"`
Value string `json:"value"`
}

func (Delegate) Transform(txData resource.ItemInterface, params ...resource.ParamInterface) resource.Interface {
data := txData.(*models.DelegateTxData)
data := txData.(*api_pb.DelegateData)

return Delegate{
PubKey: data.PubKey,
Coin: data.Coin,
Coin: new(Coin).Transform(data.Coin),
Value: helpers.PipStr2Bip(data.Value),
}
}
18 changes: 10 additions & 8 deletions transaction/data_resources/edit_candidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ package data_resources

import (
"github.com/MinterTeam/minter-explorer-api/resource"
"github.com/MinterTeam/minter-explorer-tools/v4/models"
"github.com/MinterTeam/node-grpc-gateway/api_pb"
)

type EditCandidate struct {
PubKey string `json:"pub_key"`
RewardAddress string `json:"reward_address"`
OwnerAddress string `json:"owner_address"`
PubKey string `json:"pub_key"`
RewardAddress string `json:"reward_address"`
OwnerAddress string `json:"owner_address"`
ControlAddress string `json:"control_address"`
}

func (EditCandidate) Transform(txData resource.ItemInterface, params ...resource.ParamInterface) resource.Interface {
data := txData.(*models.EditCandidateTxData)
data := txData.(*api_pb.EditCandidateData)

return EditCandidate{
PubKey: data.PubKey,
RewardAddress: data.RewardAddress,
OwnerAddress: data.OwnerAddress,
PubKey: data.PubKey,
RewardAddress: data.RewardAddress,
OwnerAddress: data.OwnerAddress,
ControlAddress: data.ControlAddress,
}
}
25 changes: 25 additions & 0 deletions transaction/data_resources/edit_multisig_owners.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package data_resources

import (
"github.com/MinterTeam/minter-explorer-api/resource"
"github.com/MinterTeam/node-grpc-gateway/api_pb"
)

type EditMultisigOwners struct {
Threshold string `json:"threshold"`
Weights []string `json:"weights"`
Addresses []string `json:"addresses"`
MultisigAddress string `json:"multisig_address"`
}

func (EditMultisigOwners) Transform(txData resource.ItemInterface, params ...resource.ParamInterface) resource.Interface {
data := txData.(*api_pb.EditMultisigOwnersData)
model := params[0].(models.Transaction)

return EditMultisigOwners{
Threshold: data.GetThreshold(),
Weights: data.GetWeights(),
Addresses: data.GetAddresses(),
MultisigAddress: `Mx` + model.Tags["tx.created_multisig"],
}
}
10 changes: 8 additions & 2 deletions transaction/data_resources/multisend.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"github.com/MinterTeam/minter-explorer-api/helpers"
"github.com/MinterTeam/minter-explorer-api/resource"
"github.com/MinterTeam/minter-explorer-tools/v4/models"
"github.com/MinterTeam/node-grpc-gateway/api_pb"
"strconv"
)

type Multisend struct {
List []Send `json:"list"`
}

func (Multisend) Transform(txData resource.ItemInterface, params ...resource.ParamInterface) resource.Interface {
data := txData.(*models.MultiSendTxData)
data := txData.(*api_pb.MultiSendData)

list := make([]Send, len(data.List))
for key, item := range data.List {
Expand All @@ -23,9 +25,13 @@ func (Multisend) Transform(txData resource.ItemInterface, params ...resource.Par

func (Multisend) TransformByTxOutput(txData resource.ItemInterface) resource.Interface {
data := txData.(*models.TransactionOutput)
coin := &api_pb.Coin{
Id: strconv.FormatUint(data.Coin.ID, 10),
Symbol: data.Coin.Symbol,
}

return Send{
Coin: data.Coin.Symbol,
Coin: new(Coin).Transform(coin),
To: data.ToAddress.GetAddress(),
Value: helpers.PipStr2Bip(data.Value),
}
Expand Down
Loading

0 comments on commit caaf81d

Please sign in to comment.