Commit 134189be authored by mdj33's avatar mdj33 Committed by vipwzw

adjust ticket bind miner

parent 1958740a
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
rpctypes "github.com/33cn/chain33/rpc/types" rpctypes "github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
ty "github.com/33cn/plugin/plugin/dapp/ticket/types" ty "github.com/33cn/plugin/plugin/dapp/ticket/types"
context "golang.org/x/net/context" "golang.org/x/net/context"
) )
func bindMiner(param *ty.ReqBindMiner) (*ty.ReplyBindMiner, error) { func bindMiner(param *ty.ReqBindMiner) (*ty.ReplyBindMiner, error) {
...@@ -28,14 +28,7 @@ func bindMiner(param *ty.ReqBindMiner) (*ty.ReplyBindMiner, error) { ...@@ -28,14 +28,7 @@ func bindMiner(param *ty.ReqBindMiner) (*ty.ReplyBindMiner, error) {
// CreateBindMiner 创建绑定挖矿 // 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) {
header, err := g.GetLastHeader() err := address.CheckAddress(in.BindAddr)
if err != nil {
return nil, err
}
if in.Amount%ty.GetTicketMinerParam(header.Height).TicketPrice != 0 || in.Amount < 0 {
return nil, types.ErrAmount
}
err = address.CheckAddress(in.BindAddr)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -45,6 +38,14 @@ func (g *channelClient) CreateBindMiner(ctx context.Context, in *ty.ReqBindMiner ...@@ -45,6 +38,14 @@ func (g *channelClient) CreateBindMiner(ctx context.Context, in *ty.ReqBindMiner
} }
if in.CheckBalance { if in.CheckBalance {
header, err := g.GetLastHeader()
if err != nil {
return nil, err
}
if in.Amount%ty.GetTicketMinerParam(header.Height).TicketPrice != 0 || in.Amount < 0 {
return nil, types.ErrAmount
}
getBalance := &types.ReqBalance{Addresses: []string{in.OriginAddr}, Execer: "coins", AssetSymbol: "bty", AssetExec: "coins"} getBalance := &types.ReqBalance{Addresses: []string{in.OriginAddr}, Execer: "coins", AssetSymbol: "bty", AssetExec: "coins"}
balances, err := g.GetCoinsAccountDB().GetBalance(g, getBalance) balances, err := g.GetCoinsAccountDB().GetBalance(g, getBalance)
if err != nil { if err != nil {
......
...@@ -26,6 +26,26 @@ import ( ...@@ -26,6 +26,26 @@ import (
var cfgstring = ` var cfgstring = `
Title="test" Title="test"
[mempool]
poolCacheSize=102400
minTxFee=100000
maxTxNumPerAccount=100
[exec]
isFree=false
minExecFee=100000
enableStat=false
enableMVCC=false
[wallet]
minFee=100000
driver="leveldb"
dbPath="wallet"
dbCache=16
signType="secp256k1"
minerdisable=false
minerwhitelist=["*"]
[mver.consensus] [mver.consensus]
fundKeyAddr = "1BQXS6TxaYYG5mADaWij4AxhZZUTpw95a5" fundKeyAddr = "1BQXS6TxaYYG5mADaWij4AxhZZUTpw95a5"
powLimitBits = "0x1f00ffff" powLimitBits = "0x1f00ffff"
...@@ -43,6 +63,46 @@ ticketWithdrawTime = 10 ...@@ -43,6 +63,46 @@ ticketWithdrawTime = 10
ticketMinerWaitTime = 2 ticketMinerWaitTime = 2
targetTimespan = 2304 targetTimespan = 2304
targetTimePerBlock = 16 targetTimePerBlock = 16
[mver.consensus.ticket.ForkChainParamV1]
ticketPrice = 3000
[mver.consensus.ticket.ForkChainParamV2]
ticketPrice = 6000
[fork.system]
ForkChainParamV1= 10
ForkChainParamV2= 20
ForkStateDBSet=-1
ForkCheckTxDup=0
ForkBlockHash= 1
ForkMinerTime= 10
ForkTransferExec= 100000
ForkExecKey= 200000
ForkTxGroup= 200000
ForkResetTx0= 200000
ForkWithdraw= 200000
ForkExecRollback= 450000
ForkTxHeight= -1
ForkTxGroupPara= -1
ForkCheckBlockTime=1200000
ForkMultiSignAddress=1298600
ForkBlockCheck=1
ForkLocalDBAccess=0
ForkBase58AddressCheck=1800000
ForkEnableParaRegExec=0
ForkCacheDriver=0
ForkTicketFundAddrV1=-1
[fork.sub.coins]
Enable=0
[fork.sub.manage]
Enable=0
ForkManageExec=100000
[fork.sub.store-kvmvccmavl]
ForkKvmvccmavl=1
` `
func newGrpc(api client.QueueProtocolAPI) *channelClient { func newGrpc(api client.QueueProtocolAPI) *channelClient {
...@@ -59,17 +119,18 @@ func TestChannelClient_BindMiner(t *testing.T) { ...@@ -59,17 +119,18 @@ func TestChannelClient_BindMiner(t *testing.T) {
api := new(mocks.QueueProtocolAPI) api := new(mocks.QueueProtocolAPI)
client := newGrpc(api) client := newGrpc(api)
client.Init("ticket", nil, nil, nil) client.Init("ticket", nil, nil, nil)
head := &types.Header{StateHash: []byte("sdfadasds")} head := &types.Header{Height: 2, StateHash: []byte("sdfadasds")}
api.On("GetLastHeader").Return(head, nil) api.On("GetLastHeader").Return(head, nil).Times(4)
var acc = &types.Account{Addr: "1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt", Balance: 100000 * types.Coin} var acc = &types.Account{Addr: "1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt", Balance: 100000 * types.Coin}
accv := types.Encode(acc) accv := types.Encode(acc)
storevalue := &types.StoreReplyValue{} storevalue := &types.StoreReplyValue{}
storevalue.Values = append(storevalue.Values, accv) storevalue.Values = append(storevalue.Values, accv)
api.On("StoreGet", mock.Anything).Return(storevalue, nil) api.On("StoreGet", mock.Anything).Return(storevalue, nil).Twice()
types.SetTitleOnlyForTest("test") types.SetTitleOnlyForTest("test")
types.InitCfgString(cfgstring) cfg, _ := types.InitCfgString(cfgstring)
types.Init("test", cfg)
//var addrs = make([]string, 1) //var addrs = make([]string, 1)
//addrs = append(addrs, "1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt") //addrs = append(addrs, "1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt")
...@@ -81,6 +142,16 @@ func TestChannelClient_BindMiner(t *testing.T) { ...@@ -81,6 +142,16 @@ func TestChannelClient_BindMiner(t *testing.T) {
} }
_, err := client.CreateBindMiner(context.Background(), in) _, err := client.CreateBindMiner(context.Background(), in)
assert.Nil(t, err) assert.Nil(t, err)
in.Amount = 200000 * types.Coin
_, err = client.CreateBindMiner(context.Background(), in)
assert.Equal(t, types.ErrNoBalance, err)
head.Height = 20 //ForkChainParamV2
api.On("GetLastHeader").Return(head, nil).Times(2)
_, err = client.CreateBindMiner(context.Background(), in)
assert.Equal(t, types.ErrAmount, err)
} }
func testGetTicketCountOK(t *testing.T) { func testGetTicketCountOK(t *testing.T) {
......
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