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

fix go lint warning

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