impl new terminate for means
@@ -15,7 +15,15 @@ type Means interface {
calcFrozen(unfreeze *pty.Unfreeze, now int64) (int64, error)
}
-func newMeans(means string) (Means, error) {
+func newMeans(means string, height int64) (Means, error) {
+ if types.IsDappFork(height, pty.UnfreezeX, "ForkTerminatePart") {
+ if means == "FixAmount" {
+ return &fixAmountV2{}, nil
+ } else if means == "LeftProportion" {
+ return &leftProportionV2{}, nil
+ }
+ return nil, types.ErrNotSupport
+ }
if means == "FixAmount" {
return &fixAmount{}, nil
} else if means == "LeftProportion" {
@@ -88,3 +96,66 @@ func withdraw(unfreeze *pty.Unfreeze, frozen int64) (*pty.Unfreeze, int64) {
unfreeze.Remaining = frozen
return unfreeze, amount
}
+
+
+type fixAmountV2 struct {
+}
+
+func (opt *fixAmountV2) setOpt(unfreeze *pty.Unfreeze, from *pty.UnfreezeCreate) (*pty.Unfreeze, error) {
+ o := from.GetFixAmount()
+ if o == nil {
+ return nil, types.ErrInvalidParam
+ }
+ if o.Amount <= 0 || o.Period <= 0 || unfreeze.TotalCount < o.Amount {
+ return nil, types.ErrInvalidParam
+ }
+ unfreeze.MeansOpt = &pty.Unfreeze_FixAmount{FixAmount: from.GetFixAmount()}
+ return unfreeze, nil
+}
+
+func (opt *fixAmountV2) calcFrozen(unfreeze *pty.Unfreeze, now int64) (int64, error) {
+ means := unfreeze.GetFixAmount()
+ if means == nil {
+ return 0, types.ErrInvalidParam
+ }
+ if unfreeze.Terminated {
+ return 0, nil
+ }
+ unfreezeTimes := (now + means.Period - unfreeze.StartTime) / means.Period
+ unfreezeAmount := means.Amount * unfreezeTimes
+ if unfreeze.TotalCount <= unfreezeAmount {
+ return 0, nil
+ }
+ return unfreeze.TotalCount - unfreezeAmount, nil
+}
+
+type leftProportionV2 struct {
+}
+
+func (opt *leftProportionV2) setOpt(unfreeze *pty.Unfreeze, from *pty.UnfreezeCreate) (*pty.Unfreeze, error) {
+ o := from.GetLeftProportion()
+ if o == nil {
+ return nil, types.ErrInvalidParam
+ }
+ if o.Period <= 0 || o.TenThousandth <= 0 || o.TenThousandth >= 10000 {
+ return nil, types.ErrInvalidParam
+ }
+ unfreeze.MeansOpt = &pty.Unfreeze_LeftProportion{LeftProportion: from.GetLeftProportion()}
+ return unfreeze, nil
+}
+
+func (opt *leftProportionV2) calcFrozen(unfreeze *pty.Unfreeze, now int64) (int64, error) {
+ means := unfreeze.GetLeftProportion()
+ if means == nil {
+ return 0, types.ErrInvalidParam
+ }
+ if unfreeze.Terminated {
+ return 0, nil
+ }
+ unfreezeTimes := (now + means.Period - unfreeze.StartTime) / means.Period
+ frozen := float64(unfreeze.TotalCount)
+ for i := int64(0); i < unfreezeTimes; i++ {
+ frozen = frozen * float64(10000-means.TenThousandth) / 10000
+ }
+ return int64(frozen), nil
+}
