Commit 523fd73b authored by jiangpeng's avatar jiangpeng Committed by vipwzw

fix go lint warning

parent dcf47976
...@@ -17,6 +17,7 @@ import ( ...@@ -17,6 +17,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// TicketCmd ticket command type
func TicketCmd() *cobra.Command { func TicketCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "ticket", Use: "ticket",
...@@ -34,7 +35,7 @@ func TicketCmd() *cobra.Command { ...@@ -34,7 +35,7 @@ func TicketCmd() *cobra.Command {
return cmd return cmd
} }
// bind miner // BindMinerCmd bind miner
func BindMinerCmd() *cobra.Command { func BindMinerCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "bind_miner", Use: "bind_miner",
...@@ -77,7 +78,7 @@ func bindMiner(cmd *cobra.Command, args []string) { ...@@ -77,7 +78,7 @@ func bindMiner(cmd *cobra.Command, args []string) {
fmt.Println(hex.EncodeToString(txHex)) fmt.Println(hex.EncodeToString(txHex))
} }
// get ticket count // CountTicketCmd get ticket count
func CountTicketCmd() *cobra.Command { func CountTicketCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "count", Use: "count",
...@@ -94,7 +95,7 @@ func countTicket(cmd *cobra.Command, args []string) { ...@@ -94,7 +95,7 @@ func countTicket(cmd *cobra.Command, args []string) {
ctx.Run() ctx.Run()
} }
// close all accessible tickets // CloseTicketCmd close all accessible tickets
func CloseTicketCmd() *cobra.Command { func CloseTicketCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "close", Use: "close",
...@@ -159,7 +160,7 @@ func getWalletStatus(rpcAddr string) (interface{}, error) { ...@@ -159,7 +160,7 @@ func getWalletStatus(rpcAddr string) (interface{}, error) {
return res, nil return res, nil
} }
// get cold address by miner // GetColdAddrByMinerCmd get cold address by miner
func GetColdAddrByMinerCmd() *cobra.Command { func GetColdAddrByMinerCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "cold", Use: "cold",
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
ty "github.com/33cn/plugin/plugin/dapp/ticket/types" ty "github.com/33cn/plugin/plugin/dapp/ticket/types"
) )
// Exec_Genesis exec genesis
func (t *Ticket) Exec_Genesis(payload *ty.TicketGenesis, tx *types.Transaction, index int) (*types.Receipt, error) { func (t *Ticket) Exec_Genesis(payload *ty.TicketGenesis, tx *types.Transaction, index int) (*types.Receipt, error) {
if payload.Count <= 0 { if payload.Count <= 0 {
return nil, ty.ErrTicketCount return nil, ty.ErrTicketCount
...@@ -17,6 +18,7 @@ func (t *Ticket) Exec_Genesis(payload *ty.TicketGenesis, tx *types.Transaction, ...@@ -17,6 +18,7 @@ func (t *Ticket) Exec_Genesis(payload *ty.TicketGenesis, tx *types.Transaction,
return actiondb.GenesisInit(payload) return actiondb.GenesisInit(payload)
} }
// Exec_Topen exec open
func (t *Ticket) Exec_Topen(payload *ty.TicketOpen, tx *types.Transaction, index int) (*types.Receipt, error) { func (t *Ticket) Exec_Topen(payload *ty.TicketOpen, tx *types.Transaction, index int) (*types.Receipt, error) {
if payload.Count <= 0 { if payload.Count <= 0 {
tlog.Error("topen ", "value", payload) tlog.Error("topen ", "value", payload)
...@@ -26,16 +28,19 @@ func (t *Ticket) Exec_Topen(payload *ty.TicketOpen, tx *types.Transaction, index ...@@ -26,16 +28,19 @@ func (t *Ticket) Exec_Topen(payload *ty.TicketOpen, tx *types.Transaction, index
return actiondb.TicketOpen(payload) return actiondb.TicketOpen(payload)
} }
// Exec_Tbind exec bind
func (t *Ticket) Exec_Tbind(payload *ty.TicketBind, tx *types.Transaction, index int) (*types.Receipt, error) { func (t *Ticket) Exec_Tbind(payload *ty.TicketBind, tx *types.Transaction, index int) (*types.Receipt, error) {
actiondb := NewAction(t, tx) actiondb := NewAction(t, tx)
return actiondb.TicketBind(payload) return actiondb.TicketBind(payload)
} }
// Exec_Tclose exec close
func (t *Ticket) Exec_Tclose(payload *ty.TicketClose, tx *types.Transaction, index int) (*types.Receipt, error) { func (t *Ticket) Exec_Tclose(payload *ty.TicketClose, tx *types.Transaction, index int) (*types.Receipt, error) {
actiondb := NewAction(t, tx) actiondb := NewAction(t, tx)
return actiondb.TicketClose(payload) return actiondb.TicketClose(payload)
} }
//Exec_Miner exec miner
func (t *Ticket) Exec_Miner(payload *ty.TicketMiner, tx *types.Transaction, index int) (*types.Receipt, error) { func (t *Ticket) Exec_Miner(payload *ty.TicketMiner, tx *types.Transaction, index int) (*types.Receipt, error) {
actiondb := NewAction(t, tx) actiondb := NewAction(t, tx)
return actiondb.TicketMiner(payload, index) return actiondb.TicketMiner(payload, index)
......
...@@ -37,22 +37,27 @@ func (t *Ticket) execDelLocal(receiptData *types.ReceiptData) (*types.LocalDBSet ...@@ -37,22 +37,27 @@ func (t *Ticket) execDelLocal(receiptData *types.ReceiptData) (*types.LocalDBSet
return dbSet, nil return dbSet, nil
} }
// ExecDelLocal_Genesis exec del local genesis
func (t *Ticket) ExecDelLocal_Genesis(payload *ty.TicketGenesis, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (t *Ticket) ExecDelLocal_Genesis(payload *ty.TicketGenesis, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return nil, nil return nil, nil
} }
// ExecDelLocal_Topen exec del local open
func (t *Ticket) ExecDelLocal_Topen(payload *ty.TicketOpen, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (t *Ticket) ExecDelLocal_Topen(payload *ty.TicketOpen, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return nil, nil return nil, nil
} }
// ExecDelLocal_Tbind exec del local bind
func (t *Ticket) ExecDelLocal_Tbind(payload *ty.TicketBind, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (t *Ticket) ExecDelLocal_Tbind(payload *ty.TicketBind, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return nil, nil return nil, nil
} }
// ExecDelLocal_Tclose exec del local close
func (t *Ticket) ExecDelLocal_Tclose(payload *ty.TicketClose, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (t *Ticket) ExecDelLocal_Tclose(payload *ty.TicketClose, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return nil, nil return nil, nil
} }
// ExecDelLocal_Miner exec del local miner
func (t *Ticket) ExecDelLocal_Miner(payload *ty.TicketMiner, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (t *Ticket) ExecDelLocal_Miner(payload *ty.TicketMiner, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return nil, nil return nil, nil
} }
...@@ -37,22 +37,27 @@ func (t *Ticket) execLocal(receiptData *types.ReceiptData) (*types.LocalDBSet, e ...@@ -37,22 +37,27 @@ func (t *Ticket) execLocal(receiptData *types.ReceiptData) (*types.LocalDBSet, e
return dbSet, nil return dbSet, nil
} }
// ExecLocal_Genesis exec local genesis
func (t *Ticket) ExecLocal_Genesis(payload *ty.TicketGenesis, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (t *Ticket) ExecLocal_Genesis(payload *ty.TicketGenesis, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return t.execLocal(receiptData) return t.execLocal(receiptData)
} }
// ExecLocal_Topen exec local open
func (t *Ticket) ExecLocal_Topen(payload *ty.TicketOpen, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (t *Ticket) ExecLocal_Topen(payload *ty.TicketOpen, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return t.execLocal(receiptData) return t.execLocal(receiptData)
} }
// ExecLocal_Tbind exec local bind
func (t *Ticket) ExecLocal_Tbind(payload *ty.TicketBind, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (t *Ticket) ExecLocal_Tbind(payload *ty.TicketBind, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return t.execLocal(receiptData) return t.execLocal(receiptData)
} }
// ExecLocal_Tclose exec local close
func (t *Ticket) ExecLocal_Tclose(payload *ty.TicketClose, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (t *Ticket) ExecLocal_Tclose(payload *ty.TicketClose, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return t.execLocal(receiptData) return t.execLocal(receiptData)
} }
// ExecLocal_Miner exec local miner
func (t *Ticket) ExecLocal_Miner(payload *ty.TicketMiner, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (t *Ticket) ExecLocal_Miner(payload *ty.TicketMiner, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return t.execLocal(receiptData) return t.execLocal(receiptData)
} }
// Copyright Fuzamei Corp. 2018 All Rights Reserved. // Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style // Use of ticket source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package executor package executor
...@@ -9,25 +9,29 @@ import ( ...@@ -9,25 +9,29 @@ import (
pty "github.com/33cn/plugin/plugin/dapp/ticket/types" pty "github.com/33cn/plugin/plugin/dapp/ticket/types"
) )
func (this *Ticket) Query_TicketInfos(param *pty.TicketInfos) (types.Message, error) { // Query_TicketInfos query tick info
return Infos(this.GetStateDB(), param) func (ticket *Ticket) Query_TicketInfos(param *pty.TicketInfos) (types.Message, error) {
return Infos(ticket.GetStateDB(), param)
} }
func (this *Ticket) Query_TicketList(param *pty.TicketList) (types.Message, error) { // Query_TicketList query tick list
return List(this.GetLocalDB(), this.GetStateDB(), param) func (ticket *Ticket) Query_TicketList(param *pty.TicketList) (types.Message, error) {
return List(ticket.GetLocalDB(), ticket.GetStateDB(), param)
} }
func (this *Ticket) Query_MinerAddress(param *types.ReqString) (types.Message, error) { // Query_MinerAddress query miner addr
value, err := this.GetLocalDB().Get(calcBindReturnKey(param.Data)) func (ticket *Ticket) Query_MinerAddress(param *types.ReqString) (types.Message, error) {
value, err := ticket.GetLocalDB().Get(calcBindReturnKey(param.Data))
if value == nil || err != nil { if value == nil || err != nil {
return nil, types.ErrNotFound return nil, types.ErrNotFound
} }
return &types.ReplyString{string(value)}, nil return &types.ReplyString{string(value)}, nil
} }
func (this *Ticket) Query_MinerSourceList(param *types.ReqString) (types.Message, error) { // Query_MinerSourceList query miner src list
func (ticket *Ticket) Query_MinerSourceList(param *types.ReqString) (types.Message, error) {
key := calcBindMinerKeyPrefix(param.Data) key := calcBindMinerKeyPrefix(param.Data)
values, err := this.GetLocalDB().List(key, nil, 0, 1) values, err := ticket.GetLocalDB().List(key, nil, 0, 1)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -33,14 +33,17 @@ func init() { ...@@ -33,14 +33,17 @@ func init() {
ety.InitFuncList(types.ListMethod(&Ticket{})) ety.InitFuncList(types.ListMethod(&Ticket{}))
} }
// Init initial
func Init(name string, sub []byte) { func Init(name string, sub []byte) {
drivers.Register(GetName(), newTicket, types.GetDappFork(driverName, "Enable")) drivers.Register(GetName(), newTicket, types.GetDappFork(driverName, "Enable"))
} }
// GetName get name
func GetName() string { func GetName() string {
return newTicket().GetName() return newTicket().GetName()
} }
// Ticket driver type
type Ticket struct { type Ticket struct {
drivers.DriverBase drivers.DriverBase
} }
...@@ -52,6 +55,7 @@ func newTicket() drivers.Driver { ...@@ -52,6 +55,7 @@ func newTicket() drivers.Driver {
return t return t
} }
// GetDriverName ...
func (t *Ticket) GetDriverName() string { func (t *Ticket) GetDriverName() string {
return driverName return driverName
} }
...@@ -160,12 +164,14 @@ func delticket(addr string, ticketID string, status int32) *types.KeyValue { ...@@ -160,12 +164,14 @@ func delticket(addr string, ticketID string, status int32) *types.KeyValue {
return kv return kv
} }
// IsFriend check is fri
func (t *Ticket) IsFriend(myexec, writekey []byte, tx *types.Transaction) bool { func (t *Ticket) IsFriend(myexec, writekey []byte, tx *types.Transaction) bool {
clog.Error("ticket IsFriend", "myex", string(myexec), "writekey", string(writekey)) clog.Error("ticket IsFriend", "myex", string(myexec), "writekey", string(writekey))
//不允许平行链 //不允许平行链
return false return false
} }
// CheckTx check tx
func (t *Ticket) CheckTx(tx *types.Transaction, index int) error { func (t *Ticket) CheckTx(tx *types.Transaction, index int) error {
//index == -1 only when check in mempool //index == -1 only when check in mempool
if index == -1 { if index == -1 {
......
...@@ -27,11 +27,13 @@ var tlog = log.New("module", "ticket.db") ...@@ -27,11 +27,13 @@ var tlog = log.New("module", "ticket.db")
//var genesisKey = []byte("mavl-acc-genesis") //var genesisKey = []byte("mavl-acc-genesis")
//var addrSeed = []byte("address seed bytes for public key") //var addrSeed = []byte("address seed bytes for public key")
// DB db
type DB struct { type DB struct {
ty.Ticket ty.Ticket
prevstatus int32 prevstatus int32
} }
// NewDB new instance
func NewDB(id, minerAddress, returnWallet string, blocktime int64, isGenesis bool) *DB { func NewDB(id, minerAddress, returnWallet string, blocktime int64, isGenesis bool) *DB {
t := &DB{} t := &DB{}
t.TicketId = id t.TicketId = id
...@@ -52,6 +54,8 @@ func NewDB(id, minerAddress, returnWallet string, blocktime int64, isGenesis boo ...@@ -52,6 +54,8 @@ func NewDB(id, minerAddress, returnWallet string, blocktime int64, isGenesis boo
//add prevStatus: 便于回退状态,以及删除原来状态 //add prevStatus: 便于回退状态,以及删除原来状态
//list 保存的方法: //list 保存的方法:
//minerAddress:status:ticketId=ticketId //minerAddress:status:ticketId=ticketId
// GetReceiptLog get receipt
func (t *DB) GetReceiptLog() *types.ReceiptLog { func (t *DB) GetReceiptLog() *types.ReceiptLog {
log := &types.ReceiptLog{} log := &types.ReceiptLog{}
if t.Status == 1 { if t.Status == 1 {
...@@ -70,12 +74,14 @@ func (t *DB) GetReceiptLog() *types.ReceiptLog { ...@@ -70,12 +74,14 @@ func (t *DB) GetReceiptLog() *types.ReceiptLog {
return log return log
} }
// GetKVSet get kv set
func (t *DB) GetKVSet() (kvset []*types.KeyValue) { func (t *DB) GetKVSet() (kvset []*types.KeyValue) {
value := types.Encode(&t.Ticket) value := types.Encode(&t.Ticket)
kvset = append(kvset, &types.KeyValue{Key(t.TicketId), value}) kvset = append(kvset, &types.KeyValue{Key(t.TicketId), value})
return kvset return kvset
} }
// Save save
func (t *DB) Save(db dbm.KV) { func (t *DB) Save(db dbm.KV) {
set := t.GetKVSet() set := t.GetKVSet()
for i := 0; i < len(set); i++ { for i := 0; i < len(set); i++ {
...@@ -83,19 +89,21 @@ func (t *DB) Save(db dbm.KV) { ...@@ -83,19 +89,21 @@ func (t *DB) Save(db dbm.KV) {
} }
} }
//address to save key //Key address to save key
func Key(id string) (key []byte) { func Key(id string) (key []byte) {
key = append(key, []byte("mavl-ticket-")...) key = append(key, []byte("mavl-ticket-")...)
key = append(key, []byte(id)...) key = append(key, []byte(id)...)
return key return key
} }
// BindKey bind key
func BindKey(id string) (key []byte) { func BindKey(id string) (key []byte) {
key = append(key, []byte("mavl-ticket-tbind-")...) key = append(key, []byte("mavl-ticket-tbind-")...)
key = append(key, []byte(id)...) key = append(key, []byte(id)...)
return key return key
} }
// Action action type
type Action struct { type Action struct {
coinsAccount *account.DB coinsAccount *account.DB
db dbm.KV db dbm.KV
...@@ -106,6 +114,7 @@ type Action struct { ...@@ -106,6 +114,7 @@ type Action struct {
execaddr string execaddr string
} }
// NewAction new action type
func NewAction(t *Ticket, tx *types.Transaction) *Action { func NewAction(t *Ticket, tx *types.Transaction) *Action {
hash := tx.Hash() hash := tx.Hash()
fromaddr := tx.From() fromaddr := tx.From()
...@@ -113,6 +122,7 @@ func NewAction(t *Ticket, tx *types.Transaction) *Action { ...@@ -113,6 +122,7 @@ func NewAction(t *Ticket, tx *types.Transaction) *Action {
t.GetBlockTime(), t.GetHeight(), dapp.ExecAddress(string(tx.Execer))} t.GetBlockTime(), t.GetHeight(), dapp.ExecAddress(string(tx.Execer))}
} }
// GenesisInit init genesis
func (action *Action) GenesisInit(genesis *ty.TicketGenesis) (*types.Receipt, error) { func (action *Action) GenesisInit(genesis *ty.TicketGenesis) (*types.Receipt, error) {
prefix := common.ToHex(action.txhash) prefix := common.ToHex(action.txhash)
prefix = genesis.MinerAddress + ":" + prefix + ":" prefix = genesis.MinerAddress + ":" + prefix + ":"
...@@ -175,9 +185,9 @@ func (action *Action) getBind(addr string) string { ...@@ -175,9 +185,9 @@ func (action *Action) getBind(addr string) string {
return bind.MinerAddress return bind.MinerAddress
} }
//授权某个地址进行挖矿 //TicketBind 授权某个地址进行挖矿
//todo: query address is a minered address
func (action *Action) TicketBind(tbind *ty.TicketBind) (*types.Receipt, error) { func (action *Action) TicketBind(tbind *ty.TicketBind) (*types.Receipt, error) {
//todo: query address is a minered address
if action.fromaddr != tbind.ReturnAddress { if action.fromaddr != tbind.ReturnAddress {
return nil, types.ErrFromAddr return nil, types.ErrFromAddr
} }
...@@ -199,6 +209,7 @@ func (action *Action) TicketBind(tbind *ty.TicketBind) (*types.Receipt, error) { ...@@ -199,6 +209,7 @@ func (action *Action) TicketBind(tbind *ty.TicketBind) (*types.Receipt, error) {
return receipt, nil return receipt, nil
} }
// TicketOpen ticket open
func (action *Action) TicketOpen(topen *ty.TicketOpen) (*types.Receipt, error) { func (action *Action) TicketOpen(topen *ty.TicketOpen) (*types.Receipt, error) {
prefix := common.ToHex(action.txhash) prefix := common.ToHex(action.txhash)
prefix = topen.MinerAddress + ":" + prefix + ":" prefix = topen.MinerAddress + ":" + prefix + ":"
...@@ -267,6 +278,7 @@ func genPubHash(tid string) string { ...@@ -267,6 +278,7 @@ func genPubHash(tid string) string {
return pubHash return pubHash
} }
// TicketMiner ticket miner
func (action *Action) TicketMiner(miner *ty.TicketMiner, index int) (*types.Receipt, error) { func (action *Action) TicketMiner(miner *ty.TicketMiner, index int) (*types.Receipt, error) {
if index != 0 { if index != 0 {
return nil, types.ErrCoinBaseIndex return nil, types.ErrCoinBaseIndex
...@@ -330,6 +342,7 @@ func (action *Action) TicketMiner(miner *ty.TicketMiner, index int) (*types.Rece ...@@ -330,6 +342,7 @@ func (action *Action) TicketMiner(miner *ty.TicketMiner, index int) (*types.Rece
return &types.Receipt{types.ExecOk, kv, logs}, nil return &types.Receipt{types.ExecOk, kv, logs}, nil
} }
// TicketClose close tick
func (action *Action) TicketClose(tclose *ty.TicketClose) (*types.Receipt, error) { func (action *Action) TicketClose(tclose *ty.TicketClose) (*types.Receipt, error) {
tickets := make([]*DB, len(tclose.TicketId)) tickets := make([]*DB, len(tclose.TicketId))
cfg := types.GetP(action.height) cfg := types.GetP(action.height)
...@@ -397,6 +410,7 @@ func (action *Action) TicketClose(tclose *ty.TicketClose) (*types.Receipt, error ...@@ -397,6 +410,7 @@ func (action *Action) TicketClose(tclose *ty.TicketClose) (*types.Receipt, error
return receipt, nil return receipt, nil
} }
// List list db
func List(db dbm.Lister, db2 dbm.KV, tlist *ty.TicketList) (types.Message, error) { func List(db dbm.Lister, db2 dbm.KV, tlist *ty.TicketList) (types.Message, error) {
values, err := db.List(calcTicketPrefix(tlist.Addr, tlist.Status), nil, 0, 0) values, err := db.List(calcTicketPrefix(tlist.Addr, tlist.Status), nil, 0, 0)
if err != nil { if err != nil {
...@@ -412,6 +426,7 @@ func List(db dbm.Lister, db2 dbm.KV, tlist *ty.TicketList) (types.Message, error ...@@ -412,6 +426,7 @@ func List(db dbm.Lister, db2 dbm.KV, tlist *ty.TicketList) (types.Message, error
return Infos(db2, &ids) return Infos(db2, &ids)
} }
// Infos info
func Infos(db dbm.KV, tinfos *ty.TicketInfos) (types.Message, error) { func Infos(db dbm.KV, tinfos *ty.TicketInfos) (types.Message, error) {
var tickets []*ty.Ticket var tickets []*ty.Ticket
for i := 0; i < len(tinfos.TicketIds); i++ { for i := 0; i < len(tinfos.TicketIds); i++ {
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"github.com/33cn/plugin/plugin/dapp/ticket/executor" "github.com/33cn/plugin/plugin/dapp/ticket/executor"
"github.com/33cn/plugin/plugin/dapp/ticket/rpc" "github.com/33cn/plugin/plugin/dapp/ticket/rpc"
"github.com/33cn/plugin/plugin/dapp/ticket/types" "github.com/33cn/plugin/plugin/dapp/ticket/types"
// init wallet
_ "github.com/33cn/plugin/plugin/dapp/ticket/wallet" _ "github.com/33cn/plugin/plugin/dapp/ticket/wallet"
) )
......
...@@ -28,7 +28,7 @@ func bindMiner(param *ty.ReqBindMiner) (*ty.ReplyBindMiner, error) { ...@@ -28,7 +28,7 @@ func bindMiner(param *ty.ReqBindMiner) (*ty.ReplyBindMiner, error) {
return &ty.ReplyBindMiner{TxHex: hex}, nil return &ty.ReplyBindMiner{TxHex: hex}, nil
} }
// 创建绑定挖矿 // CreateBindMiner 创建绑定挖矿
func (g *channelClient) CreateBindMiner(ctx context.Context, in *ty.ReqBindMiner) (*ty.ReplyBindMiner, error) { func (g *channelClient) CreateBindMiner(ctx context.Context, in *ty.ReqBindMiner) (*ty.ReplyBindMiner, error) {
if in.Amount%(10000*types.Coin) != 0 || in.Amount < 0 { if in.Amount%(10000*types.Coin) != 0 || in.Amount < 0 {
return nil, types.ErrAmount return nil, types.ErrAmount
...@@ -58,6 +58,7 @@ func (g *channelClient) CreateBindMiner(ctx context.Context, in *ty.ReqBindMiner ...@@ -58,6 +58,7 @@ func (g *channelClient) CreateBindMiner(ctx context.Context, in *ty.ReqBindMiner
return bindMiner(in) return bindMiner(in)
} }
// SetAutoMining set auto mining
func (g *channelClient) SetAutoMining(ctx context.Context, in *ty.MinerFlag) (*types.Reply, error) { func (g *channelClient) SetAutoMining(ctx context.Context, in *ty.MinerFlag) (*types.Reply, error) {
data, err := g.ExecWalletFunc(ty.TicketX, "WalletAutoMiner", in) data, err := g.ExecWalletFunc(ty.TicketX, "WalletAutoMiner", in)
if err != nil { if err != nil {
...@@ -66,6 +67,7 @@ func (g *channelClient) SetAutoMining(ctx context.Context, in *ty.MinerFlag) (*t ...@@ -66,6 +67,7 @@ func (g *channelClient) SetAutoMining(ctx context.Context, in *ty.MinerFlag) (*t
return data.(*types.Reply), nil return data.(*types.Reply), nil
} }
// GetTicketCount get count
func (g *channelClient) GetTicketCount(ctx context.Context, in *types.ReqNil) (*types.Int64, error) { func (g *channelClient) GetTicketCount(ctx context.Context, in *types.ReqNil) (*types.Int64, error) {
data, err := g.QueryConsensusFunc(ty.TicketX, "GetTicketCount", &types.ReqNil{}) data, err := g.QueryConsensusFunc(ty.TicketX, "GetTicketCount", &types.ReqNil{})
if err != nil { if err != nil {
...@@ -74,6 +76,7 @@ func (g *channelClient) GetTicketCount(ctx context.Context, in *types.ReqNil) (* ...@@ -74,6 +76,7 @@ func (g *channelClient) GetTicketCount(ctx context.Context, in *types.ReqNil) (*
return data.(*types.Int64), nil return data.(*types.Int64), nil
} }
// CloseTickets close ticket
func (g *channelClient) CloseTickets(ctx context.Context, in *types.ReqNil) (*types.ReplyHashes, error) { func (g *channelClient) CloseTickets(ctx context.Context, in *types.ReqNil) (*types.ReplyHashes, error) {
data, err := g.ExecWalletFunc(ty.TicketX, "CloseTickets", &types.ReqNil{}) data, err := g.ExecWalletFunc(ty.TicketX, "CloseTickets", &types.ReqNil{})
if err != nil { if err != nil {
...@@ -82,6 +85,7 @@ func (g *channelClient) CloseTickets(ctx context.Context, in *types.ReqNil) (*ty ...@@ -82,6 +85,7 @@ func (g *channelClient) CloseTickets(ctx context.Context, in *types.ReqNil) (*ty
return data.(*types.ReplyHashes), nil return data.(*types.ReplyHashes), nil
} }
// CreateBindMiner create bind miner
func (c *Jrpc) CreateBindMiner(in *ty.ReqBindMiner, result *interface{}) error { func (c *Jrpc) CreateBindMiner(in *ty.ReqBindMiner, result *interface{}) error {
reply, err := c.cli.CreateBindMiner(context.Background(), in) reply, err := c.cli.CreateBindMiner(context.Background(), in)
if err != nil { if err != nil {
...@@ -91,6 +95,7 @@ func (c *Jrpc) CreateBindMiner(in *ty.ReqBindMiner, result *interface{}) error { ...@@ -91,6 +95,7 @@ func (c *Jrpc) CreateBindMiner(in *ty.ReqBindMiner, result *interface{}) error {
return nil return nil
} }
// GetTicketCount get ticket count
func (c *Jrpc) GetTicketCount(in *types.ReqNil, result *int64) error { func (c *Jrpc) GetTicketCount(in *types.ReqNil, result *int64) error {
resp, err := c.cli.GetTicketCount(context.Background(), &types.ReqNil{}) resp, err := c.cli.GetTicketCount(context.Background(), &types.ReqNil{})
if err != nil { if err != nil {
...@@ -101,6 +106,7 @@ func (c *Jrpc) GetTicketCount(in *types.ReqNil, result *int64) error { ...@@ -101,6 +106,7 @@ func (c *Jrpc) GetTicketCount(in *types.ReqNil, result *int64) error {
} }
// CloseTickets close ticket
func (c *Jrpc) CloseTickets(in *types.ReqNil, result *interface{}) error { func (c *Jrpc) CloseTickets(in *types.ReqNil, result *interface{}) error {
resp, err := c.cli.CloseTickets(context.Background(), &types.ReqNil{}) resp, err := c.cli.CloseTickets(context.Background(), &types.ReqNil{})
if err != nil { if err != nil {
...@@ -114,6 +120,7 @@ func (c *Jrpc) CloseTickets(in *types.ReqNil, result *interface{}) error { ...@@ -114,6 +120,7 @@ func (c *Jrpc) CloseTickets(in *types.ReqNil, result *interface{}) error {
return nil return nil
} }
// SetAutoMining set auto mining
func (c *Jrpc) SetAutoMining(in *ty.MinerFlag, result *rpctypes.Reply) error { func (c *Jrpc) SetAutoMining(in *ty.MinerFlag, result *rpctypes.Reply) error {
resp, err := c.cli.SetAutoMining(context.Background(), in) resp, err := c.cli.SetAutoMining(context.Background(), in)
if err != nil { if err != nil {
......
...@@ -9,10 +9,11 @@ import ( ...@@ -9,10 +9,11 @@ import (
ty "github.com/33cn/plugin/plugin/dapp/ticket/types" ty "github.com/33cn/plugin/plugin/dapp/ticket/types"
) )
// Jrpc json rpc type
type Jrpc struct { type Jrpc struct {
cli *channelClient cli *channelClient
} }
// Grpc grpc type
type Grpc struct { type Grpc struct {
*channelClient *channelClient
} }
...@@ -21,6 +22,7 @@ type channelClient struct { ...@@ -21,6 +22,7 @@ type channelClient struct {
types.ChannelClient types.ChannelClient
} }
// Init initial
func Init(name string, s types.RPCServer) { func Init(name string, s types.RPCServer) {
cli := &channelClient{} cli := &channelClient{}
grpc := &Grpc{channelClient: cli} grpc := &Grpc{channelClient: cli}
......
...@@ -7,13 +7,22 @@ package types ...@@ -7,13 +7,22 @@ package types
import "errors" import "errors"
var ( var (
// ErrNoTicket error type
ErrNoTicket = errors.New("ErrNoTicket") ErrNoTicket = errors.New("ErrNoTicket")
// ErrTicketCount error type
ErrTicketCount = errors.New("ErrTicketCount") ErrTicketCount = errors.New("ErrTicketCount")
// ErrTime error type
ErrTime = errors.New("ErrTime") ErrTime = errors.New("ErrTime")
// ErrTicketClosed err type
ErrTicketClosed = errors.New("ErrTicketClosed") ErrTicketClosed = errors.New("ErrTicketClosed")
// ErrEmptyMinerTx err type
ErrEmptyMinerTx = errors.New("ErrEmptyMinerTx") ErrEmptyMinerTx = errors.New("ErrEmptyMinerTx")
// ErrMinerNotPermit err type
ErrMinerNotPermit = errors.New("ErrMinerNotPermit") ErrMinerNotPermit = errors.New("ErrMinerNotPermit")
// ErrMinerAddr err type
ErrMinerAddr = errors.New("ErrMinerAddr") ErrMinerAddr = errors.New("ErrMinerAddr")
// ErrModify err type
ErrModify = errors.New("ErrModify") ErrModify = errors.New("ErrModify")
// ErrMinerTx err type
ErrMinerTx = errors.New("ErrMinerTx") ErrMinerTx = errors.New("ErrMinerTx")
) )
...@@ -15,28 +15,44 @@ import ( ...@@ -15,28 +15,44 @@ import (
const ( const (
//log for ticket //log for ticket
//TyLogNewTicket new ticket log type
TyLogNewTicket = 111 TyLogNewTicket = 111
// TyLogCloseTicket close ticket log type
TyLogCloseTicket = 112 TyLogCloseTicket = 112
// TyLogMinerTicket miner ticket log type
TyLogMinerTicket = 113 TyLogMinerTicket = 113
// TyLogTicketBind bind ticket log type
TyLogTicketBind = 114 TyLogTicketBind = 114
) )
//ticket //ticket
const ( const (
// TicketActionGenesis action type
TicketActionGenesis = 11 TicketActionGenesis = 11
// TicketActionOpen action type
TicketActionOpen = 12 TicketActionOpen = 12
// TicketActionClose action type
TicketActionClose = 13 TicketActionClose = 13
// TicketActionList action type
TicketActionList = 14 //读的接口不直接经过transaction TicketActionList = 14 //读的接口不直接经过transaction
// TicketActionInfos action type
TicketActionInfos = 15 //读的接口不直接经过transaction TicketActionInfos = 15 //读的接口不直接经过transaction
// TicketActionMiner action miner
TicketActionMiner = 16 TicketActionMiner = 16
// TicketActionBind action bind
TicketActionBind = 17 TicketActionBind = 17
) )
// TicketOldParts old tick type
const TicketOldParts = 3 const TicketOldParts = 3
// TicketCountOpenOnce count open once
const TicketCountOpenOnce = 1000 const TicketCountOpenOnce = 1000
// ErrOpenTicketPubHash err type
var ErrOpenTicketPubHash = errors.New("ErrOpenTicketPubHash") var ErrOpenTicketPubHash = errors.New("ErrOpenTicketPubHash")
// TicketX dapp name
var TicketX = "ticket" var TicketX = "ticket"
func init() { func init() {
...@@ -46,21 +62,25 @@ func init() { ...@@ -46,21 +62,25 @@ func init() {
types.RegisterDappFork(TicketX, "ForkTicketId", 1200000) types.RegisterDappFork(TicketX, "ForkTicketId", 1200000)
} }
// TicketType ticket exec type
type TicketType struct { type TicketType struct {
types.ExecTypeBase types.ExecTypeBase
} }
// NewType new type
func NewType() *TicketType { func NewType() *TicketType {
c := &TicketType{} c := &TicketType{}
c.SetChild(c) c.SetChild(c)
return c return c
} }
func (at *TicketType) GetPayload() types.Message { // GetPayload get payload
func (ticket *TicketType) GetPayload() types.Message {
return &TicketAction{} return &TicketAction{}
} }
func (t *TicketType) GetLogMap() map[int64]*types.LogInfo { // GetLogMap get log map
func (ticket *TicketType) GetLogMap() map[int64]*types.LogInfo {
return map[int64]*types.LogInfo{ return map[int64]*types.LogInfo{
TyLogNewTicket: {reflect.TypeOf(ReceiptTicket{}), "LogNewTicket"}, TyLogNewTicket: {reflect.TypeOf(ReceiptTicket{}), "LogNewTicket"},
TyLogCloseTicket: {reflect.TypeOf(ReceiptTicket{}), "LogCloseTicket"}, TyLogCloseTicket: {reflect.TypeOf(ReceiptTicket{}), "LogCloseTicket"},
...@@ -69,6 +89,7 @@ func (t *TicketType) GetLogMap() map[int64]*types.LogInfo { ...@@ -69,6 +89,7 @@ func (t *TicketType) GetLogMap() map[int64]*types.LogInfo {
} }
} }
// Amount get amount
func (ticket TicketType) Amount(tx *types.Transaction) (int64, error) { func (ticket TicketType) Amount(tx *types.Transaction) (int64, error) {
var action TicketAction var action TicketAction
err := types.Decode(tx.GetPayload(), &action) err := types.Decode(tx.GetPayload(), &action)
...@@ -82,16 +103,19 @@ func (ticket TicketType) Amount(tx *types.Transaction) (int64, error) { ...@@ -82,16 +103,19 @@ func (ticket TicketType) Amount(tx *types.Transaction) (int64, error) {
return 0, nil return 0, nil
} }
// TODO 暂时不修改实现, 先完成结构的重构 // CreateTx create tx
func (ticket *TicketType) CreateTx(action string, message json.RawMessage) (*types.Transaction, error) { func (ticket *TicketType) CreateTx(action string, message json.RawMessage) (*types.Transaction, error) {
// TODO 暂时不修改实现, 先完成结构的重构
var tx *types.Transaction var tx *types.Transaction
return tx, nil return tx, nil
} }
// GetName get name
func (ticket *TicketType) GetName() string { func (ticket *TicketType) GetName() string {
return TicketX return TicketX
} }
// GetTypeMap get type map
func (ticket *TicketType) GetTypeMap() map[string]int32 { func (ticket *TicketType) GetTypeMap() map[string]int32 {
return map[string]int32{ return map[string]int32{
"Genesis": TicketActionGenesis, "Genesis": TicketActionGenesis,
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
ty "github.com/33cn/plugin/plugin/dapp/ticket/types" ty "github.com/33cn/plugin/plugin/dapp/ticket/types"
) )
// On_CloseTickets close ticket
func (policy *ticketPolicy) On_CloseTickets(req *types.ReqNil) (types.Message, error) { func (policy *ticketPolicy) On_CloseTickets(req *types.ReqNil) (types.Message, error) {
operater := policy.getWalletOperate() operater := policy.getWalletOperate()
reply, err := policy.forceCloseTicket(operater.GetBlockHeight() + 1) reply, err := policy.forceCloseTicket(operater.GetBlockHeight() + 1)
...@@ -25,12 +26,14 @@ func (policy *ticketPolicy) On_CloseTickets(req *types.ReqNil) (types.Message, e ...@@ -25,12 +26,14 @@ func (policy *ticketPolicy) On_CloseTickets(req *types.ReqNil) (types.Message, e
return reply, err return reply, err
} }
// On_WalletGetTickets get ticket
func (policy *ticketPolicy) On_WalletGetTickets(req *types.ReqNil) (types.Message, error) { func (policy *ticketPolicy) On_WalletGetTickets(req *types.ReqNil) (types.Message, error) {
tickets, privs, err := policy.getTicketsByStatus(1) tickets, privs, err := policy.getTicketsByStatus(1)
tks := &ty.ReplyWalletTickets{tickets, privs} tks := &ty.ReplyWalletTickets{tickets, privs}
return tks, err return tks, err
} }
// On_WalletAutoMiner auto mine
func (policy *ticketPolicy) On_WalletAutoMiner(req *ty.MinerFlag) (types.Message, error) { func (policy *ticketPolicy) On_WalletAutoMiner(req *ty.MinerFlag) (types.Message, error) {
policy.store.SetAutoMinerFlag(req.Flag) policy.store.SetAutoMinerFlag(req.Flag)
policy.setAutoMining(req.Flag) policy.setAutoMining(req.Flag)
......
...@@ -8,6 +8,7 @@ const ( ...@@ -8,6 +8,7 @@ const (
keyWalletAutoMiner = "WalletAutoMiner" keyWalletAutoMiner = "WalletAutoMiner"
) )
//CalcWalletAutoMiner calculate wallet auto miner
func CalcWalletAutoMiner() []byte { func CalcWalletAutoMiner() []byte {
return []byte(keyWalletAutoMiner) return []byte(keyWalletAutoMiner)
} }
...@@ -30,6 +30,7 @@ func init() { ...@@ -30,6 +30,7 @@ func init() {
wcom.RegisterPolicy(ty.TicketX, New()) wcom.RegisterPolicy(ty.TicketX, New())
} }
// New new instance
func New() wcom.WalletBizPolicy { func New() wcom.WalletBizPolicy {
return &ticketPolicy{mtx: &sync.Mutex{}} return &ticketPolicy{mtx: &sync.Mutex{}}
} }
...@@ -82,17 +83,20 @@ func (policy *ticketPolicy) getAPI() client.QueueProtocolAPI { ...@@ -82,17 +83,20 @@ func (policy *ticketPolicy) getAPI() client.QueueProtocolAPI {
return policy.walletOperate.GetAPI() return policy.walletOperate.GetAPI()
} }
// IsAutoMining check auto mining
func (policy *ticketPolicy) IsAutoMining() bool { func (policy *ticketPolicy) IsAutoMining() bool {
return policy.isAutoMining() return policy.isAutoMining()
} }
// IsTicketLocked check lock status
func (policy *ticketPolicy) IsTicketLocked() bool { func (policy *ticketPolicy) IsTicketLocked() bool {
return atomic.LoadInt32(&policy.isTicketLocked) != 0 return atomic.LoadInt32(&policy.isTicketLocked) != 0
} }
// Init initial
func (policy *ticketPolicy) Init(walletBiz wcom.WalletOperate, sub []byte) { func (policy *ticketPolicy) Init(walletBiz wcom.WalletOperate, sub []byte) {
policy.setWalletOperate(walletBiz) policy.setWalletOperate(walletBiz)
policy.store = NewStore(walletBiz.GetDBStore()) policy.store = newStore(walletBiz.GetDBStore())
policy.needFlush = false policy.needFlush = false
policy.isTicketLocked = 1 policy.isTicketLocked = 1
policy.autoMinerFlag = policy.store.GetAutoMinerFlag() policy.autoMinerFlag = policy.store.GetAutoMinerFlag()
...@@ -110,19 +114,23 @@ func (policy *ticketPolicy) Init(walletBiz wcom.WalletOperate, sub []byte) { ...@@ -110,19 +114,23 @@ func (policy *ticketPolicy) Init(walletBiz wcom.WalletOperate, sub []byte) {
go policy.autoMining() go policy.autoMining()
} }
// OnClose close
func (policy *ticketPolicy) OnClose() { func (policy *ticketPolicy) OnClose() {
policy.getMingTicketTicker().Stop() policy.getMingTicketTicker().Stop()
} }
func (this *ticketPolicy) OnSetQueueClient() { // OnSetQueueClient on set queue client
func (policy *ticketPolicy) OnSetQueueClient() {
} }
func (this *ticketPolicy) Call(funName string, in types.Message) (ret types.Message, err error) { // Call call
func (policy *ticketPolicy) Call(funName string, in types.Message) (ret types.Message, err error) {
err = types.ErrNotSupport err = types.ErrNotSupport
return return
} }
// OnAddBlockTx add Block tx
func (policy *ticketPolicy) OnAddBlockTx(block *types.BlockDetail, tx *types.Transaction, index int32, dbbatch db.Batch) *types.WalletTxDetail { func (policy *ticketPolicy) OnAddBlockTx(block *types.BlockDetail, tx *types.Transaction, index int32, dbbatch db.Batch) *types.WalletTxDetail {
receipt := block.Receipts[index] receipt := block.Receipts[index]
amount, _ := tx.Amount() amount, _ := tx.Amount()
...@@ -158,6 +166,7 @@ func (policy *ticketPolicy) OnAddBlockTx(block *types.BlockDetail, tx *types.Tra ...@@ -158,6 +166,7 @@ func (policy *ticketPolicy) OnAddBlockTx(block *types.BlockDetail, tx *types.Tra
return wtxdetail return wtxdetail
} }
// OnDeleteBlockTx on delete block
func (policy *ticketPolicy) OnDeleteBlockTx(block *types.BlockDetail, tx *types.Transaction, index int32, dbbatch db.Batch) *types.WalletTxDetail { func (policy *ticketPolicy) OnDeleteBlockTx(block *types.BlockDetail, tx *types.Transaction, index int32, dbbatch db.Batch) *types.WalletTxDetail {
receipt := block.Receipts[index] receipt := block.Receipts[index]
amount, _ := tx.Amount() amount, _ := tx.Amount()
...@@ -193,11 +202,13 @@ func (policy *ticketPolicy) OnDeleteBlockTx(block *types.BlockDetail, tx *types. ...@@ -193,11 +202,13 @@ func (policy *ticketPolicy) OnDeleteBlockTx(block *types.BlockDetail, tx *types.
return wtxdetail return wtxdetail
} }
// SignTransaction sign tx
func (policy *ticketPolicy) SignTransaction(key crypto.PrivKey, req *types.ReqSignRawTx) (needSysSign bool, signtx string, err error) { func (policy *ticketPolicy) SignTransaction(key crypto.PrivKey, req *types.ReqSignRawTx) (needSysSign bool, signtx string, err error) {
needSysSign = true needSysSign = true
return return
} }
// OnWalletLocked process lock event
func (policy *ticketPolicy) OnWalletLocked() { func (policy *ticketPolicy) OnWalletLocked() {
// 钱包锁住时,不允许挖矿 // 钱包锁住时,不允许挖矿
atomic.CompareAndSwapInt32(&policy.isTicketLocked, 0, 1) atomic.CompareAndSwapInt32(&policy.isTicketLocked, 0, 1)
...@@ -215,6 +226,7 @@ func (policy *ticketPolicy) resetTimeout(Timeout int64) { ...@@ -215,6 +226,7 @@ func (policy *ticketPolicy) resetTimeout(Timeout int64) {
} }
} }
// OnWalletUnlocked process unlock event
func (policy *ticketPolicy) OnWalletUnlocked(param *types.WalletUnLock) { func (policy *ticketPolicy) OnWalletUnlocked(param *types.WalletUnLock) {
if param.WalletOrTicket { if param.WalletOrTicket {
atomic.CompareAndSwapInt32(&policy.isTicketLocked, 1, 0) atomic.CompareAndSwapInt32(&policy.isTicketLocked, 1, 0)
...@@ -226,14 +238,16 @@ func (policy *ticketPolicy) OnWalletUnlocked(param *types.WalletUnLock) { ...@@ -226,14 +238,16 @@ func (policy *ticketPolicy) OnWalletUnlocked(param *types.WalletUnLock) {
FlushTicket(policy.getAPI()) FlushTicket(policy.getAPI())
} }
// OnCreateNewAccount process create new account event
func (policy *ticketPolicy) OnCreateNewAccount(acc *types.Account) { func (policy *ticketPolicy) OnCreateNewAccount(acc *types.Account) {
} }
//导入key的时候flush ticket // OnImportPrivateKey 导入key的时候flush ticket
func (policy *ticketPolicy) OnImportPrivateKey(acc *types.Account) { func (policy *ticketPolicy) OnImportPrivateKey(acc *types.Account) {
FlushTicket(policy.getAPI()) FlushTicket(policy.getAPI())
} }
// OnAddBlockFinish process finish block
func (policy *ticketPolicy) OnAddBlockFinish(block *types.BlockDetail) { func (policy *ticketPolicy) OnAddBlockFinish(block *types.BlockDetail) {
if policy.needFlush { if policy.needFlush {
// 新增区块,由于ticket具有锁定期,所以这里不需要刷新 // 新增区块,由于ticket具有锁定期,所以这里不需要刷新
...@@ -242,6 +256,7 @@ func (policy *ticketPolicy) OnAddBlockFinish(block *types.BlockDetail) { ...@@ -242,6 +256,7 @@ func (policy *ticketPolicy) OnAddBlockFinish(block *types.BlockDetail) {
policy.needFlush = false policy.needFlush = false
} }
// OnDeleteBlockFinish process finish block
func (policy *ticketPolicy) OnDeleteBlockFinish(block *types.BlockDetail) { func (policy *ticketPolicy) OnDeleteBlockFinish(block *types.BlockDetail) {
if policy.needFlush { if policy.needFlush {
FlushTicket(policy.getAPI()) FlushTicket(policy.getAPI())
...@@ -249,6 +264,7 @@ func (policy *ticketPolicy) OnDeleteBlockFinish(block *types.BlockDetail) { ...@@ -249,6 +264,7 @@ func (policy *ticketPolicy) OnDeleteBlockFinish(block *types.BlockDetail) {
policy.needFlush = false policy.needFlush = false
} }
// FlushTicket flush ticket
func FlushTicket(api client.QueueProtocolAPI) { func FlushTicket(api client.QueueProtocolAPI) {
bizlog.Info("wallet FLUSH TICKET") bizlog.Info("wallet FLUSH TICKET")
api.Notify("consensus", types.EventConsensusQuery, &types.ChainExecutor{ api.Notify("consensus", types.EventConsensusQuery, &types.ChainExecutor{
......
...@@ -9,7 +9,8 @@ import ( ...@@ -9,7 +9,8 @@ import (
wcom "github.com/33cn/chain33/wallet/common" wcom "github.com/33cn/chain33/wallet/common"
) )
func NewStore(db db.DB) *ticketStore { //newStore new storage
func newStore(db db.DB) *ticketStore {
return &ticketStore{Store: wcom.NewStore(db)} return &ticketStore{Store: wcom.NewStore(db)}
} }
...@@ -29,6 +30,7 @@ func (store *ticketStore) checkAddrIsInWallet(addr string) bool { ...@@ -29,6 +30,7 @@ func (store *ticketStore) checkAddrIsInWallet(addr string) bool {
return true return true
} }
// SetAutoMinerFlag set auto mine flag
func (store *ticketStore) SetAutoMinerFlag(flag int32) { func (store *ticketStore) SetAutoMinerFlag(flag int32) {
if flag == 1 { if flag == 1 {
store.Set(CalcWalletAutoMiner(), []byte("1")) store.Set(CalcWalletAutoMiner(), []byte("1"))
...@@ -37,6 +39,7 @@ func (store *ticketStore) SetAutoMinerFlag(flag int32) { ...@@ -37,6 +39,7 @@ func (store *ticketStore) SetAutoMinerFlag(flag int32) {
} }
} }
// GetAutoMinerFlag get auto miner flag
func (store *ticketStore) GetAutoMinerFlag() int32 { func (store *ticketStore) GetAutoMinerFlag() int32 {
flag := int32(0) flag := int32(0)
value, err := store.Get(CalcWalletAutoMiner()) value, err := store.Get(CalcWalletAutoMiner())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment