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
b1c737d3
Commit
b1c737d3
authored
Mar 08, 2019
by
linj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
imlp mint local
add token logs
parent
b7df495f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
224 additions
and
0 deletions
+224
-0
exec_del_local.go
plugin/dapp/token/executor/exec_del_local.go
+40
-0
exec_local.go
plugin/dapp/token/executor/exec_local.go
+50
-0
logs.go
plugin/dapp/token/executor/logs.go
+99
-0
query.go
plugin/dapp/token/executor/query.go
+22
-0
token.proto
plugin/dapp/token/proto/token.proto
+11
-0
const.go
plugin/dapp/token/types/const.go
+2
-0
No files found.
plugin/dapp/token/executor/exec_del_local.go
View file @
b1c737d3
...
@@ -7,6 +7,7 @@ package executor
...
@@ -7,6 +7,7 @@ package executor
import
(
import
(
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
tokenty
"github.com/33cn/plugin/plugin/dapp/token/types"
tokenty
"github.com/33cn/plugin/plugin/dapp/token/types"
"github.com/33cn/chain33/system/dapp"
)
)
func
(
t
*
token
)
execDelLocal
(
receiptData
*
types
.
ReceiptData
)
([]
*
types
.
KeyValue
,
error
)
{
func
(
t
*
token
)
execDelLocal
(
receiptData
*
types
.
ReceiptData
)
([]
*
types
.
KeyValue
,
error
)
{
...
@@ -107,6 +108,19 @@ func (t *token) ExecDelLocal_TokenFinishCreate(payload *tokenty.TokenFinishCreat
...
@@ -107,6 +108,19 @@ func (t *token) ExecDelLocal_TokenFinishCreate(payload *tokenty.TokenFinishCreat
var
set
[]
*
types
.
KeyValue
var
set
[]
*
types
.
KeyValue
set
=
append
(
set
,
&
types
.
KeyValue
{
Key
:
prepareKey
,
Value
:
types
.
Encode
(
localToken
)})
set
=
append
(
set
,
&
types
.
KeyValue
{
Key
:
prepareKey
,
Value
:
types
.
Encode
(
localToken
)})
set
=
append
(
set
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
set
=
append
(
set
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
})
table
:=
NewLogsTable
(
t
.
GetLocalDB
())
txIndex
:=
dapp
.
HeightIndexStr
(
t
.
GetHeight
(),
int64
(
index
))
err
=
table
.
Del
([]
byte
(
txIndex
))
if
err
!=
nil
{
return
nil
,
err
}
kv
,
err
:=
table
.
Save
()
if
err
!=
nil
{
return
nil
,
err
}
set
=
append
(
set
,
kv
...
)
return
&
types
.
LocalDBSet
{
KV
:
set
},
nil
return
&
types
.
LocalDBSet
{
KV
:
set
},
nil
}
}
...
@@ -123,3 +137,29 @@ func (t *token) ExecDelLocal_TokenRevokeCreate(payload *tokenty.TokenRevokeCreat
...
@@ -123,3 +137,29 @@ func (t *token) ExecDelLocal_TokenRevokeCreate(payload *tokenty.TokenRevokeCreat
set
=
append
(
set
,
&
types
.
KeyValue
{
Key
:
prepareKey
,
Value
:
types
.
Encode
(
localToken
)})
set
=
append
(
set
,
&
types
.
KeyValue
{
Key
:
prepareKey
,
Value
:
types
.
Encode
(
localToken
)})
return
&
types
.
LocalDBSet
{
KV
:
set
},
nil
return
&
types
.
LocalDBSet
{
KV
:
set
},
nil
}
}
func
(
t
*
token
)
ExecDelLocal_TokenMint
(
payload
*
tokenty
.
TokenMint
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
localToken
,
err
:=
loadLocalToken
(
payload
.
Symbol
,
tx
.
From
(),
tokenty
.
TokenStatusCreated
,
t
.
GetLocalDB
())
if
err
!=
nil
{
return
nil
,
err
}
localToken
=
resetCreated
(
localToken
)
key
:=
calcTokenStatusKeyLocal
(
payload
.
Symbol
,
tx
.
From
(),
tokenty
.
TokenStatusCreated
)
var
set
[]
*
types
.
KeyValue
set
=
append
(
set
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
localToken
)})
table
:=
NewLogsTable
(
t
.
GetLocalDB
())
txIndex
:=
dapp
.
HeightIndexStr
(
t
.
GetHeight
(),
int64
(
index
))
err
=
table
.
Del
([]
byte
(
txIndex
))
if
err
!=
nil
{
return
nil
,
err
}
kv
,
err
:=
table
.
Save
()
if
err
!=
nil
{
return
nil
,
err
}
set
=
append
(
set
,
kv
...
)
return
&
types
.
LocalDBSet
{
KV
:
set
},
nil
}
plugin/dapp/token/executor/exec_local.go
View file @
b1c737d3
...
@@ -8,6 +8,8 @@ import (
...
@@ -8,6 +8,8 @@ import (
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
tokenty
"github.com/33cn/plugin/plugin/dapp/token/types"
tokenty
"github.com/33cn/plugin/plugin/dapp/token/types"
"github.com/33cn/chain33/system/dapp"
"encoding/hex"
)
)
func
(
t
*
token
)
ExecLocal_Transfer
(
payload
*
types
.
AssetsTransfer
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
t
*
token
)
ExecLocal_Transfer
(
payload
*
types
.
AssetsTransfer
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
...
@@ -107,6 +109,19 @@ func (t *token) ExecLocal_TokenFinishCreate(payload *tokenty.TokenFinishCreate,
...
@@ -107,6 +109,19 @@ func (t *token) ExecLocal_TokenFinishCreate(payload *tokenty.TokenFinishCreate,
set
=
append
(
set
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
localToken
)})
set
=
append
(
set
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
localToken
)})
kv
:=
AddTokenToAssets
(
payload
.
Owner
,
t
.
GetLocalDB
(),
payload
.
Symbol
)
kv
:=
AddTokenToAssets
(
payload
.
Owner
,
t
.
GetLocalDB
(),
payload
.
Symbol
)
set
=
append
(
set
,
kv
...
)
set
=
append
(
set
,
kv
...
)
table
:=
NewLogsTable
(
t
.
GetLocalDB
())
txIndex
:=
dapp
.
HeightIndexStr
(
t
.
GetHeight
(),
int64
(
index
))
err
=
table
.
Add
(
&
tokenty
.
LocalLogs
{
Symbol
:
payload
.
Symbol
,
TxIndex
:
txIndex
,
ActionType
:
tokenty
.
TokenActionFinishCreate
,
TxHash
:
hex
.
EncodeToString
(
tx
.
Hash
())})
if
err
!=
nil
{
return
nil
,
err
}
kv
,
err
=
table
.
Save
()
if
err
!=
nil
{
return
nil
,
err
}
set
=
append
(
set
,
kv
...
)
return
&
types
.
LocalDBSet
{
KV
:
set
},
nil
return
&
types
.
LocalDBSet
{
KV
:
set
},
nil
}
}
...
@@ -182,6 +197,11 @@ func setRevoked(t *tokenty.LocalToken, height, time int64) *tokenty.LocalToken {
...
@@ -182,6 +197,11 @@ func setRevoked(t *tokenty.LocalToken, height, time int64) *tokenty.LocalToken {
return
t
return
t
}
}
func
setMint
(
t
*
tokenty
.
LocalToken
,
height
,
time
,
amount
int64
)
*
tokenty
.
LocalToken
{
t
.
Total
=
t
.
Total
+
amount
return
t
}
func
resetCreated
(
t
*
tokenty
.
LocalToken
)
*
tokenty
.
LocalToken
{
func
resetCreated
(
t
*
tokenty
.
LocalToken
)
*
tokenty
.
LocalToken
{
t
.
CreatedTime
=
0
t
.
CreatedTime
=
0
t
.
CreatedHeight
=
0
t
.
CreatedHeight
=
0
...
@@ -195,3 +215,33 @@ func resetRevoked(t *tokenty.LocalToken) *tokenty.LocalToken {
...
@@ -195,3 +215,33 @@ func resetRevoked(t *tokenty.LocalToken) *tokenty.LocalToken {
t
.
Status
=
tokenty
.
TokenStatusPreCreated
t
.
Status
=
tokenty
.
TokenStatusPreCreated
return
t
return
t
}
}
func
resetMint
(
t
*
tokenty
.
LocalToken
,
height
,
time
,
amount
int64
)
*
tokenty
.
LocalToken
{
t
.
Total
=
t
.
Total
-
amount
return
t
}
func
(
t
*
token
)
ExecLocal_TokenMint
(
payload
*
tokenty
.
TokenMint
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
localToken
,
err
:=
loadLocalToken
(
payload
.
Symbol
,
tx
.
From
(),
tokenty
.
TokenStatusCreated
,
t
.
GetLocalDB
())
if
err
!=
nil
{
return
nil
,
err
}
localToken
=
setMint
(
localToken
,
t
.
GetHeight
(),
t
.
GetBlockTime
(),
payload
.
Amount
)
var
set
[]
*
types
.
KeyValue
key
:=
calcTokenStatusKeyLocal
(
payload
.
Symbol
,
tx
.
From
(),
tokenty
.
TokenStatusCreated
)
set
=
append
(
set
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
localToken
)})
table
:=
NewLogsTable
(
t
.
GetLocalDB
())
txIndex
:=
dapp
.
HeightIndexStr
(
t
.
GetHeight
(),
int64
(
index
))
err
=
table
.
Add
(
&
tokenty
.
LocalLogs
{
Symbol
:
payload
.
Symbol
,
TxIndex
:
txIndex
,
ActionType
:
tokenty
.
TokenActionMint
,
TxHash
:
hex
.
EncodeToString
(
tx
.
Hash
())})
if
err
!=
nil
{
return
nil
,
err
}
kv
,
err
:=
table
.
Save
()
if
err
!=
nil
{
return
nil
,
err
}
set
=
append
(
set
,
kv
...
)
return
&
types
.
LocalDBSet
{
KV
:
set
},
nil
}
plugin/dapp/token/executor/logs.go
0 → 100644
View file @
b1c737d3
// 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
executor
// 记录token 的更改记录,
// 包含创建完成, 铸币, 以后可能包含燃烧等
import
(
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/db/table"
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/token/types"
)
var
opt_logs_table
=
&
table
.
Option
{
Prefix
:
"LODB-token"
,
Name
:
"logs"
,
Primary
:
"txIndex"
,
Index
:
[]
string
{
"symbol"
,
},
}
// LogsRow row
type
LogsRow
struct
{
*
pty
.
LocalLogs
}
// NewOrderRow create row
func
NewOrderRow
()
*
LogsRow
{
return
&
LogsRow
{
LocalLogs
:
nil
}
}
// CreateRow create row
func
(
r
*
LogsRow
)
CreateRow
()
*
table
.
Row
{
return
&
table
.
Row
{
Data
:
&
pty
.
LocalLogs
{}}
}
// SetPayload set payload
func
(
r
*
LogsRow
)
SetPayload
(
data
types
.
Message
)
error
{
if
d
,
ok
:=
data
.
(
*
pty
.
LocalLogs
);
ok
{
r
.
LocalLogs
=
d
return
nil
}
return
types
.
ErrTypeAsset
}
// Get get index key
func
(
r
*
LogsRow
)
Get
(
key
string
)
([]
byte
,
error
)
{
switch
key
{
case
"txIndex"
:
return
[]
byte
(
r
.
TxIndex
),
nil
case
"symbol"
:
return
[]
byte
(
r
.
Symbol
),
nil
default
:
return
nil
,
types
.
ErrNotFound
}
}
// NewLogsTable create table
func
NewLogsTable
(
kvdb
dbm
.
KV
)
*
table
.
Table
{
rowMeta
:=
NewOrderRow
()
rowMeta
.
SetPayload
(
&
pty
.
LocalLogs
{})
t
,
err
:=
table
.
NewTable
(
rowMeta
,
kvdb
,
opt_logs_table
)
if
err
!=
nil
{
panic
(
err
)
}
return
t
}
func
list
(
db
dbm
.
KVDB
,
indexName
string
,
data
*
pty
.
LocalLogs
,
count
,
direction
int32
)
([]
*
table
.
Row
,
error
)
{
query
:=
NewLogsTable
(
db
)
.
GetQuery
(
db
)
var
primary
[]
byte
if
len
(
data
.
TxIndex
)
>
0
{
primary
=
[]
byte
(
data
.
TxIndex
)
}
cur
:=
&
LogsRow
{
LocalLogs
:
data
}
index
,
err
:=
cur
.
Get
(
indexName
)
if
err
!=
nil
{
tokenlog
.
Error
(
"query List failed"
,
"key"
,
string
(
primary
),
"param"
,
data
,
"err"
,
err
)
return
nil
,
err
}
tokenlog
.
Debug
(
"query List dbg"
,
"indexName"
,
indexName
,
"index"
,
string
(
index
),
"primary"
,
primary
,
"count"
,
count
,
"direction"
,
direction
)
rows
,
err
:=
query
.
ListIndex
(
indexName
,
index
,
primary
,
count
,
direction
)
if
err
!=
nil
{
tokenlog
.
Error
(
"query List failed"
,
"key"
,
string
(
primary
),
"param"
,
data
,
"err"
,
err
)
return
nil
,
err
}
if
len
(
rows
)
==
0
{
return
nil
,
types
.
ErrNotFound
}
return
rows
,
nil
}
\ No newline at end of file
plugin/dapp/token/executor/query.go
View file @
b1c737d3
...
@@ -69,3 +69,25 @@ func (t *token) Query_GetTxByToken(in *tokenty.ReqTokenTx) (types.Message, error
...
@@ -69,3 +69,25 @@ func (t *token) Query_GetTxByToken(in *tokenty.ReqTokenTx) (types.Message, error
}
}
return
t
.
getTxByToken
(
in
)
return
t
.
getTxByToken
(
in
)
}
}
// Query_GetTokenHistory 获取token 的变更历史
func
(
t
*
token
)
Query_GetTokenHistory
(
in
*
types
.
ReqString
)
(
types
.
Message
,
error
)
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
rows
,
err
:=
list
(
t
.
GetLocalDB
(),
"symbol"
,
&
tokenty
.
LocalLogs
{
Symbol
:
in
.
Data
},
-
1
,
0
)
if
err
!=
nil
{
tokenlog
.
Error
(
"Query_GetTokenHistory"
,
"err"
,
err
)
return
nil
,
err
}
var
replys
tokenty
.
ReplyTokenLogs
for
_
,
row
:=
range
rows
{
o
,
ok
:=
row
.
Data
.
(
*
tokenty
.
LocalLogs
)
if
!
ok
{
tokenlog
.
Error
(
"Query_GetTokenHistory"
,
"err"
,
"bad row type"
)
return
nil
,
types
.
ErrTypeAsset
}
replys
.
Logs
=
append
(
replys
.
Logs
,
o
)
}
return
&
replys
,
nil
}
plugin/dapp/token/proto/token.proto
View file @
b1c737d3
...
@@ -93,6 +93,13 @@ message LocalToken {
...
@@ -93,6 +93,13 @@ message LocalToken {
int32
category
=
17
;
int32
category
=
17
;
}
}
message
LocalLogs
{
string
symbol
=
1
;
string
txIndex
=
2
;
int32
actionType
=
3
;
string
txHash
=
4
;
}
// query
// query
message
ReqTokens
{
message
ReqTokens
{
bool
queryAll
=
1
;
bool
queryAll
=
1
;
...
@@ -153,6 +160,10 @@ message ReqTokenTx {
...
@@ -153,6 +160,10 @@ message ReqTokenTx {
string
addr
=
7
;
string
addr
=
7
;
}
}
message
ReplyTokenLogs
{
repeated
LocalLogs
logs
=
1
;
}
service
token
{
service
token
{
// token 对外提供服务的接口
// token 对外提供服务的接口
//区块链接口
//区块链接口
...
...
plugin/dapp/token/types/const.go
View file @
b1c737d3
...
@@ -19,6 +19,8 @@ const (
...
@@ -19,6 +19,8 @@ const (
TokenActionRevokeCreate
=
9
TokenActionRevokeCreate
=
9
// TokenActionTransferToExec for token transfer to exec
// TokenActionTransferToExec for token transfer to exec
TokenActionTransferToExec
=
11
TokenActionTransferToExec
=
11
// TokenActionMint for token mint
TokenActionMint
=
12
)
)
// token status
// token status
...
...
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