Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #196 from irisnet/develop
Browse files Browse the repository at this point in the history
R4R: merge to master
  • Loading branch information
kaifei Hu authored Sep 25, 2019
2 parents f94a938 + 824a6a1 commit 3388722
Show file tree
Hide file tree
Showing 9 changed files with 485 additions and 11 deletions.
1 change: 1 addition & 0 deletions script/mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ db.tx_common.createIndex({"to": 1});
db.tx_common.createIndex({"type": 1});
db.tx_common.createIndex({"status": 1});
db.tx_common.createIndex({"proposal_id": 1}, {"background": true});
db.tx_common.createIndex({"type": -1, "time": -1, "height": -1}, {"background": true});

db.proposal.createIndex({"proposal_id": 1}, {"unique": true});
db.proposal.createIndex({"status": 1}, {"background": true});
Expand Down
6 changes: 3 additions & 3 deletions service/task/task_statistics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ func Test_assertFastSyncFinished(t *testing.T) {
}
}

func TestMakeUpdateDelegatorTask(t *testing.T) {
updateDelegator()
}
//func TestMakeUpdateDelegatorTask(t *testing.T) {
// updateDelegator()
//}
17 changes: 9 additions & 8 deletions store/document/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,20 @@ type Proposal struct {
}

type PVote struct {
Voter string `json:"voter"`
Option string `json:"option"`
TxHash string `json:"tx_hash"`
Time time.Time `json:"time"`
Voter string `json:"voter" bson:"voter"`
Option string `json:"option" bson:"option"`
TxHash string `json:"tx_hash" bson:"txhash"`
Time time.Time `json:"time" bson:"time"`
}

//-----------------------------------------------------------
// Tally Results
type PTallyResult struct {
Yes string `json:"yes"`
Abstain string `json:"abstain"`
No string `json:"no"`
NoWithVeto string `json:"no_with_veto"`
Yes string `json:"yes" bson:"yes"`
Abstain string `json:"abstain" bson:"abstain"`
No string `json:"no" bson:"no"`
NoWithVeto string `json:"no_with_veto" bson:"nowithveto"`
SystemVotingPower string `json:"system_voting_power" bson:"system_voting_power"`
}

func (m Proposal) Name() string {
Expand Down
45 changes: 45 additions & 0 deletions types/msg/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package msg
import (
itypes "github.com/irisnet/irishub-sync/types"
"github.com/irisnet/irishub-sync/util/constant"
"github.com/irisnet/irishub-sync/store"
)

type DocTxMsgSetMemoRegexp struct {
Expand All @@ -19,3 +20,47 @@ func (doctx *DocTxMsgSetMemoRegexp) BuildMsg(txMsg interface{}) {
doctx.MemoRegexp = msg.MemoRegexp
doctx.Owner = msg.Owner.String()
}

// MsgBurn - high level transaction of the coin module
type DocTxMsgBurn struct {
Owner string `bson:"owner"`
Coins store.Coins `bson:"coins"`
}

func (doctx *DocTxMsgBurn) Type() string {
return constant.TxTypeBurn
}

func (doctx *DocTxMsgBurn) BuildMsg(txMsg interface{}) {
msg := txMsg.(itypes.MsgBurn)
doctx.Owner = msg.Owner.String()
doctx.Coins = itypes.ParseCoins(msg.Coins.String())
}

// MsgSend - high level transaction of the coin module
type DocTxMsgSend struct {
Inputs []Data `bson:"inputs"`
Outputs []Data `bson:"outputs"`
}

// Transaction
type Data struct {
Address string `bson:"address"`
Coins store.Coins `bson:"coins"`
}

func (doctx *DocTxMsgSend) Type() string {
return constant.TxTypeTransfer
}

func (doctx *DocTxMsgSend) BuildMsg(txMsg interface{}) {
msg := txMsg.(itypes.MsgTransfer)
doctx.Inputs = append(doctx.Inputs, Data{
Address:msg.Inputs[0].Address.String(),
Coins:itypes.ParseCoins(msg.Inputs[0].Coins.String()),
})
doctx.Outputs = append(doctx.Outputs, Data{
Address:msg.Outputs[0].Address.String(),
Coins:itypes.ParseCoins(msg.Outputs[0].Coins.String()),
})
}
66 changes: 66 additions & 0 deletions types/msg/distribution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package msg

import (
"github.com/irisnet/irishub-sync/util/constant"
itypes "github.com/irisnet/irishub-sync/types"
)

// msg struct for changing the withdraw address for a delegator (or validator self-delegation)
type DocTxMsgSetWithdrawAddress struct {
DelegatorAddr string `bson:"delegator_addr"`
WithdrawAddr string `bson:"withdraw_addr"`
}

func (doctx *DocTxMsgSetWithdrawAddress) Type() string {
return constant.TxTypeSetWithdrawAddress
}

func (doctx *DocTxMsgSetWithdrawAddress) BuildMsg(txMsg interface{}) {
msg := txMsg.(itypes.MsgSetWithdrawAddress)
doctx.DelegatorAddr = msg.DelegatorAddr.String()
doctx.WithdrawAddr = msg.WithdrawAddr.String()
}

// msg struct for delegation withdraw from a single validator
type DocTxMsgWithdrawDelegatorReward struct {
DelegatorAddr string `bson:"delegator_addr"`
ValidatorAddr string `bson:"validator_addr"`
}

func (doctx *DocTxMsgWithdrawDelegatorReward) Type() string {
return constant.TxTypeWithdrawDelegatorReward
}

func (doctx *DocTxMsgWithdrawDelegatorReward) BuildMsg(txMsg interface{}) {
msg := txMsg.(itypes.MsgWithdrawDelegatorReward)
doctx.DelegatorAddr = msg.DelegatorAddr.String()
doctx.ValidatorAddr = msg.ValidatorAddr.String()
}

// msg struct for delegation withdraw for all of the delegator's delegations
type DocTxMsgWithdrawDelegatorRewardsAll struct {
DelegatorAddr string `bson:"delegator_addr"`
}

func (doctx *DocTxMsgWithdrawDelegatorRewardsAll) Type() string {
return constant.TxTypeWithdrawDelegatorRewardsAll
}

func (doctx *DocTxMsgWithdrawDelegatorRewardsAll) BuildMsg(txMsg interface{}) {
msg := txMsg.(itypes.MsgWithdrawDelegatorRewardsAll)
doctx.DelegatorAddr = msg.DelegatorAddr.String()
}

// msg struct for validator withdraw
type DocTxMsgWithdrawValidatorRewardsAll struct {
ValidatorAddr string `bson:"validator_addr"`
}

func (doctx *DocTxMsgWithdrawValidatorRewardsAll) Type() string {
return constant.TxTypeWithdrawDelegatorRewardsAll
}

func (doctx *DocTxMsgWithdrawValidatorRewardsAll) BuildMsg(txMsg interface{}) {
msg := txMsg.(itypes.MsgWithdrawValidatorRewardsAll)
doctx.ValidatorAddr = msg.ValidatorAddr.String()
}
109 changes: 109 additions & 0 deletions types/msg/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/irisnet/irishub-sync/store"
itypes "github.com/irisnet/irishub-sync/types"
"github.com/irisnet/irishub-sync/util/constant"
"github.com/irisnet/irishub/app/v1/gov"
)

type DocTxMsgSubmitProposal struct {
Expand All @@ -15,6 +16,77 @@ type DocTxMsgSubmitProposal struct {
Params itypes.Params `bson:"params"`
}

func (doctx *DocTxMsgSubmitProposal) Type() string {
return constant.TxTypeSubmitProposal
}

func (doctx *DocTxMsgSubmitProposal) BuildMsg(txMsg interface{}) {
msg := txMsg.(itypes.MsgSubmitProposal)
doctx.Title = msg.Title
doctx.Description = msg.Description
doctx.ProposalType = msg.ProposalType.String()
doctx.Proposer = msg.Proposer.String()
doctx.Params = loadParams(msg.Params)
doctx.InitialDeposit = itypes.ParseCoins(msg.InitialDeposit.String())
}

func loadParams(params []gov.Param) (result []itypes.Param) {
for _, val := range params {
result = append(result, itypes.Param{Subspace: val.Subspace, Value: val.Value, Key: val.Key})
}
return
}

type DocTxMsgSubmitSoftwareUpgradeProposal struct {
DocTxMsgSubmitProposal
Version uint64 `bson:"version"`
Software string `bson:"software"`
SwitchHeight uint64 `bson:"switch_height"`
Threshold string `bson:"threshold"`
}

func (doctx *DocTxMsgSubmitSoftwareUpgradeProposal) Type() string {
return constant.TxMsgTypeSubmitSoftwareUpgradeProposal
}

func (doctx *DocTxMsgSubmitSoftwareUpgradeProposal) BuildMsg(txMsg interface{}) {
msg := txMsg.(itypes.MsgSubmitSoftwareUpgradeProposal)
doctx.Title = msg.Title
doctx.Description = msg.Description
doctx.ProposalType = msg.ProposalType.String()
doctx.Proposer = msg.Proposer.String()
doctx.Params = loadParams(msg.Params)
doctx.InitialDeposit = itypes.ParseCoins(msg.InitialDeposit.String())
doctx.Version = msg.Version
doctx.Software = msg.Software
doctx.SwitchHeight = msg.SwitchHeight
doctx.Threshold = msg.Threshold.String()
}

type DocTxMsgSubmitCommunityTaxUsageProposal struct {
DocTxMsgSubmitProposal
Usage string `bson:"usage"`
DestAddress string `bson:"dest_address"`
Percent string `bson:"percent"`
}

func (doctx *DocTxMsgSubmitCommunityTaxUsageProposal) Type() string {
return constant.TxMsgTypeSubmitTaxUsageProposal
}

func (doctx *DocTxMsgSubmitCommunityTaxUsageProposal) BuildMsg(txMsg interface{}) {
msg := txMsg.(itypes.MsgSubmitTaxUsageProposal)
doctx.Title = msg.Title
doctx.Description = msg.Description
doctx.ProposalType = msg.ProposalType.String()
doctx.Proposer = msg.Proposer.String()
doctx.Params = loadParams(msg.Params)
doctx.InitialDeposit = itypes.ParseCoins(msg.InitialDeposit.String())
doctx.Usage = msg.Usage.String()
doctx.DestAddress = msg.DestAddress.String()
doctx.Percent = msg.Percent.String()
}

type DocTxMsgSubmitTokenAdditionProposal struct {
DocTxMsgSubmitProposal
Symbol string `bson:"symbol"`
Expand Down Expand Up @@ -52,3 +124,40 @@ func (doctx *DocTxMsgSubmitTokenAdditionProposal) BuildMsg(txMsg interface{}) {
doctx.Decimal = msg.Decimal
doctx.InitialSupply = msg.InitialSupply
}

// MsgVote
type DocTxMsgVote struct {
ProposalID uint64 `bson:"proposal_id"` // ID of the proposal
Voter string `bson:"voter"` // address of the voter
Option string `bson:"option"` // option from OptionSet chosen by the voter
}

func (doctx *DocTxMsgVote) Type() string {
return constant.TxTypeVote
}

func (doctx *DocTxMsgVote) BuildMsg(txMsg interface{}) {
msg := txMsg.(itypes.MsgVote)
doctx.Voter = msg.Voter.String()
doctx.Option = msg.Option.String()
doctx.ProposalID = msg.ProposalID
}

// MsgDeposit
type DocTxMsgDeposit struct {
ProposalID uint64 `bson:"proposal_id"` // ID of the proposal
Depositor string `bson:"depositor"` // Address of the depositor
Amount store.Coins `bson:"amount"` // Coins to add to the proposal's deposit
}


func (doctx *DocTxMsgDeposit) Type() string {
return constant.TxTypeDeposit
}

func (doctx *DocTxMsgDeposit) BuildMsg(txMsg interface{}) {
msg := txMsg.(itypes.MsgDeposit)
doctx.Depositor = msg.Depositor.String()
doctx.Amount = itypes.ParseCoins(msg.Amount.String())
doctx.ProposalID = msg.ProposalID
}
Loading

0 comments on commit 3388722

Please sign in to comment.