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
9b25d121
Commit
9b25d121
authored
Oct 18, 2018
by
任硕
Committed by
linj
Nov 26, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unfreeze
parent
bf9a4e38
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
268 additions
and
36 deletions
+268
-36
unfreeze.go
commands/unfreeze.go
+0
-0
action.go
executor/action.go
+175
-0
exec.go
executor/exec.go
+6
-6
exec_del_local.go
executor/exec_del_local.go
+2
-0
exec_local.go
executor/exec_local.go
+2
-0
query.go
executor/query.go
+9
-0
unfreeze.go
executor/unfreeze.go
+1
-3
unfreezedb.go
executor/unfreezedb.go
+0
-3
unfreeze.proto
proto/unfreeze.proto
+28
-12
const.go
types/const.go
+9
-9
types.go
types/types.go
+36
-3
unfreeze.pb.go
types/unfreeze.pb.go
+0
-0
No files found.
commands/
gam
e.go
→
commands/
unfreez
e.go
View file @
9b25d121
File moved
executor/action.go
0 → 100644
View file @
9b25d121
package
executor
import
(
"time"
"gitlab.33.cn/chain33/chain33/account"
dbm
"gitlab.33.cn/chain33/chain33/common/db"
uf
"gitlab.33.cn/chain33/chain33/plugin/dapp/unfreeze/types"
"gitlab.33.cn/chain33/chain33/system/dapp"
"gitlab.33.cn/chain33/chain33/types"
)
type
action
struct
{
coinsAccount
*
account
.
DB
db
dbm
.
KV
txhash
[]
byte
fromaddr
string
blocktime
int64
height
int64
index
int32
execaddr
string
}
func
newAction
(
u
*
Unfreeze
,
tx
*
types
.
Transaction
,
index
int32
)
*
action
{
hash
:=
tx
.
Hash
()
fromaddr
:=
tx
.
From
()
return
&
action
{
u
.
GetCoinsAccount
(),
u
.
GetStateDB
(),
hash
,
fromaddr
,
u
.
GetBlockTime
(),
u
.
GetHeight
(),
index
,
dapp
.
ExecAddress
(
string
(
tx
.
Execer
))}
}
//创建解冻交易
func
(
a
*
action
)
UnfreezeCreate
(
create
*
uf
.
UnfreezeCreate
)
(
*
types
.
Receipt
,
error
)
{
/*
*参数检测
*时间等
*/
if
create
.
GetStartTime
()
<=
time
.
Unix
()
//构造ID - txHash
var
unfreezeID
string
=
a
.
txhash
receipt
,
err
:=
a
.
coinsAccount
.
TransferToExec
(
a
.
fromaddr
,
a
.
execaddr
,
create
.
TotalCount
)
if
err
!=
nil
{
uflog
.
Error
(
"unfreeze create "
,
"addr"
,
a
.
fromaddr
,
"execaddr"
,
a
.
execaddr
,
"ExecFrozen amount"
,
create
.
TotalCount
)
return
nil
,
err
}
unfreeze
:=
&
uf
.
Unfreeze
{
UnfreezeID
:
unfreezeID
,
StartTime
:
create
.
StartTime
,
TokenName
:
create
.
TokenName
,
TotalCount
:
create
.
TotalCount
,
Initiator
:
a
.
fromaddr
,
Beneficiary
:
create
.
Beneficiary
,
Period
:
create
.
Period
,
Means
:
create
.
Means
,
Amount
:
create
.
Amount
,
}
a
.
saveStateDB
(
unfreeze
)
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
receiptLog
:=
a
.
getReceiptLog
(
unfreeze
)
//TODO 修改receiptLog
logs
=
append
(
logs
,
receiptLog
)
return
&
types
.
Receipt
{
types
.
ExecOk
,
kv
,
logs
},
nil
}
//提取解冻币
func
(
a
*
action
)
UnfreezeWithdraw
(
withdraw
*
uf
.
UnfreezeWithdraw
)
(
*
types
.
Receipt
,
error
)
{
//TODO pseudocode
/*
*参数检测
*检测该地址是否存在对应解冻交易ID
*/
/*
*从合约转币到该地址(收币地址)
*/
value
,
err
:=
a
.
db
.
Get
(
key
(
withdraw
.
GetUnfreezeID
()))
if
err
!=
nil
{
uflog
.
Error
(
"unfreeze withdraw "
,
"execaddr"
,
a
.
execaddr
,
"err"
,
err
)
return
nil
,
err
}
var
unfreeze
uf
.
Unfreeze
err
=
types
.
Decode
(
value
,
&
unfreeze
)
if
err
!=
nil
{
uflog
.
Error
(
"unfreeze withdraw "
,
"execaddr"
,
a
.
execaddr
,
"err"
,
err
)
return
nil
,
err
}
/*
*检测可取款状态(时间)
*计算可取款额
*计算取款次数增加量
*/
var
amount
int64
var
withdrawTimes
int32
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
receipt
,
err
:=
a
.
coinsAccount
.
ExecTransferFrozen
(
unfreeze
.
Initiator
,
unfreeze
.
Beneficiary
,
a
.
execaddr
,
amount
)
if
err
!=
nil
{
uflog
.
Error
(
"unfreeze withdraw "
,
"execaddr"
,
a
.
execaddr
,
"err"
,
err
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
unfreeze
.
WithdrawTimes
+=
withdrawTimes
a
.
saveStateDB
(
&
unfreeze
)
return
&
types
.
Receipt
{
types
.
ExecOk
,
kv
,
logs
},
nil
}
//中止定期解冻
func
(
a
*
action
)
UnfreezeTerminate
(
terminate
*
uf
.
UnfreezeTerminate
)
(
*
types
.
Receipt
,
error
)
{
//TODO pseudocode
/*
*参数检测
*检测该地址是否存在对应解冻交易ID
*/
/*
*从合约转币到该地址(发币地址)
*/
//计算合约中剩余币数
var
remain
int64
//获取发币地址
var
senderAddr
string
receipt
,
err
:=
a
.
coinsAccount
.
ExecActive
(
senderAddr
,
a
.
execaddr
,
remain
)
if
err
!=
nil
{
uflog
.
Error
(
"unfreeze terminate "
,
"addr"
,
senderAddr
,
"execaddr"
,
a
.
execaddr
,
"err"
,
err
)
return
nil
,
err
}
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
/*修改receipt
*修改数据库中状态
*/
return
&
types
.
Receipt
{
types
.
ExecOk
,
kv
,
logs
},
nil
}
func
(
a
*
action
)
saveStateDB
(
unfreeze
*
uf
.
Unfreeze
)
{
a
.
db
.
Set
(
key
(
unfreeze
.
GetUnfreezeID
()),
types
.
Encode
(
unfreeze
))
}
func
key
(
id
string
)
(
keys
[]
byte
)
{
keys
=
append
(
keys
,
[]
byte
(
"mavl-"
+
uf
.
UnfreezeX
+
"-"
)
...
)
keys
=
append
(
keys
,
[]
byte
(
id
)
...
)
return
keys
}
func
(
a
*
action
)
getReceiptLog
(
unfreeze
*
uf
.
Unfreeze
)
*
types
.
ReceiptLog
{
//TODO 判断不同类型receipt
log
:=
&
types
.
ReceiptLog
{}
r
:=
&
uf
.
ReceiptUnfreeze
{}
r
.
TokenName
=
unfreeze
.
TokenName
r
.
CreateAddr
=
unfreeze
.
Initiator
r
.
ReceiveAddr
=
unfreeze
.
Beneficiary
log
.
Log
=
types
.
Encode
(
r
)
return
log
}
//查询可提币状态
func
QueryWithdraw
(
stateDB
dbm
.
KV
,
param
*
uf
.
QueryWithdraw
)
(
types
.
Message
,
error
)
{
//查询提币次数
//计算当前可否提币
return
&
types
.
Reply
{},
nil
}
executor/exec.go
View file @
9b25d121
...
...
@@ -5,17 +5,17 @@ import (
"gitlab.33.cn/chain33/chain33/types"
)
func
(
u
*
Unfreeze
)
Exec_Create
(
payload
*
uf
.
GameCreate
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
N
ewAction
(
u
,
tx
,
index
)
func
(
u
*
Unfreeze
)
Exec_Create
(
payload
*
uf
.
UnfreezeCreate
,
tx
*
types
.
Transaction
,
index
int32
)
(
*
types
.
Receipt
,
error
)
{
action
:=
n
ewAction
(
u
,
tx
,
index
)
return
action
.
UnfreezeCreate
(
payload
)
}
func
(
u
*
Unfreeze
)
Exec_
Cancel
(
payload
*
uf
.
GameCancel
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
N
ewAction
(
u
,
tx
,
index
)
func
(
u
*
Unfreeze
)
Exec_
Withdraw
(
payload
*
uf
.
UnfreezeWithdraw
,
tx
*
types
.
Transaction
,
index
int32
)
(
*
types
.
Receipt
,
error
)
{
action
:=
n
ewAction
(
u
,
tx
,
index
)
return
action
.
UnfreezeWithdraw
(
payload
)
}
func
(
u
*
Unfreeze
)
Exec_Terminate
(
payload
*
uf
.
GameClose
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
N
ewAction
(
u
,
tx
,
index
)
func
(
u
*
Unfreeze
)
Exec_Terminate
(
payload
*
uf
.
UnfreezeTerminate
,
tx
*
types
.
Transaction
,
index
int32
)
(
*
types
.
Receipt
,
error
)
{
action
:=
n
ewAction
(
u
,
tx
,
index
)
return
action
.
UnfreezeTerminate
(
payload
)
}
executor/exec_del_local.go
View file @
9b25d121
...
...
@@ -6,6 +6,8 @@ import (
)
func
(
u
*
Unfreeze
)
execDelLocal
(
receiptData
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
dbSet
:=
&
types
.
LocalDBSet
{}
return
dbSet
,
nil
}
...
...
executor/exec_local.go
View file @
9b25d121
...
...
@@ -6,6 +6,8 @@ import (
)
func
(
u
*
Unfreeze
)
execLocal
(
receiptData
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
dbSet
:=
&
types
.
LocalDBSet
{}
return
dbSet
,
nil
}
...
...
executor/query.go
View file @
9b25d121
package
executor
import
(
uf
"gitlab.33.cn/chain33/chain33/plugin/dapp/unfreeze/types"
"gitlab.33.cn/chain33/chain33/types"
)
func
(
u
*
Unfreeze
)
Query_QueryWithdraw
(
in
*
uf
.
QueryWithdraw
)
(
types
.
Message
,
error
)
{
return
QueryWithdraw
(
u
.
GetStateDB
(),
in
)
}
executor/unfreeze.go
View file @
9b25d121
package
executor
import
(
"fmt"
log
"github.com/inconshreveable/log15"
uf
"gitlab.33.cn/chain33/chain33/plugin/dapp/unfreeze/types"
drivers
"gitlab.33.cn/chain33/chain33/system/dapp"
...
...
@@ -19,7 +17,7 @@ func init() {
}
func
Init
(
name
string
)
{
drivers
.
Register
(
GetName
(),
new
Gam
e
,
0
)
drivers
.
Register
(
GetName
(),
new
Unfreez
e
,
0
)
}
type
Unfreeze
struct
{
...
...
executor/unfreezedb.go
deleted
100644 → 0
View file @
bf9a4e38
package
executor
//database opeartion for executor unfreeze
proto/unfreeze.proto
View file @
9b25d121
...
...
@@ -3,24 +3,26 @@ syntax = "proto3";
package
types
;
message
Unfreeze
{
//解冻交易ID(唯一识别码)
string
unfreezeID
=
1
;
//开始时间
int64
startTime
=
1
;
int64
startTime
=
2
;
//币种
string
tokenName
=
2
;
string
tokenName
=
3
;
//冻结总额
int64
totalCount
=
3
;
int64
totalCount
=
4
;
//发币人地址
string
senderAddr
=
4
;
string
initiator
=
5
;
//收币人地址
string
receiverAddr
=
5
;
string
beneficiary
=
6
;
//解冻间隔
int64
unfreezeGap
=
6
;
int64
period
=
7
;
//解冻方式(百分比;固额) 1 百分比 -> 2 固额
int32
unfreezeMeans
=
7
;
int32
means
=
8
;
//解冻数量:若为百分比解冻方式该字段值为百分比乘以100,若为固额该字段值为币数量
int64
unfreezeAmount
=
8
;
int64
amount
=
9
;
//已解冻次数
int32
withdrawTimes
=
9
;
int32
withdrawTimes
=
10
;
}
// message for execs.unfreeze
...
...
@@ -34,17 +36,31 @@ message UnfreezeAction {
}
message
UnfreezeCreate
{
int64
startTime
=
1
;
string
tokenName
=
2
;
int64
totalCount
=
3
;
string
initiator
=
4
;
string
beneficiary
=
5
;
int64
period
=
6
;
int32
means
=
7
;
int64
amount
=
8
;
}
message
UnfreezeWithdraw
{
string
unfreezeID
=
1
;
}
message
UnfreezeTerminate
{
string
unfreezeID
=
1
;
}
//TODO: 更多receipt类型
message
ReceiptUnfreeze
{
string
tokenName
=
1
;
string
createAddr
=
2
;
string
receiveAddr
=
3
;
}
message
QueryWithdraw
{
string
unfreezeID
=
1
;
}
types/const.go
View file @
9b25d121
...
...
@@ -16,17 +16,17 @@ const (
//建议用github的组织名称,或者用户名字开头, 再加上自己的插件的名字
//如果发生重名,可以通过配置文件修改这些名字
var
(
PackageName
=
"chain33.unfreeze"
RpcName
=
"Chain33.Unfreeze"
UnfreezeX
=
"unfreeze"
Execer
Game
=
[]
byte
(
UnfreezeX
)
PackageName
=
"chain33.unfreeze"
RpcName
=
"Chain33.Unfreeze"
UnfreezeX
=
"unfreeze"
Execer
Unfreeze
=
[]
byte
(
UnfreezeX
)
)
const
(
Action_CreateUnfreeze
=
"createUnfreeze"
Action_WithdrawUnfreeze
=
"withdrawUnfreeze"
Action_TerminateUnfreeze
=
"terminateUnfreeze"
)
//
const (
//
Action_CreateUnfreeze = "createUnfreeze"
//
Action_WithdrawUnfreeze = "withdrawUnfreeze"
//
Action_TerminateUnfreeze = "terminateUnfreeze"
//
)
//const (
// FuncName_QueryXXX = "QueryXXX"
...
...
types/types.go
View file @
9b25d121
...
...
@@ -33,7 +33,7 @@ type UnfreezeType struct {
types
.
ExecTypeBase
}
func
(
at
*
UnfreezeType
)
GetLogMap
()
map
[
int64
]
*
types
.
LogInfo
{
func
(
u
*
UnfreezeType
)
GetLogMap
()
map
[
int64
]
*
types
.
LogInfo
{
return
map
[
int64
]
*
types
.
LogInfo
{
TyLogCreateUnfreeze
:
{
reflect
.
TypeOf
(
ReceiptUnfreeze
{}),
"LogCreateUnfreeze"
},
TyLogWithdrawUnfreeze
:
{
reflect
.
TypeOf
(
ReceiptUnfreeze
{}),
"LogWithdrawUnfreeze"
},
...
...
@@ -41,14 +41,47 @@ func (at *UnfreezeType) GetLogMap() map[int64]*types.LogInfo {
}
}
func
(
g
*
UnfreezeType
)
GetPayload
()
types
.
Message
{
func
(
u
*
UnfreezeType
)
GetPayload
()
types
.
Message
{
return
&
UnfreezeAction
{}
}
func
(
g
*
UnfreezeType
)
GetTypeMap
()
map
[
string
]
int32
{
func
(
u
*
UnfreezeType
)
GetTypeMap
()
map
[
string
]
int32
{
return
map
[
string
]
int32
{
"Create"
:
UnfreezeActionCreate
,
"Withdraw"
:
UnfreezeActionWithdraw
,
"Terminate"
:
UnfreezeActionTerminate
,
}
}
////创建解冻相关交易
//func (u UnfreezeType) CreateTx(action string, message json.RawMessage) (*types.Transaction, error) {
// tlog.Debug("UnfreezeType.CreateTx", "action", action)
// if action == Action_CreateUnfreeze {
// var param UnfreezeCreate
// err := json.Unmarshal(message, ¶m)
// if err != nil {
// tlog.Error("CreateTx", "Error", err)
// return nil, types.ErrInputPara
// }
// return CreateRawGamePreCreateTx(¶m)
// } else if action == Action_WithdrawUnfreeze {
// var param UnfreezeWithdraw
// err := json.Unmarshal(message, ¶m)
// if err != nil {
// tlog.Error("CreateTx", "Error", err)
// return nil, types.ErrInputPara
// }
// return CreateRawGamePreMatchTx(¶m)
// } else if action == Action_TerminateUnfreeze {
// var param UnfreezeTerminate
// err := json.Unmarshal(message, ¶m)
// if err != nil {
// tlog.Error("CreateTx", "Error", err)
// return nil, types.ErrInputPara
// }
// return CreateRawGamePreCancelTx(¶m)
// } else {
// return nil, types.ErrNotSupport
// }
// return nil, nil
//}
types/unfreeze.pb.go
View file @
9b25d121
This diff is collapsed.
Click to expand it.
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