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
2c40966f
Commit
2c40966f
authored
Jan 22, 2019
by
jiangpeng
Committed by
vipwzw
Jan 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adapting parachain privacy
parent
bd063a54
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
17 additions
and
201 deletions
+17
-201
ring_signature_crypto.go
plugin/dapp/privacy/crypto/ring_signature_crypto.go
+2
-1
exec.go
plugin/dapp/privacy/executor/exec.go
+1
-1
privacy.go
plugin/dapp/privacy/executor/privacy.go
+13
-9
privacy.proto
plugin/dapp/privacy/proto/privacy.proto
+1
-49
privacy.pb.go
plugin/dapp/privacy/types/privacy.pb.go
+0
-0
exec.go
plugin/dapp/privacy/wallet/exec.go
+0
-30
privacy.go
plugin/dapp/privacy/wallet/privacy.go
+0
-0
privacybizpolicy_test.go
plugin/dapp/privacy/wallet/privacybizpolicy_test.go
+0
-111
No files found.
plugin/dapp/privacy/crypto/ring_signature_crypto.go
View file @
2c40966f
...
...
@@ -22,6 +22,7 @@ import (
func
init
()
{
crypto
.
Register
(
privacytypes
.
SignNameRing
,
&
RingSignED25519
{})
crypto
.
RegisterType
(
privacytypes
.
SignNameRing
,
privacytypes
.
RingBaseonED25519
)
}
// RingSignature 环签名中对于crypto.Signature接口实现
...
...
@@ -156,7 +157,7 @@ func (pubkey *RingSignPublicKey) VerifyBytes(msg []byte, sign crypto.Signature)
return
false
}
tx
:=
new
(
types
.
Transaction
)
if
err
:=
types
.
Decode
(
msg
,
tx
);
err
!=
nil
||
!
bytes
.
Equal
([]
byte
(
privacytypes
.
PrivacyX
),
t
x
.
Execer
)
{
if
err
:=
types
.
Decode
(
msg
,
tx
);
err
!=
nil
||
!
bytes
.
Equal
([]
byte
(
privacytypes
.
PrivacyX
),
t
ypes
.
GetRealExecName
(
tx
.
Execer
)
)
{
// 目前只有隐私交易用到了环签名
return
false
}
...
...
plugin/dapp/privacy/executor/exec.go
View file @
2c40966f
...
...
@@ -102,7 +102,7 @@ func (p *privacy) Exec_Privacy2Public(payload *ty.Privacy2Public, tx *types.Tran
}
txhashstr
:=
hex
.
EncodeToString
(
tx
.
Hash
())
coinsAccount
:=
p
.
GetCoinsAccount
()
receipt
,
err
:=
coinsAccount
.
ExecDeposit
(
tx
.
To
,
address
.
ExecAddress
(
string
(
tx
.
Execer
)),
payload
.
Amount
)
receipt
,
err
:=
coinsAccount
.
ExecDeposit
(
payload
.
To
,
address
.
ExecAddress
(
string
(
tx
.
Execer
)),
payload
.
Amount
)
if
err
!=
nil
{
privacylog
.
Error
(
"PrivacyTrading Exec"
,
"ActionPrivacy2Public txhash"
,
txhashstr
,
"ExecDeposit error "
,
err
)
return
nil
,
err
...
...
plugin/dapp/privacy/executor/privacy.go
View file @
2c40966f
...
...
@@ -273,16 +273,20 @@ func (p *privacy) CheckTx(tx *types.Transaction, index int) error {
totalOutput
+=
output
.
Amount
}
var
feeAmount
int64
if
action
.
Ty
==
pty
.
ActionPrivacy2Privacy
{
feeAmount
=
totalInput
-
totalOutput
}
else
{
feeAmount
=
totalInput
-
totalOutput
-
amount
}
//平行链下的隐私交易,utxo不需要燃烧,fee只收取主链的bty,和utxo无关联
if
!
types
.
IsPara
()
{
var
feeAmount
int64
if
action
.
Ty
==
pty
.
ActionPrivacy2Privacy
{
feeAmount
=
totalInput
-
totalOutput
}
else
{
feeAmount
=
totalInput
-
totalOutput
-
amount
}
if
feeAmount
<
pty
.
PrivacyTxFee
{
privacylog
.
Error
(
"PrivacyTrading CheckTx"
,
"txhash"
,
txhashstr
,
"fee available:"
,
feeAmount
,
"required:"
,
pty
.
PrivacyTxFee
)
return
pty
.
ErrPrivacyTxFeeNotEnough
if
feeAmount
<
pty
.
PrivacyTxFee
{
privacylog
.
Error
(
"PrivacyTrading CheckTx"
,
"txhash"
,
txhashstr
,
"fee available:"
,
feeAmount
,
"required:"
,
pty
.
PrivacyTxFee
)
return
pty
.
ErrPrivacyTxFeeNotEnough
}
}
return
nil
}
...
...
plugin/dapp/privacy/proto/privacy.proto
View file @
2c40966f
...
...
@@ -38,6 +38,7 @@ message Privacy2Public {
string
tokenname
=
1
;
int64
amount
=
2
;
string
note
=
3
;
string
to
=
6
;
PrivacyInput
input
=
4
;
PrivacyOutput
output
=
5
;
}
...
...
@@ -193,49 +194,6 @@ message PrivacyAction4Print {
int32
ty
=
4
;
}
message
ReqPub2Pri
{
//接收人可见公钥A
// string viewPublic = 1;
//接收人花费公钥B
// string spendPublic = 2;
string
tokenname
=
3
;
int64
amount
=
4
;
string
note
=
5
;
//发送人地址
string
sender
=
6
;
int32
mixin
=
7
;
string
pubkeypair
=
8
;
int64
expire
=
9
;
}
message
ReqPri2Pri
{
//接收人可见公钥A
// string viewPublic = 1; //A
//接收人花费公钥B
// string spendPublic = 2; //B
string
tokenname
=
3
;
int64
amount
=
4
;
string
note
=
5
;
//隐私交易发起人地址
string
sender
=
6
;
int32
mixin
=
7
;
// string txhash = 7;
string
pubkeypair
=
8
;
int64
expire
=
9
;
}
message
ReqPri2Pub
{
string
receiver
=
1
;
string
tokenname
=
2
;
int64
amount
=
3
;
string
note
=
4
;
//隐私交易发起人地址
string
sender
=
5
;
int32
mixin
=
6
;
// string txhash = 6;
int64
expire
=
7
;
}
message
ReqCreateUTXOs
{
// string viewPublic = 1; //接收人可见公钥A
// string spendPublic = 2; //接收人花费公钥B
...
...
@@ -456,12 +414,6 @@ service privacy {
rpc
ShowPrivacyKey
(
ReqString
)
returns
(
ReplyPrivacyPkPair
)
{}
// 创建一系列UTXO
rpc
CreateUTXOs
(
ReqCreateUTXOs
)
returns
(
Reply
)
{}
// 将资金从公开到隐私转移
rpc
MakeTxPublic2Privacy
(
ReqPub2Pri
)
returns
(
Reply
)
{}
// 将资产从隐私到隐私进行转移
rpc
MakeTxPrivacy2Privacy
(
ReqPri2Pri
)
returns
(
Reply
)
{}
// 将资产从隐私到公开进行转移
rpc
MakeTxPrivacy2Public
(
ReqPri2Pub
)
returns
(
Reply
)
{}
// 扫描UTXO以及获取扫描UTXO后的状态
rpc
RescanUtxos
(
ReqRescanUtxos
)
returns
(
RepRescanUtxos
)
{}
// 使能隐私账户
...
...
plugin/dapp/privacy/types/privacy.pb.go
View file @
2c40966f
This diff is collapsed.
Click to expand it.
plugin/dapp/privacy/wallet/exec.go
View file @
2c40966f
...
...
@@ -29,36 +29,6 @@ func (policy *privacyPolicy) On_ShowPrivacyKey(req *types.ReqString) (types.Mess
return
reply
,
err
}
func
(
policy
*
privacyPolicy
)
On_Public2Privacy
(
req
*
privacytypes
.
ReqPub2Pri
)
(
types
.
Message
,
error
)
{
policy
.
getWalletOperate
()
.
GetMutex
()
.
Lock
()
defer
policy
.
getWalletOperate
()
.
GetMutex
()
.
Unlock
()
reply
,
err
:=
policy
.
sendPublic2PrivacyTransaction
(
req
)
if
err
!=
nil
{
bizlog
.
Error
(
"sendPublic2PrivacyTransaction"
,
"err"
,
err
.
Error
())
}
return
reply
,
err
}
func
(
policy
*
privacyPolicy
)
On_Privacy2Privacy
(
req
*
privacytypes
.
ReqPri2Pri
)
(
types
.
Message
,
error
)
{
policy
.
getWalletOperate
()
.
GetMutex
()
.
Lock
()
defer
policy
.
getWalletOperate
()
.
GetMutex
()
.
Unlock
()
reply
,
err
:=
policy
.
sendPrivacy2PrivacyTransaction
(
req
)
if
err
!=
nil
{
bizlog
.
Error
(
"sendPrivacy2PrivacyTransaction"
,
"err"
,
err
.
Error
())
}
return
reply
,
err
}
func
(
policy
*
privacyPolicy
)
On_Privacy2Public
(
req
*
privacytypes
.
ReqPri2Pub
)
(
types
.
Message
,
error
)
{
policy
.
getWalletOperate
()
.
GetMutex
()
.
Lock
()
defer
policy
.
getWalletOperate
()
.
GetMutex
()
.
Unlock
()
reply
,
err
:=
policy
.
sendPrivacy2PublicTransaction
(
req
)
if
err
!=
nil
{
bizlog
.
Error
(
"sendPrivacy2PublicTransaction"
,
"err"
,
err
.
Error
())
}
return
reply
,
err
}
func
(
policy
*
privacyPolicy
)
On_CreateUTXOs
(
req
*
privacytypes
.
ReqCreateUTXOs
)
(
types
.
Message
,
error
)
{
policy
.
getWalletOperate
()
.
GetMutex
()
.
Lock
()
defer
policy
.
getWalletOperate
()
.
GetMutex
()
.
Unlock
()
...
...
plugin/dapp/privacy/wallet/privacy.go
View file @
2c40966f
This diff is collapsed.
Click to expand it.
plugin/dapp/privacy/wallet/privacybizpolicy_test.go
View file @
2c40966f
...
...
@@ -360,117 +360,6 @@ func Test_CreateUTXOs(t *testing.T) {
}
}
func
Test_SendPublic2PrivacyTransaction
(
t
*
testing
.
T
)
{
mock
:=
&
testDataMock
{
mockMempool
:
true
}
mock
.
init
()
mock
.
enablePrivacy
()
testCases
:=
[]
struct
{
req
*
ty
.
ReqPub2Pri
needReply
*
types
.
Reply
needError
error
}{
{
needError
:
types
.
ErrInvalidParam
,
},
{
req
:
&
ty
.
ReqPub2Pri
{
Tokenname
:
types
.
BTY
,
Amount
:
10
*
types
.
Coin
,
Sender
:
testAddrs
[
0
],
Pubkeypair
:
testPubkeyPairs
[
0
],
},
needReply
:
&
types
.
Reply
{
IsOk
:
true
},
needError
:
types
.
ErrAddrNotExist
,
},
}
for
index
,
testCase
:=
range
testCases
{
_
,
getErr
:=
mock
.
wallet
.
GetAPI
()
.
ExecWalletFunc
(
ty
.
PrivacyX
,
"Public2Privacy"
,
testCase
.
req
)
require
.
Equalf
(
t
,
getErr
,
testCase
.
needError
,
"Publick2Privacy test case index %d"
,
index
)
}
}
func
Test_SendPrivacy2PrivacyTransaction
(
t
*
testing
.
T
)
{
mock
:=
&
testDataMock
{
mockMempool
:
true
,
mockBlockChain
:
true
,
}
mock
.
init
()
mock
.
enablePrivacy
()
// 创建辅助对象
privacyMock
:=
privacy
.
PrivacyMock
{}
privacyMock
.
Init
(
mock
.
wallet
,
mock
.
password
)
// 创建几条可用UTXO
privacyMock
.
CreateUTXOs
(
testAddrs
[
0
],
testPubkeyPairs
[
0
],
17
*
types
.
Coin
,
10000
,
5
)
mock
.
setBlockChainHeight
(
10020
)
testCases
:=
[]
struct
{
req
*
ty
.
ReqPri2Pri
needReply
*
types
.
Reply
needError
error
}{
{
needError
:
types
.
ErrInvalidParam
,
},
{
req
:
&
ty
.
ReqPri2Pri
{
Tokenname
:
types
.
BTY
,
Amount
:
10
*
types
.
Coin
,
Sender
:
testAddrs
[
0
],
Pubkeypair
:
testPubkeyPairs
[
1
],
},
needReply
:
&
types
.
Reply
{
IsOk
:
true
},
needError
:
types
.
ErrAddrNotExist
,
},
}
for
index
,
testCase
:=
range
testCases
{
_
,
getErr
:=
mock
.
wallet
.
GetAPI
()
.
ExecWalletFunc
(
ty
.
PrivacyX
,
"Privacy2Privacy"
,
testCase
.
req
)
require
.
Equalf
(
t
,
getErr
,
testCase
.
needError
,
"Privacy2Privacy test case index %d"
,
index
)
}
}
func
Test_SendPrivacy2PublicTransaction
(
t
*
testing
.
T
)
{
mock
:=
&
testDataMock
{
mockMempool
:
true
,
mockBlockChain
:
true
,
}
mock
.
init
()
mock
.
enablePrivacy
()
// 创建辅助对象
privacyMock
:=
privacy
.
PrivacyMock
{}
privacyMock
.
Init
(
mock
.
wallet
,
mock
.
password
)
// 创建几条可用UTXO
privacyMock
.
CreateUTXOs
(
testAddrs
[
0
],
testPubkeyPairs
[
0
],
17
*
types
.
Coin
,
10000
,
5
)
mock
.
setBlockChainHeight
(
10020
)
testCases
:=
[]
struct
{
req
*
ty
.
ReqPri2Pub
needReply
*
types
.
Reply
needError
error
}{
{
needError
:
types
.
ErrInvalidParam
,
},
{
req
:
&
ty
.
ReqPri2Pub
{
Tokenname
:
types
.
BTY
,
Amount
:
10
*
types
.
Coin
,
Sender
:
testAddrs
[
0
],
Receiver
:
testAddrs
[
0
],
},
needReply
:
&
types
.
Reply
{
IsOk
:
true
},
needError
:
types
.
ErrAddrNotExist
,
},
}
for
index
,
testCase
:=
range
testCases
{
_
,
getErr
:=
mock
.
wallet
.
GetAPI
()
.
ExecWalletFunc
(
ty
.
PrivacyX
,
"Privacy2Public"
,
testCase
.
req
)
require
.
Equalf
(
t
,
getErr
,
testCase
.
needError
,
"Privacy2Public 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