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
ad86eb98
Commit
ad86eb98
authored
Dec 26, 2018
by
张振华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
table
parent
ec776a94
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
125 additions
and
2 deletions
+125
-2
exec_del_local.go
plugin/dapp/guess/executor/exec_del_local.go
+24
-2
exec_local.go
plugin/dapp/guess/executor/exec_local.go
+24
-0
table.go
plugin/dapp/guess/types/table.go
+77
-0
No files found.
plugin/dapp/guess/executor/exec_del_local.go
View file @
ad86eb98
...
...
@@ -56,12 +56,13 @@ func (g *Guess) rollbackIndex(log *gty.ReceiptGuessGame) (kvs []*types.KeyValue)
return
kvs
}
func
(
g
*
Guess
)
execDelLocal
(
receipt
Data
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
g
*
Guess
)
execDelLocal
(
receipt
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
dbSet
:=
&
types
.
LocalDBSet
{}
if
receipt
Data
.
GetTy
()
!=
types
.
ExecOk
{
if
receipt
.
GetTy
()
!=
types
.
ExecOk
{
return
dbSet
,
nil
}
/*
for _, log := range receiptData.Logs {
switch log.GetTy() {
case gty.TyLogGuessGameStart, gty.TyLogGuessGameBet, gty.TyLogGuessGameStopBet, gty.TyLogGuessGameAbort, gty.TyLogGuessGamePublish, gty.TyLogGuessGameTimeout:
...
...
@@ -72,7 +73,28 @@ func (g *Guess) execDelLocal(receiptData *types.ReceiptData) (*types.LocalDBSet,
kv := g.rollbackIndex(receiptGame)
dbSet.KV = append(dbSet.KV, kv...)
}
}*/
table
:=
gty
.
NewTable
(
g
.
GetLocalDB
())
for
_
,
item
:=
range
receipt
.
Logs
{
var
gameLog
gty
.
ReceiptGuessGame
err
:=
types
.
Decode
(
item
.
Log
,
&
gameLog
)
if
err
!=
nil
{
return
nil
,
err
}
gameLog
.
Status
=
gameLog
.
PreStatus
gameLog
.
Index
=
gameLog
.
PreIndex
err
=
table
.
Replace
(
&
gameLog
)
if
err
!=
nil
{
return
nil
,
err
}
kvs
,
err
:=
table
.
Save
()
if
err
!=
nil
{
return
nil
,
err
}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kvs
...
)
}
return
dbSet
,
nil
}
...
...
plugin/dapp/guess/executor/exec_local.go
View file @
ad86eb98
...
...
@@ -60,6 +60,8 @@ func (g *Guess) execLocal(receipt *types.ReceiptData) (*types.LocalDBSet, error)
if
receipt
.
GetTy
()
!=
types
.
ExecOk
{
return
dbSet
,
nil
}
/*
for i := 0; i < len(receipt.Logs); i++ {
item := receipt.Logs[i]
if item.Ty >= gty.TyLogGuessGameStart && item.Ty <= gty.TyLogGuessGameTimeout {
...
...
@@ -72,6 +74,28 @@ func (g *Guess) execLocal(receipt *types.ReceiptData) (*types.LocalDBSet, error)
dbSet.KV = append(dbSet.KV, kv...)
}
}
*/
table
:=
gty
.
NewTable
(
g
.
GetLocalDB
())
for
_
,
item
:=
range
receipt
.
Logs
{
if
item
.
Ty
>=
gty
.
TyLogGuessGameStart
&&
item
.
Ty
<=
gty
.
TyLogGuessGameTimeout
{
var
gameLog
gty
.
ReceiptGuessGame
err
:=
types
.
Decode
(
item
.
Log
,
&
gameLog
)
if
err
!=
nil
{
return
nil
,
err
}
err
=
table
.
Replace
(
&
gameLog
)
if
err
!=
nil
{
return
nil
,
err
}
kvs
,
err
:=
table
.
Save
()
if
err
!=
nil
{
return
nil
,
err
}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kvs
...
)
}
}
return
dbSet
,
nil
}
...
...
plugin/dapp/guess/types/table.go
0 → 100644
View file @
ad86eb98
package
types
import
(
"fmt"
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/db/table"
"github.com/33cn/chain33/types"
)
/*
table struct
data: guess
index: addr,status,addr_status,admin,admin_status,category_status
*/
var
opt
=
&
table
.
Option
{
Prefix
:
"LODB"
,
Name
:
"guess"
,
Primary
:
"gameid"
,
Index
:
[]
string
{
"addr"
,
"status"
,
"addr_status"
,
"admin"
,
"admin_status"
,
"category_status"
},
}
//NewTable 新建表
func
NewTable
(
kvdb
db
.
KV
)
*
table
.
Table
{
rowmeta
:=
NewGuessRow
()
table
,
err
:=
table
.
NewTable
(
rowmeta
,
kvdb
,
opt
)
if
err
!=
nil
{
panic
(
err
)
}
return
table
}
//OracleRow table meta 结构
type
GuessRow
struct
{
*
ReceiptGuessGame
}
//NewOracleRow 新建一个meta 结构
func
NewGuessRow
()
*
GuessRow
{
return
&
GuessRow
{
ReceiptGuessGame
:
&
ReceiptGuessGame
{}}
}
//CreateRow 新建数据行(注意index 数据一定也要保存到数据中,不能就保存eventid)
func
(
tx
*
GuessRow
)
CreateRow
()
*
table
.
Row
{
return
&
table
.
Row
{
Data
:
&
ReceiptGuessGame
{}}
}
//SetPayload 设置数据
func
(
tx
*
GuessRow
)
SetPayload
(
data
types
.
Message
)
error
{
if
txdata
,
ok
:=
data
.
(
*
ReceiptGuessGame
);
ok
{
tx
.
ReceiptGuessGame
=
txdata
return
nil
}
return
types
.
ErrTypeAsset
}
//Get 按照indexName 查询 indexValue
func
(
tx
*
GuessRow
)
Get
(
key
string
)
([]
byte
,
error
)
{
if
key
==
"gameid"
{
return
[]
byte
(
tx
.
GameID
),
nil
}
else
if
key
==
"status"
{
return
[]
byte
(
fmt
.
Sprintf
(
"%2d"
,
tx
.
Status
)),
nil
}
else
if
key
==
"addr"
{
return
[]
byte
(
tx
.
Addr
),
nil
}
else
if
key
==
"addr_status"
{
return
[]
byte
(
fmt
.
Sprintf
(
"%s:%2d"
,
tx
.
Addr
,
tx
.
Status
)),
nil
}
else
if
key
==
"admin"
{
return
[]
byte
(
tx
.
AdminAddr
),
nil
}
else
if
key
==
"admin_status"
{
return
[]
byte
(
fmt
.
Sprintf
(
"%s:%2d"
,
tx
.
AdminAddr
,
tx
.
Status
)),
nil
}
else
if
key
==
"category_status"
{
return
[]
byte
(
fmt
.
Sprintf
(
"%s:%2d"
,
tx
.
Category
,
tx
.
Status
)),
nil
}
return
nil
,
types
.
ErrNotFound
}
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