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
0a56b03b
Commit
0a56b03b
authored
Mar 11, 2019
by
linj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exec burn
parent
19db86a7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
3 deletions
+64
-3
exec.go
plugin/dapp/token/executor/exec.go
+5
-0
tokendb.go
plugin/dapp/token/executor/tokendb.go
+57
-3
types.go
plugin/dapp/token/types/types.go
+2
-0
No files found.
plugin/dapp/token/executor/exec.go
View file @
0a56b03b
...
@@ -74,3 +74,8 @@ func (t *token) Exec_TokenMint(payload *tokenty.TokenMint, tx *types.Transaction
...
@@ -74,3 +74,8 @@ func (t *token) Exec_TokenMint(payload *tokenty.TokenMint, tx *types.Transaction
action
:=
newTokenAction
(
t
,
""
,
tx
)
action
:=
newTokenAction
(
t
,
""
,
tx
)
return
action
.
mint
(
payload
)
return
action
.
mint
(
payload
)
}
}
func
(
t
*
token
)
Exec_TokenBurn
(
payload
*
tokenty
.
TokenBurn
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
newTokenAction
(
t
,
""
,
tx
)
return
action
.
burn
(
payload
)
}
plugin/dapp/token/executor/tokendb.go
View file @
0a56b03b
...
@@ -89,6 +89,19 @@ func (t *tokenDB) mint(db dbm.KV, addr string, amount int64) ([]*types.KeyValue,
...
@@ -89,6 +89,19 @@ func (t *tokenDB) mint(db dbm.KV, addr string, amount int64) ([]*types.KeyValue,
return
kvs
,
logs
,
nil
return
kvs
,
logs
,
nil
}
}
func
(
t
*
tokenDB
)
burn
(
db
dbm
.
KV
,
amount
int64
)
([]
*
types
.
KeyValue
,
[]
*
types
.
ReceiptLog
,
error
)
{
if
t
.
token
.
Total
<
amount
{
return
nil
,
nil
,
types
.
ErrNoBalance
}
prevToken
:=
t
.
token
t
.
token
.
Total
-=
amount
kvs
:=
append
(
t
.
getKVSet
(
calcTokenKey
(
t
.
token
.
Symbol
)),
t
.
getKVSet
(
calcTokenAddrNewKeyS
(
t
.
token
.
Symbol
,
t
.
token
.
Owner
))
...
)
logs
:=
[]
*
types
.
ReceiptLog
{{
Ty
:
pty
.
TyLogTokenBurn
,
Log
:
types
.
Encode
(
&
pty
.
ReceiptTokenAmount
{
Prev
:
&
prevToken
,
Cur
:
&
t
.
token
})}}
return
kvs
,
logs
,
nil
}
func
getTokenFromDB
(
db
dbm
.
KV
,
symbol
string
,
owner
string
)
(
*
pty
.
Token
,
error
)
{
func
getTokenFromDB
(
db
dbm
.
KV
,
symbol
string
,
owner
string
)
(
*
pty
.
Token
,
error
)
{
key
:=
calcTokenAddrKeyS
(
symbol
,
owner
)
key
:=
calcTokenAddrKeyS
(
symbol
,
owner
)
value
,
err
:=
db
.
Get
(
key
)
value
,
err
:=
db
.
Get
(
key
)
...
@@ -507,7 +520,7 @@ func (action *tokenAction) mint(mint *pty.TokenMint) (*types.Receipt, error) {
...
@@ -507,7 +520,7 @@ func (action *tokenAction) mint(mint *pty.TokenMint) (*types.Receipt, error) {
if
mint
==
nil
{
if
mint
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
if
mint
.
GetAmount
()
<
0
||
mint
.
GetAmount
()
>
types
.
Max
Coin
||
mint
.
GetSymbol
()
==
""
{
if
mint
.
GetAmount
()
<
0
||
mint
.
GetAmount
()
>
types
.
Max
TokenBalance
||
mint
.
GetSymbol
()
==
""
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
...
@@ -516,8 +529,8 @@ func (action *tokenAction) mint(mint *pty.TokenMint) (*types.Receipt, error) {
...
@@ -516,8 +529,8 @@ func (action *tokenAction) mint(mint *pty.TokenMint) (*types.Receipt, error) {
return
nil
,
err
return
nil
,
err
}
}
if
tokendb
.
token
.
Category
&
pty
.
CategoryMintSupport
==
0
{
if
tokendb
.
token
.
Category
&
pty
.
CategoryMint
Burn
Support
==
0
{
tokenlog
.
Error
(
"Can't mint category"
,
"category"
,
tokendb
.
token
.
Category
,
"support"
,
pty
.
CategoryMintSupport
)
tokenlog
.
Error
(
"Can't mint category"
,
"category"
,
tokendb
.
token
.
Category
,
"support"
,
pty
.
CategoryMint
Burn
Support
)
return
nil
,
types
.
ErrNotSupport
return
nil
,
types
.
ErrNotSupport
}
}
...
@@ -542,3 +555,43 @@ func (action *tokenAction) mint(mint *pty.TokenMint) (*types.Receipt, error) {
...
@@ -542,3 +555,43 @@ func (action *tokenAction) mint(mint *pty.TokenMint) (*types.Receipt, error) {
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kvs
,
Logs
:
logs
},
nil
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kvs
,
Logs
:
logs
},
nil
}
}
func
(
action
*
tokenAction
)
burn
(
burn
*
pty
.
TokenBurn
)
(
*
types
.
Receipt
,
error
)
{
if
burn
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
if
burn
.
GetAmount
()
<
0
||
burn
.
GetAmount
()
>
types
.
MaxTokenBalance
||
burn
.
GetSymbol
()
==
""
{
return
nil
,
types
.
ErrInvalidParam
}
tokendb
,
err
:=
loadTokenDB
(
action
.
db
,
burn
.
GetSymbol
())
if
err
!=
nil
{
return
nil
,
err
}
if
tokendb
.
token
.
Category
&
pty
.
CategoryMintBurnSupport
==
0
{
tokenlog
.
Error
(
"Can't burn category"
,
"category"
,
tokendb
.
token
.
Category
,
"support"
,
pty
.
CategoryMintBurnSupport
)
return
nil
,
types
.
ErrNotSupport
}
kvs
,
logs
,
err
:=
tokendb
.
burn
(
action
.
db
,
burn
.
Amount
)
if
err
!=
nil
{
tokenlog
.
Error
(
"token burn "
,
"symbol"
,
burn
.
GetSymbol
(),
"error"
,
err
,
"from"
,
action
.
fromaddr
,
"owner"
,
tokendb
.
token
.
Owner
)
return
nil
,
err
}
tokenAccount
,
err
:=
account
.
NewAccountDB
(
"token"
,
burn
.
GetSymbol
(),
action
.
db
)
if
err
!=
nil
{
return
nil
,
err
}
tokenlog
.
Debug
(
"burn"
,
"token.Owner"
,
burn
.
Symbol
,
"token.GetTotal()"
,
burn
.
Amount
)
receipt
,
err
:=
tokenAccount
.
Burn
(
action
.
fromaddr
,
burn
.
Amount
)
if
err
!=
nil
{
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kvs
=
append
(
kvs
,
receipt
.
KV
...
)
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kvs
,
Logs
:
logs
},
nil
}
\ No newline at end of file
plugin/dapp/token/types/types.go
View file @
0a56b03b
...
@@ -58,6 +58,7 @@ func (t *TokenType) GetTypeMap() map[string]int32 {
...
@@ -58,6 +58,7 @@ func (t *TokenType) GetTypeMap() map[string]int32 {
"TokenRevokeCreate"
:
TokenActionRevokeCreate
,
"TokenRevokeCreate"
:
TokenActionRevokeCreate
,
"TransferToExec"
:
TokenActionTransferToExec
,
"TransferToExec"
:
TokenActionTransferToExec
,
"TokenMint"
:
TokenActionMint
,
"TokenMint"
:
TokenActionMint
,
"TokenBurn"
:
TokenActionBurn
,
}
}
}
}
...
@@ -77,6 +78,7 @@ func (t *TokenType) GetLogMap() map[int64]*types.LogInfo {
...
@@ -77,6 +78,7 @@ func (t *TokenType) GetLogMap() map[int64]*types.LogInfo {
TyLogFinishCreateToken
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptToken
{}),
Name
:
"LogFinishCreateToken"
},
TyLogFinishCreateToken
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptToken
{}),
Name
:
"LogFinishCreateToken"
},
TyLogRevokeCreateToken
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptToken
{}),
Name
:
"LogRevokeCreateToken"
},
TyLogRevokeCreateToken
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptToken
{}),
Name
:
"LogRevokeCreateToken"
},
TyLogTokenMint
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptTokenAmount
{}),
Name
:
"LogMintToken"
},
TyLogTokenMint
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptTokenAmount
{}),
Name
:
"LogMintToken"
},
TyLogTokenBurn
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptTokenAmount
{}),
Name
:
"LogBurnToken"
},
}
}
}
}
...
...
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