Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
e0ef5901
Commit
e0ef5901
authored
Jan 25, 2019
by
linj
Committed by
vipwzw
Jan 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
impl new terminate for means
parent
e0d10952
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
1 deletion
+72
-1
means.go
plugin/dapp/unfreeze/executor/means.go
+72
-1
No files found.
plugin/dapp/unfreeze/executor/means.go
View file @
e0ef5901
...
...
@@ -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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment