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
55e2f303
Commit
55e2f303
authored
Dec 26, 2018
by
张振华
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into guess
parents
ad86eb98
ef941882
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
163 additions
and
47 deletions
+163
-47
rpc_real_test.go
plugin/dapp/multisig/rpc/rpc_real_test.go
+0
-0
testcase.sh
plugin/dapp/paracross/cmd/build/testcase.sh
+32
-1
token.go
plugin/dapp/token/commands/token.go
+100
-4
utils.go
plugin/dapp/token/commands/utils.go
+0
-41
transwithdraw.go
plugin/dapp/token/executor/transwithdraw.go
+1
-1
types.go
plugin/dapp/token/types/types.go
+30
-0
No files found.
plugin/dapp/multisig/rpc/rpc_real_test.go
0 → 100644
View file @
55e2f303
This diff is collapsed.
Click to expand it.
plugin/dapp/paracross/cmd/build/testcase.sh
View file @
55e2f303
...
...
@@ -151,13 +151,15 @@ function token_create() {
echo
"wrong finish created total"
exit
1
fi
${
1
}
token token_balance
-a
1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4
-e
token
-s
GD
balance
=
$(${
1
}
token token_balance
-a
1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4
-e
token
-s
GD | jq
-r
'.[]|.balance'
)
if
[
"
${
balance
}
"
!=
"10000.0000"
]
;
then
echo
"wrong para token genesis create, should be 10000.0000"
exit
1
fi
}
function
token_transfer
()
{
echo
"=========== # 2.token transfer ============="
hash
=
$(${
1
}
send token transfer
-a
11
-s
GD
-t
1GGF8toZd96wCnfJngTwXZnWCBdWHYYvjw
-k
0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b
)
echo
"
${
hash
}
"
...
...
@@ -170,6 +172,34 @@ function token_create() {
echo
"wrong para token transfer, should be 11.0000"
exit
1
fi
echo
"=========== # 3.token send exec ============="
hash
=
$(${
1
}
send token send_exec
-a
11
-s
GD
-e
paracross
-k
0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b
)
echo
"
${
hash
}
"
block_wait
"
${
1
}
"
3
# $ ./build/chain33-cli exec addr -e user.p.para.paracross
# 19WJJv96nKAU4sHFWqGmsqfjxd37jazqii
${
1
}
tx query
-s
"
${
hash
}
"
${
1
}
token token_balance
-a
19WJJv96nKAU4sHFWqGmsqfjxd37jazqii
-e
token
-s
GD
balance
=
$(${
1
}
token token_balance
-a
19WJJv96nKAU4sHFWqGmsqfjxd37jazqii
-e
token
-s
GD | jq
-r
'.[]|.balance'
)
if
[
"
${
balance
}
"
!=
"11.0000"
]
;
then
echo
"wrong para token send exec, should be 11.0000"
exit
1
fi
echo
"=========== # 4.token withdraw ============="
hash
=
$(${
1
}
send token withdraw
-a
11
-s
GD
-e
paracross
-k
0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b
)
echo
"
${
hash
}
"
block_wait
"
${
1
}
"
3
${
1
}
tx query
-s
"
${
hash
}
"
${
1
}
token token_balance
-a
19WJJv96nKAU4sHFWqGmsqfjxd37jazqii
-e
token
-s
GD
balance
=
$(${
1
}
token token_balance
-a
19WJJv96nKAU4sHFWqGmsqfjxd37jazqii
-e
token
-s
GD | jq
-r
'.[]|.balance'
)
if
[
"
${
balance
}
"
!=
"0.0000"
]
;
then
echo
"wrong para token withdraw, should be 0.0000"
exit
1
fi
}
function
para_cross_transfer_withdraw
()
{
...
...
@@ -204,6 +234,7 @@ function para_cross_transfer_withdraw() {
function
para_test
()
{
echo
"=========== # para chain test ============="
token_create
"
${
PARA_CLI
}
"
token_transfer
"
${
PARA_CLI
}
"
para_cross_transfer_withdraw
}
...
...
plugin/dapp/token/commands/token.go
View file @
55e2f303
...
...
@@ -7,6 +7,7 @@ package commands
import
(
"encoding/json"
"fmt"
"math"
"os"
"strconv"
"strings"
...
...
@@ -40,6 +41,7 @@ func TokenCmd() *cobra.Command {
CreateRawTokenPreCreateTxCmd
(),
CreateRawTokenFinishTxCmd
(),
CreateRawTokenRevokeTxCmd
(),
CreateTokenTransferExecCmd
(),
)
return
cmd
...
...
@@ -74,12 +76,89 @@ func createTokenTransfer(cmd *cobra.Command, args []string) {
amount
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"amount"
)
note
,
_
:=
cmd
.
Flags
()
.
GetString
(
"note"
)
symbol
,
_
:=
cmd
.
Flags
()
.
GetString
(
"symbol"
)
txHex
,
err
:=
CreateRawTx
(
cmd
,
toAddr
,
amount
,
note
,
false
,
symbol
,
""
)
payload
:=
&
types
.
AssetsTransfer
{
To
:
toAddr
,
Amount
:
int64
(
math
.
Trunc
((
amount
+
0.0000001
)
*
1e4
))
*
1e4
,
Note
:
[]
byte
(
note
),
Cointoken
:
symbol
,
}
data
,
err
:=
json
.
Marshal
(
&
payload
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
}
fmt
.
Println
(
txHex
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
tokenty
.
TokenX
),
ActionName
:
"Transfer"
,
Payload
:
data
,
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
nil
)
ctx
.
RunWithoutMarshal
()
}
// CreateTokenTransferExecCmd 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
)
{
paraName
,
_
:=
cmd
.
Flags
()
.
GetString
(
"paraName"
)
exec
,
_
:=
cmd
.
Flags
()
.
GetString
(
"exec"
)
exec
=
getRealExecName
(
paraName
,
exec
)
to
,
err
:=
GetExecAddr
(
exec
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
}
amount
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"amount"
)
note
,
_
:=
cmd
.
Flags
()
.
GetString
(
"note"
)
symbol
,
_
:=
cmd
.
Flags
()
.
GetString
(
"symbol"
)
payload
:=
&
types
.
AssetsTransferToExec
{
To
:
to
,
Amount
:
int64
(
math
.
Trunc
((
amount
+
0.0000001
)
*
1e4
))
*
1e4
,
Note
:
[]
byte
(
note
),
Cointoken
:
symbol
,
ExecName
:
exec
,
}
data
,
err
:=
json
.
Marshal
(
&
payload
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
}
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
tokenty
.
TokenX
),
ActionName
:
"TransferToExec"
,
Payload
:
data
,
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
nil
)
ctx
.
RunWithoutMarshal
()
}
// CreateTokenWithdrawCmd create raw withdraw tx
...
...
@@ -113,17 +192,34 @@ func createTokenWithdraw(cmd *cobra.Command, args []string) {
amount
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"amount"
)
note
,
_
:=
cmd
.
Flags
()
.
GetString
(
"note"
)
symbol
,
_
:=
cmd
.
Flags
()
.
GetString
(
"symbol"
)
exec
=
getRealExecName
(
paraName
,
exec
)
execAddr
,
err
:=
GetExecAddr
(
exec
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
}
txHex
,
err
:=
CreateRawTx
(
cmd
,
execAddr
,
amount
,
note
,
true
,
symbol
,
exec
)
payload
:=
&
types
.
AssetsWithdraw
{
To
:
execAddr
,
Amount
:
int64
(
math
.
Trunc
((
amount
+
0.0000001
)
*
1e4
))
*
1e4
,
Note
:
[]
byte
(
note
),
Cointoken
:
symbol
,
ExecName
:
exec
,
}
data
,
err
:=
json
.
Marshal
(
&
payload
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
}
fmt
.
Println
(
txHex
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
tokenty
.
TokenX
),
ActionName
:
"Withdraw"
,
Payload
:
data
,
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
nil
)
ctx
.
RunWithoutMarshal
()
}
// GetTokensPreCreatedCmd get precreated tokens
...
...
plugin/dapp/token/commands/utils.go
View file @
55e2f303
...
...
@@ -5,53 +5,12 @@
package
commands
import
(
"encoding/hex"
"math"
"strings"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/types"
tokenty
"github.com/33cn/plugin/plugin/dapp/token/types"
"github.com/spf13/cobra"
)
// CreateRawTx 创建交易
func
CreateRawTx
(
cmd
*
cobra
.
Command
,
to
string
,
amount
float64
,
note
string
,
isWithdraw
bool
,
tokenSymbol
,
execName
string
)
(
string
,
error
)
{
if
amount
<
0
{
return
""
,
types
.
ErrAmount
}
paraName
,
_
:=
cmd
.
Flags
()
.
GetString
(
"paraName"
)
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
transfer
:=
&
tokenty
.
TokenAction
{}
if
!
isWithdraw
{
v
:=
&
tokenty
.
TokenAction_Transfer
{
Transfer
:
&
types
.
AssetsTransfer
{
Cointoken
:
tokenSymbol
,
Amount
:
amountInt64
,
Note
:
[]
byte
(
note
),
To
:
to
}}
transfer
.
Value
=
v
transfer
.
Ty
=
tokenty
.
ActionTransfer
}
else
{
v
:=
&
tokenty
.
TokenAction_Withdraw
{
Withdraw
:
&
types
.
AssetsWithdraw
{
Cointoken
:
tokenSymbol
,
Amount
:
amountInt64
,
Note
:
[]
byte
(
note
),
To
:
to
}}
transfer
.
Value
=
v
transfer
.
Ty
=
tokenty
.
ActionWithdraw
}
execer
:=
[]
byte
(
getRealExecName
(
paraName
,
"token"
))
if
paraName
==
""
{
tx
=
&
types
.
Transaction
{
Execer
:
execer
,
Payload
:
types
.
Encode
(
transfer
),
To
:
to
}
}
else
{
tx
=
&
types
.
Transaction
{
Execer
:
execer
,
Payload
:
types
.
Encode
(
transfer
),
To
:
address
.
ExecAddress
(
string
(
execer
))}
}
tx
,
err
:=
types
.
FormatTx
(
string
(
execer
),
tx
)
if
err
!=
nil
{
return
""
,
err
}
txHex
:=
types
.
Encode
(
tx
)
return
hex
.
EncodeToString
(
txHex
),
nil
}
// GetExecAddr 获取执行器地址
func
GetExecAddr
(
exec
string
)
(
string
,
error
)
{
if
ok
:=
types
.
IsAllowExecName
([]
byte
(
exec
),
[]
byte
(
exec
));
!
ok
{
...
...
plugin/dapp/token/executor/transwithdraw.go
View file @
55e2f303
...
...
@@ -24,7 +24,7 @@ func (t *token) ExecTransWithdraw(accountDB *account.DB, tx *types.Transaction,
return
accountDB
.
Transfer
(
from
,
tx
.
GetRealToAddr
(),
transfer
.
Amount
)
}
else
if
(
action
.
Ty
==
tokenty
.
ActionWithdraw
)
&&
action
.
GetWithdraw
()
!=
nil
{
withdraw
:=
action
.
GetWithdraw
()
if
types
.
IsFork
(
t
.
GetHeight
(),
"ForkWithdraw"
)
{
if
!
types
.
IsFork
(
t
.
GetHeight
(),
"ForkWithdraw"
)
{
withdraw
.
ExecName
=
""
}
from
:=
tx
.
From
()
...
...
plugin/dapp/token/types/types.go
View file @
55e2f303
...
...
@@ -5,11 +5,16 @@
package
types
import
(
"encoding/json"
"reflect"
log
"github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/types"
)
var
tokenlog
=
log
.
New
(
"module"
,
"execs.token.types"
)
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
TokenX
))
types
.
RegistorExecutor
(
TokenX
,
NewType
())
...
...
@@ -92,3 +97,28 @@ func (t *TokenType) RPC_Default_Process(action string, msg interface{}) (*types.
}
return
tx
,
err
}
// CreateTx token 创建合约
func
(
t
*
TokenType
)
CreateTx
(
action
string
,
msg
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
tx
,
err
:=
t
.
ExecTypeBase
.
CreateTx
(
action
,
msg
)
if
err
!=
nil
{
tokenlog
.
Error
(
"token CreateTx failed"
,
"err"
,
err
,
"action"
,
action
,
"msg"
,
string
(
msg
))
return
nil
,
err
}
if
!
types
.
IsPara
()
{
var
transfer
TokenAction
err
=
types
.
Decode
(
tx
.
Payload
,
&
transfer
)
if
err
!=
nil
{
tokenlog
.
Error
(
"token CreateTx failed"
,
"decode payload err"
,
err
,
"action"
,
action
,
"msg"
,
string
(
msg
))
return
nil
,
err
}
if
action
==
"Transfer"
{
tx
.
To
=
transfer
.
GetTransfer
()
.
To
}
else
if
action
==
"Withdraw"
{
tx
.
To
=
transfer
.
GetWithdraw
()
.
To
}
else
if
action
==
"TransferToExec"
{
tx
.
To
=
transfer
.
GetTransferToExec
()
.
To
}
}
return
tx
,
nil
}
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