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
da0637cd
Commit
da0637cd
authored
Dec 06, 2018
by
heyubin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add by hyb for bug
parent
2d0bd9cc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
164 additions
and
7 deletions
+164
-7
multisig.go
plugin/dapp/multisig/commands/multisig.go
+8
-7
multisig.go
plugin/dapp/multisig/executor/multisig.go
+155
-0
errors.go
plugin/dapp/multisig/types/errors.go
+1
-0
No files found.
plugin/dapp/multisig/commands/multisig.go
View file @
da0637cd
...
@@ -105,8 +105,8 @@ func createMultiSigAccTransfer(cmd *cobra.Command, args []string) {
...
@@ -105,8 +105,8 @@ func createMultiSigAccTransfer(cmd *cobra.Command, args []string) {
var
ownerCount
int
=
0
var
ownerCount
int
=
0
for
_
,
weight
:=
range
weightsArr
{
for
_
,
weight
:=
range
weightsArr
{
ownerweight
,
err
:=
strconv
.
ParseInt
(
weight
,
10
,
64
)
ownerweight
,
err
:=
strconv
.
ParseInt
(
weight
,
10
,
64
)
if
err
!=
nil
||
ownerweight
<
0
{
if
err
!=
nil
||
ownerweight
<
=
0
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
fmt
.
Fprintln
(
os
.
Stderr
,
"weight invalid"
)
return
return
}
}
weights
=
append
(
weights
,
uint64
(
ownerweight
))
weights
=
append
(
weights
,
uint64
(
ownerweight
))
...
@@ -121,8 +121,11 @@ func createMultiSigAccTransfer(cmd *cobra.Command, args []string) {
...
@@ -121,8 +121,11 @@ func createMultiSigAccTransfer(cmd *cobra.Command, args []string) {
}
}
}
}
requiredweight
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"required_weight"
)
requiredweight
,
err
:=
cmd
.
Flags
()
.
GetUint64
(
"required_weight"
)
if
err
!=
nil
||
requiredweight
==
0
{
fmt
.
Fprintln
(
os
.
Stderr
,
"required weight invalid"
)
return
}
if
requiredweight
>
totalweight
{
if
requiredweight
>
totalweight
{
fmt
.
Fprintln
(
os
.
Stderr
,
"Requiredweight more than totalweight"
)
fmt
.
Fprintln
(
os
.
Stderr
,
"Requiredweight more than totalweight"
)
return
return
...
@@ -137,7 +140,7 @@ func createMultiSigAccTransfer(cmd *cobra.Command, args []string) {
...
@@ -137,7 +140,7 @@ func createMultiSigAccTransfer(cmd *cobra.Command, args []string) {
execer
,
_
:=
cmd
.
Flags
()
.
GetString
(
"execer"
)
execer
,
_
:=
cmd
.
Flags
()
.
GetString
(
"execer"
)
symbol
,
_
:=
cmd
.
Flags
()
.
GetString
(
"symbol"
)
symbol
,
_
:=
cmd
.
Flags
()
.
GetString
(
"symbol"
)
err
:
=
mty
.
IsAssetsInvalid
(
execer
,
symbol
)
err
=
mty
.
IsAssetsInvalid
(
execer
,
symbol
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
return
...
@@ -474,7 +477,6 @@ func createMultiSigAccTransferInFlags(cmd *cobra.Command) {
...
@@ -474,7 +477,6 @@ func createMultiSigAccTransferInFlags(cmd *cobra.Command) {
cmd
.
MarkFlagRequired
(
"symbol"
)
cmd
.
MarkFlagRequired
(
"symbol"
)
cmd
.
Flags
()
.
StringP
(
"note"
,
"n"
,
""
,
"transaction note info"
)
cmd
.
Flags
()
.
StringP
(
"note"
,
"n"
,
""
,
"transaction note info"
)
cmd
.
MarkFlagRequired
(
"note"
)
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"a"
,
0
,
"transaction amount"
)
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"a"
,
0
,
"transaction amount"
)
cmd
.
MarkFlagRequired
(
"amount"
)
cmd
.
MarkFlagRequired
(
"amount"
)
...
@@ -532,7 +534,6 @@ func createMultiSigAccTransferOutFlags(cmd *cobra.Command) {
...
@@ -532,7 +534,6 @@ func createMultiSigAccTransferOutFlags(cmd *cobra.Command) {
cmd
.
MarkFlagRequired
(
"symbol"
)
cmd
.
MarkFlagRequired
(
"symbol"
)
cmd
.
Flags
()
.
StringP
(
"note"
,
"n"
,
""
,
"transaction note info"
)
cmd
.
Flags
()
.
StringP
(
"note"
,
"n"
,
""
,
"transaction note info"
)
cmd
.
MarkFlagRequired
(
"note"
)
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"a"
,
0
,
"transaction amount"
)
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"a"
,
0
,
"transaction amount"
)
cmd
.
MarkFlagRequired
(
"amount"
)
cmd
.
MarkFlagRequired
(
"amount"
)
...
...
plugin/dapp/multisig/executor/multisig.go
View file @
da0637cd
...
@@ -19,6 +19,7 @@ import (
...
@@ -19,6 +19,7 @@ import (
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/common/address"
log
"github.com/33cn/chain33/common/log/log15"
log
"github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/system/dapp"
drivers
"github.com/33cn/chain33/system/dapp"
drivers
"github.com/33cn/chain33/system/dapp"
...
@@ -65,6 +66,8 @@ func (m *MultiSig) GetDriverName() string {
...
@@ -65,6 +66,8 @@ func (m *MultiSig) GetDriverName() string {
// CheckTx 检测multisig合约交易,转账交易amount不能为负数
// CheckTx 检测multisig合约交易,转账交易amount不能为负数
func
(
m
*
MultiSig
)
CheckTx
(
tx
*
types
.
Transaction
,
index
int
)
error
{
func
(
m
*
MultiSig
)
CheckTx
(
tx
*
types
.
Transaction
,
index
int
)
error
{
ety
:=
m
.
GetExecutorType
()
ety
:=
m
.
GetExecutorType
()
//amount check
amount
,
err
:=
ety
.
Amount
(
tx
)
amount
,
err
:=
ety
.
Amount
(
tx
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -72,6 +75,158 @@ func (m *MultiSig) CheckTx(tx *types.Transaction, index int) error {
...
@@ -72,6 +75,158 @@ func (m *MultiSig) CheckTx(tx *types.Transaction, index int) error {
if
amount
<
0
{
if
amount
<
0
{
return
types
.
ErrAmount
return
types
.
ErrAmount
}
}
_
,
v
,
err
:=
ety
.
DecodePayloadValue
(
tx
)
if
err
!=
nil
{
return
err
}
payload
:=
v
.
Interface
()
//MultiSigAccCreate 交易校验
if
ato
,
ok
:=
payload
.
(
*
mty
.
MultiSigAccCreate
);
ok
{
err
:=
checkAccountCreateTx
(
ato
)
if
err
!=
nil
{
return
err
}
}
//MultiSigExecTransfer to 地址检测
if
ato
,
ok
:=
payload
.
(
*
mty
.
MultiSigExecTransfer
);
ok
{
if
err
:=
address
.
CheckAddress
(
ato
.
GetTo
());
err
!=
nil
{
return
types
.
ErrInvalidAddress
}
//assets check
if
err
:=
mty
.
IsAssetsInvalid
(
ato
.
GetExecname
(),
ato
.
GetSymbol
());
err
!=
nil
{
return
err
}
}
//MultiSigOwnerOperate 交易的检测
if
ato
,
ok
:=
payload
.
(
*
mty
.
MultiSigOwnerOperate
);
ok
{
err
:=
checkOwnerOperateTx
(
ato
)
if
err
!=
nil
{
return
err
}
}
//MultiSigAccOperate to 地址检测
if
ato
,
ok
:=
payload
.
(
*
mty
.
MultiSigAccOperate
);
ok
{
err
:=
checkAccountOperateTx
(
ato
)
if
err
!=
nil
{
return
err
}
}
//MultiSigConfirmTx multiSigAccAddr地址检测
if
ato
,
ok
:=
payload
.
(
*
mty
.
MultiSigConfirmTx
);
ok
{
if
err
:=
address
.
CheckAddress
(
ato
.
GetMultiSigAccAddr
());
err
!=
nil
{
return
types
.
ErrInvalidAddress
}
}
return
nil
}
func
checkAccountCreateTx
(
ato
*
mty
.
MultiSigAccCreate
)
error
{
var
totalweight
uint64
=
0
var
ownerCount
int
=
0
requiredWeight
:=
ato
.
GetRequiredWeight
()
if
requiredWeight
==
0
{
return
mty
.
ErrInvalidWeight
}
owners
:=
ato
.
GetOwners
()
//创建时requiredweight权重的值不能大于所有owner权重之和
for
_
,
owner
:=
range
owners
{
if
owner
!=
nil
{
if
err
:=
address
.
CheckAddress
(
owner
.
OwnerAddr
);
err
!=
nil
{
return
types
.
ErrInvalidAddress
}
if
owner
.
Weight
==
0
{
return
mty
.
ErrInvalidWeight
}
totalweight
+=
owner
.
Weight
ownerCount
=
ownerCount
+
1
}
}
if
ato
.
RequiredWeight
>
totalweight
{
return
mty
.
ErrRequiredweight
}
//创建时最少设置两个owner
if
ownerCount
<
mty
.
MinOwnersInit
{
return
mty
.
ErrOwnerLessThanTwo
}
//owner总数不能大于最大值
if
ownerCount
>
mty
.
MaxOwnersCount
{
return
mty
.
ErrMaxOwnerCount
}
dailyLimit
:=
ato
.
GetDailyLimit
()
//assets check
if
err
:=
mty
.
IsAssetsInvalid
(
dailyLimit
.
GetExecer
(),
dailyLimit
.
GetSymbol
());
err
!=
nil
{
return
err
}
return
nil
}
func
checkOwnerOperateTx
(
ato
*
mty
.
MultiSigOwnerOperate
)
error
{
OldOwner
:=
ato
.
GetOldOwner
()
NewOwner
:=
ato
.
GetNewOwner
()
NewWeight
:=
ato
.
GetNewWeight
()
MultiSigAccAddr
:=
ato
.
GetMultiSigAccAddr
()
if
err
:=
address
.
CheckAddress
(
MultiSigAccAddr
);
err
!=
nil
{
return
types
.
ErrInvalidAddress
}
if
ato
.
OperateFlag
==
mty
.
OwnerAdd
{
if
err
:=
address
.
CheckAddress
(
NewOwner
);
err
!=
nil
{
return
types
.
ErrInvalidAddress
}
if
NewWeight
<=
0
{
return
mty
.
ErrInvalidWeight
}
}
if
ato
.
OperateFlag
==
mty
.
OwnerDel
{
if
err
:=
address
.
CheckAddress
(
OldOwner
);
err
!=
nil
{
return
types
.
ErrInvalidAddress
}
}
if
ato
.
OperateFlag
==
mty
.
OwnerModify
{
if
err
:=
address
.
CheckAddress
(
OldOwner
);
err
!=
nil
{
return
types
.
ErrInvalidAddress
}
if
NewWeight
<=
0
{
return
mty
.
ErrInvalidWeight
}
}
if
ato
.
OperateFlag
==
mty
.
OwnerReplace
{
if
err
:=
address
.
CheckAddress
(
OldOwner
);
err
!=
nil
{
return
types
.
ErrInvalidAddress
}
if
err
:=
address
.
CheckAddress
(
NewOwner
);
err
!=
nil
{
return
types
.
ErrInvalidAddress
}
}
return
nil
}
func
checkAccountOperateTx
(
ato
*
mty
.
MultiSigAccOperate
)
error
{
//MultiSigAccOperate to 地址检测
MultiSigAccAddr
:=
ato
.
GetMultiSigAccAddr
()
if
err
:=
address
.
CheckAddress
(
MultiSigAccAddr
);
err
!=
nil
{
return
types
.
ErrInvalidAddress
}
if
ato
.
OperateFlag
==
mty
.
AccWeightOp
{
NewWeight
:=
ato
.
GetNewRequiredWeight
()
if
NewWeight
<=
0
{
return
mty
.
ErrInvalidWeight
}
}
if
ato
.
OperateFlag
==
mty
.
AccDailyLimitOp
{
dailyLimit
:=
ato
.
GetDailyLimit
()
//assets check
if
err
:=
mty
.
IsAssetsInvalid
(
dailyLimit
.
GetExecer
(),
dailyLimit
.
GetSymbol
());
err
!=
nil
{
return
err
}
}
return
nil
return
nil
}
}
...
...
plugin/dapp/multisig/types/errors.go
View file @
da0637cd
...
@@ -38,4 +38,5 @@ var (
...
@@ -38,4 +38,5 @@ var (
ErrMaxOwnerCount
=
errors
.
New
(
"ErrMaxOwnerCount"
)
ErrMaxOwnerCount
=
errors
.
New
(
"ErrMaxOwnerCount"
)
ErrInvalidSymbol
=
errors
.
New
(
"ErrInvalidSymbol"
)
ErrInvalidSymbol
=
errors
.
New
(
"ErrInvalidSymbol"
)
ErrInvalidExec
=
errors
.
New
(
"ErrInvalidExec"
)
ErrInvalidExec
=
errors
.
New
(
"ErrInvalidExec"
)
ErrInvalidWeight
=
errors
.
New
(
"ErrInvalidWeight"
)
)
)
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