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
52221b3b
Commit
52221b3b
authored
Jan 03, 2019
by
vipwzw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update chain33
parent
13e2d54e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
14 deletions
+73
-14
util.go
vendor/github.com/33cn/chain33/system/dapp/util.go
+9
-1
util_test.go
vendor/github.com/33cn/chain33/system/dapp/util_test.go
+9
-3
chain33.go
vendor/github.com/33cn/chain33/util/cli/chain33.go
+15
-9
util.go
vendor/github.com/33cn/chain33/util/util.go
+22
-0
util_test.go
vendor/github.com/33cn/chain33/util/util_test.go
+18
-1
No files found.
vendor/github.com/33cn/chain33/system/dapp/util.go
View file @
52221b3b
...
@@ -108,7 +108,15 @@ func (c *KVCreator) AddNoPrefix(key, value []byte) *KVCreator {
...
@@ -108,7 +108,15 @@ func (c *KVCreator) AddNoPrefix(key, value []byte) *KVCreator {
//AddListNoPrefix only add KVList
//AddListNoPrefix only add KVList
func
(
c
*
KVCreator
)
AddListNoPrefix
(
list
[]
*
types
.
KeyValue
)
*
KVCreator
{
func
(
c
*
KVCreator
)
AddListNoPrefix
(
list
[]
*
types
.
KeyValue
)
*
KVCreator
{
for
_
,
kv
:=
range
list
{
for
_
,
kv
:=
range
list
{
c
.
add
(
kv
.
Key
,
kv
.
Value
,
false
)
c
.
addnoprefix
(
kv
.
Key
,
kv
.
Value
,
true
)
}
return
c
}
//AddList only add KVList
func
(
c
*
KVCreator
)
AddList
(
list
[]
*
types
.
KeyValue
)
*
KVCreator
{
for
_
,
kv
:=
range
list
{
c
.
add
(
kv
.
Key
,
kv
.
Value
,
true
)
}
}
return
c
return
c
}
}
...
...
vendor/github.com/33cn/chain33/system/dapp/util_test.go
View file @
52221b3b
...
@@ -28,15 +28,21 @@ func TestKVCreator(t *testing.T) {
...
@@ -28,15 +28,21 @@ func TestKVCreator(t *testing.T) {
{
Key
:
[]
byte
(
"l1"
),
Value
:
[]
byte
(
"vl1"
)},
{
Key
:
[]
byte
(
"l1"
),
Value
:
[]
byte
(
"vl1"
)},
{
Key
:
[]
byte
(
"l2"
),
Value
:
[]
byte
(
"vl2"
)},
{
Key
:
[]
byte
(
"l2"
),
Value
:
[]
byte
(
"vl2"
)},
})
})
creator
.
AddListNoPrefix
([]
*
types
.
KeyValue
{
{
Key
:
[]
byte
(
"l1"
),
Value
:
[]
byte
(
"vl1"
)},
{
Key
:
[]
byte
(
"l2"
),
Value
:
[]
byte
(
"vl2"
)},
})
creator
.
Add
([]
byte
(
"c1"
),
nil
)
creator
.
Add
([]
byte
(
"c1"
),
nil
)
creator
.
Add
([]
byte
(
"l2"
),
nil
)
creator
.
Add
([]
byte
(
"l2"
),
nil
)
creator
.
AddRollbackKV
()
creator
.
AddRollbackKV
()
assert
.
Equal
(
t
,
7
,
len
(
creator
.
KVList
()))
assert
.
Equal
(
t
,
9
,
len
(
creator
.
KVList
()))
util
.
SaveKVList
(
ldb
,
creator
.
KVList
())
util
.
SaveKVList
(
ldb
,
creator
.
KVList
())
kvs
,
err
:=
creator
.
GetRollbackKVList
()
kvs
,
err
:=
creator
.
GetRollbackKVList
()
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
6
,
len
(
kvs
))
assert
.
Equal
(
t
,
8
,
len
(
kvs
))
assert
.
Equal
(
t
,
[]
byte
(
"b"
),
kvs
[
5
]
.
Value
)
assert
.
Equal
(
t
,
[]
byte
(
"b"
),
kvs
[
7
]
.
Value
)
assert
.
Equal
(
t
,
[]
byte
(
nil
),
kvs
[
6
]
.
Value
)
assert
.
Equal
(
t
,
[]
byte
(
nil
),
kvs
[
5
]
.
Value
)
assert
.
Equal
(
t
,
[]
byte
(
nil
),
kvs
[
4
]
.
Value
)
assert
.
Equal
(
t
,
[]
byte
(
nil
),
kvs
[
4
]
.
Value
)
assert
.
Equal
(
t
,
[]
byte
(
nil
),
kvs
[
3
]
.
Value
)
assert
.
Equal
(
t
,
[]
byte
(
nil
),
kvs
[
3
]
.
Value
)
assert
.
Equal
(
t
,
[]
byte
(
nil
),
kvs
[
2
]
.
Value
)
assert
.
Equal
(
t
,
[]
byte
(
nil
),
kvs
[
2
]
.
Value
)
...
...
vendor/github.com/33cn/chain33/util/cli/chain33.go
View file @
52221b3b
...
@@ -130,7 +130,12 @@ func RunChain33(name string) {
...
@@ -130,7 +130,12 @@ func RunChain33(name string) {
q
:=
queue
.
New
(
"channel"
)
q
:=
queue
.
New
(
"channel"
)
log
.
Info
(
"loading mempool module"
)
log
.
Info
(
"loading mempool module"
)
mem
:=
mempool
.
New
(
cfg
.
Mempool
,
sub
.
Mempool
)
var
mem
queue
.
Module
if
!
types
.
IsPara
()
{
mem
=
mempool
.
New
(
cfg
.
Mempool
,
sub
.
Mempool
)
}
else
{
mem
=
&
util
.
MockModule
{
Key
:
"mempool"
}
}
mem
.
SetQueueClient
(
q
.
Client
())
mem
.
SetQueueClient
(
q
.
Client
())
log
.
Info
(
"loading execs module"
)
log
.
Info
(
"loading execs module"
)
...
@@ -150,12 +155,15 @@ func RunChain33(name string) {
...
@@ -150,12 +155,15 @@ func RunChain33(name string) {
cs
:=
consensus
.
New
(
cfg
.
Consensus
,
sub
.
Consensus
)
cs
:=
consensus
.
New
(
cfg
.
Consensus
,
sub
.
Consensus
)
cs
.
SetQueueClient
(
q
.
Client
())
cs
.
SetQueueClient
(
q
.
Client
())
var
network
*
p2p
.
P2p
log
.
Info
(
"loading p2p module"
)
if
cfg
.
P2P
.
Enable
{
var
network
queue
.
Module
log
.
Info
(
"loading p2p module"
)
if
cfg
.
P2P
.
Enable
&&
!
types
.
IsPara
()
{
network
=
p2p
.
New
(
cfg
.
P2P
)
network
=
p2p
.
New
(
cfg
.
P2P
)
network
.
SetQueueClient
(
q
.
Client
())
}
else
{
network
=
&
util
.
MockModule
{
Key
:
"p2p"
}
}
}
network
.
SetQueueClient
(
q
.
Client
())
//jsonrpc, grpc, channel 三种模式
//jsonrpc, grpc, channel 三种模式
rpcapi
:=
rpc
.
New
(
cfg
.
RPC
)
rpcapi
:=
rpc
.
New
(
cfg
.
RPC
)
rpcapi
.
SetQueueClient
(
q
.
Client
())
rpcapi
.
SetQueueClient
(
q
.
Client
())
...
@@ -169,10 +177,8 @@ func RunChain33(name string) {
...
@@ -169,10 +177,8 @@ func RunChain33(name string) {
chain
.
Close
()
chain
.
Close
()
log
.
Info
(
"begin close mempool module"
)
log
.
Info
(
"begin close mempool module"
)
mem
.
Close
()
mem
.
Close
()
if
cfg
.
P2P
.
Enable
{
log
.
Info
(
"begin close P2P module"
)
log
.
Info
(
"begin close P2P module"
)
network
.
Close
()
network
.
Close
()
}
log
.
Info
(
"begin close execs module"
)
log
.
Info
(
"begin close execs module"
)
exec
.
Close
()
exec
.
Close
()
log
.
Info
(
"begin close store module"
)
log
.
Info
(
"begin close store module"
)
...
...
vendor/github.com/33cn/chain33/util/util.go
View file @
52221b3b
...
@@ -453,3 +453,25 @@ func PrintKV(kvs []*types.KeyValue) {
...
@@ -453,3 +453,25 @@ func PrintKV(kvs []*types.KeyValue) {
fmt
.
Printf
(
"KV %d %s(%s)
\n
"
,
i
,
string
(
kvs
[
i
]
.
Key
),
common
.
ToHex
(
kvs
[
i
]
.
Value
))
fmt
.
Printf
(
"KV %d %s(%s)
\n
"
,
i
,
string
(
kvs
[
i
]
.
Key
),
common
.
ToHex
(
kvs
[
i
]
.
Value
))
}
}
}
}
// MockModule struct
type
MockModule
struct
{
Key
string
}
// SetQueueClient method
func
(
m
*
MockModule
)
SetQueueClient
(
client
queue
.
Client
)
{
go
func
()
{
client
.
Sub
(
m
.
Key
)
for
msg
:=
range
client
.
Recv
()
{
msg
.
Reply
(
client
.
NewMessage
(
m
.
Key
,
types
.
EventReply
,
&
types
.
Reply
{
IsOk
:
false
,
Msg
:
[]
byte
(
fmt
.
Sprintf
(
"mock %s module not handle message %v"
,
m
.
Key
,
msg
.
Ty
))}))
}
}()
}
// Wait for ready
func
(
m
*
MockModule
)
Wait
()
{}
// Close method
func
(
m
*
MockModule
)
Close
()
{}
vendor/github.com/33cn/chain33/util/util_test.go
View file @
52221b3b
...
@@ -8,7 +8,7 @@ import (
...
@@ -8,7 +8,7 @@ import (
"testing"
"testing"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/queue"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
...
@@ -187,3 +187,20 @@ func TestDB(t *testing.T) {
...
@@ -187,3 +187,20 @@ func TestDB(t *testing.T) {
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
value
,
[]
byte
(
"b"
))
assert
.
Equal
(
t
,
value
,
[]
byte
(
"b"
))
}
}
func
TestMockModule
(
t
*
testing
.
T
)
{
q
:=
queue
.
New
(
"channel"
)
client
:=
q
.
Client
()
memKey
:=
"mempool"
mem
:=
&
MockModule
{
Key
:
memKey
}
mem
.
SetQueueClient
(
client
)
msg
:=
client
.
NewMessage
(
memKey
,
types
.
EventTx
,
&
types
.
Transaction
{})
client
.
Send
(
msg
,
true
)
resp
,
err
:=
client
.
Wait
(
msg
)
assert
.
Nil
(
t
,
err
)
reply
,
ok
:=
resp
.
GetData
()
.
(
*
types
.
Reply
)
assert
.
Equal
(
t
,
ok
,
true
)
assert
.
Equal
(
t
,
reply
.
GetIsOk
(),
false
)
assert
.
Equal
(
t
,
reply
.
GetMsg
(),
[]
byte
(
"mock mempool module not handle message 1"
))
}
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