add delegation

This commit is contained in:
mossid 2018-05-06 20:39:50 +02:00 committed by rigelrozanski
parent 79fdbe2f3a
commit 2e9e2835ff
3 changed files with 52 additions and 2 deletions

View File

@ -25,6 +25,19 @@ type ValidatorSet interface {
type ValidatorSetKeeper interface {
ValidatorSet(Context) ValidatorSet
GetByAddress(Context, Address) Validator
Validator(Context, Address) Validator
TotalPower(Context) Rat
DelegationSet(Context, Address) DelegationSet
Delegation(Context, Address, Address) Delegation
}
type Delegation interface {
GetDelegator() Address
GetValidator() Address
GetDelegated() Rat
}
type DelegationSet interface {
Iterate(func(int, Delegation))
Size() int
}

View File

@ -510,7 +510,7 @@ func (k Keeper) ValidatorSet(ctx sdk.Context) sdk.ValidatorSet {
return ValidatorSet(vals)
}
func (k Keeper) GetByAddress(ctx sdk.Context, addr sdk.Address) sdk.Validator {
func (k Keeper) Validator(ctx sdk.Context, addr sdk.Address) sdk.Validator {
can, ok := k.GetCandidate(ctx, addr)
if !ok {
return nil
@ -525,3 +525,16 @@ func (k Keeper) TotalPower(ctx sdk.Context) sdk.Rat {
pool := k.GetPool(ctx)
return pool.BondedShares
}
func (k Keeper) Delegation(ctx sdk.Context, del sdk.Address, val sdk.Address) sdk.Delegation {
bond, ok := k.GetDelegatorBond(ctx, del, val)
if !ok {
return nil
}
return bond
}
func (k Keeper) DelegationSet(ctx sdk.Context, del sdk.Address) sdk.DelegationSet {
bs := k.GetDelegatorBonds(ctx, del, 32767)
return DelegationSet(bs)
}

View File

@ -355,3 +355,27 @@ func (b DelegatorBond) equal(b2 DelegatorBond) bool {
b.Height == b2.Height &&
b.Shares.Equal(b2.Shares)
}
func (b DelegatorBond) GetDelegator() sdk.Address {
return b.DelegatorAddr
}
func (b DelegatorBond) GetValidator() sdk.Address {
return b.CandidateAddr
}
func (b DelegatorBond) GetDelegated() sdk.Rat {
return b.Shares
}
type DelegationSet []DelegatorBond
func (ds DelegationSet) Iterate(fn func(int, sdk.Delegation)) {
for i, d := range ds {
fn(i, d)
}
}
func (ds DelegationSet) Size() int {
return len(ds)
}