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
38c12844
Commit
38c12844
authored
Dec 25, 2018
by
mdj33
Committed by
vipwzw
Dec 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix ticket bind bug
parent
ef941882
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
71 additions
and
16 deletions
+71
-16
ticket.go
plugin/consensus/ticket/ticket.go
+1
-1
ticket.go
plugin/dapp/ticket/commands/ticket.go
+18
-2
types.go
plugin/dapp/ticket/commands/types.go
+9
-0
ticket.proto
plugin/dapp/ticket/proto/ticket.proto
+1
-0
rpc.go
plugin/dapp/ticket/rpc/rpc.go
+4
-4
exec.go
plugin/dapp/ticket/wallet/exec.go
+2
-2
ticket.go
plugin/dapp/ticket/wallet/ticket.go
+36
-7
No files found.
plugin/consensus/ticket/ticket.go
View file @
38c12844
...
...
@@ -222,7 +222,7 @@ func (client *Client) flushTicket() error {
client
.
setTicket
(
nil
,
nil
)
return
nil
}
if
err
!=
nil
{
if
err
!=
nil
&&
err
!=
ty
.
ErrNoTicket
{
tlog
.
Error
(
"flushTicket error"
,
"err"
,
err
)
return
err
}
...
...
plugin/dapp/ticket/commands/ticket.go
View file @
38c12844
...
...
@@ -10,6 +10,7 @@ import (
"fmt"
"os"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
...
...
@@ -102,11 +103,17 @@ func CloseTicketCmd() *cobra.Command {
Short
:
"Close tickets"
,
Run
:
closeTicket
,
}
addCloseBindAddr
(
cmd
)
return
cmd
}
func
addCloseBindAddr
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"miner_addr"
,
"m"
,
""
,
"miner address (optional)"
)
}
func
closeTicket
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
bindAddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"miner_addr"
)
status
,
err
:=
getWalletStatus
(
rpcLaddr
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
...
...
@@ -119,13 +126,17 @@ func closeTicket(cmd *cobra.Command, args []string) {
return
}
tClose
:=
&
ty
.
TicketClose
{
MinerAddress
:
bindAddr
,
}
var
res
types
.
ReplyHashes
rpc
,
err
:=
jsonclient
.
NewJSONClient
(
rpcLaddr
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
}
err
=
rpc
.
Call
(
"ticket.CloseTickets"
,
nil
,
&
res
)
err
=
rpc
.
Call
(
"ticket.CloseTickets"
,
tClose
,
&
res
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
...
...
@@ -135,7 +146,12 @@ func closeTicket(cmd *cobra.Command, args []string) {
return
}
data
,
err
:=
json
.
MarshalIndent
(
res
,
""
,
" "
)
var
tx
txHashes
for
_
,
hash
:=
range
res
.
Hashes
{
tx
.
Hashes
=
append
(
tx
.
Hashes
,
common
.
ToHex
(
hash
))
}
data
,
err
:=
json
.
MarshalIndent
(
tx
,
""
,
" "
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
...
...
plugin/dapp/ticket/commands/types.go
0 → 100644
View file @
38c12844
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
commands
type
txHashes
struct
{
Hashes
[]
string
`json:"hashes"`
}
plugin/dapp/ticket/proto/ticket.proto
View file @
38c12844
...
...
@@ -79,6 +79,7 @@ message TicketGenesis {
message
TicketClose
{
repeated
string
ticketId
=
1
;
string
minerAddress
=
2
;
}
message
TicketList
{
...
...
plugin/dapp/ticket/rpc/rpc.go
View file @
38c12844
...
...
@@ -77,8 +77,8 @@ func (g *channelClient) GetTicketCount(ctx context.Context, in *types.ReqNil) (*
}
// CloseTickets close ticket
func
(
g
*
channelClient
)
CloseTickets
(
ctx
context
.
Context
,
in
*
ty
pes
.
ReqNil
)
(
*
types
.
ReplyHashes
,
error
)
{
data
,
err
:=
g
.
ExecWalletFunc
(
ty
.
TicketX
,
"CloseTickets"
,
&
types
.
ReqNil
{}
)
func
(
g
*
channelClient
)
CloseTickets
(
ctx
context
.
Context
,
in
*
ty
.
TicketClose
)
(
*
types
.
ReplyHashes
,
error
)
{
data
,
err
:=
g
.
ExecWalletFunc
(
ty
.
TicketX
,
"CloseTickets"
,
in
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -107,8 +107,8 @@ func (c *Jrpc) GetTicketCount(in *types.ReqNil, result *int64) error {
}
// CloseTickets close ticket
func
(
c
*
Jrpc
)
CloseTickets
(
in
*
ty
pes
.
ReqNil
,
result
*
interface
{})
error
{
resp
,
err
:=
c
.
cli
.
CloseTickets
(
context
.
Background
(),
&
types
.
ReqNil
{}
)
func
(
c
*
Jrpc
)
CloseTickets
(
in
*
ty
.
TicketClose
,
result
*
interface
{})
error
{
resp
,
err
:=
c
.
cli
.
CloseTickets
(
context
.
Background
(),
in
)
if
err
!=
nil
{
return
err
}
...
...
plugin/dapp/ticket/wallet/exec.go
View file @
38c12844
...
...
@@ -10,9 +10,9 @@ import (
)
// On_CloseTickets close ticket
func
(
policy
*
ticketPolicy
)
On_CloseTickets
(
req
*
ty
pes
.
ReqNil
)
(
types
.
Message
,
error
)
{
func
(
policy
*
ticketPolicy
)
On_CloseTickets
(
req
*
ty
.
TicketClose
)
(
types
.
Message
,
error
)
{
operater
:=
policy
.
getWalletOperate
()
reply
,
err
:=
policy
.
forceCloseTicket
(
operater
.
GetBlockHeight
()
+
1
)
reply
,
err
:=
policy
.
forceCloseTicket
(
operater
.
GetBlockHeight
()
+
1
,
req
.
MinerAddress
)
if
err
!=
nil
{
bizlog
.
Error
(
"onCloseTickets"
,
"forceCloseTicket error"
,
err
.
Error
())
}
else
{
...
...
plugin/dapp/ticket/wallet/ticket.go
View file @
38c12844
...
...
@@ -298,18 +298,29 @@ func (policy *ticketPolicy) checkNeedFlushTicket(tx *types.Transaction, receipt
return
policy
.
needFlushTicket
(
tx
,
receipt
)
}
func
(
policy
*
ticketPolicy
)
forceCloseTicket
(
height
int64
)
(
*
types
.
ReplyHashes
,
error
)
{
return
policy
.
forceCloseAllTicket
(
height
)
func
(
policy
*
ticketPolicy
)
forceCloseTicket
(
height
int64
,
minerAddr
string
)
(
*
types
.
ReplyHashes
,
error
)
{
return
policy
.
forceCloseAllTicket
(
height
,
minerAddr
)
}
func
(
policy
*
ticketPolicy
)
forceCloseAllTicket
(
height
int64
)
(
*
types
.
ReplyHashes
,
error
)
{
func
(
policy
*
ticketPolicy
)
forceCloseAllTicket
(
height
int64
,
minerAddr
string
)
(
*
types
.
ReplyHashes
,
error
)
{
var
tlistMiner
[]
*
ty
.
Ticket
var
err
error
// get miner addr's tickets if any
if
minerAddr
!=
""
{
tlistMiner
,
err
=
policy
.
getForceCloseTickets
(
minerAddr
)
if
err
!=
nil
{
return
nil
,
err
}
}
keys
,
err
:=
policy
.
getWalletOperate
()
.
GetAllPrivKeys
()
if
err
!=
nil
{
return
nil
,
err
}
var
hashes
types
.
ReplyHashes
for
_
,
key
:=
range
keys
{
hash
,
err
:=
policy
.
forceCloseTicketsByAddr
(
height
,
key
)
hash
,
err
:=
policy
.
forceCloseTicketsByAddr
(
height
,
key
,
tlistMiner
)
if
err
!=
nil
{
bizlog
.
Error
(
"forceCloseAllTicket"
,
"forceCloseTicketsByAddr error"
,
err
)
continue
...
...
@@ -334,8 +345,10 @@ func (policy *ticketPolicy) getTickets(addr string, status int32) ([]*ty.Ticket,
return
reply
.
Tickets
,
nil
}
func
(
policy
*
ticketPolicy
)
forceCloseTicketsByAddr
(
height
int64
,
priv
crypto
.
PrivKey
)
([]
byte
,
error
)
{
addr
:=
address
.
PubKeyToAddress
(
priv
.
PubKey
()
.
Bytes
())
.
String
()
func
(
policy
*
ticketPolicy
)
getForceCloseTickets
(
addr
string
)
([]
*
ty
.
Ticket
,
error
)
{
if
addr
==
""
{
return
nil
,
nil
}
tlist1
,
err1
:=
policy
.
getTickets
(
addr
,
1
)
if
err1
!=
nil
&&
err1
!=
types
.
ErrNotFound
{
return
nil
,
err1
...
...
@@ -344,7 +357,23 @@ func (policy *ticketPolicy) forceCloseTicketsByAddr(height int64, priv crypto.Pr
if
err2
!=
nil
&&
err2
!=
types
.
ErrNotFound
{
return
nil
,
err1
}
tlist
:=
append
(
tlist1
,
tlist2
...
)
return
append
(
tlist1
,
tlist2
...
),
nil
}
func
(
policy
*
ticketPolicy
)
forceCloseTicketsByAddr
(
height
int64
,
priv
crypto
.
PrivKey
,
tListMiner
[]
*
ty
.
Ticket
)
([]
byte
,
error
)
{
addr
:=
address
.
PubKeyToAddress
(
priv
.
PubKey
()
.
Bytes
())
.
String
()
tlist
,
err
:=
policy
.
getForceCloseTickets
(
addr
)
if
err
!=
nil
{
return
nil
,
err
}
for
_
,
ticket
:=
range
tListMiner
{
if
ticket
.
ReturnAddress
==
addr
{
tlist
=
append
(
tlist
,
ticket
)
}
}
var
ids
[]
string
var
tl
[]
*
ty
.
Ticket
now
:=
types
.
Now
()
.
Unix
()
...
...
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