Skip to content

Commit

Permalink
Merge branch 'iip13_v2' into iip13_v2_2
Browse files Browse the repository at this point in the history
  • Loading branch information
envestcc committed May 22, 2023
2 parents 37b2ea6 + 7a745bd commit 979812f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
2 changes: 1 addition & 1 deletion action/protocol/staking/contractstaking/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Bucket struct {
StakeStartBlockHeight uint64
UnstakeStartBlockHeight uint64
AutoStake bool
ContractAddress string
ContractAddress string // contract address for the bucket
}

func assembleBucket(token uint64, bi *bucketInfo, bt *BucketType) (*Bucket, error) {
Expand Down
39 changes: 20 additions & 19 deletions action/protocol/staking/contractstaking/bucket_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@ type (
}
)

func (bi *bucketInfo) toProto() *contractstakingpb.BucketInfo {
pb := &contractstakingpb.BucketInfo{
TypeIndex: bi.TypeIndex,
Delegate: bi.Delegate.String(),
CreatedAt: bi.CreatedAt,
Owner: bi.Owner.String(),
UnlockedAt: bi.UnlockedAt,
UnstakedAt: bi.UnstakedAt,
}
return pb
}

// Serialize serializes the bucket info
func (bi *bucketInfo) Serialize() []byte {
return byteutil.Must(proto.Marshal(bi.toProto()))
Expand All @@ -51,19 +39,32 @@ func (bi *bucketInfo) Deserialize(b []byte) error {
return bi.loadProto(&m)
}

func (bi *bucketInfo) toProto() *contractstakingpb.BucketInfo {
pb := &contractstakingpb.BucketInfo{
TypeIndex: bi.TypeIndex,
Delegate: bi.Delegate.String(),
CreatedAt: bi.CreatedAt,
Owner: bi.Owner.String(),
UnlockedAt: bi.UnlockedAt,
UnstakedAt: bi.UnstakedAt,
}
return pb
}

func (bi *bucketInfo) loadProto(p *contractstakingpb.BucketInfo) error {
var err error
bi.TypeIndex = p.TypeIndex
bi.CreatedAt = p.CreatedAt
bi.UnlockedAt = p.UnlockedAt
bi.UnstakedAt = p.UnstakedAt
bi.Delegate, err = address.FromString(p.Delegate)
delegate, err := address.FromString(p.Delegate)
if err != nil {
return err
}
bi.Owner, err = address.FromString(p.Owner)
owner, err := address.FromString(p.Owner)
if err != nil {
return err
}
bi.TypeIndex = p.TypeIndex
bi.CreatedAt = p.CreatedAt
bi.UnlockedAt = p.UnlockedAt
bi.UnstakedAt = p.UnstakedAt
bi.Delegate = delegate
bi.Owner = owner
return nil
}
32 changes: 16 additions & 16 deletions action/protocol/staking/contractstaking/bucket_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ type (
}
)

// Serialize serializes the bucket type
func (bt *BucketType) Serialize() []byte {
return byteutil.Must(proto.Marshal(bt.toProto()))
}

// Deserialize deserializes the bucket type
func (bt *BucketType) Deserialize(b []byte) error {
m := contractstakingpb.BucketType{}
if err := proto.Unmarshal(b, &m); err != nil {
return err
}
return bt.loadProto(&m)
}

func (bt *BucketType) toProto() *contractstakingpb.BucketType {
return &contractstakingpb.BucketType{
Amount: bt.Amount.String(),
Expand All @@ -33,26 +47,12 @@ func (bt *BucketType) toProto() *contractstakingpb.BucketType {
}

func (bt *BucketType) loadProto(p *contractstakingpb.BucketType) error {
var ok bool
bt.Amount, ok = big.NewInt(0).SetString(p.Amount, 10)
amount, ok := big.NewInt(0).SetString(p.Amount, 10)
if !ok {
return errors.New("failed to parse amount")
}
bt.Amount = amount
bt.Duration = p.Duration
bt.ActivatedAt = p.ActivatedAt
return nil
}

// Serialize serializes the bucket type
func (bt *BucketType) Serialize() []byte {
return byteutil.Must(proto.Marshal(bt.toProto()))
}

// Deserialize deserializes the bucket type
func (bt *BucketType) Deserialize(b []byte) error {
m := contractstakingpb.BucketType{}
if err := proto.Unmarshal(b, &m); err != nil {
return err
}
return bt.loadProto(&m)
}

0 comments on commit 979812f

Please sign in to comment.