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
01b150b4
Commit
01b150b4
authored
Dec 21, 2018
by
linj
Committed by
vipwzw
Dec 25, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client support token send to exec
parent
43c22d00
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
6 deletions
+61
-6
token.go
plugin/dapp/token/commands/token.go
+38
-0
utils.go
plugin/dapp/token/commands/utils.go
+23
-6
No files found.
plugin/dapp/token/commands/token.go
View file @
01b150b4
...
@@ -40,6 +40,7 @@ func TokenCmd() *cobra.Command {
...
@@ -40,6 +40,7 @@ func TokenCmd() *cobra.Command {
CreateRawTokenPreCreateTxCmd
(),
CreateRawTokenPreCreateTxCmd
(),
CreateRawTokenFinishTxCmd
(),
CreateRawTokenFinishTxCmd
(),
CreateRawTokenRevokeTxCmd
(),
CreateRawTokenRevokeTxCmd
(),
CreateTokenTransferExecCmd
(),
)
)
return
cmd
return
cmd
...
@@ -82,6 +83,43 @@ func createTokenTransfer(cmd *cobra.Command, args []string) {
...
@@ -82,6 +83,43 @@ func createTokenTransfer(cmd *cobra.Command, args []string) {
fmt
.
Println
(
txHex
)
fmt
.
Println
(
txHex
)
}
}
// CreateTokenTransferCmd create raw transfer tx
func
CreateTokenTransferExecCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"send_exec"
,
Short
:
"Create a token send to executor transaction"
,
Run
:
createTokenSendToExec
,
}
addCreateTokenSendToExecFlags
(
cmd
)
return
cmd
}
func
addCreateTokenSendToExecFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"exec"
,
"e"
,
""
,
"receiver executor address"
)
cmd
.
MarkFlagRequired
(
"exec"
)
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"a"
,
0
,
"transaction amount"
)
cmd
.
MarkFlagRequired
(
"amount"
)
cmd
.
Flags
()
.
StringP
(
"note"
,
"n"
,
""
,
"transaction note info"
)
cmd
.
Flags
()
.
StringP
(
"symbol"
,
"s"
,
""
,
"token symbol"
)
cmd
.
MarkFlagRequired
(
"symbol"
)
}
func
createTokenSendToExec
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
exec
,
_
:=
cmd
.
Flags
()
.
GetString
(
"exec"
)
amount
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"amount"
)
note
,
_
:=
cmd
.
Flags
()
.
GetString
(
"note"
)
symbol
,
_
:=
cmd
.
Flags
()
.
GetString
(
"symbol"
)
txHex
,
err
:=
CreateRawTx
(
cmd
,
""
,
amount
,
note
,
false
,
symbol
,
exec
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
}
fmt
.
Println
(
txHex
)
}
// CreateTokenWithdrawCmd create raw withdraw tx
// CreateTokenWithdrawCmd create raw withdraw tx
func
CreateTokenWithdrawCmd
()
*
cobra
.
Command
{
func
CreateTokenWithdrawCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
...
...
plugin/dapp/token/commands/utils.go
View file @
01b150b4
...
@@ -6,8 +6,9 @@ package commands
...
@@ -6,8 +6,9 @@ package commands
import
(
import
(
"encoding/hex"
"encoding/hex"
"fmt"
"math"
"math"
"os"
"strings"
"strings"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/address"
...
@@ -17,22 +18,38 @@ import (
...
@@ -17,22 +18,38 @@ import (
)
)
// CreateRawTx 创建交易
// CreateRawTx 创建交易
// 主链交易使用 Transaction 的 To
// 平行链使用的 payload 的 To, Transaction 的 To 作为执行器的合约地址
// 在执行合约时, 有GetRealTo 用来读取这个项
// 在命令行中, 参数需要加前缀才是对的
// 在平行链上 执行器地址注册不带前缀, withdraw To地址有前缀, 算出来不一致
func
CreateRawTx
(
cmd
*
cobra
.
Command
,
to
string
,
amount
float64
,
note
string
,
isWithdraw
bool
,
tokenSymbol
,
execName
string
)
(
string
,
error
)
{
func
CreateRawTx
(
cmd
*
cobra
.
Command
,
to
string
,
amount
float64
,
note
string
,
isWithdraw
bool
,
tokenSymbol
,
execName
string
)
(
string
,
error
)
{
if
amount
<
0
{
if
amount
<
0
{
return
""
,
types
.
ErrAmount
return
""
,
types
.
ErrAmount
}
}
paraName
,
_
:=
cmd
.
Flags
()
.
GetString
(
"paraName"
)
paraName
,
_
:=
cmd
.
Flags
()
.
GetString
(
"paraName"
)
amountInt64
:=
int64
(
math
.
Trunc
((
amount
+
0.0000001
)
*
1e4
))
*
1e4
amountInt64
:=
int64
(
math
.
Trunc
((
amount
+
0.0000001
)
*
1e4
))
*
1e4
execName
=
getRealExecName
(
paraName
,
execName
)
if
execName
!=
""
&&
!
types
.
IsAllowExecName
([]
byte
(
execName
),
[]
byte
(
execName
))
{
return
""
,
types
.
ErrExecNameNotMatch
}
var
tx
*
types
.
Transaction
var
tx
*
types
.
Transaction
transfer
:=
&
tokenty
.
TokenAction
{}
transfer
:=
&
tokenty
.
TokenAction
{}
if
isWithdraw
{
if
isWithdraw
{
v
:=
&
tokenty
.
TokenAction_Withdraw
{
Withdraw
:
&
types
.
AssetsWithdraw
{
Cointoken
:
tokenSymbol
,
Amount
:
amountInt64
,
Note
:
[]
byte
(
note
),
To
:
to
}}
v
:=
&
tokenty
.
TokenAction_Withdraw
{
Withdraw
:
&
types
.
AssetsWithdraw
{
Cointoken
:
tokenSymbol
,
Amount
:
amountInt64
,
Note
:
[]
byte
(
note
),
To
:
to
,
ExecName
:
getRealExecName
(
paraName
,
execName
)}}
transfer
.
Value
=
v
transfer
.
Value
=
v
transfer
.
Ty
=
tokenty
.
ActionWithdraw
transfer
.
Ty
=
tokenty
.
ActionWithdraw
}
else
if
execName
!=
""
{
execName
=
getRealExecName
(
paraName
,
execName
)
if
execName
!=
""
&&
!
types
.
IsAllowExecName
([]
byte
(
execName
),
[]
byte
(
execName
))
{
return
""
,
types
.
ErrExecNameNotMatch
}
to
,
err
:=
GetExecAddr
(
execName
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
""
,
err
}
v
:=
&
tokenty
.
TokenAction_TransferToExec
{
TransferToExec
:
&
types
.
AssetsTransferToExec
{
Cointoken
:
tokenSymbol
,
Amount
:
amountInt64
,
Note
:
[]
byte
(
note
),
ExecName
:
execName
,
To
:
to
}}
transfer
.
Value
=
v
transfer
.
Ty
=
tokenty
.
TokenActionTransferToExec
}
else
{
}
else
{
v
:=
&
tokenty
.
TokenAction_Transfer
{
Transfer
:
&
types
.
AssetsTransfer
{
Cointoken
:
tokenSymbol
,
Amount
:
amountInt64
,
Note
:
[]
byte
(
note
),
To
:
to
}}
v
:=
&
tokenty
.
TokenAction_Transfer
{
Transfer
:
&
types
.
AssetsTransfer
{
Cointoken
:
tokenSymbol
,
Amount
:
amountInt64
,
Note
:
[]
byte
(
note
),
To
:
to
}}
transfer
.
Value
=
v
transfer
.
Value
=
v
...
...
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