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
13f60945
Unverified
Commit
13f60945
authored
Oct 12, 2019
by
lyh169
Committed by
GitHub
Oct 12, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into mod_global_config
parents
93bd040a
e89dbbfa
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
415 additions
and
61 deletions
+415
-61
Makefile
Makefile
+1
-0
find-fork.bash
build/find-fork.bash
+0
-44
main.go
cli/fork_config/main.go
+80
-0
go.mod
go.mod
+1
-1
go.sum
go.sum
+2
-0
round_state.go
plugin/consensus/tendermint/types/round_state.go
+1
-1
pokerbull_test.go
plugin/dapp/pokerbull/executor/pokerbull_test.go
+230
-0
jrpc_channel_test.go
plugin/dapp/pokerbull/rpc/jrpc_channel_test.go
+13
-0
rpc.go
plugin/dapp/ticket/rpc/rpc.go
+12
-11
rpc_test.go
plugin/dapp/ticket/rpc/rpc_test.go
+75
-4
No files found.
Makefile
View file @
13f60945
...
...
@@ -25,6 +25,7 @@ default: depends build
build
:
depends
go build
$(BUILD_FLAGS)
-v
-i
-o
$(APP)
go build
$(BUILD_FLAGS)
-v
-i
-o
$(CLI)
$(SRC_CLI)
go build
$(BUILD_FLAGS)
-v
-i
-o
build/fork-config github.com/33cn/plugin/cli/fork_config/
@
cp
chain33.toml
$(CHAIN33_PATH)
/build/system-test-rpc.sh build/
@
cp
chain33.para.toml build/ci/paracross/
...
...
build/find-fork.bash
deleted
100755 → 0
View file @
93bd040a
#!/bin/bash
# 在 plugin/plugin_type/plugin_name 找出fork
function
subdir_forks
()
{
plugin_dir
=
$1
plugin_name
=
$2
full_dir
=
$1
forks
=
$(
grep
types.RegisterDappFork
"
${
full_dir
}
"
-R
|
cut
-d
'('
-f
2 |
cut
-d
')'
-f
1 |
sed
's/ //g'
)
if
[
-z
"
${
forks
}
"
]
;
then
return
fi
cnt
=
$(
echo
"
${
forks
}
"
|
grep
"^
\"
"
|
wc
-l
)
if
[
$cnt
-gt
0
]
;
then
name
=
$(
echo
$forks
|
head
-n1
|
cut
-d
','
-f
1 |
sed
's/"//g'
)
echo
"[fork.sub.
${
name
}
]"
else
echo
"[fork.sub.
${
plugin_name
}
]"
;
fi
for
fork
in
"
${
forks
}
"
do
echo
"
${
fork
}
"
|
awk
-F
','
'{ \
if(match($2,"\"")) gsub("\"","",$2); else gsub("X$","",$2); \
print $2 "=" $3}'
#/*print "debug" $1 $2 $3;*/ \
done
echo
}
dir
=
$(
go list
-f
'{{.Dir}}'
github.com/33cn/plugin
)
/plugin/
plugins
=
$(
find
$dir
-maxdepth
2
-mindepth
2
-type
d |
sort
)
for
plugin
in
${
plugins
}
do
name
=
$(
echo
$plugin
|
sed
's/.*\///g'
)
subdir_forks
$plugin
$name
done
cli/fork_config/main.go
0 → 100644
View file @
13f60945
package
main
import
(
"fmt"
"os"
"sort"
"strings"
_
"github.com/33cn/chain33/system"
"github.com/33cn/chain33/types"
_
"github.com/33cn/plugin/plugin"
)
func
main
()
{
forks
,
err
:=
types
.
CloneFork
(
"chain33"
)
if
err
!=
nil
{
fmt
.
Printf
(
"clone fork failed: %v"
,
err
)
return
}
fmtForks
(
forks
)
}
/*
两个规则:
key 有 ".", Part1.Part2 为 [fork.sub.Part1] Part2=value
key 没有 "." [fork.system] key=value
把相同段的fork打印到一起
[fork.system]
ForkChainParamV1= 0 # ForkBlockCheck=1560000
[fork.sub.ticket]
Enable=0 # manage.ForkManageExec=400000
[fork.sub.store-kvmvccmavl]
ForkKvmvccmavl=2270000 # store-kvmvccmavl.ForkKvmvccmavl=1870000
*/
func
fmtForks
(
forks
map
[
string
]
int64
)
{
systemFork
:=
make
(
map
[
string
]
int64
)
subFork
:=
make
(
map
[
string
]
map
[
string
]
int64
)
for
k
,
v
:=
range
forks
{
if
strings
.
Contains
(
k
,
"."
)
{
str2
:=
strings
.
SplitN
(
k
,
"."
,
2
)
if
len
(
str2
)
!=
2
{
fmt
.
Fprintf
(
os
.
Stderr
,
"can't deal key=%s "
,
k
)
continue
}
_
,
ok
:=
subFork
[
str2
[
0
]]
if
!
ok
{
subFork
[
str2
[
0
]]
=
make
(
map
[
string
]
int64
)
}
subFork
[
str2
[
0
]][
str2
[
1
]]
=
v
}
else
{
systemFork
[
k
]
=
v
}
}
fmt
.
Println
(
"[fork.system]"
)
for
k
,
v
:=
range
systemFork
{
fmt
.
Printf
(
"%s=%d
\n
"
,
k
,
v
)
}
fmt
.
Println
(
""
)
plugins
:=
make
([]
string
,
0
)
for
plugin
:=
range
subFork
{
plugins
=
append
(
plugins
,
plugin
)
}
sort
.
Strings
(
plugins
)
for
_
,
plugin
:=
range
plugins
{
fmt
.
Printf
(
"[fork.sub.%s]
\n
"
,
plugin
)
forks
:=
subFork
[
plugin
]
for
k
,
v
:=
range
forks
{
fmt
.
Printf
(
"%s=%d
\n
"
,
k
,
v
)
}
fmt
.
Println
(
""
)
}
}
go.mod
View file @
13f60945
...
...
@@ -3,7 +3,7 @@ module github.com/33cn/plugin
go 1.12
require (
github.com/33cn/chain33 v0.0.0-2019
0925142515-31e357c36c74
github.com/33cn/chain33 v0.0.0-2019
1011025601-06dbefe7d2e8
github.com/BurntSushi/toml v0.3.1
github.com/NebulousLabs/Sia v1.3.7
github.com/btcsuite/btcd v0.0.0-20181013004428-67e573d211ac
...
...
go.sum
View file @
13f60945
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/33cn/chain33 v0.0.0-20190925142515-31e357c36c74 h1:8PC5TDbLIV5haxz3uhiSS2zrgDwkAFQKOSa6KgNTn9c=
github.com/33cn/chain33 v0.0.0-20190925142515-31e357c36c74/go.mod h1:4I8n+Zyf3t0UKM5jjpqJY627Tub62oXkLsdzIv4r6rQ=
github.com/33cn/chain33 v0.0.0-20191011025601-06dbefe7d2e8 h1:YorXd8yAS26S49lY8Mdmn7Z5HhGJ1pat9QfXAEZfkw4=
github.com/33cn/chain33 v0.0.0-20191011025601-06dbefe7d2e8/go.mod h1:4I8n+Zyf3t0UKM5jjpqJY627Tub62oXkLsdzIv4r6rQ=
github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7 h1:PqzgE6kAMi81xWQA2QIVxjWkFHptGgC547vchpUbtFo=
github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
...
...
plugin/consensus/tendermint/types/round_state.go
View file @
13f60945
...
...
@@ -39,7 +39,7 @@ const (
ProposalPOLID
=
byte
(
0x05
)
VoteID
=
byte
(
0x06
)
HasVoteID
=
byte
(
0x07
)
VoteSetMaj23ID
=
byte
(
0
X
08
)
VoteSetMaj23ID
=
byte
(
0
x
08
)
VoteSetBitsID
=
byte
(
0x09
)
ProposalHeartbeatID
=
byte
(
0x0a
)
ProposalBlockID
=
byte
(
0x0b
)
...
...
plugin/dapp/pokerbull/executor/pokerbull_test.go
0 → 100644
View file @
13f60945
package
executor
import
(
"testing"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/crypto"
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
pkt
"github.com/33cn/plugin/plugin/dapp/pokerbull/types"
"github.com/stretchr/testify/assert"
)
type
execEnv
struct
{
blockTime
int64
blockHeight
int64
difficulty
uint64
}
var
(
PrivKeyA
=
"0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
// 1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4
PrivKeyB
=
"0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4"
// 1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR
Nodes
=
[][]
byte
{
[]
byte
(
"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"
),
[]
byte
(
"1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR"
),
}
)
func
TestPokerbull
(
t
*
testing
.
T
)
{
types
.
SetTitleOnlyForTest
(
"chain33"
)
total
:=
1000
*
types
.
Coin
accountA
:=
types
.
Account
{
Balance
:
total
,
Frozen
:
0
,
Addr
:
string
(
Nodes
[
0
]),
}
accountB
:=
types
.
Account
{
Balance
:
total
,
Frozen
:
0
,
Addr
:
string
(
Nodes
[
1
]),
}
execAddr
:=
dapp
.
ExecAddress
(
pkt
.
PokerBullX
)
stateDB
,
_
:=
dbm
.
NewGoMemDB
(
"1"
,
"2"
,
100
)
_
,
_
,
kvdb
:=
util
.
CreateTestDB
()
accA
:=
account
.
NewCoinsAccount
()
accA
.
SetDB
(
stateDB
)
accA
.
SaveExecAccount
(
execAddr
,
&
accountA
)
accB
:=
account
.
NewCoinsAccount
()
accB
.
SetDB
(
stateDB
)
accB
.
SaveExecAccount
(
execAddr
,
&
accountB
)
env
:=
execEnv
{
10
,
types
.
GetDappFork
(
pkt
.
PokerBullX
,
"Enable"
),
1539918074
,
}
// start game
p1
:=
&
pkt
.
PBGameStart
{
Value
:
5
*
types
.
Coin
,
PlayerNum
:
2
,
}
createTx
,
err
:=
types
.
CallCreateTransaction
(
pkt
.
PokerBullX
,
"Start"
,
p1
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
pkt
.
ExecerPokerBull
createTx
,
err
=
signTx
(
createTx
,
PrivKeyA
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
:=
newPBGame
()
exec
.
SetStateDB
(
stateDB
)
assert
.
Equal
(
t
,
exec
.
GetCoinsAccount
()
.
LoadExecAccount
(
string
(
Nodes
[
0
]),
execAddr
)
.
GetBalance
(),
total
)
exec
.
SetLocalDB
(
kvdb
)
exec
.
SetEnv
(
env
.
blockHeight
,
env
.
blockTime
,
env
.
difficulty
)
receipt
,
err
:=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
:=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
:=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
gameID
:=
createTx
.
Hash
()
// start game p2
createTx
,
err
=
types
.
CallCreateTransaction
(
pkt
.
PokerBullX
,
"Start"
,
p1
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
pkt
.
ExecerPokerBull
createTx
,
err
=
signTx
(
createTx
,
PrivKeyB
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
1
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// continue game
p2
:=
&
pkt
.
PBGameContinue
{
GameId
:
common
.
ToHex
(
gameID
),
}
createTx
,
err
=
types
.
CallCreateTransaction
(
pkt
.
PokerBullX
,
"Continue"
,
p2
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
pkt
.
ExecerPokerBull
createTx
,
err
=
signTx
(
createTx
,
PrivKeyA
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
1
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// quit game
p3
:=
&
pkt
.
PBGameQuit
{
GameId
:
common
.
ToHex
(
gameID
),
}
createTx
,
err
=
types
.
CallCreateTransaction
(
pkt
.
PokerBullX
,
"Quit"
,
p3
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
pkt
.
ExecerPokerBull
createTx
,
err
=
signTx
(
createTx
,
PrivKeyA
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
2
,
env
.
blockTime
+
2
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// query
res
,
err
:=
exec
.
Query
(
pkt
.
FuncNameQueryGameByID
,
types
.
Encode
(
&
pkt
.
QueryPBGameInfo
{
GameId
:
common
.
ToHex
(
gameID
)}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
res
,
err
=
exec
.
Query
(
pkt
.
FuncNameQueryGameByAddr
,
types
.
Encode
(
&
pkt
.
QueryPBGameInfo
{
Addr
:
string
(
Nodes
[
0
])}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
res
,
err
=
exec
.
Query
(
pkt
.
FuncNameQueryGameByStatus
,
types
.
Encode
(
&
pkt
.
QueryPBGameInfo
{
Status
:
pkt
.
PBGameActionQuit
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
res
,
err
=
exec
.
Query
(
pkt
.
FuncNameQueryGameByRound
,
types
.
Encode
(
&
pkt
.
QueryPBGameByRound
{
GameId
:
common
.
ToHex
(
gameID
),
Round
:
int32
(
1
)}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
var
gameIDsS
[]
string
gameIDsS
=
append
(
gameIDsS
,
common
.
ToHex
(
gameID
))
res
,
err
=
exec
.
Query
(
pkt
.
FuncNameQueryGameListByIDs
,
types
.
Encode
(
&
pkt
.
QueryPBGameInfos
{
GameIds
:
gameIDsS
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
}
func
signTx
(
tx
*
types
.
Transaction
,
hexPrivKey
string
)
(
*
types
.
Transaction
,
error
)
{
signType
:=
types
.
SECP256K1
c
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
pkt
.
PokerBullX
,
signType
))
if
err
!=
nil
{
return
tx
,
err
}
bytes
,
err
:=
common
.
FromHex
(
hexPrivKey
[
:
])
if
err
!=
nil
{
return
tx
,
err
}
privKey
,
err
:=
c
.
PrivKeyFromBytes
(
bytes
)
if
err
!=
nil
{
return
tx
,
err
}
tx
.
Sign
(
int32
(
signType
),
privKey
)
return
tx
,
nil
}
plugin/dapp/pokerbull/rpc/jrpc_channel_test.go
View file @
13f60945
...
...
@@ -41,7 +41,9 @@ func TestJRPCChannel(t *testing.T) {
{
fn
:
testStartRawTxCmd
},
{
fn
:
testContinueRawTxCmd
},
{
fn
:
testQuitRawTxCmd
},
{
fn
:
testPlayRawTxCmd
},
}
for
_
,
testCase
:=
range
testCases
{
err
:=
testCase
.
fn
(
t
,
jrpcClient
)
assert
.
Nil
(
t
,
err
)
...
...
@@ -93,6 +95,17 @@ func testContinueRawTxCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
return
jrpc
.
Call
(
"Chain33.CreateTransaction"
,
params
,
&
res
)
}
func
testPlayRawTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
payload
:=
&
pty
.
PBGamePlay
{
GameId
:
"123"
,
Round
:
1
,
Value
:
5
,
Address
:
[]
string
{
"a"
,
"b"
}}
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pty
.
PokerBullX
),
ActionName
:
pty
.
CreatePlayTx
,
Payload
:
types
.
MustPBToJSON
(
payload
),
}
var
res
string
return
jrpc
.
Call
(
"Chain33.CreateTransaction"
,
params
,
&
res
)
}
func
testQuitRawTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
payload
:=
&
pty
.
PBGameQuit
{
GameId
:
"123"
}
params
:=
&
rpctypes
.
CreateTxIn
{
...
...
plugin/dapp/ticket/rpc/rpc.go
View file @
13f60945
...
...
@@ -10,7 +10,7 @@ import (
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
ty
"github.com/33cn/plugin/plugin/dapp/ticket/types"
context
"golang.org/x/net/context"
"golang.org/x/net/context"
)
func
bindMiner
(
cfg
*
types
.
Chain33Config
,
param
*
ty
.
ReqBindMiner
)
(
*
ty
.
ReplyBindMiner
,
error
)
{
...
...
@@ -28,15 +28,7 @@ func bindMiner(cfg *types.Chain33Config, param *ty.ReqBindMiner) (*ty.ReplyBindM
// CreateBindMiner 创建绑定挖矿
func
(
g
*
channelClient
)
CreateBindMiner
(
ctx
context
.
Context
,
in
*
ty
.
ReqBindMiner
)
(
*
ty
.
ReplyBindMiner
,
error
)
{
header
,
err
:=
g
.
GetLastHeader
()
if
err
!=
nil
{
return
nil
,
err
}
cfg
:=
g
.
GetConfig
()
if
in
.
Amount
%
ty
.
GetTicketMinerParam
(
cfg
,
header
.
Height
)
.
TicketPrice
!=
0
||
in
.
Amount
<
0
{
return
nil
,
types
.
ErrAmount
}
err
=
address
.
CheckAddress
(
in
.
BindAddr
)
err
:=
address
.
CheckAddress
(
in
.
BindAddr
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -44,8 +36,17 @@ func (g *channelClient) CreateBindMiner(ctx context.Context, in *ty.ReqBindMiner
if
err
!=
nil
{
return
nil
,
err
}
cfg
:=
g
.
GetConfig
()
if
in
.
CheckBalance
{
header
,
err
:=
g
.
GetLastHeader
()
if
err
!=
nil
{
return
nil
,
err
}
if
in
.
Amount
%
ty
.
GetTicketMinerParam
(
cfg
,
header
.
Height
)
.
TicketPrice
!=
0
||
in
.
Amount
<
0
{
return
nil
,
types
.
ErrAmount
}
getBalance
:=
&
types
.
ReqBalance
{
Addresses
:
[]
string
{
in
.
OriginAddr
},
Execer
:
"coins"
,
AssetSymbol
:
"bty"
,
AssetExec
:
"coins"
}
balances
,
err
:=
g
.
GetCoinsAccountDB
()
.
GetBalance
(
g
,
getBalance
)
if
err
!=
nil
{
...
...
plugin/dapp/ticket/rpc/rpc_test.go
View file @
13f60945
...
...
@@ -26,6 +26,26 @@ import (
var
cfgstring
=
`
Title="test"
[mempool]
poolCacheSize=102400
minTxFee=100000
maxTxNumPerAccount=100
[exec]
isFree=false
minExecFee=100000
enableStat=false
enableMVCC=false
[wallet]
minFee=100000
driver="leveldb"
dbPath="wallet"
dbCache=16
signType="secp256k1"
minerdisable=false
minerwhitelist=["*"]
[mver.consensus]
fundKeyAddr = "1BQXS6TxaYYG5mADaWij4AxhZZUTpw95a5"
powLimitBits = "0x1f00ffff"
...
...
@@ -43,6 +63,46 @@ ticketWithdrawTime = 10
ticketMinerWaitTime = 2
targetTimespan = 2304
targetTimePerBlock = 16
[mver.consensus.ticket.ForkChainParamV1]
ticketPrice = 3000
[mver.consensus.ticket.ForkChainParamV2]
ticketPrice = 6000
[fork.system]
ForkChainParamV1= 10
ForkChainParamV2= 20
ForkStateDBSet=-1
ForkCheckTxDup=0
ForkBlockHash= 1
ForkMinerTime= 10
ForkTransferExec= 100000
ForkExecKey= 200000
ForkTxGroup= 200000
ForkResetTx0= 200000
ForkWithdraw= 200000
ForkExecRollback= 450000
ForkTxHeight= -1
ForkTxGroupPara= -1
ForkCheckBlockTime=1200000
ForkMultiSignAddress=1298600
ForkBlockCheck=1
ForkLocalDBAccess=0
ForkBase58AddressCheck=1800000
ForkEnableParaRegExec=0
ForkCacheDriver=0
ForkTicketFundAddrV1=-1
[fork.sub.coins]
Enable=0
[fork.sub.manage]
Enable=0
ForkManageExec=100000
[fork.sub.store-kvmvccmavl]
ForkKvmvccmavl=1
`
func
newGrpc
(
api
client
.
QueueProtocolAPI
)
*
channelClient
{
...
...
@@ -59,17 +119,18 @@ func TestChannelClient_BindMiner(t *testing.T) {
api
:=
new
(
mocks
.
QueueProtocolAPI
)
client
:=
newGrpc
(
api
)
client
.
Init
(
"ticket"
,
nil
,
nil
,
nil
)
head
:=
&
types
.
Header
{
StateHash
:
[]
byte
(
"sdfadasds"
)}
api
.
On
(
"GetLastHeader"
)
.
Return
(
head
,
nil
)
head
:=
&
types
.
Header
{
Height
:
2
,
StateHash
:
[]
byte
(
"sdfadasds"
)}
api
.
On
(
"GetLastHeader"
)
.
Return
(
head
,
nil
)
.
Times
(
4
)
var
acc
=
&
types
.
Account
{
Addr
:
"1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt"
,
Balance
:
100000
*
types
.
Coin
}
accv
:=
types
.
Encode
(
acc
)
storevalue
:=
&
types
.
StoreReplyValue
{}
storevalue
.
Values
=
append
(
storevalue
.
Values
,
accv
)
api
.
On
(
"StoreGet"
,
mock
.
Anything
)
.
Return
(
storevalue
,
nil
)
api
.
On
(
"StoreGet"
,
mock
.
Anything
)
.
Return
(
storevalue
,
nil
)
.
Twice
()
types
.
SetTitleOnlyForTest
(
"test"
)
types
.
InitCfgString
(
cfgstring
)
cfg
,
_
:=
types
.
InitCfgString
(
cfgstring
)
types
.
Init
(
"test"
,
cfg
)
//var addrs = make([]string, 1)
//addrs = append(addrs, "1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt")
...
...
@@ -81,6 +142,16 @@ func TestChannelClient_BindMiner(t *testing.T) {
}
_
,
err
:=
client
.
CreateBindMiner
(
context
.
Background
(),
in
)
assert
.
Nil
(
t
,
err
)
in
.
Amount
=
200000
*
types
.
Coin
_
,
err
=
client
.
CreateBindMiner
(
context
.
Background
(),
in
)
assert
.
Equal
(
t
,
types
.
ErrNoBalance
,
err
)
head
.
Height
=
20
//ForkChainParamV2
api
.
On
(
"GetLastHeader"
)
.
Return
(
head
,
nil
)
.
Times
(
2
)
_
,
err
=
client
.
CreateBindMiner
(
context
.
Background
(),
in
)
assert
.
Equal
(
t
,
types
.
ErrAmount
,
err
)
}
func
testGetTicketCountOK
(
t
*
testing
.
T
)
{
...
...
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