Skip to content

Commit

Permalink
change url ==> info of candidate (fractalplatform#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
elvis88 authored and erickyan86 committed Oct 15, 2019
1 parent 685d41e commit f8f23b7
Show file tree
Hide file tree
Showing 24 changed files with 103 additions and 103 deletions.
4 changes: 2 additions & 2 deletions blockchain/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type GenesisAccount struct {
// GenesisCandidate is an candidate in the state of the genesis block.
type GenesisCandidate struct {
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
Info string `json:"info,omitempty"`
Stake *big.Int `json:"stake,omitempty"`
}

Expand Down Expand Up @@ -403,7 +403,7 @@ func (g *Genesis) ToBlock(db fdb.Database) (*types.Block, []*types.Receipt, erro
if err := sys.SetCandidate(&dpos.CandidateInfo{
Epoch: epoch,
Name: candidate.Name,
URL: candidate.URL,
Info: candidate.Info,
Quantity: big.NewInt(0),
TotalQuantity: big.NewInt(0),
Number: number.Uint64(),
Expand Down
6 changes: 3 additions & 3 deletions consensus/dpos/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func (api *API) BrowserEpochRecord(reqEpochNumber uint64) (interface{}, error) {
}
}
candidateInfo.Holder = balance.String()
// candidateInfo.URL = tmp.URL
// candidateInfo.Info = tmp.Info
candidateInfos.Data = append(candidateInfos.Data, candidateInfo)
}

Expand Down Expand Up @@ -434,7 +434,7 @@ func (api *API) BrowserVote(reqEpochNumber uint64) (interface{}, error) {

candidateInfo.Quantity = c.Quantity.Mul(c.Quantity, api.dpos.config.unitStake()).String()
candidateInfo.TotalQuantity = c.TotalQuantity.String()
// candidateInfo.URL = c.URL
// candidateInfo.Info = c.Info
candidateInfo.Holder = balance.String()

tmp, err := sys.GetCandidate(req, c.Name)
Expand Down Expand Up @@ -570,7 +570,7 @@ func (api *API) VoterInfo(reqEpochNumber uint64) (interface{}, error) {
tmp := c.Quantity.Mul(c.Quantity, api.dpos.config.unitStake())
voter.Quantity = tmp.Div(tmp, declimsBigInt).String()
voter.TotalQuantity = c.TotalQuantity.String()
voter.URL = c.URL
voter.Info = c.Info
voter.Holder = balance.Div(balance, declimsBigInt).String()

data = append(data, voter)
Expand Down
8 changes: 4 additions & 4 deletions consensus/dpos/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (t *CandidateType) UnmarshalJSON(data []byte) error {
type CandidateInfo struct {
Epoch uint64 `json:"epoch"`
Name string `json:"name"` // candidate name
URL string `json:"url"` // candidate url
Info string `json:"info"` // candidate url
Quantity *big.Int `json:"quantity"` // candidate stake quantity
TotalQuantity *big.Int `json:"totalQuantity"` // candidate total stake quantity
Number uint64 `json:"number"` // timestamp
Expand All @@ -143,7 +143,7 @@ func (candidateInfo *CandidateInfo) copy() *CandidateInfo {
return &CandidateInfo{
Epoch: candidateInfo.Epoch,
Name: candidateInfo.Name,
URL: candidateInfo.URL,
Info: candidateInfo.Info,
Quantity: candidateInfo.Quantity,
TotalQuantity: candidateInfo.TotalQuantity,
Number: candidateInfo.Number,
Expand Down Expand Up @@ -210,7 +210,7 @@ type CandidateInfoForBrowser struct {
ActualCounter uint64 `json:"actualCounter"`
NowCounter uint64 `json:"nowShouldCounter"`
NowActualCounter uint64 `json:"nowActualCounter"`
// URL string `json:"url"`
// Info string `json:"info"`
// Status uint64 `json:"status"` //0:die 1:activate 2:spare
}

Expand All @@ -219,7 +219,7 @@ type VoterInfoFractal struct {
Holder string `json:"holder"`
Quantity string `json:"quantity"`
TotalQuantity string `json:"totalQuantity"`
URL string `json:"url"`
Info string `json:"info"`
State uint64 `json:"state"`
Vote uint64 `json:"vote"`
CanVote bool `json:"canVote"`
Expand Down
4 changes: 2 additions & 2 deletions consensus/dpos/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"math/big"
"testing"

"gopkg.in/yaml.v2"
yaml "gopkg.in/yaml.v2"
)

func TestCandidateMarshalText(t *testing.T) {
Expand All @@ -47,7 +47,7 @@ func TestCandidateInfo(t *testing.T) {
candidateInfo := &CandidateInfo{
Epoch: 1,
Name: "candidate1",
URL: "",
Info: "",
Quantity: big.NewInt(100),
TotalQuantity: big.NewInt(100),
Number: 1,
Expand Down
2 changes: 1 addition & 1 deletion consensus/dpos/dpos.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func Genesis(cfg *Config, state *state.StateDB, timestamp uint64, number uint64)
if err := sys.SetCandidate(&CandidateInfo{
Epoch: epoch,
Name: cfg.SystemName,
URL: cfg.SystemURL,
Info: cfg.SystemURL,
Quantity: big.NewInt(0),
TotalQuantity: big.NewInt(0),
Number: number,
Expand Down
4 changes: 2 additions & 2 deletions consensus/dpos/ldb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestLDBCandidate(t *testing.T) {
candidateInfo := &CandidateInfo{
Epoch: uint64(index),
Name: candidate,
URL: fmt.Sprintf("www.%v.com", candidate),
Info: fmt.Sprintf("www.%v.com", candidate),
Quantity: big.NewInt(0),
TotalQuantity: big.NewInt(0),
}
Expand Down Expand Up @@ -281,7 +281,7 @@ func TestLDBVoter(t *testing.T) {
candidateInfo := &CandidateInfo{
Epoch: 0,
Name: candidate,
URL: fmt.Sprintf("www.%v.com", candidate),
Info: fmt.Sprintf("www.%v.com", candidate),
Quantity: big.NewInt(0),
TotalQuantity: big.NewInt(0),
}
Expand Down
8 changes: 4 additions & 4 deletions consensus/dpos/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ import (

// RegisterCandidate candidate info
type RegisterCandidate struct {
URL string
Info string
}

// UpdateCandidate candidate info
type UpdateCandidate struct {
URL string
Info string
}

// VoteCandidate vote info
Expand Down Expand Up @@ -95,7 +95,7 @@ func (dpos *Dpos) processAction(fid uint64, number uint64, chainCfg *params.Chai
if err := rlp.DecodeBytes(action.Data(), &arg); err != nil {
return nil, err
}
if err := sys.RegCandidate(epoch, action.Sender().String(), arg.URL, action.Value(), number, fid); err != nil {
if err := sys.RegCandidate(epoch, action.Sender().String(), arg.Info, action.Value(), number, fid); err != nil {
return nil, err
}
case types.UpdateCandidate:
Expand All @@ -108,7 +108,7 @@ func (dpos *Dpos) processAction(fid uint64, number uint64, chainCfg *params.Chai
if err := rlp.DecodeBytes(action.Data(), &arg); err != nil {
return nil, err
}
if err := sys.UpdateCandidate(epoch, action.Sender().String(), arg.URL, action.Value(), number, fid); err != nil {
if err := sys.UpdateCandidate(epoch, action.Sender().String(), arg.Info, action.Value(), number, fid); err != nil {
return nil, err
}
case types.UnregCandidate:
Expand Down
8 changes: 4 additions & 4 deletions consensus/dpos/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (sys *System) RegCandidate(epoch uint64, candidate string, url string, stak
prod = &CandidateInfo{
Epoch: epoch,
Name: candidate,
URL: url,
Info: url,
Quantity: big.NewInt(0),
TotalQuantity: big.NewInt(0),
Number: number,
Expand Down Expand Up @@ -125,9 +125,9 @@ func (sys *System) RegCandidate(epoch uint64, candidate string, url string, stak
}

// UpdateCandidate update a candidate
func (sys *System) UpdateCandidate(epoch uint64, candidate string, url string, nstake *big.Int, number uint64, fid uint64) error {
func (sys *System) UpdateCandidate(epoch uint64, candidate string, info string, nstake *big.Int, number uint64, fid uint64) error {
// url validity
if uint64(len(url)) > sys.config.MaxURLLen {
if uint64(len(info)) > sys.config.MaxURLLen {
return fmt.Errorf("invalid url (too long, max %v)", sys.config.MaxURLLen)
}

Expand Down Expand Up @@ -185,7 +185,7 @@ func (sys *System) UpdateCandidate(epoch uint64, candidate string, url string, n
// })
// }

prod.URL = url
prod.Info = info
prod.Quantity = new(big.Int).Add(prod.Quantity, q)
prod.TotalQuantity = new(big.Int).Add(prod.TotalQuantity, q)
prod.Number = number
Expand Down
4 changes: 2 additions & 2 deletions sdk/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestRegCandidate(t *testing.T) {
// RegCandidate
act := NewAccount(api, common.StrToName(name), priv, chainCfg.SysTokenID, math.MaxUint64, true, chainCfg.ChainID)
hash, err := act.RegCandidate(common.StrToName(chainCfg.DposName), new(big.Int).Mul(new(big.Int).Div(val, big.NewInt(4)), decimals), chainCfg.SysTokenID, gas, &dpos.RegisterCandidate{
URL: fmt.Sprintf("www.%s.com", name),
Info: fmt.Sprintf("www.%s.com", name),
})
So(err, ShouldBeNil)
So(hash, ShouldNotBeNil)
Expand All @@ -204,7 +204,7 @@ func TestUpdateCandidate(t *testing.T) {
// UpdateCandidate
act := NewAccount(api, common.StrToName(name), priv, chainCfg.SysTokenID, math.MaxUint64, true, chainCfg.ChainID)
hash, err := act.UpdateCandidate(common.StrToName(chainCfg.DposName), new(big.Int).Mul(new(big.Int).Div(val, big.NewInt(4)), decimals), chainCfg.SysTokenID, gas, &dpos.UpdateCandidate{
URL: fmt.Sprintf("www.%s.com", name),
Info: fmt.Sprintf("www.%s.com", name),
})
So(err, ShouldBeNil)
So(hash, ShouldNotBeNil)
Expand Down
24 changes: 12 additions & 12 deletions sdk/test/dpos/createandregcandidate.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"gas": 30000000,
"value": 20000000000000000000000,
"payload": {
"URL": "www.xxxxxx.com"
"Info": "www.xxxxxx.com"
},
"priv": "289c2857d4598e37fb9647507e47a309d6133539bf21a8b9cb6df88fd5232032",
"succeed": true,
Expand All @@ -34,7 +34,7 @@
"gas": 30000000,
"value": 5000000000000000000000,
"payload": {
"URL": "www.dpos0001.com"
"Info": "www.dpos0001.com"
},
"priv": "289c2857d4598e37fb9647507e47a309d6133539bf21a8b9cb6df88fd5232032",
"succeed": true
Expand Down Expand Up @@ -64,7 +64,7 @@
"gas": 30000000,
"value": 20000000000000000000000,
"payload": {
"URL": "www.xxxxx.com"
"Info": "www.xxxxx.com"
},
"priv": "289c2857d4598e37fb9647507e47a309d6133539bf21a8b9cb6df88fd5232032",
"succeed": true,
Expand All @@ -76,7 +76,7 @@
"gas": 30000000,
"value": 5000000000000000000000,
"payload": {
"URL": "www.dpos0002.com"
"Info": "www.dpos0002.com"
},
"priv": "289c2857d4598e37fb9647507e47a309d6133539bf21a8b9cb6df88fd5232032",
"succeed": true
Expand Down Expand Up @@ -106,7 +106,7 @@
"gas": 30000000,
"value": 20000000000000000000000,
"payload": {
"URL": "www.xxxxxx.com"
"Info": "www.xxxxxx.com"
},
"priv": "289c2857d4598e37fb9647507e47a309d6133539bf21a8b9cb6df88fd5232032",
"succeed": true,
Expand All @@ -118,7 +118,7 @@
"gas": 30000000,
"value": 5000000000000000000000,
"payload": {
"URL": "www.dpos0003.com"
"Info": "www.dpos0003.com"
},
"priv": "289c2857d4598e37fb9647507e47a309d6133539bf21a8b9cb6df88fd5232032",
"succeed": true
Expand Down Expand Up @@ -148,7 +148,7 @@
"gas": 30000000,
"value": 20000000000000000000000,
"payload": {
"URL": "www.xxxxxx.com"
"Info": "www.xxxxxx.com"
},
"priv": "289c2857d4598e37fb9647507e47a309d6133539bf21a8b9cb6df88fd5232032",
"succeed": true,
Expand All @@ -160,7 +160,7 @@
"gas": 30000000,
"value": 5000000000000000000000,
"payload": {
"URL": "www.dpos0004.com"
"Info": "www.dpos0004.com"
},
"priv": "289c2857d4598e37fb9647507e47a309d6133539bf21a8b9cb6df88fd5232032",
"succeed": true
Expand Down Expand Up @@ -190,7 +190,7 @@
"gas": 30000000,
"value": 20000000000000000000000,
"payload": {
"URL": "www.xxxxxx.com"
"Info": "www.xxxxxx.com"
},
"priv": "289c2857d4598e37fb9647507e47a309d6133539bf21a8b9cb6df88fd5232032",
"succeed": true,
Expand All @@ -202,7 +202,7 @@
"gas": 30000000,
"value": 5000000000000000000000,
"payload": {
"URL": "www.dpos0005.com"
"Info": "www.dpos0005.com"
},
"priv": "289c2857d4598e37fb9647507e47a309d6133539bf21a8b9cb6df88fd5232032",
"succeed": true
Expand Down Expand Up @@ -232,7 +232,7 @@
"gas": 30000000,
"value": 20000000000000000000000,
"payload": {
"URL": "www.xxxxxx.com"
"Info": "www.xxxxxx.com"
},
"priv": "289c2857d4598e37fb9647507e47a309d6133539bf21a8b9cb6df88fd5232032",
"succeed": true,
Expand All @@ -244,7 +244,7 @@
"gas": 30000000,
"value": 5000000000000000000000,
"payload": {
"URL": "www.dpos0006.com"
"Info": "www.dpos0006.com"
},
"priv": "289c2857d4598e37fb9647507e47a309d6133539bf21a8b9cb6df88fd5232032",
"succeed": true
Expand Down
Loading

0 comments on commit f8f23b7

Please sign in to comment.