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
04a57e12
Commit
04a57e12
authored
Oct 10, 2019
by
张振华
Committed by
vipwzw
Oct 16, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
a4f5f694
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
85 deletions
+85
-85
guess_test.go
plugin/dapp/guess/rpc/guess_test.go
+85
-85
No files found.
plugin/dapp/guess/rpc/guess_test.go
View file @
04a57e12
package
rpc
package
rpc
import
(
import
(
jsonrpc
"github.com/33cn/chain33/rpc/jsonclient"
cty
"github.com/33cn/chain33/system/dapp/coins/types"
"github.com/33cn/chain33/system/consensus/solo"
gty
"github.com/33cn/plugin/plugin/dapp/guess/types"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/stretchr/testify/assert"
"strings"
"context"
"context"
"encoding/binary"
"encoding/binary"
"encoding/hex"
"encoding/hex"
"errors"
"errors"
"flag"
"flag"
"fmt"
"fmt"
gty
"github.com/33cn/plugin/plugin/dapp/guess/types"
"io/ioutil"
"io/ioutil"
"math/rand"
"math/rand"
"os"
"os"
"strings"
"testing"
"testing"
"time"
"time"
...
@@ -32,21 +32,29 @@ import (
...
@@ -32,21 +32,29 @@ import (
"github.com/33cn/chain33/queue"
"github.com/33cn/chain33/queue"
"github.com/33cn/chain33/rpc"
"github.com/33cn/chain33/rpc"
"github.com/33cn/chain33/store"
"github.com/33cn/chain33/store"
"github.com/33cn/chain33/types"
_
"github.com/33cn/chain33/system"
_
"github.com/33cn/chain33/system"
_
"github.com/33cn/chain33/system/consensus/solo"
_
"github.com/33cn/chain33/system/consensus/solo"
cty
"github.com/33cn/chain33/system/dapp/coins/types"
jsonrpc
"github.com/33cn/chain33/rpc/jsonclient"
"github.com/33cn/chain33/types"
rpctypes
"github.com/33cn/chain33/rpc/types"
dty
"github.com/33cn/plugin/plugin/dapp/guess/types"
"github.com/33cn/chain33/system/consensus/solo"
_
"github.com/33cn/plugin/plugin/dapp/init"
_
"github.com/33cn/plugin/plugin/dapp/init"
pty
"github.com/33cn/plugin/plugin/dapp/norm/types"
pty
"github.com/33cn/plugin/plugin/dapp/norm/types"
_
"github.com/33cn/plugin/plugin/store/init"
_
"github.com/33cn/plugin/plugin/store/init"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"google.golang.org/grpc"
)
)
var
(
var
(
secp
crypto
.
Crypto
secp
crypto
.
Crypto
config
=
`# Title为local,表示此配置文件为本地单节点的配置。此时本地节点所在的链上只有这一个节点,共识模块一般采用solo模式。
config
=
`# Title为local,表示此配置文件为本地单节点的配置。此时本地节点所在的链上只有这一个节点,共识模块一般采用solo模式。
Title="local"
Title="local"
TestNet=true
TestNet=true
...
@@ -303,15 +311,14 @@ superManager=[
...
@@ -303,15 +311,14 @@ superManager=[
`
`
)
)
var
(
var
(
random
*
rand
.
Rand
random
*
rand
.
Rand
//loopCount = 10
loopCount
=
1
conn
*
grpc
.
ClientConn
conn
*
grpc
.
ClientConn
c
types
.
Chain33Client
c
types
.
Chain33Client
adminPriv
=
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
adminPriv
=
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
adminAddr
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
adminAddr
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
//userAPubkey = "03EF0E1D3112CF571743A3318125EDE2E52A4EB904BCBAA4B1F75020C2846A7EB4"
//userAPubkey = "03EF0E1D3112CF571743A3318125EDE2E52A4EB904BCBAA4B1F75020C2846A7EB4"
userAAddr
=
"15LsTP6tkYGZcN7tc1Xo2iYifQfowxot3b"
userAAddr
=
"15LsTP6tkYGZcN7tc1Xo2iYifQfowxot3b"
...
@@ -386,10 +393,10 @@ func testGuessImp(t *testing.T) {
...
@@ -386,10 +393,10 @@ func testGuessImp(t *testing.T) {
time
.
Sleep
(
2
*
time
.
Second
)
time
.
Sleep
(
2
*
time
.
Second
)
fmt
.
Println
(
"=======start NormPut!======="
)
fmt
.
Println
(
"=======start NormPut!======="
)
//
for i := 0; i < loopCount; i++ {
for
i
:=
0
;
i
<
loopCount
;
i
++
{
//
NormPut()
NormPut
()
//
time.Sleep(time.Second)
time
.
Sleep
(
time
.
Second
)
//
}
}
fmt
.
Println
(
"=======start sendTransferTx sendTransferToExecTx!======="
)
fmt
.
Println
(
"=======start sendTransferTx sendTransferToExecTx!======="
)
//从创世地址向测试地址A转入代币
//从创世地址向测试地址A转入代币
...
@@ -417,7 +424,6 @@ func testGuessImp(t *testing.T) {
...
@@ -417,7 +424,6 @@ func testGuessImp(t *testing.T) {
}
}
assert
.
Equal
(
t
,
true
,
acct2
.
Acc
[
0
]
.
Balance
==
2000000000000
)
assert
.
Equal
(
t
,
true
,
acct2
.
Acc
[
0
]
.
Balance
==
2000000000000
)
//从测试地址向dos合约转入代币
//从测试地址向dos合约转入代币
sendTransferToExecTx
(
userAPriv
,
"guess"
,
1000000000000
)
sendTransferToExecTx
(
userAPriv
,
"guess"
,
1000000000000
)
sendTransferToExecTx
(
userBPriv
,
"guess"
,
1000000000000
)
sendTransferToExecTx
(
userBPriv
,
"guess"
,
1000000000000
)
...
@@ -446,7 +452,7 @@ func testGuessImp(t *testing.T) {
...
@@ -446,7 +452,7 @@ func testGuessImp(t *testing.T) {
assert
.
Equal
(
t
,
true
,
acct4
.
Acc
[
0
]
.
Balance
==
1000000000000
)
assert
.
Equal
(
t
,
true
,
acct4
.
Acc
[
0
]
.
Balance
==
1000000000000
)
fmt
.
Println
(
"=======start sendGuessStartTx!======="
)
fmt
.
Println
(
"=======start sendGuessStartTx!======="
)
ok
,
gameid
:=
sendGuessStartTx
(
"WorldCup Final"
,
"A:France;B:Claodia"
,
"football"
,
adminPriv
)
ok
,
gameid
:=
sendGuessStartTx
(
"WorldCup Final"
,
"A:France;B:Claodia"
,
"football"
,
adminPriv
)
if
!
ok
{
if
!
ok
{
panic
(
"Guess start failed."
)
panic
(
"Guess start failed."
)
}
else
{
}
else
{
...
@@ -454,12 +460,11 @@ func testGuessImp(t *testing.T) {
...
@@ -454,12 +460,11 @@ func testGuessImp(t *testing.T) {
}
}
time
.
Sleep
(
2
*
time
.
Second
)
time
.
Sleep
(
2
*
time
.
Second
)
strGameID1
:=
"0x"
+
hex
.
EncodeToString
(
gameid
)
strGameID1
:=
"0x"
+
hex
.
EncodeToString
(
gameid
)
reply
:=
queryGuessByIds
(
strGameID1
)
reply
:=
queryGuessByIds
(
strGameID1
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
7
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
7
)
fmt
.
Println
(
"=======start sendGuessBetTx!======="
)
fmt
.
Println
(
"=======start sendGuessBetTx!======="
)
ok
,
txid
:=
sendGuessBetTx
(
strGameID1
,
"A"
,
5e8
,
userAPriv
)
ok
,
txid
:=
sendGuessBetTx
(
strGameID1
,
"A"
,
5e8
,
userAPriv
)
if
!
ok
{
if
!
ok
{
...
@@ -549,7 +554,7 @@ func testGuessImp(t *testing.T) {
...
@@ -549,7 +554,7 @@ func testGuessImp(t *testing.T) {
//再来一次,测试异常流程:start->abort->stop
//再来一次,测试异常流程:start->abort->stop
fmt
.
Println
(
"=======start sendGuessStartTx!======="
)
fmt
.
Println
(
"=======start sendGuessStartTx!======="
)
ok
,
gameid
=
sendGuessStartTx
(
"WorldCup Final"
,
"A:France;B:Claodia"
,
"football"
,
adminPriv
)
ok
,
gameid
=
sendGuessStartTx
(
"WorldCup Final"
,
"A:France;B:Claodia"
,
"football"
,
adminPriv
)
if
!
ok
{
if
!
ok
{
fmt
.
Println
(
"Guess start failed."
)
fmt
.
Println
(
"Guess start failed."
)
}
else
{
}
else
{
...
@@ -557,7 +562,7 @@ func testGuessImp(t *testing.T) {
...
@@ -557,7 +562,7 @@ func testGuessImp(t *testing.T) {
}
}
time
.
Sleep
(
2
*
time
.
Second
)
time
.
Sleep
(
2
*
time
.
Second
)
strGameID2
:=
"0x"
+
hex
.
EncodeToString
(
gameid
)
strGameID2
:=
"0x"
+
hex
.
EncodeToString
(
gameid
)
reply
=
queryGuessByIds
(
strGameID2
)
reply
=
queryGuessByIds
(
strGameID2
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
7
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
7
)
...
@@ -586,7 +591,7 @@ func testGuessImp(t *testing.T) {
...
@@ -586,7 +591,7 @@ func testGuessImp(t *testing.T) {
//再来一次,测试流程:start->stop->abort
//再来一次,测试流程:start->stop->abort
fmt
.
Println
(
"=======start sendGuessStartTx!======="
)
fmt
.
Println
(
"=======start sendGuessStartTx!======="
)
ok
,
gameid
=
sendGuessStartTx
(
"WorldCup Final"
,
"A:France;B:Claodia"
,
"football"
,
adminPriv
)
ok
,
gameid
=
sendGuessStartTx
(
"WorldCup Final"
,
"A:France;B:Claodia"
,
"football"
,
adminPriv
)
if
!
ok
{
if
!
ok
{
fmt
.
Println
(
"Guess start failed."
)
fmt
.
Println
(
"Guess start failed."
)
}
else
{
}
else
{
...
@@ -594,7 +599,7 @@ func testGuessImp(t *testing.T) {
...
@@ -594,7 +599,7 @@ func testGuessImp(t *testing.T) {
}
}
time
.
Sleep
(
2
*
time
.
Second
)
time
.
Sleep
(
2
*
time
.
Second
)
strGameID3
:=
"0x"
+
hex
.
EncodeToString
(
gameid
)
strGameID3
:=
"0x"
+
hex
.
EncodeToString
(
gameid
)
reply
=
queryGuessByIds
(
strGameID3
)
reply
=
queryGuessByIds
(
strGameID3
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
7
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
7
)
...
@@ -618,7 +623,6 @@ func testGuessImp(t *testing.T) {
...
@@ -618,7 +623,6 @@ func testGuessImp(t *testing.T) {
}
}
time
.
Sleep
(
2
*
time
.
Second
)
time
.
Sleep
(
2
*
time
.
Second
)
//以下测试查询接口
//以下测试查询接口
fmt
.
Println
(
"=======start queryGuessByIds!======="
)
fmt
.
Println
(
"=======start queryGuessByIds!======="
)
reply
=
queryGuessByIds
(
strGameID3
)
reply
=
queryGuessByIds
(
strGameID3
)
...
@@ -657,7 +661,6 @@ func testGuessImp(t *testing.T) {
...
@@ -657,7 +661,6 @@ func testGuessImp(t *testing.T) {
record
=
queryGuessByAdminAddrStatus
(
adminAddr
,
11
)
record
=
queryGuessByAdminAddrStatus
(
adminAddr
,
11
)
assert
.
Equal
(
t
,
true
,
len
(
record
.
Records
)
==
1
)
assert
.
Equal
(
t
,
true
,
len
(
record
.
Records
)
==
1
)
fmt
.
Println
(
"=======start queryGuessByCategoryStatus!======="
)
fmt
.
Println
(
"=======start queryGuessByCategoryStatus!======="
)
record
=
queryGuessByCategoryStatus
(
"football"
,
11
)
record
=
queryGuessByCategoryStatus
(
"football"
,
11
)
assert
.
Equal
(
t
,
true
,
len
(
record
.
Records
)
==
1
)
assert
.
Equal
(
t
,
true
,
len
(
record
.
Records
)
==
1
)
...
@@ -714,7 +717,6 @@ func createConn() error {
...
@@ -714,7 +717,6 @@ func createConn() error {
return
nil
return
nil
}
}
func
generateKey
(
i
,
valI
int
)
string
{
func
generateKey
(
i
,
valI
int
)
string
{
key
:=
make
([]
byte
,
valI
)
key
:=
make
([]
byte
,
valI
)
binary
.
PutUvarint
(
key
[
:
10
],
uint64
(
valI
))
binary
.
PutUvarint
(
key
[
:
10
],
uint64
(
valI
))
...
@@ -852,24 +854,24 @@ func sendTransferToExecTx(fromKey, execName string, amount int64) bool {
...
@@ -852,24 +854,24 @@ func sendTransferToExecTx(fromKey, execName string, amount int64) bool {
func
sendGuessStartTx
(
topic
,
option
,
category
,
privKey
string
)
(
bool
,
[]
byte
)
{
func
sendGuessStartTx
(
topic
,
option
,
category
,
privKey
string
)
(
bool
,
[]
byte
)
{
signer
:=
util
.
HexToPrivkey
(
privKey
)
signer
:=
util
.
HexToPrivkey
(
privKey
)
var
tx
*
types
.
Transaction
var
tx
*
types
.
Transaction
action
:=
&
d
ty
.
GuessGameAction
{}
action
:=
&
g
ty
.
GuessGameAction
{}
v
:=
&
d
ty
.
GuessGameAction_Start
{
v
:=
&
g
ty
.
GuessGameAction_Start
{
Start
:
&
d
ty
.
GuessGameStart
{
Start
:
&
g
ty
.
GuessGameStart
{
Topic
:
topic
,
Topic
:
topic
,
Options
:
option
,
Options
:
option
,
Category
:
category
,
Category
:
category
,
MaxBetsOneTime
:
100e8
,
MaxBetsOneTime
:
100e8
,
MaxBetsNumber
:
1000e8
,
MaxBetsNumber
:
1000e8
,
DevFeeFactor
:
5
,
DevFeeFactor
:
5
,
DevFeeAddr
:
"1D6RFZNp2rh6QdbcZ1d7RWuBUz61We6SD7"
,
DevFeeAddr
:
"1D6RFZNp2rh6QdbcZ1d7RWuBUz61We6SD7"
,
PlatFeeFactor
:
5
,
PlatFeeFactor
:
5
,
PlatFeeAddr
:
"1PHtChNt3UcfssR7v7trKSk3WJtAWjKjjX"
,
PlatFeeAddr
:
"1PHtChNt3UcfssR7v7trKSk3WJtAWjKjjX"
,
},
},
}
}
action
.
Value
=
v
action
.
Value
=
v
action
.
Ty
=
d
ty
.
GuessGameActionStart
action
.
Ty
=
g
ty
.
GuessGameActionStart
execer
:=
[]
byte
(
"guess"
)
execer
:=
[]
byte
(
"guess"
)
tx
=
&
types
.
Transaction
{
Execer
:
execer
,
Payload
:
types
.
Encode
(
action
),
To
:
address
.
ExecAddress
(
string
(
execer
)),
Fee
:
fee
}
tx
=
&
types
.
Transaction
{
Execer
:
execer
,
Payload
:
types
.
Encode
(
action
),
To
:
address
.
ExecAddress
(
string
(
execer
)),
Fee
:
fee
}
tx
,
err
:=
types
.
FormatTx
(
string
(
execer
),
tx
)
tx
,
err
:=
types
.
FormatTx
(
string
(
execer
),
tx
)
...
@@ -900,22 +902,21 @@ func sendGuessStartTx(topic, option, category, privKey string) (bool, []byte) {
...
@@ -900,22 +902,21 @@ func sendGuessStartTx(topic, option, category, privKey string) (bool, []byte) {
return
true
,
reply
.
Msg
return
true
,
reply
.
Msg
}
}
func
sendGuessBetTx
(
gameID
,
option
string
,
betsNum
int64
,
privKey
string
)
(
bool
,
[]
byte
)
{
func
sendGuessBetTx
(
gameID
,
option
string
,
betsNum
int64
,
privKey
string
)
(
bool
,
[]
byte
)
{
signer
:=
util
.
HexToPrivkey
(
privKey
)
signer
:=
util
.
HexToPrivkey
(
privKey
)
var
tx
*
types
.
Transaction
var
tx
*
types
.
Transaction
action
:=
&
d
ty
.
GuessGameAction
{}
action
:=
&
g
ty
.
GuessGameAction
{}
v
:=
&
d
ty
.
GuessGameAction_Bet
{
v
:=
&
g
ty
.
GuessGameAction_Bet
{
Bet
:
&
d
ty
.
GuessGameBet
{
Bet
:
&
g
ty
.
GuessGameBet
{
GameID
:
gameID
,
GameID
:
gameID
,
Option
:
option
,
Option
:
option
,
BetsNum
:
betsNum
,
BetsNum
:
betsNum
,
},
},
}
}
action
.
Value
=
v
action
.
Value
=
v
action
.
Ty
=
d
ty
.
GuessGameActionBet
action
.
Ty
=
g
ty
.
GuessGameActionBet
execer
:=
[]
byte
(
"guess"
)
execer
:=
[]
byte
(
"guess"
)
tx
=
&
types
.
Transaction
{
Execer
:
execer
,
Payload
:
types
.
Encode
(
action
),
To
:
address
.
ExecAddress
(
string
(
execer
)),
Fee
:
fee
}
tx
=
&
types
.
Transaction
{
Execer
:
execer
,
Payload
:
types
.
Encode
(
action
),
To
:
address
.
ExecAddress
(
string
(
execer
)),
Fee
:
fee
}
tx
,
err
:=
types
.
FormatTx
(
string
(
execer
),
tx
)
tx
,
err
:=
types
.
FormatTx
(
string
(
execer
),
tx
)
...
@@ -946,19 +947,19 @@ func sendGuessBetTx(gameID, option string, betsNum int64 , privKey string) (bool
...
@@ -946,19 +947,19 @@ func sendGuessBetTx(gameID, option string, betsNum int64 , privKey string) (bool
return
true
,
reply
.
Msg
return
true
,
reply
.
Msg
}
}
func
sendGuessStopTx
(
gameID
,
privKey
string
)
(
bool
,
[]
byte
)
{
func
sendGuessStopTx
(
gameID
,
privKey
string
)
(
bool
,
[]
byte
)
{
signer
:=
util
.
HexToPrivkey
(
privKey
)
signer
:=
util
.
HexToPrivkey
(
privKey
)
var
tx
*
types
.
Transaction
var
tx
*
types
.
Transaction
action
:=
&
d
ty
.
GuessGameAction
{}
action
:=
&
g
ty
.
GuessGameAction
{}
v
:=
&
d
ty
.
GuessGameAction_StopBet
{
v
:=
&
g
ty
.
GuessGameAction_StopBet
{
StopBet
:
&
d
ty
.
GuessGameStopBet
{
StopBet
:
&
g
ty
.
GuessGameStopBet
{
GameID
:
gameID
,
GameID
:
gameID
,
},
},
}
}
action
.
Value
=
v
action
.
Value
=
v
action
.
Ty
=
d
ty
.
GuessGameActionStopBet
action
.
Ty
=
g
ty
.
GuessGameActionStopBet
execer
:=
[]
byte
(
"guess"
)
execer
:=
[]
byte
(
"guess"
)
tx
=
&
types
.
Transaction
{
Execer
:
execer
,
Payload
:
types
.
Encode
(
action
),
To
:
address
.
ExecAddress
(
string
(
execer
)),
Fee
:
fee
}
tx
=
&
types
.
Transaction
{
Execer
:
execer
,
Payload
:
types
.
Encode
(
action
),
To
:
address
.
ExecAddress
(
string
(
execer
)),
Fee
:
fee
}
tx
,
err
:=
types
.
FormatTx
(
string
(
execer
),
tx
)
tx
,
err
:=
types
.
FormatTx
(
string
(
execer
),
tx
)
...
@@ -989,19 +990,19 @@ func sendGuessStopTx(gameID , privKey string) (bool, []byte) {
...
@@ -989,19 +990,19 @@ func sendGuessStopTx(gameID , privKey string) (bool, []byte) {
return
true
,
reply
.
Msg
return
true
,
reply
.
Msg
}
}
func
sendGuessAbortTx
(
gameID
,
privKey
string
)
(
bool
,
[]
byte
)
{
func
sendGuessAbortTx
(
gameID
,
privKey
string
)
(
bool
,
[]
byte
)
{
signer
:=
util
.
HexToPrivkey
(
privKey
)
signer
:=
util
.
HexToPrivkey
(
privKey
)
var
tx
*
types
.
Transaction
var
tx
*
types
.
Transaction
action
:=
&
d
ty
.
GuessGameAction
{}
action
:=
&
g
ty
.
GuessGameAction
{}
v
:=
&
d
ty
.
GuessGameAction_Abort
{
v
:=
&
g
ty
.
GuessGameAction_Abort
{
Abort
:
&
d
ty
.
GuessGameAbort
{
Abort
:
&
g
ty
.
GuessGameAbort
{
GameID
:
gameID
,
GameID
:
gameID
,
},
},
}
}
action
.
Value
=
v
action
.
Value
=
v
action
.
Ty
=
d
ty
.
GuessGameActionAbort
action
.
Ty
=
g
ty
.
GuessGameActionAbort
execer
:=
[]
byte
(
"guess"
)
execer
:=
[]
byte
(
"guess"
)
tx
=
&
types
.
Transaction
{
Execer
:
execer
,
Payload
:
types
.
Encode
(
action
),
To
:
address
.
ExecAddress
(
string
(
execer
)),
Fee
:
fee
}
tx
=
&
types
.
Transaction
{
Execer
:
execer
,
Payload
:
types
.
Encode
(
action
),
To
:
address
.
ExecAddress
(
string
(
execer
)),
Fee
:
fee
}
tx
,
err
:=
types
.
FormatTx
(
string
(
execer
),
tx
)
tx
,
err
:=
types
.
FormatTx
(
string
(
execer
),
tx
)
...
@@ -1032,20 +1033,20 @@ func sendGuessAbortTx(gameID , privKey string) (bool, []byte) {
...
@@ -1032,20 +1033,20 @@ func sendGuessAbortTx(gameID , privKey string) (bool, []byte) {
return
true
,
reply
.
Msg
return
true
,
reply
.
Msg
}
}
func
sendGuessPublishTx
(
gameID
,
result
,
privKey
string
)
(
bool
,
[]
byte
)
{
func
sendGuessPublishTx
(
gameID
,
result
,
privKey
string
)
(
bool
,
[]
byte
)
{
signer
:=
util
.
HexToPrivkey
(
privKey
)
signer
:=
util
.
HexToPrivkey
(
privKey
)
var
tx
*
types
.
Transaction
var
tx
*
types
.
Transaction
action
:=
&
d
ty
.
GuessGameAction
{}
action
:=
&
g
ty
.
GuessGameAction
{}
v
:=
&
d
ty
.
GuessGameAction_Publish
{
v
:=
&
g
ty
.
GuessGameAction_Publish
{
Publish
:
&
d
ty
.
GuessGamePublish
{
Publish
:
&
g
ty
.
GuessGamePublish
{
GameID
:
gameID
,
GameID
:
gameID
,
Result
:
result
,
Result
:
result
,
},
},
}
}
action
.
Value
=
v
action
.
Value
=
v
action
.
Ty
=
d
ty
.
GuessGameActionPublish
action
.
Ty
=
g
ty
.
GuessGameActionPublish
execer
:=
[]
byte
(
"guess"
)
execer
:=
[]
byte
(
"guess"
)
tx
=
&
types
.
Transaction
{
Execer
:
execer
,
Payload
:
types
.
Encode
(
action
),
To
:
address
.
ExecAddress
(
string
(
execer
)),
Fee
:
fee
}
tx
=
&
types
.
Transaction
{
Execer
:
execer
,
Payload
:
types
.
Encode
(
action
),
To
:
address
.
ExecAddress
(
string
(
execer
)),
Fee
:
fee
}
tx
,
err
:=
types
.
FormatTx
(
string
(
execer
),
tx
)
tx
,
err
:=
types
.
FormatTx
(
string
(
execer
),
tx
)
...
@@ -1076,7 +1077,7 @@ func sendGuessPublishTx(gameID , result, privKey string) (bool, []byte) {
...
@@ -1076,7 +1077,7 @@ func sendGuessPublishTx(gameID , result, privKey string) (bool, []byte) {
return
true
,
reply
.
Msg
return
true
,
reply
.
Msg
}
}
func
queryGuessByIds
(
gameIDs
string
)
(
*
gty
.
ReplyGuessGameInfos
)
{
func
queryGuessByIds
(
gameIDs
string
)
*
gty
.
ReplyGuessGameInfos
{
var
params
rpctypes
.
Query4Jrpc
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
gty
.
GuessX
params
.
Execer
=
gty
.
GuessX
...
@@ -1087,12 +1088,12 @@ func queryGuessByIds(gameIDs string) (*gty.ReplyGuessGameInfos) {
...
@@ -1087,12 +1088,12 @@ func queryGuessByIds(gameIDs string) (*gty.ReplyGuessGameInfos) {
params
.
FuncName
=
gty
.
FuncNameQueryGamesByIDs
params
.
FuncName
=
gty
.
FuncNameQueryGamesByIDs
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
gty
.
ReplyGuessGameInfos
var
res
gty
.
ReplyGuessGameInfos
ctx
:=
jsonrpc
.
NewRPCCtx
(
"http://"
+
types
.
Conf
(
"config.rpc"
)
.
GStr
(
"jrpcBindAddr"
),
"Chain33.Query"
,
params
,
&
res
)
ctx
:=
jsonrpc
.
NewRPCCtx
(
"http://"
+
types
.
Conf
(
"config.rpc"
)
.
GStr
(
"jrpcBindAddr"
),
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
ctx
.
Run
()
return
&
res
return
&
res
}
}
func
queryGuessByID
(
gameID
string
)
(
*
gty
.
ReplyGuessGameInfo
)
{
func
queryGuessByID
(
gameID
string
)
*
gty
.
ReplyGuessGameInfo
{
var
params
rpctypes
.
Query4Jrpc
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
gty
.
GuessX
params
.
Execer
=
gty
.
GuessX
...
@@ -1102,12 +1103,12 @@ func queryGuessByID(gameID string) (*gty.ReplyGuessGameInfo) {
...
@@ -1102,12 +1103,12 @@ func queryGuessByID(gameID string) (*gty.ReplyGuessGameInfo) {
params
.
FuncName
=
gty
.
FuncNameQueryGameByID
params
.
FuncName
=
gty
.
FuncNameQueryGameByID
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
gty
.
ReplyGuessGameInfo
var
res
gty
.
ReplyGuessGameInfo
ctx
:=
jsonrpc
.
NewRPCCtx
(
"http://"
+
types
.
Conf
(
"config.rpc"
)
.
GStr
(
"jrpcBindAddr"
),
"Chain33.Query"
,
params
,
&
res
)
ctx
:=
jsonrpc
.
NewRPCCtx
(
"http://"
+
types
.
Conf
(
"config.rpc"
)
.
GStr
(
"jrpcBindAddr"
),
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
ctx
.
Run
()
return
&
res
return
&
res
}
}
func
queryGuessByAddr
(
addr
string
)
(
*
gty
.
GuessGameRecords
)
{
func
queryGuessByAddr
(
addr
string
)
*
gty
.
GuessGameRecords
{
var
params
rpctypes
.
Query4Jrpc
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
gty
.
GuessX
params
.
Execer
=
gty
.
GuessX
...
@@ -1117,13 +1118,12 @@ func queryGuessByAddr(addr string) (*gty.GuessGameRecords) {
...
@@ -1117,13 +1118,12 @@ func queryGuessByAddr(addr string) (*gty.GuessGameRecords) {
params
.
FuncName
=
gty
.
FuncNameQueryGameByAddr
params
.
FuncName
=
gty
.
FuncNameQueryGameByAddr
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
gty
.
GuessGameRecords
var
res
gty
.
GuessGameRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
"http://"
+
types
.
Conf
(
"config.rpc"
)
.
GStr
(
"jrpcBindAddr"
),
"Chain33.Query"
,
params
,
&
res
)
ctx
:=
jsonrpc
.
NewRPCCtx
(
"http://"
+
types
.
Conf
(
"config.rpc"
)
.
GStr
(
"jrpcBindAddr"
),
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
ctx
.
Run
()
return
&
res
return
&
res
}
}
func
queryGuessByStatus
(
status
int32
)
*
gty
.
GuessGameRecords
{
func
queryGuessByStatus
(
status
int32
)
(
*
gty
.
GuessGameRecords
)
{
var
params
rpctypes
.
Query4Jrpc
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
gty
.
GuessX
params
.
Execer
=
gty
.
GuessX
...
@@ -1133,12 +1133,12 @@ func queryGuessByStatus(status int32) (*gty.GuessGameRecords) {
...
@@ -1133,12 +1133,12 @@ func queryGuessByStatus(status int32) (*gty.GuessGameRecords) {
params
.
FuncName
=
gty
.
FuncNameQueryGameByStatus
params
.
FuncName
=
gty
.
FuncNameQueryGameByStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
gty
.
GuessGameRecords
var
res
gty
.
GuessGameRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
"http://"
+
types
.
Conf
(
"config.rpc"
)
.
GStr
(
"jrpcBindAddr"
),
"Chain33.Query"
,
params
,
&
res
)
ctx
:=
jsonrpc
.
NewRPCCtx
(
"http://"
+
types
.
Conf
(
"config.rpc"
)
.
GStr
(
"jrpcBindAddr"
),
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
ctx
.
Run
()
return
&
res
return
&
res
}
}
func
queryGuessByAdminAddr
(
addr
string
)
(
*
gty
.
GuessGameRecords
)
{
func
queryGuessByAdminAddr
(
addr
string
)
*
gty
.
GuessGameRecords
{
var
params
rpctypes
.
Query4Jrpc
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
gty
.
GuessX
params
.
Execer
=
gty
.
GuessX
...
@@ -1148,55 +1148,55 @@ func queryGuessByAdminAddr(addr string) (*gty.GuessGameRecords) {
...
@@ -1148,55 +1148,55 @@ func queryGuessByAdminAddr(addr string) (*gty.GuessGameRecords) {
params
.
FuncName
=
gty
.
FuncNameQueryGameByAdminAddr
params
.
FuncName
=
gty
.
FuncNameQueryGameByAdminAddr
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
gty
.
GuessGameRecords
var
res
gty
.
GuessGameRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
"http://"
+
types
.
Conf
(
"config.rpc"
)
.
GStr
(
"jrpcBindAddr"
),
"Chain33.Query"
,
params
,
&
res
)
ctx
:=
jsonrpc
.
NewRPCCtx
(
"http://"
+
types
.
Conf
(
"config.rpc"
)
.
GStr
(
"jrpcBindAddr"
),
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
ctx
.
Run
()
return
&
res
return
&
res
}
}
func
queryGuessByAddrStatus
(
addr
string
,
status
int32
)
(
*
gty
.
GuessGameRecords
)
{
func
queryGuessByAddrStatus
(
addr
string
,
status
int32
)
*
gty
.
GuessGameRecords
{
var
params
rpctypes
.
Query4Jrpc
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
gty
.
GuessX
params
.
Execer
=
gty
.
GuessX
req
:=
&
gty
.
QueryGuessGameInfo
{
req
:=
&
gty
.
QueryGuessGameInfo
{
Addr
:
addr
,
Addr
:
addr
,
Status
:
status
,
Status
:
status
,
}
}
params
.
FuncName
=
gty
.
FuncNameQueryGameByAddrStatus
params
.
FuncName
=
gty
.
FuncNameQueryGameByAddrStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
gty
.
GuessGameRecords
var
res
gty
.
GuessGameRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
"http://"
+
types
.
Conf
(
"config.rpc"
)
.
GStr
(
"jrpcBindAddr"
),
"Chain33.Query"
,
params
,
&
res
)
ctx
:=
jsonrpc
.
NewRPCCtx
(
"http://"
+
types
.
Conf
(
"config.rpc"
)
.
GStr
(
"jrpcBindAddr"
),
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
ctx
.
Run
()
return
&
res
return
&
res
}
}
func
queryGuessByAdminAddrStatus
(
addr
string
,
status
int32
)
(
*
gty
.
GuessGameRecords
)
{
func
queryGuessByAdminAddrStatus
(
addr
string
,
status
int32
)
*
gty
.
GuessGameRecords
{
var
params
rpctypes
.
Query4Jrpc
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
gty
.
GuessX
params
.
Execer
=
gty
.
GuessX
req
:=
&
gty
.
QueryGuessGameInfo
{
req
:=
&
gty
.
QueryGuessGameInfo
{
AdminAddr
:
addr
,
AdminAddr
:
addr
,
Status
:
status
,
Status
:
status
,
}
}
params
.
FuncName
=
gty
.
FuncNameQueryGameByAdminStatus
params
.
FuncName
=
gty
.
FuncNameQueryGameByAdminStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
gty
.
GuessGameRecords
var
res
gty
.
GuessGameRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
"http://"
+
types
.
Conf
(
"config.rpc"
)
.
GStr
(
"jrpcBindAddr"
),
"Chain33.Query"
,
params
,
&
res
)
ctx
:=
jsonrpc
.
NewRPCCtx
(
"http://"
+
types
.
Conf
(
"config.rpc"
)
.
GStr
(
"jrpcBindAddr"
),
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
ctx
.
Run
()
return
&
res
return
&
res
}
}
func
queryGuessByCategoryStatus
(
category
string
,
status
int32
)
(
*
gty
.
GuessGameRecords
)
{
func
queryGuessByCategoryStatus
(
category
string
,
status
int32
)
*
gty
.
GuessGameRecords
{
var
params
rpctypes
.
Query4Jrpc
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
gty
.
GuessX
params
.
Execer
=
gty
.
GuessX
req
:=
&
gty
.
QueryGuessGameInfo
{
req
:=
&
gty
.
QueryGuessGameInfo
{
Category
:
category
,
Category
:
category
,
Status
:
status
,
Status
:
status
,
}
}
params
.
FuncName
=
gty
.
FuncNameQueryGameByCategoryStatus
params
.
FuncName
=
gty
.
FuncNameQueryGameByCategoryStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
gty
.
GuessGameRecords
var
res
gty
.
GuessGameRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
"http://"
+
types
.
Conf
(
"config.rpc"
)
.
GStr
(
"jrpcBindAddr"
),
"Chain33.Query"
,
params
,
&
res
)
ctx
:=
jsonrpc
.
NewRPCCtx
(
"http://"
+
types
.
Conf
(
"config.rpc"
)
.
GStr
(
"jrpcBindAddr"
),
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
ctx
.
Run
()
return
&
res
return
&
res
}
}
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