Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #33 from irisnet/develop
Browse files Browse the repository at this point in the history
R4R: change WithdrawValidatorRewardsAll tx struct
  • Loading branch information
kaifei Hu authored Mar 10, 2020
2 parents 7aef994 + dbb761d commit 0d9c0a0
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 50 deletions.
29 changes: 21 additions & 8 deletions block/parse_tx.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package block

import (
"github.com/irisnet/irishub/app/v1/auth"
"github.com/irisnet/rainbow-sync/constant"
"github.com/irisnet/rainbow-sync/helper"
"github.com/irisnet/rainbow-sync/logger"
imodel "github.com/irisnet/rainbow-sync/model"
imsg "github.com/irisnet/rainbow-sync/model/msg"
"github.com/irisnet/rainbow-sync/utils"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/irisnet/irishub/app/v1/auth"
"github.com/tendermint/tendermint/types"
"github.com/irisnet/rainbow-sync/helper"
"github.com/irisnet/rainbow-sync/constant"
)

// parse iris txs from block result txs
Expand Down Expand Up @@ -224,16 +224,29 @@ func (iris *Iris_Block) ParseIrisTxModel(txBytes types.Tx, block *types.Block) i
msg := msg.(imodel.MsgWithdrawValidatorRewardsAll)

docTx.From = msg.ValidatorAddr.String()
docTx.Initiator = msg.ValidatorAddr.String()
if v := msg.GetSigners(); len(v) > 0 {
docTx.Initiator = v[0].String()
}
docTx.Type = constant.Iris_TxTypeWithdrawValidatorRewardsAll

var totalReward string
var withdrawAddr string
for _, tag := range result.Tags {
key := string(tag.Key)
if key == imodel.TagDistributionReward {
reward := string(tag.Value)
docTx.Amount = utils.ParseCoins(reward)
break
switch key {
case imodel.TagDistributionReward:
if totalReward == "" {
totalReward = string(tag.Value)
}
case imodel.TagDistributionWithdrawAddr:
if withdrawAddr == "" {
withdrawAddr = string(tag.Value)
}
}
}

docTx.To = withdrawAddr
docTx.Amount = utils.ParseCoins(totalReward)
case imodel.MsgSubmitProposal:
msg := msg.(imodel.MsgSubmitProposal)

Expand Down
10 changes: 5 additions & 5 deletions block/parse_tx_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package block

import (
"testing"
"github.com/irisnet/rainbow-sync/helper"
irisConf "github.com/irisnet/rainbow-sync/conf"
"encoding/json"
irisConf "github.com/irisnet/rainbow-sync/conf"
"github.com/irisnet/rainbow-sync/helper"
"testing"
)

func TestIris_Block_ParseIrisTx(t *testing.T) {
Expand All @@ -24,7 +24,7 @@ func TestIris_Block_ParseIrisTx(t *testing.T) {
{
name: "test parse iris tx",
args: args{
b: 408960,
b: 2877965,
client: client,
},
},
Expand All @@ -36,7 +36,7 @@ func TestIris_Block_ParseIrisTx(t *testing.T) {
if err != nil {
t.Fatal(err)
}
resBytes, _ := json.MarshalIndent(res, "", "\t")
resBytes, _ := json.Marshal(res)
t.Log(string(resBytes))
})
}
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/libp2p/go-buffer-pool v0.0.2 h1:QNK2iAFa8gjAe1SPz6mHSMuCcjs+X1wlHzeOSqcmlfs=
github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoRZd1Vi32+RXyFM=
Expand Down Expand Up @@ -190,6 +192,7 @@ google.golang.org/genproto v0.0.0-20181029155118-b69ba1387ce2/go.mod h1:JiN7NxoA
google.golang.org/grpc v1.22.0 h1:J0UbZOIrCAl+fpTOf8YLs4dJo8L/owV4LYVtAXQoPkw=
google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
Expand All @@ -198,6 +201,7 @@ gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3M
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 h1:yiW+nvdHb9LVqSHQBXfZCieqV4fzYhNBql77zY0ykqs=
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637/go.mod h1:BHsqpu/nsuzkT5BpiH1EMZPLyqSMM8JbIavyFACoFNk=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
Expand Down
75 changes: 38 additions & 37 deletions model/tx.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package model

import (
"gopkg.in/mgo.v2/bson"
"time"
"github.com/irisnet/irishub/app/v1/stake"
"github.com/irisnet/irishub/app/v1/asset"
"github.com/irisnet/irishub/app/v1/bank"
"github.com/irisnet/irishub/app/v1/distribution"
dtags "github.com/irisnet/irishub/app/v1/distribution/tags"
dtypes "github.com/irisnet/irishub/app/v1/distribution/types"
"github.com/irisnet/irishub/app/v1/gov"
"github.com/irisnet/irishub/app/v1/bank"
"github.com/irisnet/irishub/app/v1/rand"
"github.com/irisnet/irishub/app/v1/slashing"
dtypes "github.com/irisnet/irishub/app/v1/distribution/types"
dtags "github.com/irisnet/irishub/app/v1/distribution/tags"
"github.com/irisnet/irishub/app/v1/stake"
"github.com/irisnet/irishub/types"
"github.com/irisnet/irishub/app/v1/asset"
"github.com/irisnet/irishub/app/v1/rand"
"gopkg.in/mgo.v2"
"github.com/irisnet/rainbow-sync/db"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"time"
)

type IrisTx struct {
Expand Down Expand Up @@ -64,63 +64,64 @@ func (d IrisTx) EnsureIndexes() {
mgo.Index{
Key: []string{"-tx_hash"},
Unique: true,
Background: true,},
Background: true},
mgo.Index{
Key: []string{"-type"},
Background: true,},
Background: true},
mgo.Index{
Key: []string{"-from"},
Background: true,},
Background: true},
mgo.Index{
Key: []string{"-to", "-height"},
Background: true,},
Background: true},
mgo.Index{
Key: []string{"-initiator"},
Background: true,},
Background: true},
)

db.EnsureIndexes(d.Name(), indexes)
}

type (
MsgTransfer = bank.MsgSend
MsgBurn = bank.MsgBurn
MsgTransfer = bank.MsgSend
MsgBurn = bank.MsgBurn
MsgSetMemoRegexp = bank.MsgSetMemoRegexp

MsgStakeCreate = stake.MsgCreateValidator
MsgStakeEdit = stake.MsgEditValidator
MsgStakeDelegate = stake.MsgDelegate
MsgStakeBeginUnbonding = stake.MsgBeginUnbonding
MsgBeginRedelegate = stake.MsgBeginRedelegate
MsgUnjail = slashing.MsgUnjail
MsgSetWithdrawAddress = dtypes.MsgSetWithdrawAddress
MsgWithdrawDelegatorReward = distribution.MsgWithdrawDelegatorReward
MsgStakeCreate = stake.MsgCreateValidator
MsgStakeEdit = stake.MsgEditValidator
MsgStakeDelegate = stake.MsgDelegate
MsgStakeBeginUnbonding = stake.MsgBeginUnbonding
MsgBeginRedelegate = stake.MsgBeginRedelegate
MsgUnjail = slashing.MsgUnjail
MsgSetWithdrawAddress = dtypes.MsgSetWithdrawAddress
MsgWithdrawDelegatorReward = distribution.MsgWithdrawDelegatorReward
MsgWithdrawDelegatorRewardsAll = distribution.MsgWithdrawDelegatorRewardsAll
MsgWithdrawValidatorRewardsAll = distribution.MsgWithdrawValidatorRewardsAll

MsgDeposit = gov.MsgDeposit
MsgSubmitProposal = gov.MsgSubmitProposal
MsgDeposit = gov.MsgDeposit
MsgSubmitProposal = gov.MsgSubmitProposal
MsgSubmitSoftwareUpgradeProposal = gov.MsgSubmitSoftwareUpgradeProposal
MsgSubmitTaxUsageProposal = gov.MsgSubmitCommunityTaxUsageProposal
MsgSubmitTokenAdditionProposal = gov.MsgSubmitTokenAdditionProposal
MsgVote = gov.MsgVote
MsgSubmitTaxUsageProposal = gov.MsgSubmitCommunityTaxUsageProposal
MsgSubmitTokenAdditionProposal = gov.MsgSubmitTokenAdditionProposal
MsgVote = gov.MsgVote

MsgRequestRand = rand.MsgRequestRand

AssetIssueToken = asset.MsgIssueToken
AssetEditToken = asset.MsgEditToken
AssetMintToken = asset.MsgMintToken
AssetTransferTokenOwner = asset.MsgTransferTokenOwner
AssetCreateGateway = asset.MsgCreateGateway
AssetEditGateWay = asset.MsgEditGateway
AssetIssueToken = asset.MsgIssueToken
AssetEditToken = asset.MsgEditToken
AssetMintToken = asset.MsgMintToken
AssetTransferTokenOwner = asset.MsgTransferTokenOwner
AssetCreateGateway = asset.MsgCreateGateway
AssetEditGateWay = asset.MsgEditGateway
AssetTransferGatewayOwner = asset.MsgTransferGatewayOwner

SdkCoins = types.Coins
KVPair = types.KVPair
KVPair = types.KVPair
)

var (
TagDistributionReward = dtags.Reward
TagDistributionReward = dtags.Reward
TagDistributionWithdrawAddr = dtags.WithdrawAddr
)

type Coin struct {
Expand Down

0 comments on commit 0d9c0a0

Please sign in to comment.