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
37950a05
Commit
37950a05
authored
Jul 25, 2019
by
jiangpeng
Committed by
33cn
Jul 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
privacy:remove rpc createUtxos
parent
6a6fefbe
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
2 additions
and
244 deletions
+2
-244
createutxosCase.go
plugin/dapp/privacy/autotest/createutxosCase.go
+1
-0
privacy.toml
plugin/dapp/privacy/autotest/privacy.toml
+0
-24
privacy.go
plugin/dapp/privacy/commands/privacy.go
+0
-53
privacy.proto
plugin/dapp/privacy/proto/privacy.proto
+0
-14
rpc.go
plugin/dapp/privacy/rpc/rpc.go
+0
-21
rpc_channel_test.go
plugin/dapp/privacy/rpc/rpc_channel_test.go
+1
-19
privacy.pb.go
plugin/dapp/privacy/types/privacy.pb.go
+0
-0
exec.go
plugin/dapp/privacy/wallet/exec.go
+0
-10
privacy.go
plugin/dapp/privacy/wallet/privacy.go
+0
-71
privacybizpolicy_test.go
plugin/dapp/privacy/wallet/privacybizpolicy_test.go
+0
-32
No files found.
plugin/dapp/privacy/autotest/createutxosCase.go
View file @
37950a05
...
...
@@ -11,6 +11,7 @@ import (
)
//CreateUtxosCase pub2priv case
//Deprecated:已经删除CreateUtxo功能, 用pub2priv替代
type
CreateUtxosCase
struct
{
types
.
BaseCase
From
string
`toml:"from"`
...
...
plugin/dapp/privacy/autotest/privacy.toml
View file @
37950a05
...
...
@@ -213,27 +213,3 @@ amount = "3"
checkItem
=
[
"balance"
,
"utxo"
]
dep
=
["priv2pub2"]
fail
=
true
#createutxosCase
[[CreateutxosCase]]
id
=
"privCreateutxos"
command
=
"privacy createutxos -a 20 -f 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -p 0a9d212b2505aefaa8da370319088bbccfac097b007f52ed71d8133456c8185823c8eac43c5e937953d7b6c8e68b0db1f4f03df4946a29f524875118960a35fb"
from
=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
to
=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
amount
=
"20"
checkItem
=
[
"balance"
,
"utxo"
]
dep
=
["trans1"]
#failcreateutxosCase
[[CreateutxosCase]]
id
=
"failprivCreateutxos"
command
=
"privacy createutxos -a 1000 -f 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -p 0a9d212b2505aefaa8da370319088bbccfac097b007f52ed71d8133456c8185823c8eac43c5e937953d7b6c8e68b0db1f4f03df4946a29f524875118960a35fb"
from
=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
to
=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
amount
=
"1000"
checkItem
=
[
"balance"
,
"utxo"
]
dep
=
["trans1"]
fail
=
true
plugin/dapp/privacy/commands/privacy.go
View file @
37950a05
...
...
@@ -41,7 +41,6 @@ func PrivacyCmd() *cobra.Command {
createPriv2PubTxCmd
(),
showAmountsOfUTXOCmd
(),
showUTXOs4SpecifiedAmountCmd
(),
createUTXOsCmd
(),
showPrivacyAccountInfoCmd
(),
listPrivacyTxsCmd
(),
rescanUtxosOptCmd
(),
...
...
@@ -431,58 +430,6 @@ func parseShowUTXOs4SpecifiedAmountRes(arg interface{}) (interface{}, error) {
return
ret
,
nil
}
func
createUTXOsCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"createutxos"
,
Short
:
"Create specified count UTXOs with specified amount"
,
Run
:
createUTXOs
,
}
createUTXOsFlag
(
cmd
)
return
cmd
}
func
createUTXOsFlag
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"from"
,
"f"
,
""
,
"from account address"
)
cmd
.
MarkFlagRequired
(
"from"
)
cmd
.
Flags
()
.
StringP
(
"pubkeypair"
,
"p"
,
""
,
"to view spend public key pair"
)
cmd
.
MarkFlagRequired
(
"pubkeypair"
)
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"a"
,
0
,
"amount"
)
cmd
.
MarkFlagRequired
(
"amount"
)
cmd
.
Flags
()
.
StringP
(
"symbol"
,
"s"
,
"BTY"
,
"asset symbol, default BTY"
)
cmd
.
Flags
()
.
StringP
(
"exec"
,
"e"
,
"coins"
,
"asset executor(coins, token, paracross), default coins"
)
cmd
.
Flags
()
.
StringP
(
"note"
,
"n"
,
""
,
"transfer note"
)
cmd
.
Flags
()
.
Int64P
(
"expire"
,
"x"
,
0
,
"transfer expire, default one hour"
)
}
func
createUTXOs
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
from
,
_
:=
cmd
.
Flags
()
.
GetString
(
"from"
)
pubkeypair
,
_
:=
cmd
.
Flags
()
.
GetString
(
"pubkeypair"
)
note
,
_
:=
cmd
.
Flags
()
.
GetString
(
"note"
)
amount
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"amount"
)
amountInt64
:=
int64
(
amount
*
types
.
InputPrecision
)
*
types
.
Multiple1E4
expire
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"expire"
)
symbol
,
_
:=
cmd
.
Flags
()
.
GetString
(
"symbol"
)
assetExec
,
_
:=
cmd
.
Flags
()
.
GetString
(
"exec"
)
if
expire
<=
0
{
expire
=
int64
(
time
.
Minute
*
10
)
}
params
:=
&
pty
.
ReqCreateUTXOs
{
Tokenname
:
symbol
,
Sender
:
from
,
Pubkeypair
:
pubkeypair
,
Amount
:
amountInt64
,
Note
:
note
,
Expire
:
expire
,
AssetExec
:
assetExec
,
}
var
res
rpctypes
.
ReplyHash
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"privacy.CreateUTXOs"
,
params
,
&
res
)
ctx
.
Run
()
}
// showPrivacyAccountInfoCmd
func
showPrivacyAccountInfoCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
...
...
plugin/dapp/privacy/proto/privacy.proto
View file @
37950a05
...
...
@@ -196,18 +196,6 @@ message PrivacyAction4Print {
int32
ty
=
4
;
}
message
ReqCreateUTXOs
{
// string viewPublic = 1; //接收人可见公钥A
// string spendPublic = 2; //接收人花费公钥B
string
tokenname
=
3
;
int64
amount
=
4
;
string
note
=
5
;
string
sender
=
6
;
//发送人地址
string
pubkeypair
=
8
;
int64
expire
=
9
;
string
assetExec
=
10
;
}
message
ReplyPrivacyPkPair
{
bool
showSuccessful
=
1
;
// string viewPub = 2;
...
...
@@ -435,8 +423,6 @@ service privacy {
// Privacy Trading
// 显示指定地址的公钥对信息,可以作为后续交易参数
rpc
ShowPrivacyKey
(
ReqString
)
returns
(
ReplyPrivacyPkPair
)
{}
// 创建一系列UTXO
rpc
CreateUTXOs
(
ReqCreateUTXOs
)
returns
(
Reply
)
{}
// 扫描UTXO以及获取扫描UTXO后的状态
rpc
RescanUtxos
(
ReqRescanUtxos
)
returns
(
RepRescanUtxos
)
{}
// 使能隐私账户
...
...
plugin/dapp/privacy/rpc/rpc.go
View file @
37950a05
...
...
@@ -8,7 +8,6 @@ import (
"encoding/hex"
"encoding/json"
"github.com/33cn/chain33/common"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/privacy/types"
...
...
@@ -24,15 +23,6 @@ func (g *channelClient) ShowPrivacyKey(ctx context.Context, in *types.ReqString)
return
data
.
(
*
pty
.
ReplyPrivacyPkPair
),
nil
}
// 创建一系列UTXO
func
(
g
*
channelClient
)
CreateUTXOs
(
ctx
context
.
Context
,
in
*
pty
.
ReqCreateUTXOs
)
(
*
types
.
Reply
,
error
)
{
data
,
err
:=
g
.
ExecWalletFunc
(
pty
.
PrivacyX
,
"CreateUTXOs"
,
in
)
if
err
!=
nil
{
return
nil
,
err
}
return
data
.
(
*
types
.
Reply
),
nil
}
// 扫描UTXO以及获取扫描UTXO后的状态
func
(
g
*
channelClient
)
RescanUtxos
(
ctx
context
.
Context
,
in
*
pty
.
ReqRescanUtxos
)
(
*
pty
.
RepRescanUtxos
,
error
)
{
data
,
err
:=
g
.
ExecWalletFunc
(
pty
.
PrivacyX
,
"RescanUtxos"
,
in
)
...
...
@@ -95,17 +85,6 @@ func (c *Jrpc) ShowPrivacyKey(in *types.ReqString, result *json.RawMessage) erro
return
err
}
// CreateUTXOs create utxos for json rpc
func
(
c
*
Jrpc
)
CreateUTXOs
(
in
*
pty
.
ReqCreateUTXOs
,
result
*
interface
{})
error
{
reply
,
err
:=
c
.
cli
.
CreateUTXOs
(
context
.
Background
(),
in
)
if
err
!=
nil
{
return
err
}
*
result
=
rpctypes
.
ReplyHash
{
Hash
:
common
.
ToHex
(
reply
.
GetMsg
())}
return
nil
}
// GetPrivacyTxByAddr get all privacy transaction list by param
func
(
c
*
Jrpc
)
GetPrivacyTxByAddr
(
in
*
pty
.
ReqPrivacyTransactionList
,
result
*
interface
{})
error
{
if
in
.
Direction
!=
0
&&
in
.
Direction
!=
1
{
...
...
plugin/dapp/privacy/rpc/rpc_channel_test.go
View file @
37950a05
...
...
@@ -8,7 +8,6 @@ import (
"fmt"
"strings"
"testing"
"time"
commonlog
"github.com/33cn/chain33/common/log"
"github.com/33cn/chain33/rpc/jsonclient"
...
...
@@ -47,7 +46,6 @@ func TestRPCChannel(t *testing.T) {
{
fn
:
testShowPrivacyAccountSpend
},
{
fn
:
testShowAmountsOfUTXO
},
{
fn
:
testShowUTXOs4SpecifiedAmount
},
{
fn
:
testCreateUTXOs
},
{
fn
:
testListPrivacyTxs
},
{
fn
:
testRescanUtxosOpt
},
{
fn
:
testEnablePrivacy
},
...
...
@@ -121,22 +119,6 @@ func testShowUTXOs4SpecifiedAmount(t *testing.T, jrpc *jsonclient.JSONClient) er
return
err
}
func
testCreateUTXOs
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
params
:=
&
pty
.
ReqCreateUTXOs
{
AssetExec
:
"coins"
,
Tokenname
:
types
.
BTY
,
Sender
:
"1JSRSwp16NvXiTjYBYK9iUQ9wqp3sCxz2p"
,
Pubkeypair
:
"92fe6cfec2e19cd15f203f83b5d440ddb63d0cb71559f96dc81208d819fea85886b08f6e874fca15108d244b40f9086d8c03260d4b954a40dfb3cbe41ebc7389"
,
Amount
:
123456
,
Note
:
"for test"
,
Expire
:
int64
(
time
.
Hour
),
}
var
res
rpctypes
.
ReplyHash
err
:=
jrpc
.
Call
(
"privacy.CreateUTXOs"
,
params
,
&
res
)
return
err
}
func
testListPrivacyTxs
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
params
:=
pty
.
ReqPrivacyTransactionList
{
Tokenname
:
types
.
BTY
,
...
...
@@ -147,7 +129,7 @@ func testListPrivacyTxs(t *testing.T, jrpc *jsonclient.JSONClient) error {
Seedtxhash
:
[]
byte
(
"0xa64296792f90f364371e0b66fdac622080ceb7b2537ff9152e189aa9e88e61bd"
),
}
var
res
rpctypes
.
WalletTxDetails
err
:=
jrpc
.
Call
(
"privacy.
CreateUTXOs
"
,
params
,
&
res
)
err
:=
jrpc
.
Call
(
"privacy.
GetPrivacyTxByAddr
"
,
params
,
&
res
)
return
err
}
...
...
plugin/dapp/privacy/types/privacy.pb.go
View file @
37950a05
This diff is collapsed.
Click to expand it.
plugin/dapp/privacy/wallet/exec.go
View file @
37950a05
...
...
@@ -29,16 +29,6 @@ func (policy *privacyPolicy) On_ShowPrivacyKey(req *types.ReqString) (types.Mess
return
reply
,
err
}
func
(
policy
*
privacyPolicy
)
On_CreateUTXOs
(
req
*
privacytypes
.
ReqCreateUTXOs
)
(
types
.
Message
,
error
)
{
policy
.
getWalletOperate
()
.
GetMutex
()
.
Lock
()
defer
policy
.
getWalletOperate
()
.
GetMutex
()
.
Unlock
()
reply
,
err
:=
policy
.
createUTXOs
(
req
)
if
err
!=
nil
{
bizlog
.
Error
(
"createUTXOs"
,
"err"
,
err
.
Error
())
}
return
reply
,
err
}
func
(
policy
*
privacyPolicy
)
On_CreateTransaction
(
req
*
privacytypes
.
ReqCreatePrivacyTx
)
(
types
.
Message
,
error
)
{
ok
,
err
:=
policy
.
getWalletOperate
()
.
CheckWalletStatus
()
if
!
ok
{
...
...
plugin/dapp/privacy/wallet/privacy.go
View file @
37950a05
...
...
@@ -105,29 +105,6 @@ func (policy *privacyPolicy) isRescanUtxosFlagScaning() (bool, error) {
return
false
,
nil
}
func
(
policy
*
privacyPolicy
)
createUTXOs
(
createUTXOs
*
privacytypes
.
ReqCreateUTXOs
)
(
*
types
.
Reply
,
error
)
{
ok
,
err
:=
policy
.
getWalletOperate
()
.
CheckWalletStatus
()
if
!
ok
{
return
nil
,
err
}
if
ok
,
err
:=
policy
.
isRescanUtxosFlagScaning
();
ok
{
return
nil
,
err
}
if
createUTXOs
==
nil
{
bizlog
.
Error
(
"createUTXOs input para is nil"
)
return
nil
,
types
.
ErrInvalidParam
}
if
!
checkAmountValid
(
createUTXOs
.
GetAmount
())
{
bizlog
.
Error
(
"not allow amount number"
)
return
nil
,
types
.
ErrAmount
}
priv
,
err
:=
policy
.
getPrivKeyByAddr
(
createUTXOs
.
GetSender
())
if
err
!=
nil
{
return
nil
,
err
}
return
policy
.
createUTXOsByPub2Priv
(
priv
,
createUTXOs
)
}
func
(
policy
*
privacyPolicy
)
parseViewSpendPubKeyPair
(
in
string
)
(
viewPubKey
,
spendPubKey
[]
byte
,
err
error
)
{
src
,
err
:=
common
.
FromHex
(
in
)
if
err
!=
nil
{
...
...
@@ -142,54 +119,6 @@ func (policy *privacyPolicy) parseViewSpendPubKeyPair(in string) (viewPubKey, sp
return
}
//批量创建通过public2Privacy实现
func
(
policy
*
privacyPolicy
)
createUTXOsByPub2Priv
(
priv
crypto
.
PrivKey
,
reqCreateUTXOs
*
privacytypes
.
ReqCreateUTXOs
)
(
*
types
.
Reply
,
error
)
{
viewPubSlice
,
spendPubSlice
,
err
:=
parseViewSpendPubKeyPair
(
reqCreateUTXOs
.
GetPubkeypair
())
if
err
!=
nil
{
bizlog
.
Error
(
"createUTXOsByPub2Priv"
,
"parseViewSpendPubKeyPair error."
,
err
)
return
nil
,
err
}
operater
:=
policy
.
getWalletOperate
()
viewPublic
:=
(
*
[
32
]
byte
)(
unsafe
.
Pointer
(
&
viewPubSlice
[
0
]))
spendPublic
:=
(
*
[
32
]
byte
)(
unsafe
.
Pointer
(
&
spendPubSlice
[
0
]))
//因为此时是pub2priv的交易,此时不需要构造找零的输出,同时设置fee为0,也是为了简化计算
privacyOutput
,
err
:=
generateOuts
(
viewPublic
,
spendPublic
,
nil
,
nil
,
reqCreateUTXOs
.
Amount
,
reqCreateUTXOs
.
Amount
,
0
)
if
err
!=
nil
{
bizlog
.
Error
(
"createUTXOsByPub2Priv"
,
"genCustomOuts error."
,
err
)
return
nil
,
err
}
value
:=
&
privacytypes
.
Public2Privacy
{
Tokenname
:
reqCreateUTXOs
.
Tokenname
,
Amount
:
reqCreateUTXOs
.
Amount
,
Note
:
reqCreateUTXOs
.
Note
,
Output
:
privacyOutput
,
AssetExec
:
reqCreateUTXOs
.
AssetExec
,
}
action
:=
&
privacytypes
.
PrivacyAction
{
Ty
:
privacytypes
.
ActionPublic2Privacy
,
Value
:
&
privacytypes
.
PrivacyAction_Public2Privacy
{
Public2Privacy
:
value
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
privacytypes
.
PrivacyX
)),
Payload
:
types
.
Encode
(
action
),
Nonce
:
operater
.
Nonce
(),
To
:
address
.
ExecAddress
(
privacytypes
.
PrivacyX
),
}
txSize
:=
types
.
Size
(
tx
)
+
types
.
SignatureSize
realFee
:=
int64
((
txSize
+
1023
)
>>
types
.
Size1Kshiftlen
)
*
types
.
GInt
(
"MinFee"
)
tx
.
Fee
=
realFee
tx
.
Sign
(
int32
(
operater
.
GetSignType
()),
priv
)
reply
,
err
:=
operater
.
GetAPI
()
.
SendTx
(
tx
)
if
err
!=
nil
{
bizlog
.
Error
(
"transPub2PriV2"
,
"Send err"
,
err
)
return
nil
,
err
}
return
reply
,
nil
}
func
(
policy
*
privacyPolicy
)
getPrivKeyByAddr
(
addr
string
)
(
crypto
.
PrivKey
,
error
)
{
//获取指定地址在钱包里的账户信息
Accountstor
,
err
:=
policy
.
store
.
getAccountByAddr
(
addr
)
...
...
plugin/dapp/privacy/wallet/privacybizpolicy_test.go
View file @
37950a05
...
...
@@ -328,38 +328,6 @@ func Test_ShowPrivacyKey(t *testing.T) {
}
}
func
Test_CreateUTXOs
(
t
*
testing
.
T
)
{
mock
:=
&
testDataMock
{
mockMempool
:
true
}
mock
.
init
()
mock
.
enablePrivacy
()
testCases
:=
[]
struct
{
req
*
ty
.
ReqCreateUTXOs
needReply
*
types
.
Reply
needError
error
}{
{
needError
:
types
.
ErrInvalidParam
,
},
{
req
:
&
ty
.
ReqCreateUTXOs
{
AssetExec
:
"coins"
,
Tokenname
:
types
.
BTY
,
Amount
:
10
*
types
.
Coin
,
Note
:
"say something"
,
Sender
:
testAddrs
[
0
],
Pubkeypair
:
testPubkeyPairs
[
0
],
},
needError
:
types
.
ErrAddrNotExist
,
},
}
for
index
,
testCase
:=
range
testCases
{
_
,
getErr
:=
mock
.
wallet
.
GetAPI
()
.
ExecWalletFunc
(
ty
.
PrivacyX
,
"CreateUTXOs"
,
testCase
.
req
)
require
.
Equalf
(
t
,
getErr
,
testCase
.
needError
,
"CreateUTXOs test case index %d"
,
index
)
}
}
func
Test_CreateTransaction
(
t
*
testing
.
T
)
{
mock
:=
&
testDataMock
{
mockMempool
:
true
,
...
...
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