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
8e521d5c
Commit
8e521d5c
authored
Oct 09, 2019
by
liuyuhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify some dapp and store some config
parent
b09e1e21
Hide whitespace changes
Inline
Side-by-side
Showing
61 changed files
with
746 additions
and
486 deletions
+746
-486
main.go
cli/main.go
+1
-1
main.go
main.go
+1
-1
block.go
plugin/consensus/pbft/block.go
+3
-2
autonomy.go
plugin/dapp/autonomy/executor/autonomy.go
+8
-7
types.go
plugin/dapp/autonomy/types/types.go
+12
-4
blackwhite.go
plugin/dapp/blackwhite/executor/blackwhite.go
+8
-7
types.go
plugin/dapp/blackwhite/types/types.go
+13
-5
cert.go
plugin/dapp/cert/executor/cert.go
+12
-10
types.go
plugin/dapp/cert/types/types.go
+12
-3
dposvote.go
plugin/dapp/dposvote/executor/dposvote.go
+14
-13
types.go
plugin/dapp/dposvote/types/types.go
+12
-3
echo.go
plugin/dapp/echo/executor/echo.go
+10
-7
types.go
plugin/dapp/echo/types/echo/types.go
+12
-3
evm.go
plugin/dapp/evm/executor/evm.go
+19
-13
evm.go
plugin/dapp/evm/types/evm.go
+27
-19
game.go
plugin/dapp/game/executor/game.go
+7
-6
types.go
plugin/dapp/game/types/types.go
+38
-29
hashlock.go
plugin/dapp/hashlock/executor/hashlock.go
+7
-6
hashlock.go
plugin/dapp/hashlock/types/hashlock.go
+26
-16
js.go
plugin/dapp/js/executor/js.go
+21
-17
js.go
plugin/dapp/js/types/js.go
+12
-3
lottery.go
plugin/dapp/lottery/executor/lottery.go
+8
-7
lottery.go
plugin/dapp/lottery/types/lottery.go
+38
-28
multisig.go
plugin/dapp/multisig/executor/multisig.go
+10
-7
types.go
plugin/dapp/multisig/types/types.go
+12
-3
norm.go
plugin/dapp/norm/executor/norm.go
+8
-7
norm.go
plugin/dapp/norm/types/norm.go
+12
-3
oracle.go
plugin/dapp/oracle/executor/oracle.go
+9
-7
types.go
plugin/dapp/oracle/types/types.go
+12
-3
paracross.go
plugin/dapp/paracross/executor/paracross.go
+13
-10
paracross.go
plugin/dapp/paracross/types/paracross.go
+25
-24
type.go
plugin/dapp/paracross/types/type.go
+26
-14
pokerbull.go
plugin/dapp/pokerbull/executor/pokerbull.go
+6
-4
types.go
plugin/dapp/pokerbull/types/types.go
+11
-3
privacy.go
plugin/dapp/privacy/executor/privacy.go
+10
-8
privacy.go
plugin/dapp/privacy/types/privacy.go
+12
-3
relay.go
plugin/dapp/relay/executor/relay.go
+10
-7
relay.go
plugin/dapp/relay/types/relay.go
+12
-3
retrieve.go
plugin/dapp/retrieve/executor/retrieve.go
+7
-6
const.go
plugin/dapp/retrieve/types/const.go
+0
-6
types.go
plugin/dapp/retrieve/types/types.go
+15
-6
ticket.go
plugin/dapp/ticket/executor/ticket.go
+7
-6
ticket.go
plugin/dapp/ticket/types/ticket.go
+15
-5
token.go
plugin/dapp/token/executor/token.go
+12
-9
types.go
plugin/dapp/token/types/types.go
+21
-10
trade.go
plugin/dapp/trade/executor/trade.go
+7
-6
trade.go
plugin/dapp/trade/types/trade.go
+16
-8
trade_test.go
plugin/dapp/trade/types/trade_test.go
+3
-3
unfreeze.go
plugin/dapp/unfreeze/executor/unfreeze.go
+7
-6
types.go
plugin/dapp/unfreeze/types/types.go
+15
-6
valnode.go
plugin/dapp/valnode/executor/valnode.go
+9
-7
valnode.go
plugin/dapp/valnode/types/valnode.go
+11
-3
base.go
plugin/mempool/para/base.go
+12
-9
kvdb.go
plugin/store/kvdb/kvdb.go
+1
-1
kvdb_test.go
plugin/store/kvdb/kvdb_test.go
+6
-6
kvmvccdb.go
plugin/store/kvmvcc/kvmvccdb.go
+1
-1
kvmvccdb_test.go
plugin/store/kvmvcc/kvmvccdb_test.go
+23
-23
kvmvcc_mavl.go
plugin/store/kvmvccmavl/kvmvcc_mavl.go
+9
-3
kvmvcc_mavl_test.go
plugin/store/kvmvccmavl/kvmvcc_mavl_test.go
+29
-29
mpt.go
plugin/store/mpt/mpt.go
+1
-1
mpt_test.go
plugin/store/mpt/mpt_test.go
+10
-10
No files found.
cli/main.go
View file @
8e521d5c
...
...
@@ -18,5 +18,5 @@ func main() {
if
buildflags
.
RPCAddr
==
""
{
buildflags
.
RPCAddr
=
"http://localhost:8801"
}
cli
.
Run
(
buildflags
.
RPCAddr
,
buildflags
.
ParaName
)
cli
.
Run
(
buildflags
.
RPCAddr
,
buildflags
.
ParaName
,
""
)
}
main.go
View file @
8e521d5c
...
...
@@ -18,5 +18,5 @@ import (
)
func
main
()
{
cli
.
RunChain33
(
""
)
cli
.
RunChain33
(
""
,
""
)
}
plugin/consensus/pbft/block.go
View file @
8e521d5c
...
...
@@ -70,13 +70,14 @@ func (client *Client) CreateBlock() {
if
!
client
.
isPrimary
{
return
}
cfg
:=
client
.
GetQueueClient
()
.
GetConfig
()
for
{
if
issleep
{
time
.
Sleep
(
10
*
time
.
Second
)
}
plog
.
Info
(
"=============start get tx==============="
)
lastBlock
:=
client
.
GetCurrentBlock
()
txs
:=
client
.
RequestTx
(
int
(
types
.
GetP
(
lastBlock
.
Height
+
1
)
.
MaxTxNumber
),
nil
)
txs
:=
client
.
RequestTx
(
int
(
cfg
.
GetP
(
lastBlock
.
Height
+
1
)
.
MaxTxNumber
),
nil
)
if
len
(
txs
)
==
0
{
issleep
=
true
continue
...
...
@@ -88,7 +89,7 @@ func (client *Client) CreateBlock() {
//fmt.Println(len(txs))
var
newblock
types
.
Block
newblock
.
ParentHash
=
lastBlock
.
Hash
()
newblock
.
ParentHash
=
lastBlock
.
Hash
(
cfg
)
newblock
.
Height
=
lastBlock
.
Height
+
1
newblock
.
Txs
=
txs
newblock
.
TxHash
=
merkle
.
CalcMerkleRoot
(
newblock
.
Txs
)
...
...
plugin/dapp/autonomy/executor/autonomy.go
View file @
8e521d5c
...
...
@@ -24,17 +24,18 @@ var (
cfg
subConfig
)
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Autonomy
{}))
}
// Init 重命名执行器名称
func
Init
(
name
string
,
sub
[]
byte
)
{
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
if
sub
!=
nil
{
types
.
MustDecode
(
sub
,
&
cfg
)
}
drivers
.
Register
(
GetName
(),
newAutonomy
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
drivers
.
Register
(
cfg
,
GetName
(),
newAutonomy
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
}
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Autonomy
{}))
}
// Autonomy 执行器结构体
...
...
plugin/dapp/autonomy/types/types.go
View file @
8e521d5c
...
...
@@ -15,15 +15,23 @@ var name string
func
init
()
{
name
=
AutonomyX
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
name
))
// init executor type
types
.
RegistorExecutor
(
name
,
NewType
())
types
.
RegisterDappFork
(
name
,
"Enable"
,
0
)
types
.
RegFork
(
name
,
InitFork
)
types
.
RegExec
(
name
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
AutonomyX
,
"Enable"
,
0
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
AutonomyX
,
NewType
(
cfg
))
}
// NewType 生成新的基础类型
func
NewType
()
*
AutonomyType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
AutonomyType
{
c
:=
&
AutonomyType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
plugin/dapp/blackwhite/executor/blackwhite.go
View file @
8e521d5c
...
...
@@ -20,17 +20,18 @@ var blackwhiteAddr = address.ExecAddress(gt.BlackwhiteX)
var
driverName
=
gt
.
BlackwhiteX
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Blackwhite
{}))
}
// Init 重命名执行器名称
func
Init
(
name
string
,
sub
[]
byte
)
{
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
driverName
=
name
gt
.
BlackwhiteX
=
driverName
gt
.
ExecerBlackwhite
=
[]
byte
(
driverName
)
drivers
.
Register
(
name
,
newBlackwhite
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
drivers
.
Register
(
cfg
,
name
,
newBlackwhite
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
}
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Blackwhite
{}))
}
// Blackwhite 几类执行器结构体
...
...
plugin/dapp/blackwhite/types/types.go
View file @
8e521d5c
...
...
@@ -24,10 +24,17 @@ const (
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
ExecerBlackwhite
)
// init executor type
types
.
RegistorExecutor
(
BlackwhiteX
,
NewType
())
types
.
RegisterDappFork
(
BlackwhiteX
,
"ForkBlackWhiteV2"
,
900000
)
types
.
RegisterDappFork
(
BlackwhiteX
,
"Enable"
,
850000
)
types
.
RegFork
(
BlackwhiteX
,
InitFork
)
types
.
RegExec
(
BlackwhiteX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
BlackwhiteX
,
"ForkBlackWhiteV2"
,
900000
)
cfg
.
RegisterDappFork
(
BlackwhiteX
,
"Enable"
,
850000
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
BlackwhiteX
,
NewType
(
cfg
))
}
// BlackwhiteType 执行器基类结构体
...
...
@@ -36,9 +43,10 @@ type BlackwhiteType struct {
}
// NewType 创建执行器类型
func
NewType
()
*
BlackwhiteType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
BlackwhiteType
{
c
:=
&
BlackwhiteType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
plugin/dapp/cert/executor/cert.go
View file @
8e521d5c
...
...
@@ -15,24 +15,26 @@ import (
var
clog
=
log
.
New
(
"module"
,
"execs.cert"
)
var
driverName
=
ct
.
CertX
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Cert
{}))
}
// Init 初始化
func
Init
(
name
string
,
sub
[]
byte
)
{
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
driverName
=
name
var
cfg
ct
.
Authority
var
s
cfg
ct
.
Authority
if
sub
!=
nil
{
types
.
MustDecode
(
sub
,
&
cfg
)
types
.
MustDecode
(
sub
,
&
s
cfg
)
}
err
:=
authority
.
Author
.
Init
(
&
cfg
)
err
:=
authority
.
Author
.
Init
(
&
s
cfg
)
if
err
!=
nil
{
clog
.
Error
(
"error to initialize authority"
,
err
)
return
}
drivers
.
Register
(
driverName
,
newCert
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
drivers
.
Register
(
cfg
,
driverName
,
newCert
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
}
// InitExecType Init Exec Type
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Cert
{}))
}
// GetName 获取cert执行器名
...
...
plugin/dapp/cert/types/types.go
View file @
8e521d5c
...
...
@@ -18,9 +18,17 @@ const (
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
ExecerCert
)
types
.
RegistorExecutor
(
CertX
,
NewType
())
// init executor type
types
.
RegisterDappFork
(
CertX
,
"Enable"
,
0
)
types
.
RegFork
(
CertX
,
InitFork
)
types
.
RegExec
(
CertX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
CertX
,
"Enable"
,
0
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
CertX
,
NewType
(
cfg
))
}
// CertType cert执行器类型结构
...
...
@@ -29,9 +37,10 @@ type CertType struct {
}
// NewType 新建cert类型结构
func
NewType
()
*
CertType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
CertType
{
c
:=
&
CertType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
plugin/dapp/dposvote/executor/dposvote.go
View file @
8e521d5c
...
...
@@ -49,29 +49,30 @@ func calcTopNVersion(height int64) (version, left int64) {
return
height
/
blockNumToUpdateDelegate
,
height
%
blockNumToUpdateDelegate
}
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
DPos
{}))
}
// Init DPos Executor
func
Init
(
name
string
,
sub
[]
byte
)
{
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
driverName
:=
GetName
()
if
name
!=
driverName
{
panic
(
"system dapp can't be rename"
)
}
drivers
.
Register
(
driverName
,
newDposVote
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
drivers
.
Register
(
cfg
,
driverName
,
newDposVote
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
//读取一下配置项,用于和共识模块一致计算cycle
dposDelegateNum
=
types
.
Conf
(
"config.consensus.sub.dpos"
)
.
GInt
(
"delegateNum"
)
dposBlockInterval
=
types
.
Conf
(
"config.consensus.sub.dpos"
)
.
GInt
(
"blockInterval"
)
dposContinueBlockNum
=
types
.
Conf
(
"config.consensus.sub.dpos"
)
.
GInt
(
"continueBlockNum"
)
blockNumToUpdateDelegate
=
types
.
Conf
(
"config.consensus.sub.dpos"
)
.
GInt
(
"blockNumToUpdateDelegate"
)
registTopNHeightLimit
=
types
.
Conf
(
"config.consensus.sub.dpos"
)
.
GInt
(
"registTopNHeightLimit"
)
updateTopNHeightLimit
=
types
.
Conf
(
"config.consensus.sub.dpos"
)
.
GInt
(
"updateTopNHeightLimit"
)
dposDelegateNum
=
types
.
Conf
(
cfg
,
"config.consensus.sub.dpos"
)
.
GInt
(
"delegateNum"
)
dposBlockInterval
=
types
.
Conf
(
cfg
,
"config.consensus.sub.dpos"
)
.
GInt
(
"blockInterval"
)
dposContinueBlockNum
=
types
.
Conf
(
cfg
,
"config.consensus.sub.dpos"
)
.
GInt
(
"continueBlockNum"
)
blockNumToUpdateDelegate
=
types
.
Conf
(
cfg
,
"config.consensus.sub.dpos"
)
.
GInt
(
"blockNumToUpdateDelegate"
)
registTopNHeightLimit
=
types
.
Conf
(
cfg
,
"config.consensus.sub.dpos"
)
.
GInt
(
"registTopNHeightLimit"
)
updateTopNHeightLimit
=
types
.
Conf
(
cfg
,
"config.consensus.sub.dpos"
)
.
GInt
(
"updateTopNHeightLimit"
)
dposCycle
=
dposDelegateNum
*
dposBlockInterval
*
dposContinueBlockNum
dposPeriod
=
dposBlockInterval
*
dposContinueBlockNum
InitExecType
()
}
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
DPos
{}))
}
//DPos 执行器,用于Dpos候选节点注册、投票,VRF信息注册管理等功能
...
...
plugin/dapp/dposvote/types/types.go
View file @
8e521d5c
...
...
@@ -12,9 +12,17 @@ import (
func
init
()
{
// init executor type
types
.
RegistorExecutor
(
DPosX
,
NewType
())
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
ExecerDposVote
)
types
.
RegisterDappFork
(
DPosX
,
"Enable"
,
0
)
types
.
RegFork
(
DPosX
,
InitFork
)
types
.
RegExec
(
DPosX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
DPosX
,
"Enable"
,
0
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
DPosX
,
NewType
(
cfg
))
}
// DPosType struct
...
...
@@ -23,9 +31,10 @@ type DPosType struct {
}
// NewType method
func
NewType
()
*
DPosType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
DPosType
{
c
:=
&
DPosType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
plugin/dapp/echo/executor/echo.go
View file @
8e521d5c
...
...
@@ -18,15 +18,18 @@ var (
KeyPrefixPangLocal
=
"LODB-echo-pang:%s"
)
// init 初始化时通过反射获取本执行器的方法列表
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
echotypes
.
EchoX
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Echo
{}))
}
// Init 本执行器的初始化动作,向系统注册本执行器,这里生效高度暂写为0
func
Init
(
name
string
,
sub
[]
byte
)
{
dapp
.
Register
(
echotypes
.
EchoX
,
newEcho
,
0
)
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
dapp
.
Register
(
cfg
,
echotypes
.
EchoX
,
newEcho
,
0
)
InitExecType
()
}
// InitExecType 初始化时通过反射获取本执行器的方法列表
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
echotypes
.
EchoX
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Echo
{}))
}
// Echo 定义执行器对象
...
...
plugin/dapp/echo/types/echo/types.go
View file @
8e521d5c
...
...
@@ -38,8 +38,16 @@ var elog = log.New("module", EchoX)
func
init
()
{
// 将本执行器添加到系统白名单
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
EchoX
))
// 向系统注册本执行器类型
types
.
RegistorExecutor
(
EchoX
,
NewType
())
types
.
RegFork
(
EchoX
,
InitFork
)
types
.
RegExec
(
EchoX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
EchoX
,
"Enable"
,
0
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
EchoX
,
NewType
(
cfg
))
}
// Type 定义本执行器类型
...
...
@@ -48,9 +56,10 @@ type Type struct {
}
// NewType 初始化本执行器类型
func
NewType
()
*
Type
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
Type
{
c
:=
&
Type
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
plugin/dapp/evm/executor/evm.go
View file @
8e521d5c
...
...
@@ -30,18 +30,20 @@ var (
var
driverName
=
evmtypes
.
ExecutorName
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
EVMExecutor
{}))
}
// Init 初始化本合约对象
func
Init
(
name
string
,
sub
[]
byte
)
{
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
driverName
=
name
drivers
.
Register
(
driverName
,
newEVMDriver
,
types
.
GetDappFork
(
driverName
,
evmtypes
.
EVMEnable
))
EvmAddress
=
address
.
ExecAddress
(
types
.
ExecName
(
name
))
drivers
.
Register
(
cfg
,
driverName
,
newEVMDriver
,
cfg
.
GetDappFork
(
driverName
,
evmtypes
.
EVMEnable
))
EvmAddress
=
address
.
ExecAddress
(
cfg
.
ExecName
(
name
))
// 初始化硬分叉数据
state
.
InitForkData
()
InitExecType
()
}
// InitExecType Init Exec Type
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
EVMExecutor
{}))
}
// GetName 返回本合约名称
...
...
@@ -86,7 +88,8 @@ func (evm *EVMExecutor) GetDriverName() string {
// ExecutorOrder 设置localdb的EnableRead
func
(
evm
*
EVMExecutor
)
ExecutorOrder
()
int64
{
if
types
.
IsFork
(
evm
.
GetHeight
(),
"ForkLocalDBAccess"
)
{
cfg
:=
evm
.
GetAPI
()
.
GetConfig
()
if
cfg
.
IsFork
(
evm
.
GetHeight
(),
"ForkLocalDBAccess"
)
{
return
drivers
.
ExecLocalSameTime
}
return
evm
.
DriverBase
.
ExecutorOrder
()
...
...
@@ -101,7 +104,8 @@ func (evm *EVMExecutor) Allow(tx *types.Transaction, index int) error {
//增加新的规则:
//主链: user.evm.xxx 执行 evm 合约
//平行链: user.p.guodun.user.evm.xxx 执行 evm 合约
exec
:=
types
.
GetParaExec
(
tx
.
Execer
)
cfg
:=
evm
.
GetAPI
()
.
GetConfig
()
exec
:=
cfg
.
GetParaExec
(
tx
.
Execer
)
if
evm
.
AllowIsUserDot2
(
exec
)
{
return
nil
}
...
...
@@ -113,7 +117,8 @@ func (evm *EVMExecutor) IsFriend(myexec, writekey []byte, othertx *types.Transac
if
othertx
==
nil
{
return
false
}
exec
:=
types
.
GetParaExec
(
othertx
.
Execer
)
cfg
:=
evm
.
GetAPI
()
.
GetConfig
()
exec
:=
cfg
.
GetParaExec
(
othertx
.
Execer
)
if
exec
==
nil
||
len
(
bytes
.
TrimSpace
(
exec
))
==
0
{
return
false
}
...
...
@@ -142,8 +147,9 @@ func (evm *EVMExecutor) CheckTx(tx *types.Transaction, index int) error {
// GetActionName 获取运行状态名
func
(
evm
*
EVMExecutor
)
GetActionName
(
tx
*
types
.
Transaction
)
string
{
if
bytes
.
Equal
(
tx
.
Execer
,
[]
byte
(
types
.
ExecName
(
evmtypes
.
ExecutorName
)))
{
return
types
.
ExecName
(
evmtypes
.
ExecutorName
)
cfg
:=
evm
.
GetAPI
()
.
GetConfig
()
if
bytes
.
Equal
(
tx
.
Execer
,
[]
byte
(
cfg
.
ExecName
(
evmtypes
.
ExecutorName
)))
{
return
cfg
.
ExecName
(
evmtypes
.
ExecutorName
)
}
return
tx
.
ActionName
()
}
...
...
plugin/dapp/evm/types/evm.go
View file @
8e521d5c
...
...
@@ -28,18 +28,24 @@ var (
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
ExecerEvm
)
// init executor type
types
.
RegistorExecutor
(
ExecutorName
,
NewType
())
types
.
RegFork
(
ExecutorName
,
InitFork
)
types
.
RegExec
(
ExecutorName
,
InitExecutor
)
}
types
.
RegisterDappFork
(
ExecutorName
,
EVMEnable
,
500000
)
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
ExecutorName
,
EVMEnable
,
500000
)
// EVM合约中的数据分散存储,支持大数据量
types
.
RegisterDappFork
(
ExecutorName
,
ForkEVMState
,
650000
)
cfg
.
RegisterDappFork
(
ExecutorName
,
ForkEVMState
,
650000
)
// EVM合约状态数据生成哈希,保存在主链的StateDB中
types
.
RegisterDappFork
(
ExecutorName
,
ForkEVMKVHash
,
1000000
)
cfg
.
RegisterDappFork
(
ExecutorName
,
ForkEVMKVHash
,
1000000
)
// EVM合约支持ABI绑定和调用
types
.
RegisterDappFork
(
ExecutorName
,
ForkEVMABI
,
1250000
)
cfg
.
RegisterDappFork
(
ExecutorName
,
ForkEVMABI
,
1250000
)
// EEVM合约用户金额冻结
types
.
RegisterDappFork
(
ExecutorName
,
ForkEVMFrozen
,
1300000
)
cfg
.
RegisterDappFork
(
ExecutorName
,
ForkEVMFrozen
,
1300000
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
ExecutorName
,
NewType
(
cfg
))
}
// EvmType EVM类型定义
...
...
@@ -48,9 +54,10 @@ type EvmType struct {
}
// NewType 新建EVM类型对象
func
NewType
()
*
EvmType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
EvmType
{
c
:=
&
EvmType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
@@ -68,7 +75,8 @@ func (evm *EvmType) GetPayload() types.Message {
func
(
evm
EvmType
)
ActionName
(
tx
*
types
.
Transaction
)
string
{
// 这个需要通过合约交易目标地址来判断Action
// 如果目标地址为空,或为evm的固定合约地址,则为创建合约,否则为调用合约
if
strings
.
EqualFold
(
tx
.
To
,
address
.
ExecAddress
(
types
.
ExecName
(
ExecutorName
)))
{
cfg
:=
evm
.
GetConfig
()
if
strings
.
EqualFold
(
tx
.
To
,
address
.
ExecAddress
(
cfg
.
ExecName
(
ExecutorName
)))
{
return
"createEvmContract"
}
return
"callEvmContract"
...
...
@@ -107,7 +115,7 @@ func (evm EvmType) CreateTx(action string, message json.RawMessage) (*types.Tran
elog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
createEvmTx
(
&
param
)
return
createEvmTx
(
evm
.
GetConfig
(),
&
param
)
}
return
nil
,
types
.
ErrNotSupport
}
...
...
@@ -117,7 +125,7 @@ func (evm *EvmType) GetLogMap() map[int64]*types.LogInfo {
return
logInfo
}
func
createEvmTx
(
param
*
CreateCallTx
)
(
*
types
.
Transaction
,
error
)
{
func
createEvmTx
(
cfg
*
types
.
Chain33Config
,
param
*
CreateCallTx
)
(
*
types
.
Transaction
,
error
)
{
if
param
==
nil
{
elog
.
Error
(
"createEvmTx"
,
"param"
,
param
)
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -153,27 +161,27 @@ func createEvmTx(param *CreateCallTx) (*types.Transaction, error) {
return
nil
,
errors
.
New
(
"code must be set in create tx"
)
}
return
createRawTx
(
action
,
""
,
param
.
Fee
)
return
createRawTx
(
cfg
,
action
,
""
,
param
.
Fee
)
}
return
createRawTx
(
action
,
param
.
Name
,
param
.
Fee
)
return
createRawTx
(
cfg
,
action
,
param
.
Name
,
param
.
Fee
)
}
func
createRawTx
(
action
proto
.
Message
,
name
string
,
fee
int64
)
(
*
types
.
Transaction
,
error
)
{
func
createRawTx
(
cfg
*
types
.
Chain33Config
,
action
proto
.
Message
,
name
string
,
fee
int64
)
(
*
types
.
Transaction
,
error
)
{
tx
:=
&
types
.
Transaction
{}
if
len
(
name
)
==
0
{
tx
=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
ExecutorName
)),
Execer
:
[]
byte
(
cfg
.
ExecName
(
ExecutorName
)),
Payload
:
types
.
Encode
(
action
),
To
:
address
.
ExecAddress
(
types
.
ExecName
(
ExecutorName
)),
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
ExecutorName
)),
}
}
else
{
tx
=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
name
)),
Execer
:
[]
byte
(
cfg
.
ExecName
(
name
)),
Payload
:
types
.
Encode
(
action
),
To
:
address
.
ExecAddress
(
types
.
ExecName
(
name
)),
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
name
)),
}
}
tx
,
err
:=
types
.
FormatTx
(
string
(
tx
.
Execer
),
tx
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
string
(
tx
.
Execer
),
tx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
plugin/dapp/game/executor/game.go
View file @
8e521d5c
...
...
@@ -17,14 +17,15 @@ var glog = log.New("module", "execs.game")
var
driverName
=
gt
.
GameX
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Game
{}))
// Init register dapp
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
drivers
.
Register
(
cfg
,
GetName
(),
newGame
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
}
// Init register dapp
func
Init
(
name
string
,
sub
[]
byte
)
{
drivers
.
Register
(
GetName
(),
newGame
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Game
{}
))
}
// Game the game inherits all the attributes of the driverBase.
...
...
plugin/dapp/game/types/types.go
View file @
8e521d5c
...
...
@@ -18,20 +18,28 @@ var tlog = log.New("module", GameX)
func
init
()
{
// init executor type
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
GameX
))
types
.
RegistorExecutor
(
GameX
,
NewType
())
types
.
RegisterDappFork
(
GameX
,
"Enable"
,
0
)
types
.
RegFork
(
GameX
,
InitFork
)
types
.
RegExec
(
GameX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
GameX
,
"Enable"
,
0
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
GameX
,
NewType
(
cfg
))
}
//getRealExecName
//如果paraName == "", 那么自动用 types.ExecName("game")
//如果设置了paraName , 那么强制用paraName
//也就是说,我们可以构造其他平行链的交易
func
getRealExecName
(
paraName
string
)
string
{
return
types
.
ExecName
(
paraName
+
GameX
)
func
getRealExecName
(
cfg
*
types
.
Chain33Config
,
paraName
string
)
string
{
return
cfg
.
ExecName
(
paraName
+
GameX
)
}
// NewType new type
func
NewType
()
*
GameType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
GameType
{
c
:=
&
GameType
{}
c
.
SetChild
(
c
)
return
c
...
...
@@ -75,6 +83,7 @@ func (gt *GameType) GetTypeMap() map[string]int32 {
// CreateTx unused,just empty implementation
func
(
gt
GameType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
tlog
.
Debug
(
"Game.CreateTx"
,
"action"
,
action
)
cfg
:=
gt
.
GetConfig
()
if
action
==
ActionCreateGame
{
var
param
GamePreCreateTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -83,7 +92,7 @@ func (gt GameType) CreateTx(action string, message json.RawMessage) (*types.Tran
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawGamePreCreateTx
(
&
param
)
return
CreateRawGamePreCreateTx
(
cfg
,
&
param
)
}
else
if
action
==
ActionMatchGame
{
var
param
GamePreMatchTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -92,7 +101,7 @@ func (gt GameType) CreateTx(action string, message json.RawMessage) (*types.Tran
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawGamePreMatchTx
(
&
param
)
return
CreateRawGamePreMatchTx
(
cfg
,
&
param
)
}
else
if
action
==
ActionCancelGame
{
var
param
GamePreCancelTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -101,7 +110,7 @@ func (gt GameType) CreateTx(action string, message json.RawMessage) (*types.Tran
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawGamePreCancelTx
(
&
param
)
return
CreateRawGamePreCancelTx
(
cfg
,
&
param
)
}
else
if
action
==
ActionCloseGame
{
var
param
GamePreCloseTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -110,13 +119,13 @@ func (gt GameType) CreateTx(action string, message json.RawMessage) (*types.Tran
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawGamePreCloseTx
(
&
param
)
return
CreateRawGamePreCloseTx
(
cfg
,
&
param
)
}
return
nil
,
types
.
ErrNotSupport
}
// CreateRawGamePreCreateTx unused,just empty implementation
func
CreateRawGamePreCreateTx
(
parm
*
GamePreCreateTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawGamePreCreateTx
(
cfg
*
types
.
Chain33Config
,
parm
*
GamePreCreateTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
tlog
.
Error
(
"CreateRawGamePreCreateTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -132,13 +141,13 @@ func CreateRawGamePreCreateTx(parm *GamePreCreateTx) (*types.Transaction, error)
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
getRealExecName
(
types
.
GetParaName
())),
Execer
:
[]
byte
(
getRealExecName
(
cfg
,
cfg
.
GetParaName
())),
Payload
:
types
.
Encode
(
precreate
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
getRealExecName
(
types
.
GetParaName
())),
To
:
address
.
ExecAddress
(
getRealExecName
(
cfg
,
cfg
.
GetParaName
())),
}
name
:=
getRealExecName
(
types
.
GetParaName
())
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
name
:=
getRealExecName
(
cfg
,
cfg
.
GetParaName
())
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -146,7 +155,7 @@ func CreateRawGamePreCreateTx(parm *GamePreCreateTx) (*types.Transaction, error)
}
// CreateRawGamePreMatchTx unused,just empty implementation
func
CreateRawGamePreMatchTx
(
parm
*
GamePreMatchTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawGamePreMatchTx
(
cfg
*
types
.
Chain33Config
,
parm
*
GamePreMatchTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
@@ -160,13 +169,13 @@ func CreateRawGamePreMatchTx(parm *GamePreMatchTx) (*types.Transaction, error) {
Value
:
&
GameAction_Match
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
getRealExecName
(
types
.
GetParaName
())),
Execer
:
[]
byte
(
getRealExecName
(
cfg
,
cfg
.
GetParaName
())),
Payload
:
types
.
Encode
(
game
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
getRealExecName
(
types
.
GetParaName
())),
To
:
address
.
ExecAddress
(
getRealExecName
(
cfg
,
cfg
.
GetParaName
())),
}
name
:=
getRealExecName
(
types
.
GetParaName
())
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
name
:=
getRealExecName
(
cfg
,
cfg
.
GetParaName
())
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -174,7 +183,7 @@ func CreateRawGamePreMatchTx(parm *GamePreMatchTx) (*types.Transaction, error) {
}
// CreateRawGamePreCancelTx unused,just empty implementation
func
CreateRawGamePreCancelTx
(
parm
*
GamePreCancelTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawGamePreCancelTx
(
cfg
*
types
.
Chain33Config
,
parm
*
GamePreCancelTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
@@ -186,13 +195,13 @@ func CreateRawGamePreCancelTx(parm *GamePreCancelTx) (*types.Transaction, error)
Value
:
&
GameAction_Cancel
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
getRealExecName
(
types
.
GetParaName
())),
Execer
:
[]
byte
(
getRealExecName
(
cfg
,
cfg
.
GetParaName
())),
Payload
:
types
.
Encode
(
cancel
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
getRealExecName
(
types
.
GetParaName
())),
To
:
address
.
ExecAddress
(
getRealExecName
(
cfg
,
cfg
.
GetParaName
())),
}
name
:=
getRealExecName
(
types
.
GetParaName
())
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
name
:=
getRealExecName
(
cfg
,
cfg
.
GetParaName
())
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -200,7 +209,7 @@ func CreateRawGamePreCancelTx(parm *GamePreCancelTx) (*types.Transaction, error)
}
// CreateRawGamePreCloseTx unused,just empty implementation
func
CreateRawGamePreCloseTx
(
parm
*
GamePreCloseTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawGamePreCloseTx
(
cfg
*
types
.
Chain33Config
,
parm
*
GamePreCloseTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
@@ -213,13 +222,13 @@ func CreateRawGamePreCloseTx(parm *GamePreCloseTx) (*types.Transaction, error) {
Value
:
&
GameAction_Close
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
getRealExecName
(
types
.
GetParaName
())),
Execer
:
[]
byte
(
getRealExecName
(
cfg
,
cfg
.
GetParaName
())),
Payload
:
types
.
Encode
(
close
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
getRealExecName
(
types
.
GetParaName
())),
To
:
address
.
ExecAddress
(
getRealExecName
(
cfg
,
cfg
.
GetParaName
())),
}
name
:=
getRealExecName
(
types
.
GetParaName
())
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
name
:=
getRealExecName
(
cfg
,
cfg
.
GetParaName
())
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
plugin/dapp/hashlock/executor/hashlock.go
View file @
8e521d5c
...
...
@@ -16,14 +16,15 @@ const minLockTime = 60
var
driverName
=
"hashlock"
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Hashlock
{}))
// Init hashlock
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
drivers
.
Register
(
cfg
,
GetName
(),
newHashlock
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
}
// Init hashlock
func
Init
(
name
string
,
sub
[]
byte
)
{
drivers
.
Register
(
GetName
(),
newHashlock
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Hashlock
{}
))
}
// GetName for hashlock
...
...
plugin/dapp/hashlock/types/hashlock.go
View file @
8e521d5c
...
...
@@ -19,9 +19,17 @@ var (
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
HashlockX
))
types
.
RegistorExecutor
(
HashlockX
,
NewType
())
types
.
RegisterDappFork
(
HashlockX
,
"Enable"
,
0
)
types
.
RegisterDappFork
(
HashlockX
,
ForkBadRepeatSecretX
,
2715575
)
types
.
RegFork
(
HashlockX
,
InitFork
)
types
.
RegExec
(
HashlockX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
HashlockX
,
"Enable"
,
0
)
cfg
.
RegisterDappFork
(
HashlockX
,
ForkBadRepeatSecretX
,
2715575
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
HashlockX
,
NewType
(
cfg
))
}
// HashlockType def
...
...
@@ -30,9 +38,10 @@ type HashlockType struct {
}
// NewType method
func
NewType
()
*
HashlockType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
HashlockType
{
c
:=
&
HashlockType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
@@ -50,6 +59,7 @@ func (hashlock *HashlockType) GetPayload() types.Message {
func
(
hashlock
*
HashlockType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
hlog
.
Debug
(
"hashlock.CreateTx"
,
"action"
,
action
)
cfg
:=
hashlock
.
GetConfig
()
if
action
==
"HashlockLock"
{
var
param
HashlockLockTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -57,7 +67,7 @@ func (hashlock *HashlockType) CreateTx(action string, message json.RawMessage) (
hlog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawHashlockLockTx
(
&
param
)
return
CreateRawHashlockLockTx
(
cfg
,
&
param
)
}
else
if
action
==
"HashlockUnlock"
{
var
param
HashlockUnlockTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -65,7 +75,7 @@ func (hashlock *HashlockType) CreateTx(action string, message json.RawMessage) (
hlog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawHashlockUnlockTx
(
&
param
)
return
CreateRawHashlockUnlockTx
(
cfg
,
&
param
)
}
else
if
action
==
"HashlockSend"
{
var
param
HashlockSendTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -73,7 +83,7 @@ func (hashlock *HashlockType) CreateTx(action string, message json.RawMessage) (
hlog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawHashlockSendTx
(
&
param
)
return
CreateRawHashlockSendTx
(
cfg
,
&
param
)
}
return
nil
,
types
.
ErrNotSupport
...
...
@@ -94,7 +104,7 @@ func (hashlock *HashlockType) GetLogMap() map[int64]*types.LogInfo {
}
// CreateRawHashlockLockTx method
func
CreateRawHashlockLockTx
(
parm
*
HashlockLockTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawHashlockLockTx
(
cfg
*
types
.
Chain33Config
,
parm
*
HashlockLockTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
hlog
.
Error
(
"CreateRawHashlockLockTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -112,12 +122,12 @@ func CreateRawHashlockLockTx(parm *HashlockLockTx) (*types.Transaction, error) {
Value
:
&
HashlockAction_Hlock
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
HashlockX
)),
Execer
:
[]
byte
(
cfg
.
ExecName
(
HashlockX
)),
Payload
:
types
.
Encode
(
lock
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
types
.
ExecName
(
HashlockX
)),
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
HashlockX
)),
}
tx
,
err
:=
types
.
FormatTx
(
types
.
ExecName
(
HashlockX
),
tx
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
cfg
.
ExecName
(
HashlockX
),
tx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -125,7 +135,7 @@ func CreateRawHashlockLockTx(parm *HashlockLockTx) (*types.Transaction, error) {
}
// CreateRawHashlockUnlockTx method
func
CreateRawHashlockUnlockTx
(
parm
*
HashlockUnlockTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawHashlockUnlockTx
(
cfg
*
types
.
Chain33Config
,
parm
*
HashlockUnlockTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
hlog
.
Error
(
"CreateRawHashlockUnlockTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -139,13 +149,13 @@ func CreateRawHashlockUnlockTx(parm *HashlockUnlockTx) (*types.Transaction, erro
Value
:
&
HashlockAction_Hunlock
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
HashlockX
)),
Execer
:
[]
byte
(
cfg
.
ExecName
(
HashlockX
)),
Payload
:
types
.
Encode
(
unlock
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
HashlockX
),
}
tx
,
err
:=
types
.
FormatTx
(
types
.
ExecName
(
HashlockX
),
tx
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
cfg
.
ExecName
(
HashlockX
),
tx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -154,7 +164,7 @@ func CreateRawHashlockUnlockTx(parm *HashlockUnlockTx) (*types.Transaction, erro
}
// CreateRawHashlockSendTx method
func
CreateRawHashlockSendTx
(
parm
*
HashlockSendTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawHashlockSendTx
(
cfg
*
types
.
Chain33Config
,
parm
*
HashlockSendTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
hlog
.
Error
(
"CreateRawHashlockSendTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -173,7 +183,7 @@ func CreateRawHashlockSendTx(parm *HashlockSendTx) (*types.Transaction, error) {
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
HashlockX
),
}
tx
,
err
:=
types
.
FormatTx
(
types
.
ExecName
(
HashlockX
),
tx
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
cfg
.
ExecName
(
HashlockX
),
tx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
plugin/dapp/js/executor/js.go
View file @
8e521d5c
...
...
@@ -21,22 +21,10 @@ var driverName = ptypes.JsX
var
basevm
*
otto
.
Otto
var
codecache
*
lru
.
Cache
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
js
{}))
basevm
=
otto
.
New
()
_
,
err
:=
basevm
.
Run
(
callcode
)
if
err
!=
nil
{
panic
(
err
)
}
execaddressFunc
(
basevm
)
sha256Func
(
basevm
)
}
var
isinit
int64
//Init 插件初始化
func
Init
(
name
string
,
sub
[]
byte
)
{
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
if
atomic
.
CompareAndSwapInt64
(
&
isinit
,
0
,
1
)
{
//最新的64个code做cache
var
err
error
...
...
@@ -44,8 +32,21 @@ func Init(name string, sub []byte) {
if
err
!=
nil
{
panic
(
err
)
}
drivers
.
Register
(
GetName
(),
newjs
,
0
)
drivers
.
Register
(
cfg
,
GetName
(),
newjs
,
0
)
}
InitExecType
()
}
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
js
{}))
basevm
=
otto
.
New
()
_
,
err
:=
basevm
.
Run
(
callcode
)
if
err
!=
nil
{
panic
(
err
)
}
execaddressFunc
(
basevm
)
sha256Func
(
basevm
)
}
type
js
struct
{
...
...
@@ -80,7 +81,8 @@ func (u *js) IsFriend(myexec, writekey []byte, othertx *types.Transaction) bool
if
othertx
==
nil
{
return
false
}
exec
:=
types
.
GetParaExec
(
othertx
.
Execer
)
cfg
:=
u
.
GetAPI
()
.
GetConfig
()
exec
:=
cfg
.
GetParaExec
(
othertx
.
Execer
)
if
exec
==
nil
||
len
(
bytes
.
TrimSpace
(
exec
))
==
0
{
return
false
}
...
...
@@ -235,8 +237,9 @@ func (u *js) localdbFunc(vm *otto.Otto, name string) {
}
func
(
u
*
js
)
execnameFunc
(
vm
*
otto
.
Otto
,
name
string
)
{
cfg
:=
u
.
GetAPI
()
.
GetConfig
()
vm
.
Set
(
"execname"
,
func
(
call
otto
.
FunctionCall
)
otto
.
Value
{
return
okReturn
(
vm
,
types
.
ExecName
(
"user."
+
ptypes
.
JsX
+
"."
+
name
))
return
okReturn
(
vm
,
cfg
.
ExecName
(
"user."
+
ptypes
.
JsX
+
"."
+
name
))
})
}
...
...
@@ -382,7 +385,8 @@ func (u *js) Allow(tx *types.Transaction, index int) error {
//增加新的规则:
//主链: user.jsvm.xxx 执行 jsvm 合约
//平行链: user.p.guodun.user.jsvm.xxx 执行 jsvm 合约
exec
:=
types
.
GetParaExec
(
tx
.
Execer
)
cfg
:=
u
.
GetAPI
()
.
GetConfig
()
exec
:=
cfg
.
GetParaExec
(
tx
.
Execer
)
if
u
.
AllowIsUserDot2
(
exec
)
{
return
nil
}
...
...
plugin/dapp/js/types/js.go
View file @
8e521d5c
...
...
@@ -56,8 +56,16 @@ var (
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
JsX
))
types
.
RegistorExecutor
(
JsX
,
NewType
())
types
.
RegisterDappFork
(
JsX
,
"Enable"
,
0
)
types
.
RegFork
(
JsX
,
InitFork
)
types
.
RegExec
(
JsX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
JsX
,
"Enable"
,
0
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
"coins"
,
NewType
(
cfg
))
}
//JsType 类型
...
...
@@ -66,9 +74,10 @@ type JsType struct {
}
//NewType 新建一个plugin 类型
func
NewType
()
*
JsType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
JsType
{
c
:=
&
JsType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
plugin/dapp/lottery/executor/lottery.go
View file @
8e521d5c
...
...
@@ -17,11 +17,6 @@ import (
var
llog
=
log
.
New
(
"module"
,
"execs.lottery"
)
var
driverName
=
pty
.
LotteryX
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Lottery
{}))
}
type
subConfig
struct
{
ParaRemoteGrpcClient
string
`json:"paraRemoteGrpcClient"`
}
...
...
@@ -29,7 +24,7 @@ type subConfig struct {
var
cfg
subConfig
// Init lottery
func
Init
(
name
string
,
sub
[]
byte
)
{
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
driverName
:=
GetName
()
if
name
!=
driverName
{
panic
(
"system dapp can't be rename"
)
...
...
@@ -37,7 +32,13 @@ func Init(name string, sub []byte) {
if
sub
!=
nil
{
types
.
MustDecode
(
sub
,
&
cfg
)
}
drivers
.
Register
(
driverName
,
newLottery
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
drivers
.
Register
(
cfg
,
driverName
,
newLottery
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
}
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Lottery
{}))
}
// GetName for lottery
...
...
plugin/dapp/lottery/types/lottery.go
View file @
8e521d5c
...
...
@@ -19,19 +19,29 @@ var (
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
LotteryX
))
types
.
Reg
istorExecutor
(
LotteryX
,
NewType
()
)
types
.
Reg
isterDappFork
(
LotteryX
,
"Enable"
,
0
)
types
.
Reg
Fork
(
LotteryX
,
InitFork
)
types
.
Reg
Exec
(
LotteryX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
LotteryX
,
"Enable"
,
0
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
LotteryX
,
NewType
(
cfg
))
}
// LotteryType def
type
LotteryType
struct
{
types
.
ExecTypeBase
}
// NewType method
func
NewType
()
*
LotteryType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
LotteryType
{
c
:=
&
LotteryType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
@@ -58,7 +68,7 @@ func (lottery *LotteryType) GetPayload() types.Message {
// CreateTx method
func
(
lottery
LotteryType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
llog
.
Debug
(
"lottery.CreateTx"
,
"action"
,
action
)
cfg
:=
lottery
.
GetConfig
()
if
action
==
"LotteryCreate"
{
var
param
LotteryCreateTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -66,7 +76,7 @@ func (lottery LotteryType) CreateTx(action string, message json.RawMessage) (*ty
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawLotteryCreateTx
(
&
param
)
return
CreateRawLotteryCreateTx
(
cfg
,
&
param
)
}
else
if
action
==
"LotteryBuy"
{
var
param
LotteryBuyTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -74,7 +84,7 @@ func (lottery LotteryType) CreateTx(action string, message json.RawMessage) (*ty
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawLotteryBuyTx
(
&
param
)
return
CreateRawLotteryBuyTx
(
cfg
,
&
param
)
}
else
if
action
==
"LotteryDraw"
{
var
param
LotteryDrawTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -82,7 +92,7 @@ func (lottery LotteryType) CreateTx(action string, message json.RawMessage) (*ty
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawLotteryDrawTx
(
&
param
)
return
CreateRawLotteryDrawTx
(
cfg
,
&
param
)
}
else
if
action
==
"LotteryClose"
{
var
param
LotteryCloseTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -90,7 +100,7 @@ func (lottery LotteryType) CreateTx(action string, message json.RawMessage) (*ty
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawLotteryCloseTx
(
&
param
)
return
CreateRawLotteryCloseTx
(
cfg
,
&
param
)
}
else
{
return
nil
,
types
.
ErrNotSupport
}
...
...
@@ -107,7 +117,7 @@ func (lottery LotteryType) GetTypeMap() map[string]int32 {
}
// CreateRawLotteryCreateTx method
func
CreateRawLotteryCreateTx
(
parm
*
LotteryCreateTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawLotteryCreateTx
(
cfg
*
types
.
Chain33Config
,
parm
*
LotteryCreateTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawLotteryCreateTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -124,13 +134,13 @@ func CreateRawLotteryCreateTx(parm *LotteryCreateTx) (*types.Transaction, error)
Value
:
&
LotteryAction_Create
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
LotteryX
)),
Execer
:
[]
byte
(
cfg
.
ExecName
(
LotteryX
)),
Payload
:
types
.
Encode
(
create
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
types
.
ExecName
(
LotteryX
)),
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
LotteryX
)),
}
name
:=
types
.
ExecName
(
LotteryX
)
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
name
:=
cfg
.
ExecName
(
LotteryX
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -138,7 +148,7 @@ func CreateRawLotteryCreateTx(parm *LotteryCreateTx) (*types.Transaction, error)
}
// CreateRawLotteryBuyTx method
func
CreateRawLotteryBuyTx
(
parm
*
LotteryBuyTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawLotteryBuyTx
(
cfg
*
types
.
Chain33Config
,
parm
*
LotteryBuyTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawLotteryBuyTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -155,13 +165,13 @@ func CreateRawLotteryBuyTx(parm *LotteryBuyTx) (*types.Transaction, error) {
Value
:
&
LotteryAction_Buy
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
LotteryX
)),
Execer
:
[]
byte
(
cfg
.
ExecName
(
LotteryX
)),
Payload
:
types
.
Encode
(
buy
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
types
.
ExecName
(
LotteryX
)),
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
LotteryX
)),
}
name
:=
types
.
ExecName
(
LotteryX
)
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
name
:=
cfg
.
ExecName
(
LotteryX
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -169,7 +179,7 @@ func CreateRawLotteryBuyTx(parm *LotteryBuyTx) (*types.Transaction, error) {
}
// CreateRawLotteryDrawTx method
func
CreateRawLotteryDrawTx
(
parm
*
LotteryDrawTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawLotteryDrawTx
(
cfg
*
types
.
Chain33Config
,
parm
*
LotteryDrawTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawLotteryDrawTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -183,13 +193,13 @@ func CreateRawLotteryDrawTx(parm *LotteryDrawTx) (*types.Transaction, error) {
Value
:
&
LotteryAction_Draw
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
LotteryX
)),
Execer
:
[]
byte
(
cfg
.
ExecName
(
LotteryX
)),
Payload
:
types
.
Encode
(
draw
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
types
.
ExecName
(
LotteryX
)),
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
LotteryX
)),
}
name
:=
types
.
ExecName
(
LotteryX
)
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
name
:=
cfg
.
ExecName
(
LotteryX
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -197,7 +207,7 @@ func CreateRawLotteryDrawTx(parm *LotteryDrawTx) (*types.Transaction, error) {
}
// CreateRawLotteryCloseTx method
func
CreateRawLotteryCloseTx
(
parm
*
LotteryCloseTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawLotteryCloseTx
(
cfg
*
types
.
Chain33Config
,
parm
*
LotteryCloseTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawLotteryCloseTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -211,14 +221,14 @@ func CreateRawLotteryCloseTx(parm *LotteryCloseTx) (*types.Transaction, error) {
Value
:
&
LotteryAction_Close
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
LotteryX
)),
Execer
:
[]
byte
(
cfg
.
ExecName
(
LotteryX
)),
Payload
:
types
.
Encode
(
close
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
types
.
ExecName
(
LotteryX
)),
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
LotteryX
)),
}
name
:=
types
.
ExecName
(
LotteryX
)
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
name
:=
cfg
.
ExecName
(
LotteryX
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
plugin/dapp/multisig/executor/multisig.go
View file @
8e521d5c
...
...
@@ -32,14 +32,16 @@ var multisiglog = log.New("module", "execs.multisig")
var
driverName
=
"multisig"
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
MultiSig
{}))
}
// Init multisig模块初始化
func
Init
(
name
string
,
sub
[]
byte
)
{
drivers
.
Register
(
GetName
(),
newMultiSig
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
drivers
.
Register
(
cfg
,
GetName
(),
newMultiSig
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
}
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
MultiSig
{}))
}
// GetName multisig合约name
...
...
@@ -887,7 +889,8 @@ func (m *MultiSig) getMultiSigAccAssets(multiSigAddr string, assets *mty.Assets)
}
var
acc1
*
types
.
Account
execaddress
:=
dapp
.
ExecAddress
(
types
.
ExecName
(
m
.
GetName
()))
cfg
:=
m
.
GetAPI
()
.
GetConfig
()
execaddress
:=
dapp
.
ExecAddress
(
cfg
.
ExecName
(
m
.
GetName
()))
acc1
=
acc
.
LoadExecAccount
(
multiSigAddr
,
execaddress
)
return
acc1
,
nil
}
...
...
plugin/dapp/multisig/types/types.go
View file @
8e521d5c
...
...
@@ -12,8 +12,16 @@ import (
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
MultiSigX
))
types
.
RegistorExecutor
(
MultiSigX
,
NewType
())
types
.
RegisterDappFork
(
MultiSigX
,
"Enable"
,
0
)
types
.
RegFork
(
MultiSigX
,
InitFork
)
types
.
RegExec
(
MultiSigX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
MultiSigX
,
"Enable"
,
0
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
MultiSigX
,
NewType
(
cfg
))
}
// MultiSigType multisig合约结构体
...
...
@@ -22,9 +30,10 @@ type MultiSigType struct {
}
// NewType new一个新的multisig合约实例
func
NewType
()
*
MultiSigType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
MultiSigType
{
c
:=
&
MultiSigType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
plugin/dapp/norm/executor/norm.go
View file @
8e521d5c
...
...
@@ -13,15 +13,16 @@ import (
var
clog
=
log
.
New
(
"module"
,
"execs.norm"
)
var
driverName
=
"norm"
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Norm
{}))
}
// Init norm
func
Init
(
name
string
,
sub
[]
byte
)
{
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
clog
.
Debug
(
"register norm execer"
)
drivers
.
Register
(
GetName
(),
newNorm
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
drivers
.
Register
(
cfg
,
GetName
(),
newNorm
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
}
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Norm
{}))
}
// GetName for norm
...
...
plugin/dapp/norm/types/norm.go
View file @
8e521d5c
...
...
@@ -13,8 +13,16 @@ var NormX = "norm"
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
NormX
))
types
.
RegistorExecutor
(
NormX
,
NewType
())
types
.
RegisterDappFork
(
NormX
,
"Enable"
,
0
)
types
.
RegFork
(
CoinsX
,
InitFork
)
types
.
RegExec
(
CoinsX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
NormX
,
"Enable"
,
0
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
NormX
,
NewType
(
cfg
))
}
// NormType def
...
...
@@ -23,9 +31,10 @@ type NormType struct {
}
// NewType method
func
NewType
()
*
NormType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
NormType
{
c
:=
&
NormType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
plugin/dapp/oracle/executor/oracle.go
View file @
8e521d5c
...
...
@@ -17,10 +17,17 @@ var olog = log.New("module", "execs.oracle")
var
driverName
=
oty
.
OracleX
// Init 执行器初始化
func
Init
(
name
string
,
sub
[]
byte
)
{
drivers
.
Register
(
newOracle
()
.
GetName
(),
newOracle
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
drivers
.
Register
(
cfg
,
newOracle
()
.
GetName
(),
newOracle
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
}
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
oracle
{}))
}
// GetName 获取oracle执行器名
func
GetName
()
string
{
return
newOracle
()
.
GetName
()
...
...
@@ -33,11 +40,6 @@ func newOracle() drivers.Driver {
return
t
}
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
oracle
{}))
}
// oracle driver
type
oracle
struct
{
drivers
.
DriverBase
...
...
plugin/dapp/oracle/types/types.go
View file @
8e521d5c
...
...
@@ -15,8 +15,16 @@ import (
func
init
()
{
// init executor type
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
OracleX
))
types
.
RegistorExecutor
(
OracleX
,
NewType
())
types
.
RegisterDappFork
(
OracleX
,
"Enable"
,
0
)
types
.
RegFork
(
OracleX
,
InitFork
)
types
.
RegExec
(
OracleX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
OracleX
,
"Enable"
,
0
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
OracleX
,
NewType
(
cfg
))
}
// OracleType 预言机执行器类型
...
...
@@ -25,9 +33,10 @@ type OracleType struct {
}
// NewType 创建执行器类型
func
NewType
()
*
OracleType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
OracleType
{
c
:=
&
OracleType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
plugin/dapp/paracross/executor/paracross.go
View file @
8e521d5c
...
...
@@ -27,17 +27,18 @@ type Paracross struct {
drivers
.
DriverBase
}
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Paracross
{}))
}
//Init paracross exec register
func
Init
(
name
string
,
sub
[]
byte
)
{
drivers
.
Register
(
GetName
(),
newParacross
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
drivers
.
Register
(
cfg
,
GetName
(),
newParacross
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
setPrefix
()
}
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Paracross
{}))
}
//GetName return paracross name
func
GetName
()
string
{
return
newParacross
()
.
GetName
()
...
...
@@ -280,7 +281,8 @@ func (c *Paracross) updateLocalAssetTransfer(paraHeight int64, tx *types.Transac
//IsFriend call exec is same seariase exec
func
(
c
*
Paracross
)
IsFriend
(
myexec
,
writekey
[]
byte
,
tx
*
types
.
Transaction
)
bool
{
//不允许平行链
if
types
.
IsPara
()
{
cfg
:=
c
.
GetAPI
()
.
GetConfig
()
if
cfg
.
IsPara
()
{
return
false
}
//friend 调用必须是自己在调用
...
...
@@ -299,7 +301,8 @@ func (c *Paracross) allow(tx *types.Transaction, index int) error {
// 增加新的规则: 在主链执行器带着title的 asset-transfer/asset-withdraw 交易允许执行
// 1. user.p.${tilte}.${paraX}
// 1. payload 的 actionType = t/w
if
!
types
.
IsPara
()
&&
c
.
allowIsParaTx
(
tx
.
Execer
)
{
cfg
:=
c
.
GetAPI
()
.
GetConfig
()
if
!
cfg
.
IsPara
()
&&
c
.
allowIsParaTx
(
tx
.
Execer
)
{
var
payload
pt
.
ParacrossAction
err
:=
types
.
Decode
(
tx
.
Payload
,
&
payload
)
if
err
!=
nil
{
...
...
@@ -308,7 +311,7 @@ func (c *Paracross) allow(tx *types.Transaction, index int) error {
if
payload
.
Ty
==
pt
.
ParacrossActionAssetTransfer
||
payload
.
Ty
==
pt
.
ParacrossActionAssetWithdraw
{
return
nil
}
if
types
.
IsDappFork
(
c
.
GetHeight
(),
pt
.
ParaX
,
pt
.
ForkCommitTx
)
{
if
cfg
.
IsDappFork
(
c
.
GetHeight
(),
pt
.
ParaX
,
pt
.
ForkCommitTx
)
{
if
payload
.
Ty
==
pt
.
ParacrossActionCommit
||
payload
.
Ty
==
pt
.
ParacrossActionNodeConfig
||
payload
.
Ty
==
pt
.
ParacrossActionNodeGroupApply
{
return
nil
...
...
plugin/dapp/paracross/types/paracross.go
View file @
8e521d5c
...
...
@@ -160,19 +160,19 @@ func CalcMinerHeightKey(title string, height int64) []byte {
}
// CreateRawCommitTx4MainChain create commit tx to main chain
func
CreateRawCommitTx4MainChain
(
status
*
ParacrossNodeStatus
,
name
string
,
fee
int64
)
(
*
types
.
Transaction
,
error
)
{
return
createRawCommitTx
(
status
,
name
,
fee
)
func
CreateRawCommitTx4MainChain
(
cfg
*
types
.
Chain33Config
,
status
*
ParacrossNodeStatus
,
name
string
,
fee
int64
)
(
*
types
.
Transaction
,
error
)
{
return
createRawCommitTx
(
cfg
,
status
,
name
,
fee
)
}
func
createRawParacrossCommitTx
(
parm
*
paracrossCommitTx
)
(
*
types
.
Transaction
,
error
)
{
func
createRawParacrossCommitTx
(
cfg
*
types
.
Chain33Config
,
parm
*
paracrossCommitTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
tlog
.
Error
(
"createRawParacrossCommitTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
return
createRawCommitTx
(
&
parm
.
Status
,
types
.
ExecName
(
ParaX
),
parm
.
Fee
)
return
createRawCommitTx
(
cfg
,
&
parm
.
Status
,
cfg
.
ExecName
(
ParaX
),
parm
.
Fee
)
}
func
createRawCommitTx
(
status
*
ParacrossNodeStatus
,
name
string
,
feeRate
int64
)
(
*
types
.
Transaction
,
error
)
{
func
createRawCommitTx
(
cfg
*
types
.
Chain33Config
,
status
*
ParacrossNodeStatus
,
name
string
,
feeRate
int64
)
(
*
types
.
Transaction
,
error
)
{
v
:=
&
ParacrossCommitAction
{
Status
:
status
,
}
...
...
@@ -186,7 +186,7 @@ func createRawCommitTx(status *ParacrossNodeStatus, name string, feeRate int64)
To
:
address
.
ExecAddress
(
name
),
Expire
:
types
.
Now
()
.
Unix
()
+
int64
(
120
),
//120s
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -200,8 +200,8 @@ func createRawCommitTx(status *ParacrossNodeStatus, name string, feeRate int64)
}
// CreateRawNodeConfigTx create raw tx for node config
func
CreateRawNodeConfigTx
(
config
*
ParaNodeAddrConfig
)
(
*
types
.
Transaction
,
error
)
{
config
.
Title
=
types
.
GetTitle
()
func
CreateRawNodeConfigTx
(
c
fg
*
types
.
Chain33Config
,
c
onfig
*
ParaNodeAddrConfig
)
(
*
types
.
Transaction
,
error
)
{
config
.
Title
=
cfg
.
GetTitle
()
config
.
Addr
=
strings
.
Trim
(
config
.
Addr
,
" "
)
config
.
Id
=
strings
.
Trim
(
config
.
Id
,
" "
)
...
...
@@ -217,8 +217,8 @@ func CreateRawNodeConfigTx(config *ParaNodeAddrConfig) (*types.Transaction, erro
}
//CreateRawNodeGroupApplyTx create raw tx for node group
func
CreateRawNodeGroupApplyTx
(
apply
*
ParaNodeGroupConfig
)
(
*
types
.
Transaction
,
error
)
{
apply
.
Title
=
types
.
GetTitle
()
func
CreateRawNodeGroupApplyTx
(
cfg
*
types
.
Chain33Config
,
apply
*
ParaNodeGroupConfig
)
(
*
types
.
Transaction
,
error
)
{
apply
.
Title
=
cfg
.
GetTitle
()
apply
.
Id
=
strings
.
Trim
(
apply
.
Id
,
" "
)
action
:=
&
ParacrossAction
{
...
...
@@ -235,7 +235,7 @@ func CreateRawNodeGroupApplyTx(apply *ParaNodeGroupConfig) (*types.Transaction,
}
// CreateRawAssetTransferTx create asset transfer tx
func
CreateRawAssetTransferTx
(
param
*
types
.
CreateTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawAssetTransferTx
(
cfg
*
types
.
Chain33Config
,
param
*
types
.
CreateTx
)
(
*
types
.
Transaction
,
error
)
{
// 跨链交易需要在主链和平行链上执行, 所以应该可以在主链和平行链上构建
if
!
types
.
IsParaExecName
(
param
.
GetExecName
())
{
tlog
.
Error
(
"CreateRawAssetTransferTx"
,
"exec"
,
param
.
GetExecName
())
...
...
@@ -260,7 +260,7 @@ func CreateRawAssetTransferTx(param *types.CreateTx) (*types.Transaction, error)
To
:
address
.
ExecAddress
(
param
.
GetExecName
()),
Fee
:
param
.
Fee
,
}
tx
,
err
:=
types
.
FormatTx
(
param
.
GetExecName
(),
tx
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
param
.
GetExecName
(),
tx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -268,19 +268,19 @@ func CreateRawAssetTransferTx(param *types.CreateTx) (*types.Transaction, error)
}
// CreateRawMinerTx create miner tx
func
CreateRawMinerTx
(
value
*
ParacrossMinerAction
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawMinerTx
(
cfg
*
types
.
Chain33Config
,
value
*
ParacrossMinerAction
)
(
*
types
.
Transaction
,
error
)
{
action
:=
&
ParacrossAction
{
Ty
:
ParacrossActionMiner
,
Value
:
&
ParacrossAction_Miner
{
value
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
ParaX
)),
Execer
:
[]
byte
(
cfg
.
ExecName
(
ParaX
)),
Payload
:
types
.
Encode
(
action
),
Nonce
:
0
,
//for consensus purpose, block hash need same, different auth node need keep totally same vote tx
To
:
address
.
ExecAddress
(
types
.
ExecName
(
ParaX
)),
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
ParaX
)),
}
err
:=
tx
.
SetRealFee
(
types
.
GInt
(
"MinFee"
))
err
:=
tx
.
SetRealFee
(
cfg
.
GInt
(
"MinFee"
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -295,7 +295,8 @@ func (p ParacrossType) CreateRawTransferTx(action string, param json.RawMessage)
tlog
.
Error
(
"ParacrossType CreateTx failed"
,
"err"
,
err
,
"action"
,
action
,
"msg"
,
string
(
param
))
return
nil
,
err
}
if
!
types
.
IsPara
()
{
cfg
:=
p
.
GetConfig
()
if
!
cfg
.
IsPara
()
{
var
transfer
ParacrossAction
err
=
types
.
Decode
(
tx
.
Payload
,
&
transfer
)
if
err
!=
nil
{
...
...
@@ -315,9 +316,9 @@ func (p ParacrossType) CreateRawTransferTx(action string, param json.RawMessage)
}
//GetDappForkHeight get paracross dapp fork height
func
GetDappForkHeight
(
forkKey
string
)
int64
{
func
GetDappForkHeight
(
cfg
*
types
.
Chain33Config
,
forkKey
string
)
int64
{
var
forkHeight
int64
if
types
.
IsPara
()
{
if
cfg
.
IsPara
()
{
key
:=
forkKey
switch
forkKey
{
case
ForkCommitTx
:
...
...
@@ -326,15 +327,15 @@ func GetDappForkHeight(forkKey string) int64 {
key
=
MainLoopCheckCommitTxDoneForkHeight
}
forkHeight
=
types
.
Conf
(
"config.consensus.sub.para"
)
.
GInt
(
key
)
forkHeight
=
types
.
Conf
(
cfg
,
"config.consensus.sub.para"
)
.
GInt
(
key
)
if
forkHeight
<=
0
{
forkHeight
=
types
.
MaxHeight
}
}
else
{
forkHeight
=
types
.
GetDappFork
(
ParaX
,
forkKey
)
forkHeight
=
cfg
.
GetDappFork
(
ParaX
,
forkKey
)
// CI特殊处理,主链是local,fork都是0,平行链有些配置项需要设置为非0,不然获取到的高度为MaxHeight
if
types
.
IsLocal
()
{
if
cfg
.
IsLocal
()
{
switch
forkKey
{
case
ForkCommitTx
:
forkHeight
=
10
...
...
@@ -347,6 +348,6 @@ func GetDappForkHeight(forkKey string) int64 {
}
// IsParaForkHeight check height more than fork height
func
IsParaForkHeight
(
height
int64
,
forkKey
string
)
bool
{
return
height
>=
GetDappForkHeight
(
forkKey
)
func
IsParaForkHeight
(
cfg
*
types
.
Chain33Config
,
height
int64
,
forkKey
string
)
bool
{
return
height
>=
GetDappForkHeight
(
cfg
,
forkKey
)
}
plugin/dapp/paracross/types/type.go
View file @
8e521d5c
...
...
@@ -31,16 +31,26 @@ var (
func
init
()
{
// init executor type
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
ParaX
))
types
.
RegistorExecutor
(
ParaX
,
NewType
())
types
.
RegisterDappFork
(
ParaX
,
"Enable"
,
0
)
types
.
RegisterDappFork
(
ParaX
,
"ForkParacrossWithdrawFromParachain"
,
1298600
)
types
.
RegisterDappFork
(
ParaX
,
ForkCommitTx
,
1850000
)
types
.
RegisterDappFork
(
ParaX
,
ForkLoopCheckCommitTxDone
,
3230000
)
types
.
RegFork
(
ParaX
,
InitFork
)
types
.
RegExec
(
ParaX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
ParaX
,
"Enable"
,
0
)
cfg
.
RegisterDappFork
(
ParaX
,
"ForkParacrossWithdrawFromParachain"
,
1298600
)
cfg
.
RegisterDappFork
(
ParaX
,
ForkCommitTx
,
1850000
)
cfg
.
RegisterDappFork
(
ParaX
,
ForkLoopCheckCommitTxDone
,
3230000
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
ParaX
,
NewType
(
cfg
))
}
// GetExecName get para exec name
func
GetExecName
()
string
{
return
types
.
ExecName
(
ParaX
)
func
GetExecName
(
cfg
*
types
.
Chain33Config
)
string
{
return
cfg
.
ExecName
(
ParaX
)
}
// ParacrossType base paracross type
...
...
@@ -49,9 +59,10 @@ type ParacrossType struct {
}
// NewType get paracross type
func
NewType
()
*
ParacrossType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
ParacrossType
{
c
:=
&
ParacrossType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
@@ -101,6 +112,7 @@ func (p *ParacrossType) GetPayload() types.Message {
// CreateTx paracross create tx by different action
func
(
p
ParacrossType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
cfg
:=
p
.
GetConfig
()
if
action
==
"ParacrossCommit"
{
var
param
paracrossCommitTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -109,7 +121,7 @@ func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types.
return
nil
,
types
.
ErrInvalidParam
}
return
createRawParacrossCommitTx
(
&
param
)
return
createRawParacrossCommitTx
(
cfg
,
&
param
)
}
else
if
action
==
"ParacrossAssetTransfer"
||
action
==
"ParacrossAssetWithdraw"
{
var
param
types
.
CreateTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -117,7 +129,7 @@ func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types.
glog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawAssetTransferTx
(
&
param
)
return
CreateRawAssetTransferTx
(
cfg
,
&
param
)
}
else
if
action
==
"ParacrossTransfer"
||
action
==
"Transfer"
||
action
==
"ParacrossWithdraw"
||
action
==
"Withdraw"
||
...
...
@@ -125,7 +137,7 @@ func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types.
return
p
.
CreateRawTransferTx
(
action
,
message
)
}
else
if
action
==
"NodeConfig"
{
if
!
types
.
IsPara
()
{
if
!
cfg
.
IsPara
()
{
return
nil
,
types
.
ErrNotSupport
}
var
param
ParaNodeAddrConfig
...
...
@@ -134,9 +146,9 @@ func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types.
glog
.
Error
(
"CreateTx.NodeConfig"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawNodeConfigTx
(
&
param
)
return
CreateRawNodeConfigTx
(
cfg
,
&
param
)
}
else
if
action
==
"NodeGroupConfig"
{
if
!
types
.
IsPara
()
{
if
!
cfg
.
IsPara
()
{
return
nil
,
types
.
ErrNotSupport
}
var
param
ParaNodeGroupConfig
...
...
@@ -146,7 +158,7 @@ func (p ParacrossType) CreateTx(action string, message json.RawMessage) (*types.
glog
.
Error
(
"CreateTx.NodeGroupApply"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawNodeGroupApplyTx
(
&
param
)
return
CreateRawNodeGroupApplyTx
(
cfg
,
&
param
)
}
return
nil
,
types
.
ErrNotSupport
...
...
plugin/dapp/pokerbull/executor/pokerbull.go
View file @
8e521d5c
...
...
@@ -16,13 +16,14 @@ import (
var
logger
=
log
.
New
(
"module"
,
"execs.pokerbull"
)
// Init 执行器初始化
func
Init
(
name
string
,
sub
[]
byte
)
{
drivers
.
Register
(
newPBGame
()
.
GetName
(),
newPBGame
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
drivers
.
Register
(
cfg
,
newPBGame
()
.
GetName
(),
newPBGame
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
}
var
driverName
=
pkt
.
PokerBullX
func
init
()
{
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
PokerBull
{}))
}
...
...
@@ -147,7 +148,8 @@ func (g *PokerBull) CheckReceiptExecOk() bool {
// ExecutorOrder 设置localdb的EnableRead
func
(
g
*
PokerBull
)
ExecutorOrder
()
int64
{
if
types
.
IsFork
(
g
.
GetHeight
(),
"ForkLocalDBAccess"
)
{
cfg
:=
g
.
GetAPI
()
.
GetConfig
()
if
cfg
.
IsFork
(
g
.
GetHeight
(),
"ForkLocalDBAccess"
)
{
return
drivers
.
ExecLocalSameTime
}
return
g
.
DriverBase
.
ExecutorOrder
()
...
...
plugin/dapp/pokerbull/types/types.go
View file @
8e521d5c
...
...
@@ -12,9 +12,17 @@ import (
func
init
()
{
// init executor type
types
.
RegistorExecutor
(
PokerBullX
,
NewType
())
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
ExecerPokerBull
)
types
.
RegisterDappFork
(
PokerBullX
,
"Enable"
,
0
)
types
.
RegFork
(
PokerBullX
,
InitFork
)
types
.
RegExec
(
PokerBullX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
PokerBullX
,
"Enable"
,
0
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
PokerBullX
,
NewType
(
cfg
))
}
// PokerBullType 斗牛执行器类型
...
...
@@ -23,7 +31,7 @@ type PokerBullType struct {
}
// NewType 创建pokerbull执行器类型
func
NewType
()
*
PokerBullType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
PokerBullType
{
c
:=
&
PokerBullType
{}
c
.
SetChild
(
c
)
return
c
...
...
plugin/dapp/privacy/executor/privacy.go
View file @
8e521d5c
...
...
@@ -38,16 +38,17 @@ var privacylog = log.New("module", "execs.privacy")
var
driverName
=
"privacy"
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
privacy
{}))
}
// Init initialize executor driver
func
Init
(
name
string
,
sub
[]
byte
)
{
drivers
.
Register
(
GetName
(),
newPrivacy
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
drivers
.
Register
(
cfg
,
GetName
(),
newPrivacy
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
// 如果需要在开发环境下使用隐私交易,则需要使用下面这行代码,否则用上面的代码
//drivers.Register(newPrivacy().GetName(), newPrivacy, 0)
InitExecType
()
}
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
privacy
{}))
}
// GetName get privacy name
...
...
@@ -269,7 +270,8 @@ func (p *privacy) CheckTx(tx *types.Transaction, index int) error {
}
//只有主链coins隐私转账才收取特殊交易费, assertExec空情况适配老版本
if
!
types
.
IsPara
()
&&
(
assertExec
==
""
||
assertExec
==
"coins"
)
{
cfg
:=
p
.
GetAPI
()
.
GetConfig
()
if
!
cfg
.
IsPara
()
&&
(
assertExec
==
""
||
assertExec
==
"coins"
)
{
for
_
,
output
:=
range
output
.
Keyoutput
{
totalOutput
+=
output
.
Amount
...
...
plugin/dapp/privacy/types/privacy.go
View file @
8e521d5c
...
...
@@ -76,8 +76,16 @@ var mapSignName2Type = map[string]int{
func
init
()
{
// init executor type
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
PrivacyX
))
types
.
RegistorExecutor
(
PrivacyX
,
NewType
())
types
.
RegisterDappFork
(
PrivacyX
,
"Enable"
,
980000
)
types
.
RegFork
(
PrivacyX
,
InitFork
)
types
.
RegExec
(
PrivacyX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
PrivacyX
,
"Enable"
,
980000
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
PrivacyX
,
NewType
(
cfg
))
}
// PrivacyType declare PrivacyType class
...
...
@@ -86,9 +94,10 @@ type PrivacyType struct {
}
// NewType create PrivacyType object
func
NewType
()
*
PrivacyType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
PrivacyType
{
c
:=
&
PrivacyType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
plugin/dapp/relay/executor/relay.go
View file @
8e521d5c
...
...
@@ -17,14 +17,16 @@ var relaylog = log.New("module", "execs.relay")
var
driverName
=
"relay"
var
subconfig
=
types
.
ConfSub
(
driverName
)
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
relay
{}))
}
// Init relay register driver
func
Init
(
name
string
,
sub
[]
byte
)
{
drivers
.
Register
(
GetName
(),
newRelay
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
//TODO: ForkV18Relay
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
drivers
.
Register
(
cfg
,
GetName
(),
newRelay
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
//TODO: ForkV18Relay
InitExecType
()
}
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
relay
{}))
}
// GetName relay get driver name
...
...
@@ -251,7 +253,8 @@ func (r *relay) CheckReceiptExecOk() bool {
// ExecutorOrder 设置localdb的EnableRead
func
(
r
*
relay
)
ExecutorOrder
()
int64
{
if
types
.
IsFork
(
r
.
GetHeight
(),
"ForkLocalDBAccess"
)
{
cfg
:=
r
.
GetAPI
()
.
GetConfig
()
if
cfg
.
IsFork
(
r
.
GetHeight
(),
"ForkLocalDBAccess"
)
{
return
drivers
.
ExecLocalSameTime
}
return
r
.
DriverBase
.
ExecutorOrder
()
...
...
plugin/dapp/relay/types/relay.go
View file @
8e521d5c
...
...
@@ -57,14 +57,23 @@ const (
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
RelayX
))
types
.
RegistorExecutor
(
RelayX
,
NewType
())
types
.
RegisterDappFork
(
RelayX
,
"Enable"
,
570000
)
types
.
RegFork
(
RelayX
,
InitFork
)
types
.
RegExec
(
RelayX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
RelayX
,
"Enable"
,
570000
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
RelayX
,
NewType
(
cfg
))
}
// NewType new relay type
func
NewType
()
*
RelayType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
RelayType
{
c
:=
&
RelayType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
plugin/dapp/retrieve/executor/retrieve.go
View file @
8e521d5c
...
...
@@ -27,14 +27,15 @@ var (
var
driverName
=
"retrieve"
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Retrieve
{}))
//Init retrieve
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
drivers
.
Register
(
cfg
,
GetName
(),
newRetrieve
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
}
//Init retrieve
func
Init
(
name
string
,
sub
[]
byte
)
{
drivers
.
Register
(
GetName
(),
newRetrieve
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Retrieve
{}
))
}
// GetName method
...
...
plugin/dapp/retrieve/types/const.go
View file @
8e521d5c
...
...
@@ -4,8 +4,6 @@
package
types
import
"github.com/33cn/chain33/types"
//retrieve
const
(
RetrieveBackup
=
iota
+
1
...
...
@@ -39,7 +37,3 @@ var (
ForkRetriveAssetX
=
"ForkRetriveAsset"
ForkRetriveX
=
"ForkRetrive"
)
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
ExecerRetrieve
)
}
plugin/dapp/retrieve/types/types.go
View file @
8e521d5c
...
...
@@ -12,11 +12,19 @@ import (
)
func
init
()
{
// init executor type
types
.
RegistorExecutor
(
RetrieveX
,
NewType
())
types
.
RegisterDappFork
(
RetrieveX
,
"Enable"
,
0
)
types
.
RegisterDappFork
(
RetrieveX
,
ForkRetriveX
,
180000
)
types
.
RegisterDappFork
(
RetrieveX
,
ForkRetriveAssetX
,
3150000
)
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
ExecerRetrieve
)
types
.
RegFork
(
RetrieveX
,
InitFork
)
types
.
RegExec
(
RetrieveX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
RetrieveX
,
"Enable"
,
0
)
cfg
.
RegisterDappFork
(
RetrieveX
,
ForkRetriveX
,
180000
)
cfg
.
RegisterDappFork
(
RetrieveX
,
ForkRetriveAssetX
,
3150000
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
RetrieveX
,
NewType
(
cfg
))
}
// RetrieveType def
...
...
@@ -25,9 +33,10 @@ type RetrieveType struct {
}
// NewType for retrieve
func
NewType
()
*
RetrieveType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
RetrieveType
{
c
:=
&
RetrieveType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
plugin/dapp/ticket/executor/ticket.go
View file @
8e521d5c
...
...
@@ -28,14 +28,15 @@ import (
var
clog
=
log
.
New
(
"module"
,
"execs.ticket"
)
var
driverName
=
"ticket"
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Ticket
{}))
// Init initial
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
drivers
.
Register
(
cfg
,
GetName
(),
newTicket
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
}
// Init initial
func
Init
(
name
string
,
sub
[]
byte
)
{
drivers
.
Register
(
GetName
(),
newTicket
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Ticket
{}
))
}
// GetName get name
...
...
plugin/dapp/ticket/types/ticket.go
View file @
8e521d5c
...
...
@@ -58,10 +58,19 @@ var TicketX = "ticket"
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
TicketX
))
types
.
RegistorExecutor
(
TicketX
,
NewType
())
types
.
RegisterDappFork
(
TicketX
,
"Enable"
,
0
)
types
.
RegisterDappFork
(
TicketX
,
"ForkTicketId"
,
1062000
)
types
.
RegisterDappFork
(
TicketX
,
"ForkTicketVrf"
,
1770000
)
types
.
RegFork
(
TicketX
,
InitFork
)
types
.
RegExec
(
TicketX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
TicketX
,
"Enable"
,
0
)
cfg
.
RegisterDappFork
(
TicketX
,
"ForkTicketId"
,
1062000
)
cfg
.
RegisterDappFork
(
TicketX
,
"ForkTicketVrf"
,
1770000
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
TicketX
,
NewType
(
cfg
))
}
// TicketType ticket exec type
...
...
@@ -70,9 +79,10 @@ type TicketType struct {
}
// NewType new type
func
NewType
()
*
TicketType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
TicketType
{
c
:=
&
TicketType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
plugin/dapp/token/executor/token.go
View file @
8e521d5c
...
...
@@ -35,11 +35,6 @@ const (
var
driverName
=
"token"
var
conf
=
types
.
ConfSub
(
driverName
)
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
token
{}))
}
type
subConfig
struct
{
SaveTokenTxList
bool
`json:"saveTokenTxList"`
}
...
...
@@ -47,11 +42,17 @@ type subConfig struct {
var
cfg
subConfig
// Init 重命名执行器名称
func
Init
(
name
string
,
sub
[]
byte
)
{
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
if
sub
!=
nil
{
types
.
MustDecode
(
sub
,
&
cfg
)
}
drivers
.
Register
(
GetName
(),
newToken
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
drivers
.
Register
(
cfg
,
GetName
(),
newToken
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
}
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
token
{}))
}
// GetName 获取执行器别名
...
...
@@ -238,8 +239,9 @@ func (t *token) saveLogs(receipt *tokenty.ReceiptToken) []*types.KeyValue {
var
kv
[]
*
types
.
KeyValue
key
:=
calcTokenStatusKeyLocal
(
receipt
.
Symbol
,
receipt
.
Owner
,
receipt
.
Status
)
cfg
:=
t
.
GetAPI
()
.
GetConfig
()
var
value
[]
byte
if
types
.
IsFork
(
t
.
GetHeight
(),
"ForkExecKey"
)
{
if
cfg
.
IsFork
(
t
.
GetHeight
(),
"ForkExecKey"
)
{
value
=
calcTokenAddrNewKeyS
(
receipt
.
Symbol
,
receipt
.
Owner
)
}
else
{
value
=
calcTokenAddrKeyS
(
receipt
.
Symbol
,
receipt
.
Owner
)
...
...
@@ -262,7 +264,8 @@ func (t *token) deleteLogs(receipt *tokenty.ReceiptToken) []*types.KeyValue {
if
receipt
.
Status
!=
tokenty
.
TokenStatusPreCreated
{
key
=
calcTokenStatusKeyLocal
(
receipt
.
Symbol
,
receipt
.
Owner
,
tokenty
.
TokenStatusPreCreated
)
var
value
[]
byte
if
types
.
IsFork
(
t
.
GetHeight
(),
"ForkExecKey"
)
{
cfg
:=
t
.
GetAPI
()
.
GetConfig
()
if
cfg
.
IsFork
(
t
.
GetHeight
(),
"ForkExecKey"
)
{
value
=
calcTokenAddrNewKeyS
(
receipt
.
Symbol
,
receipt
.
Owner
)
}
else
{
value
=
calcTokenAddrKeyS
(
receipt
.
Symbol
,
receipt
.
Owner
)
...
...
plugin/dapp/token/types/types.go
View file @
8e521d5c
...
...
@@ -17,13 +17,21 @@ var tokenlog = log.New("module", "execs.token.types")
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
TokenX
))
types
.
RegistorExecutor
(
TokenX
,
NewType
())
types
.
RegisterDappFork
(
TokenX
,
"Enable"
,
100899
)
types
.
RegisterDappFork
(
TokenX
,
ForkTokenBlackListX
,
190000
)
types
.
RegisterDappFork
(
TokenX
,
ForkBadTokenSymbolX
,
184000
)
types
.
RegisterDappFork
(
TokenX
,
ForkTokenPriceX
,
560000
)
types
.
RegisterDappFork
(
TokenX
,
ForkTokenSymbolWithNumberX
,
1298600
)
types
.
RegisterDappFork
(
TokenX
,
ForkTokenCheckX
,
1600000
)
types
.
RegFork
(
TokenX
,
InitFork
)
types
.
RegExec
(
TokenX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
TokenX
,
"Enable"
,
100899
)
cfg
.
RegisterDappFork
(
TokenX
,
ForkTokenBlackListX
,
190000
)
cfg
.
RegisterDappFork
(
TokenX
,
ForkBadTokenSymbolX
,
184000
)
cfg
.
RegisterDappFork
(
TokenX
,
ForkTokenPriceX
,
560000
)
cfg
.
RegisterDappFork
(
TokenX
,
ForkTokenSymbolWithNumberX
,
1298600
)
cfg
.
RegisterDappFork
(
TokenX
,
ForkTokenCheckX
,
1600000
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
TokenX
,
NewType
(
cfg
))
}
// TokenType 执行器基类结构体
...
...
@@ -32,9 +40,10 @@ type TokenType struct {
}
// NewType 创建执行器类型
func
NewType
()
*
TokenType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
TokenType
{
c
:=
&
TokenType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
@@ -98,7 +107,8 @@ func (t *TokenType) RPC_Default_Process(action string, msg interface{}) (*types.
return
nil
,
err
}
//to地址的问题,如果是主链交易,to地址就是直接是设置to
if
!
types
.
IsPara
()
{
cfg
:=
t
.
GetConfig
()
if
!
cfg
.
IsPara
()
{
tx
.
To
=
create
.
To
}
return
tx
,
err
...
...
@@ -111,7 +121,8 @@ func (t *TokenType) CreateTx(action string, msg json.RawMessage) (*types.Transac
tokenlog
.
Error
(
"token CreateTx failed"
,
"err"
,
err
,
"action"
,
action
,
"msg"
,
string
(
msg
))
return
nil
,
err
}
if
!
types
.
IsPara
()
{
cfg
:=
t
.
GetConfig
()
if
!
cfg
.
IsPara
()
{
var
transfer
TokenAction
err
=
types
.
Decode
(
tx
.
Payload
,
&
transfer
)
if
err
!=
nil
{
...
...
plugin/dapp/trade/executor/trade.go
View file @
8e521d5c
...
...
@@ -32,14 +32,15 @@ var (
defaultPriceExec
=
"coins"
)
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
trade
{}))
// Init : 注册当前trade合约
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
drivers
.
Register
(
cfg
,
GetName
(),
newTrade
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
}
// Init : 注册当前trade合约
func
Init
(
name
string
,
sub
[]
byte
)
{
drivers
.
Register
(
GetName
(),
newTrade
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
trade
{}
))
}
// GetName : 获取trade合约名字
...
...
plugin/dapp/trade/types/trade.go
View file @
8e521d5c
...
...
@@ -50,20 +50,28 @@ func (t *tradeType) GetLogMap() map[int64]*types.LogInfo {
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
TradeX
))
types
.
RegistorExecutor
(
TradeX
,
newType
())
types
.
RegisterDappFork
(
TradeX
,
"Enable"
,
100899
)
types
.
RegisterDappFork
(
TradeX
,
ForkTradeBuyLimitX
,
301000
)
types
.
RegisterDappFork
(
TradeX
,
ForkTradeAssetX
,
1010000
)
types
.
RegisterDappFork
(
TradeX
,
ForkTradeIDX
,
1450000
)
types
.
RegisterDappFork
(
TradeX
,
ForkTradeFixAssetDBX
,
2500000
)
types
.
RegisterDappFork
(
TradeX
,
ForkTradePriceX
,
3150000
)
types
.
RegFork
(
TradeX
,
InitFork
)
types
.
RegExec
(
TradeX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
TradeX
,
"Enable"
,
100899
)
cfg
.
RegisterDappFork
(
TradeX
,
ForkTradeBuyLimitX
,
301000
)
cfg
.
RegisterDappFork
(
TradeX
,
ForkTradeAssetX
,
1010000
)
cfg
.
RegisterDappFork
(
TradeX
,
ForkTradeIDX
,
1450000
)
cfg
.
RegisterDappFork
(
TradeX
,
ForkTradeFixAssetDBX
,
2500000
)
cfg
.
RegisterDappFork
(
TradeX
,
ForkTradePriceX
,
3150000
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
TradeX
,
NewType
(
cfg
))
}
type
tradeType
struct
{
types
.
ExecTypeBase
}
func
newType
(
)
*
tradeType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
tradeType
{
c
:=
&
tradeType
{}
c
.
SetChild
(
c
)
return
c
...
...
plugin/dapp/trade/types/trade_test.go
View file @
8e521d5c
...
...
@@ -11,19 +11,19 @@ import (
)
func
TestTradeType_GetName
(
t
*
testing
.
T
)
{
tp
:=
n
ewType
()
tp
:=
N
ewType
()
assert
.
Equal
(
t
,
TradeX
,
tp
.
GetName
())
}
func
TestTradeType_GetTypeMap
(
t
*
testing
.
T
)
{
tp
:=
n
ewType
()
tp
:=
N
ewType
()
actoins
:=
tp
.
GetTypeMap
()
assert
.
NotNil
(
t
,
actoins
)
assert
.
NotEqual
(
t
,
0
,
len
(
actoins
))
}
func
TestTradeType_GetLogMap
(
t
*
testing
.
T
)
{
tp
:=
n
ewType
()
tp
:=
N
ewType
()
l
:=
tp
.
GetLogMap
()
assert
.
NotNil
(
t
,
l
)
assert
.
NotEqual
(
t
,
0
,
len
(
l
))
...
...
plugin/dapp/unfreeze/executor/unfreeze.go
View file @
8e521d5c
...
...
@@ -15,14 +15,15 @@ var uflog = log.New("module", "execs.unfreeze")
var
driverName
=
uf
.
UnfreezeX
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Unfreeze
{}))
// Init 重命名执行器名称
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
drivers
.
Register
(
cfg
,
GetName
(),
newUnfreeze
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
}
// Init 重命名执行器名称
func
Init
(
name
string
,
sub
[]
byte
)
{
drivers
.
Register
(
GetName
(),
newUnfreeze
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Unfreeze
{}
))
}
// Unfreeze 执行器结构体
...
...
plugin/dapp/unfreeze/types/types.go
View file @
8e521d5c
...
...
@@ -22,11 +22,19 @@ var tlog = log.New("module", name)
func
init
()
{
name
=
UnfreezeX
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
UnfreezeX
))
// init executor type
types
.
RegistorExecutor
(
name
,
NewType
())
types
.
RegisterDappFork
(
name
,
"Enable"
,
0
)
types
.
RegisterDappFork
(
name
,
ForkTerminatePartX
,
1298600
)
types
.
RegisterDappFork
(
name
,
ForkUnfreezeIDX
,
1450000
)
types
.
RegFork
(
name
,
InitFork
)
types
.
RegExec
(
name
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
name
=
UnfreezeX
cfg
.
RegisterDappFork
(
name
,
"Enable"
,
0
)
cfg
.
RegisterDappFork
(
name
,
ForkTerminatePartX
,
1298600
)
cfg
.
RegisterDappFork
(
name
,
ForkUnfreezeIDX
,
1450000
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
UnfreezeX
,
NewType
(
cfg
))
}
//getRealExecName
...
...
@@ -35,9 +43,10 @@ func getRealExecName(paraName string) string {
}
// NewType 生成新的基础类型
func
NewType
()
*
UnfreezeType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
UnfreezeType
{
c
:=
&
UnfreezeType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
...
...
plugin/dapp/valnode/executor/valnode.go
View file @
8e521d5c
...
...
@@ -15,15 +15,17 @@ import (
var
clog
=
log
.
New
(
"module"
,
"execs.valnode"
)
var
driverName
=
"valnode"
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
ValNode
{}))
}
// Init method
func
Init
(
name
string
,
sub
[]
byte
)
{
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
clog
.
Debug
(
"register valnode execer"
)
drivers
.
Register
(
GetName
(),
newValNode
,
0
)
drivers
.
Register
(
cfg
,
GetName
(),
newValNode
,
0
)
InitExecType
()
}
// TODO 调整InitExecType的大小写
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
ValNode
{}))
}
// GetName method
...
...
plugin/dapp/valnode/types/valnode.go
View file @
8e521d5c
...
...
@@ -13,8 +13,16 @@ var ValNodeX = "valnode"
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
ValNodeX
))
types
.
RegistorExecutor
(
ValNodeX
,
NewType
())
types
.
RegisterDappFork
(
ValNodeX
,
"Enable"
,
0
)
types
.
RegFork
(
ValNodeX
,
InitFork
)
types
.
RegExec
(
ValNodeX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
ValNodeX
,
"Enable"
,
0
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
ValNodeX
,
NewType
(
cfg
))
}
// GetExecName get exec name
...
...
@@ -28,7 +36,7 @@ type ValNodeType struct {
}
// NewType method
func
NewType
()
*
ValNodeType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
ValNodeType
{
c
:=
&
ValNodeType
{}
c
.
SetChild
(
c
)
return
c
...
...
plugin/mempool/para/base.go
View file @
8e521d5c
...
...
@@ -8,8 +8,8 @@ import (
log
"github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/queue"
"github.com/33cn/chain33/rpc/grpcclient"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/rpc/grpcclient"
)
var
mlog
=
log
.
New
(
"module"
,
"mempool.para"
)
...
...
@@ -28,14 +28,6 @@ type Mempool struct {
func
NewMempool
(
cfg
*
types
.
Mempool
)
*
Mempool
{
pool
:=
&
Mempool
{}
pool
.
key
=
topic
if
types
.
IsPara
()
{
grpcCli
,
err
:=
grpcclient
.
NewMainChainClient
(
""
)
if
err
!=
nil
{
panic
(
err
)
}
pool
.
mainGrpcCli
=
grpcCli
}
return
pool
}
...
...
@@ -43,6 +35,7 @@ func NewMempool(cfg *types.Mempool) *Mempool {
func
(
mem
*
Mempool
)
SetQueueClient
(
client
queue
.
Client
)
{
mem
.
client
=
client
mem
.
client
.
Sub
(
mem
.
key
)
mem
.
setMainGrpcCli
(
client
.
GetConfig
())
mem
.
wg
.
Add
(
1
)
go
func
()
{
defer
mem
.
wg
.
Done
()
...
...
@@ -68,6 +61,16 @@ func (mem *Mempool) SetQueueClient(client queue.Client) {
}()
}
func
(
mem
*
Mempool
)
setMainGrpcCli
(
cfg
*
types
.
Chain33Config
)
{
if
cfg
!=
nil
&&
cfg
.
IsPara
()
{
grpcCli
,
err
:=
grpcclient
.
NewMainChainClient
(
cfg
,
""
)
if
err
!=
nil
{
panic
(
err
)
}
mem
.
mainGrpcCli
=
grpcCli
}
}
// Wait for ready
func
(
mem
*
Mempool
)
Wait
()
{}
...
...
plugin/store/kvdb/kvdb.go
View file @
8e521d5c
...
...
@@ -37,7 +37,7 @@ type KVStore struct {
}
// New KVStore module
func
New
(
cfg
*
types
.
Store
,
sub
[]
byte
)
queue
.
Module
{
func
New
(
cfg
*
types
.
Store
,
sub
[]
byte
,
chain33cfg
*
types
.
Chain33Config
)
queue
.
Module
{
bs
:=
drivers
.
NewBaseStore
(
cfg
)
kvs
:=
&
KVStore
{
bs
,
make
(
map
[
string
]
map
[
string
]
*
types
.
KeyValue
)}
bs
.
SetChild
(
kvs
)
...
...
plugin/store/kvdb/kvdb_test.go
View file @
8e521d5c
...
...
@@ -24,7 +24,7 @@ func TestKvdbNewClose(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
assert
.
NotNil
(
t
,
store
)
store
.
Close
()
...
...
@@ -36,7 +36,7 @@ func TestKvddbSetGet(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVStore
)
assert
.
NotNil
(
t
,
store
)
keys0
:=
[][]
byte
{[]
byte
(
"mk1"
),
[]
byte
(
"mk2"
)}
...
...
@@ -82,7 +82,7 @@ func TestKvdbMemSet(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVStore
)
assert
.
NotNil
(
t
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -114,7 +114,7 @@ func TestKvdbMemSetUpgrade(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVStore
)
assert
.
NotNil
(
t
,
store
)
store
.
MemSetUpgrade
(
nil
,
false
)
}
...
...
@@ -126,7 +126,7 @@ func TestKvdbCommitUpgrade(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVStore
)
assert
.
NotNil
(
t
,
store
)
store
.
CommitUpgrade
(
nil
)
}
...
...
@@ -137,7 +137,7 @@ func TestKvdbRollback(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVStore
)
assert
.
NotNil
(
t
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
plugin/store/kvmvcc/kvmvccdb.go
View file @
8e521d5c
...
...
@@ -45,7 +45,7 @@ type subConfig struct {
}
// New construct KVMVCCStore module
func
New
(
cfg
*
types
.
Store
,
sub
[]
byte
)
queue
.
Module
{
func
New
(
cfg
*
types
.
Store
,
sub
[]
byte
,
chain33cfg
*
types
.
Chain33Config
)
queue
.
Module
{
bs
:=
drivers
.
NewBaseStore
(
cfg
)
var
kvs
*
KVMVCCStore
enable
:=
false
...
...
plugin/store/kvmvcc/kvmvccdb_test.go
View file @
8e521d5c
...
...
@@ -36,7 +36,7 @@ func TestKvmvccdbNewClose(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
t
,
store
)
store
.
Close
()
...
...
@@ -48,7 +48,7 @@ func TestKvmvccdbSetGet(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
t
,
store
)
keys0
:=
[][]
byte
{[]
byte
(
"mk1"
),
[]
byte
(
"mk2"
)}
...
...
@@ -94,7 +94,7 @@ func TestKvmvccdbMemSet(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
t
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -133,7 +133,7 @@ func TestKvmvccdbMemSetUpgrade(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
t
,
store
)
store
.
MemSetUpgrade
(
nil
,
false
)
}
...
...
@@ -145,7 +145,7 @@ func TestKvmvccdbCommitUpgrade(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
t
,
store
)
store
.
CommitUpgrade
(
nil
)
}
...
...
@@ -156,7 +156,7 @@ func TestKvmvccdbRollback(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
t
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -189,7 +189,7 @@ func TestKvmvccdbRollbackBatch(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
t
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -285,7 +285,7 @@ func TestIterateRangeByStateHash(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
storeCfg
,
sub
:=
newStoreCfgIter
(
dir
)
store
:=
New
(
storeCfg
,
sub
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
sub
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
t
,
store
)
execaddr
:=
"0111vcBNSEA7fZhAdLJphDwQRQJa111"
...
...
@@ -294,7 +294,7 @@ func TestIterateRangeByStateHash(t *testing.T) {
addr2
:=
"26htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp"
addr3
:=
"36htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp"
addr4
:=
"46htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp"
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
:=
account
.
NewCoinsAccount
(
&
types
.
Chain33Config
{}
)
account1
:=
&
types
.
Account
{
Balance
:
1000
*
1e8
,
...
...
@@ -431,7 +431,7 @@ func BenchmarkGet(b *testing.B) {
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
b
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -475,7 +475,7 @@ func BenchmarkStoreGetKvs4N(b *testing.B) {
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
b
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -520,7 +520,7 @@ func BenchmarkStoreGetKvsForNN(b *testing.B) {
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
b
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -580,7 +580,7 @@ func BenchmarkStoreGetKvsFor10000(b *testing.B) {
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
b
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -645,7 +645,7 @@ func BenchmarkGetIter(b *testing.B) {
os
.
RemoveAll
(
dir
)
//删除已存在目录
storeCfg
,
sub
:=
newStoreCfgIter
(
dir
)
store
:=
New
(
storeCfg
,
sub
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
sub
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
b
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -688,7 +688,7 @@ func BenchmarkSet(b *testing.B) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
b
,
store
)
b
.
Log
(
dir
)
...
...
@@ -725,7 +725,7 @@ func BenchmarkStoreSet(b *testing.B) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
b
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -760,7 +760,7 @@ func BenchmarkSetIter(b *testing.B) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
storeCfg
,
sub
:=
newStoreCfgIter
(
dir
)
store
:=
New
(
storeCfg
,
sub
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
sub
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
b
,
store
)
b
.
Log
(
dir
)
...
...
@@ -797,7 +797,7 @@ func BenchmarkMemSet(b *testing.B) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
b
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -831,7 +831,7 @@ func BenchmarkStoreMemSet(b *testing.B) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
b
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -869,7 +869,7 @@ func BenchmarkCommit(b *testing.B) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
b
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -910,7 +910,7 @@ func BenchmarkStoreCommit(b *testing.B) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
b
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -954,7 +954,7 @@ func BenchmarkIterMemSet(b *testing.B) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
storeCfg
,
sub
:=
newStoreCfgIter
(
dir
)
store
:=
New
(
storeCfg
,
sub
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
sub
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
b
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -987,7 +987,7 @@ func BenchmarkIterCommit(b *testing.B) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
storeCfg
,
sub
:=
newStoreCfgIter
(
dir
)
store
:=
New
(
storeCfg
,
sub
)
.
(
*
KVMVCCStore
)
store
:=
New
(
storeCfg
,
sub
,
nil
)
.
(
*
KVMVCCStore
)
assert
.
NotNil
(
b
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
plugin/store/kvmvccmavl/kvmvcc_mavl.go
View file @
8e521d5c
...
...
@@ -61,7 +61,11 @@ func DisableLog() {
func
init
()
{
drivers
.
Reg
(
"kvmvccmavl"
,
New
)
types
.
RegisterDappFork
(
"store-kvmvccmavl"
,
"ForkKvmvccmavl"
,
187
*
10000
)
types
.
RegFork
(
"store-kvmvccmavl"
,
InitFork
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
"store-kvmvccmavl"
,
"ForkKvmvccmavl"
,
187
*
10000
)
}
// KVmMavlStore provide kvmvcc and mavl store interface implementation
...
...
@@ -106,7 +110,7 @@ type subConfig struct {
}
// New construct KVMVCCStore module
func
New
(
cfg
*
types
.
Store
,
sub
[]
byte
)
queue
.
Module
{
func
New
(
cfg
*
types
.
Store
,
sub
[]
byte
,
chain33cfg
*
types
.
Chain33Config
)
queue
.
Module
{
var
kvms
*
KVmMavlStore
var
subcfg
subConfig
var
subKVMVCCcfg
subKVMVCCConfig
...
...
@@ -142,7 +146,9 @@ func New(cfg *types.Store, sub []byte) queue.Module {
// 查询是否是删除裁剪版mavl
isPrunedMavl
=
isPrunedMavlDB
(
bs
.
GetDB
())
// 读取fork高度
kvmvccMavlFork
=
types
.
GetDappFork
(
"store-kvmvccmavl"
,
"ForkKvmvccmavl"
)
if
chain33cfg
!=
nil
{
kvmvccMavlFork
=
chain33cfg
.
GetDappFork
(
"store-kvmvccmavl"
,
"ForkKvmvccmavl"
)
}
delMavlDataHeight
=
kvmvccMavlFork
+
10000
bs
.
SetChild
(
kvms
)
return
kvms
...
...
plugin/store/kvmvccmavl/kvmvcc_mavl_test.go
View file @
8e521d5c
...
...
@@ -41,7 +41,7 @@ func TestKvmvccMavlNewClose(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
t
,
store
)
store
.
Close
()
...
...
@@ -53,7 +53,7 @@ func TestKvmvccMavlSetGet(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
t
,
store
)
kvmvccMavlFork
=
50
...
...
@@ -86,7 +86,7 @@ func TestKvmvccMavlMemSet(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
t
,
store
)
kvmvccMavlFork
=
50
...
...
@@ -124,7 +124,7 @@ func TestKvmvccMavlMemSetUpgrade(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
t
,
store
)
kvmvccMavlFork
=
50
...
...
@@ -162,7 +162,7 @@ func TestKvmvccMavlCommit(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
t
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -229,7 +229,7 @@ func TestKvmvccMavlRollback(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
t
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -292,7 +292,7 @@ func TestKvmvccdbRollbackBatch(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
t
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -393,7 +393,7 @@ func TestIterateRangeByStateHash(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
storeCfg
,
sub
:=
newStoreCfgIter
(
dir
)
store
:=
New
(
storeCfg
,
sub
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
sub
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
t
,
store
)
execaddr
:=
"0111vcBNSEA7fZhAdLJphDwQRQJa111"
...
...
@@ -402,7 +402,7 @@ func TestIterateRangeByStateHash(t *testing.T) {
addr2
:=
"26htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp"
addr3
:=
"36htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp"
addr4
:=
"46htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp"
accCoin
:=
account
.
NewCoinsAccount
()
accCoin
:=
account
.
NewCoinsAccount
(
&
types
.
Chain33Config
{}
)
account1
:=
&
types
.
Account
{
Balance
:
1000
*
1e8
,
...
...
@@ -543,7 +543,7 @@ func TestProcEvent(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
storeCfg
,
sub
:=
newStoreCfgIter
(
dir
)
store
:=
New
(
storeCfg
,
sub
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
sub
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
t
,
store
)
store
.
ProcEvent
(
nil
)
...
...
@@ -560,7 +560,7 @@ func TestDelMavlData(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
storeCfg
:=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
t
,
store
)
db
:=
store
.
GetDB
()
...
...
@@ -607,7 +607,7 @@ func TestPruning(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
storeCfg
:=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
t
,
store
)
kvmvccStore
:=
NewKVMVCC
(
&
subKVMVCCConfig
{},
store
.
GetDB
())
...
...
@@ -682,7 +682,7 @@ func TestGetKeyVersion(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
storeCfg
:=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
t
,
store
)
mvcc
:=
dbm
.
NewMVCC
(
store
.
GetDB
())
...
...
@@ -724,7 +724,7 @@ func TestIsCommitMavl(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
storeCfg
:=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
t
,
store
)
isComm
:=
isPrunedMavlDB
(
store
.
GetDB
())
...
...
@@ -742,7 +742,7 @@ func TestDeletePrunedMavl(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
storeCfg
:=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
t
,
store
)
deletePrunedMavlData
(
store
.
GetDB
(),
hashNodePrefix
)
...
...
@@ -780,7 +780,7 @@ func benchmarkGet(b *testing.B, isResetForkHeight bool) {
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
b
,
store
)
if
isResetForkHeight
{
...
...
@@ -841,7 +841,7 @@ func benchmarkStoreGetKvs4N(b *testing.B, isResetForkHeight bool) {
}
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
b
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -889,7 +889,7 @@ func benchmarkStoreGetKvsForNN(b *testing.B, isResetForkHeight bool) {
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
b
,
store
)
if
isResetForkHeight
{
...
...
@@ -959,7 +959,7 @@ func benchmarkStoreGetKvsFor10000(b *testing.B, isResetForkHeight bool) {
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
b
,
store
)
if
isResetForkHeight
{
...
...
@@ -1034,7 +1034,7 @@ func benchmarkGetIter(b *testing.B, isResetForkHeight bool) {
os
.
RemoveAll
(
dir
)
//删除已存在目录
storeCfg
,
sub
:=
newStoreCfgIter
(
dir
)
store
:=
New
(
storeCfg
,
sub
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
sub
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
b
,
store
)
if
isResetForkHeight
{
...
...
@@ -1087,7 +1087,7 @@ func benchmarkSet(b *testing.B, isResetForkHeight bool) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
b
,
store
)
b
.
Log
(
dir
)
...
...
@@ -1134,7 +1134,7 @@ func benchmarkStoreSet(b *testing.B, isResetForkHeight bool) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
b
,
store
)
if
isResetForkHeight
{
...
...
@@ -1179,7 +1179,7 @@ func benchmarkSetIter(b *testing.B, isResetForkHeight bool) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
storeCfg
,
sub
:=
newStoreCfgIter
(
dir
)
store
:=
New
(
storeCfg
,
sub
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
sub
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
b
,
store
)
b
.
Log
(
dir
)
...
...
@@ -1226,7 +1226,7 @@ func benchmarkMemSet(b *testing.B, isResetForkHeight bool) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
b
,
store
)
if
isResetForkHeight
{
...
...
@@ -1270,7 +1270,7 @@ func benchmarkStoreMemSet(b *testing.B, isResetForkHeight bool) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
b
,
store
)
if
isResetForkHeight
{
...
...
@@ -1318,7 +1318,7 @@ func benchmarkCommit(b *testing.B, isResetForkHeight bool) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
b
,
store
)
if
isResetForkHeight
{
...
...
@@ -1368,7 +1368,7 @@ func benchmarkStoreCommit(b *testing.B, isResetForkHeight bool) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
b
,
store
)
if
isResetForkHeight
{
...
...
@@ -1422,7 +1422,7 @@ func benchmarkIterMemSet(b *testing.B, isResetForkHeight bool) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
storeCfg
,
sub
:=
newStoreCfgIter
(
dir
)
store
:=
New
(
storeCfg
,
sub
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
sub
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
b
,
store
)
if
isResetForkHeight
{
...
...
@@ -1465,7 +1465,7 @@ func benchmarkIterCommit(b *testing.B, isResetForkHeight bool) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
storeCfg
,
sub
:=
newStoreCfgIter
(
dir
)
store
:=
New
(
storeCfg
,
sub
)
.
(
*
KVmMavlStore
)
store
:=
New
(
storeCfg
,
sub
,
nil
)
.
(
*
KVmMavlStore
)
assert
.
NotNil
(
b
,
store
)
if
isResetForkHeight
{
...
...
plugin/store/mpt/mpt.go
View file @
8e521d5c
...
...
@@ -39,7 +39,7 @@ func init() {
}
// New new mpt store module
func
New
(
cfg
*
types
.
Store
,
sub
[]
byte
)
queue
.
Module
{
func
New
(
cfg
*
types
.
Store
,
sub
[]
byte
,
chain33cfg
*
types
.
Chain33Config
)
queue
.
Module
{
bs
:=
drivers
.
NewBaseStore
(
cfg
)
mpts
:=
&
Store
{
bs
,
make
(
map
[
string
]
*
mpt
.
TrieEx
),
nil
}
mpts
.
cache
,
_
=
lru
.
New
(
10
)
...
...
plugin/store/mpt/mpt_test.go
View file @
8e521d5c
...
...
@@ -30,7 +30,7 @@ func TestKvdbNewClose(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
assert
.
NotNil
(
t
,
store
)
store
.
Close
()
...
...
@@ -42,7 +42,7 @@ func TestKvddbSetGet(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
Store
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
Store
)
assert
.
NotNil
(
t
,
store
)
keys0
:=
[][]
byte
{[]
byte
(
"mk1"
),
[]
byte
(
"mk2"
)}
...
...
@@ -89,7 +89,7 @@ func TestKvdbMemSet(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
Store
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
Store
)
assert
.
NotNil
(
t
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -121,7 +121,7 @@ func TestKvmvccdbMemSetUpgrade(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
Store
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
Store
)
assert
.
NotNil
(
t
,
store
)
store
.
MemSetUpgrade
(
nil
,
false
)
}
...
...
@@ -133,7 +133,7 @@ func TestKvmvccdbCommitUpgrade(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
Store
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
Store
)
assert
.
NotNil
(
t
,
store
)
store
.
CommitUpgrade
(
nil
)
}
...
...
@@ -144,7 +144,7 @@ func TestKvdbRollback(t *testing.T) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
Store
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
Store
)
assert
.
NotNil
(
t
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -179,7 +179,7 @@ func BenchmarkGet(b *testing.B) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
Store
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
Store
)
assert
.
NotNil
(
b
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -220,7 +220,7 @@ func BenchmarkSet(b *testing.B) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
Store
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
Store
)
assert
.
NotNil
(
b
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -254,7 +254,7 @@ func BenchmarkMemSet(b *testing.B) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
Store
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
Store
)
assert
.
NotNil
(
b
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
@@ -287,7 +287,7 @@ func BenchmarkCommit(b *testing.B) {
defer
os
.
RemoveAll
(
dir
)
// clean up
os
.
RemoveAll
(
dir
)
//删除已存在目录
var
storeCfg
=
newStoreCfg
(
dir
)
store
:=
New
(
storeCfg
,
nil
)
.
(
*
Store
)
store
:=
New
(
storeCfg
,
nil
,
nil
)
.
(
*
Store
)
assert
.
NotNil
(
b
,
store
)
var
kv
[]
*
types
.
KeyValue
...
...
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