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
6a6fefbe
Commit
6a6fefbe
authored
Jul 25, 2019
by
jiangpeng
Committed by
33cn
Jul 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
privacy:add asset support
parent
a17b2960
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
116 additions
and
51 deletions
+116
-51
privacy.go
plugin/dapp/privacy/commands/privacy.go
+26
-15
exec.go
plugin/dapp/privacy/executor/exec.go
+23
-11
privacy.go
plugin/dapp/privacy/executor/privacy.go
+10
-6
privacy.proto
plugin/dapp/privacy/proto/privacy.proto
+5
-1
rpc_channel_test.go
plugin/dapp/privacy/rpc/rpc_channel_test.go
+1
-1
privacy.go
plugin/dapp/privacy/types/privacy.go
+12
-0
privacy.pb.go
plugin/dapp/privacy/types/privacy.pb.go
+0
-0
exec.go
plugin/dapp/privacy/wallet/exec.go
+12
-0
privacy.go
plugin/dapp/privacy/wallet/privacy.go
+22
-16
privacy_test.go
plugin/dapp/privacy/wallet/privacy_test.go
+1
-0
privacybizpolicy_test.go
plugin/dapp/privacy/wallet/privacybizpolicy_test.go
+4
-1
No files found.
plugin/dapp/privacy/commands/privacy.go
View file @
6a6fefbe
...
...
@@ -96,9 +96,10 @@ func createPub2PrivTxFlags(cmd *cobra.Command) {
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"a"
,
0.0
,
"transfer amount, at most 4 decimal places"
)
cmd
.
MarkFlagRequired
(
"amount"
)
cmd
.
Flags
()
.
StringP
(
"symbol"
,
"s"
,
"BTY"
,
"token symbol"
)
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"
,
""
,
"note for transaction"
)
cmd
.
Flags
()
.
Int64P
(
"expire"
,
""
,
0
,
"transfer expire, default one hour"
)
cmd
.
Flags
()
.
Int64P
(
"expire"
,
"
x
"
,
0
,
"transfer expire, default one hour"
)
cmd
.
Flags
()
.
IntP
(
"expiretype"
,
""
,
1
,
"0: height 1: time default is 1"
)
}
...
...
@@ -110,6 +111,7 @@ func createPub2PrivTx(cmd *cobra.Command, args []string) {
note
,
_
:=
cmd
.
Flags
()
.
GetString
(
"note"
)
expire
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"expire"
)
expiretype
,
_
:=
cmd
.
Flags
()
.
GetInt
(
"expiretype"
)
assetExec
,
_
:=
cmd
.
Flags
()
.
GetString
(
"exec"
)
if
expiretype
==
0
{
if
expire
<=
0
{
fmt
.
Println
(
"Invalid expire. expire must large than 0 in expiretype==0, expire"
,
expire
)
...
...
@@ -117,7 +119,7 @@ func createPub2PrivTx(cmd *cobra.Command, args []string) {
}
}
else
if
expiretype
==
1
{
if
expire
<=
0
{
expire
=
int64
(
time
.
Hour
)
expire
=
int64
(
time
.
Minute
*
10
)
}
}
else
{
fmt
.
Println
(
"Invalid expiretype"
,
expiretype
)
...
...
@@ -131,6 +133,7 @@ func createPub2PrivTx(cmd *cobra.Command, args []string) {
Note
:
note
,
Pubkeypair
:
pubkeypair
,
Expire
:
expire
,
AssetExec
:
assetExec
,
}
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"privacy.CreateRawTransaction"
,
params
,
nil
)
ctx
.
RunWithoutMarshal
()
...
...
@@ -156,9 +159,10 @@ func createPriv2PrivTxFlags(cmd *cobra.Command) {
cmd
.
MarkFlagRequired
(
"from"
)
cmd
.
Flags
()
.
Int32P
(
"mixcount"
,
"m"
,
defMixCount
,
"utxo mix count"
)
cmd
.
Flags
()
.
StringP
(
"symbol"
,
"s"
,
"BTY"
,
"token symbol"
)
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"
,
""
,
"note for transaction"
)
cmd
.
Flags
()
.
Int64P
(
"expire"
,
""
,
0
,
"transfer expire, default one hour"
)
cmd
.
Flags
()
.
Int64P
(
"expire"
,
"
x
"
,
0
,
"transfer expire, default one hour"
)
cmd
.
Flags
()
.
IntP
(
"expiretype"
,
""
,
1
,
"0: height 1: time default is 1"
)
}
...
...
@@ -172,6 +176,7 @@ func createPriv2PrivTx(cmd *cobra.Command, args []string) {
sender
,
_
:=
cmd
.
Flags
()
.
GetString
(
"from"
)
expire
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"expire"
)
expiretype
,
_
:=
cmd
.
Flags
()
.
GetInt
(
"expiretype"
)
assetExec
,
_
:=
cmd
.
Flags
()
.
GetString
(
"exec"
)
if
expiretype
==
0
{
if
expire
<=
0
{
fmt
.
Println
(
"Invalid expire. expire must large than 0 in expiretype==0, expire"
,
expire
)
...
...
@@ -179,7 +184,7 @@ func createPriv2PrivTx(cmd *cobra.Command, args []string) {
}
}
else
if
expiretype
==
1
{
if
expire
<=
0
{
expire
=
int64
(
time
.
Hour
)
expire
=
int64
(
time
.
Minute
*
10
)
}
}
else
{
fmt
.
Println
(
"Invalid expiretype"
,
expiretype
)
...
...
@@ -195,6 +200,7 @@ func createPriv2PrivTx(cmd *cobra.Command, args []string) {
From
:
sender
,
Mixcount
:
mixCount
,
Expire
:
expire
,
AssetExec
:
assetExec
,
}
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"privacy.CreateRawTransaction"
,
params
,
nil
)
ctx
.
RunWithoutMarshal
()
...
...
@@ -220,9 +226,10 @@ func createPriv2PubTxFlags(cmd *cobra.Command) {
cmd
.
MarkFlagRequired
(
"to"
)
cmd
.
Flags
()
.
Int32P
(
"mixcount"
,
"m"
,
defMixCount
,
"utxo mix count"
)
cmd
.
Flags
()
.
StringP
(
"symbol"
,
"s"
,
"BTY"
,
"token symbol"
)
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"
,
""
,
"note for transaction"
)
cmd
.
Flags
()
.
Int64P
(
"expire"
,
""
,
0
,
"transfer expire, default one hour"
)
cmd
.
Flags
()
.
Int64P
(
"expire"
,
"
x
"
,
0
,
"transfer expire, default one hour"
)
cmd
.
Flags
()
.
IntP
(
"expiretype"
,
""
,
1
,
"0: height 1: time default is 1"
)
}
...
...
@@ -236,6 +243,7 @@ func createPriv2PubTx(cmd *cobra.Command, args []string) {
note
,
_
:=
cmd
.
Flags
()
.
GetString
(
"note"
)
expire
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"expire"
)
expiretype
,
_
:=
cmd
.
Flags
()
.
GetInt
(
"expiretype"
)
assetExec
,
_
:=
cmd
.
Flags
()
.
GetString
(
"exec"
)
if
expiretype
==
0
{
if
expire
<=
0
{
fmt
.
Println
(
"Invalid expire. expire must large than 0 in expiretype==0, expire"
,
expire
)
...
...
@@ -243,7 +251,7 @@ func createPriv2PubTx(cmd *cobra.Command, args []string) {
}
}
else
if
expiretype
==
1
{
if
expire
<=
0
{
expire
=
int64
(
time
.
Hour
)
expire
=
int64
(
time
.
Minute
*
10
)
}
}
else
{
fmt
.
Println
(
"Invalid expiretype"
,
expiretype
)
...
...
@@ -259,6 +267,7 @@ func createPriv2PubTx(cmd *cobra.Command, args []string) {
To
:
to
,
Mixcount
:
mixCount
,
Expire
:
expire
,
AssetExec
:
assetExec
,
}
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"privacy.CreateRawTransaction"
,
params
,
nil
)
ctx
.
RunWithoutMarshal
()
...
...
@@ -439,9 +448,10 @@ func createUTXOsFlag(cmd *cobra.Command) {
cmd
.
MarkFlagRequired
(
"pubkeypair"
)
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"a"
,
0
,
"amount"
)
cmd
.
MarkFlagRequired
(
"amount"
)
cmd
.
Flags
()
.
Int32P
(
"count"
,
"c"
,
0
,
"mix count, default 0"
)
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"
,
"
"
,
int64
(
time
.
Hour
)
,
"transfer expire, default one hour"
)
cmd
.
Flags
()
.
Int64P
(
"expire"
,
"
x"
,
0
,
"transfer expire, default one hour"
)
}
func
createUTXOs
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
...
...
@@ -449,22 +459,23 @@ func createUTXOs(cmd *cobra.Command, args []string) {
from
,
_
:=
cmd
.
Flags
()
.
GetString
(
"from"
)
pubkeypair
,
_
:=
cmd
.
Flags
()
.
GetString
(
"pubkeypair"
)
note
,
_
:=
cmd
.
Flags
()
.
GetString
(
"note"
)
count
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"count"
)
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
.
Hour
)
expire
=
int64
(
time
.
Minute
*
10
)
}
params
:=
&
pty
.
ReqCreateUTXOs
{
Tokenname
:
types
.
BTY
,
Tokenname
:
symbol
,
Sender
:
from
,
Pubkeypair
:
pubkeypair
,
Amount
:
amountInt64
,
Count
:
count
,
Note
:
note
,
Expire
:
expire
,
AssetExec
:
assetExec
,
}
var
res
rpctypes
.
ReplyHash
...
...
plugin/dapp/privacy/executor/exec.go
View file @
6a6fefbe
...
...
@@ -7,6 +7,8 @@ package executor
import
(
"encoding/hex"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/types"
...
...
@@ -15,13 +17,15 @@ import (
// Exec_Public2Privacy execute public to privacy
func
(
p
*
privacy
)
Exec_Public2Privacy
(
payload
*
ty
.
Public2Privacy
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
if
payload
.
Tokenname
!=
types
.
BTY
{
return
nil
,
types
.
ErrNotSupport
accDB
,
err
:=
p
.
createAccountDB
(
payload
.
GetAssetExec
(),
payload
.
GetTokenname
())
if
err
!=
nil
{
privacylog
.
Error
(
"Exec_pub2priv_newAccountDB"
,
"exec"
,
payload
.
GetAssetExec
(),
"symbol"
,
payload
.
GetTokenname
(),
"err"
,
err
)
}
txhashstr
:=
hex
.
EncodeToString
(
tx
.
Hash
())
coinsAccount
:=
p
.
GetCoinsAccount
()
from
:=
tx
.
From
()
receipt
,
err
:=
coinsAccount
.
ExecWithdraw
(
address
.
ExecAddress
(
string
(
tx
.
Execer
)),
from
,
payload
.
Amount
)
receipt
,
err
:=
accDB
.
ExecWithdraw
(
address
.
ExecAddress
(
string
(
tx
.
Execer
)),
from
,
payload
.
Amount
)
if
err
!=
nil
{
privacylog
.
Error
(
"PrivacyTrading Exec"
,
"txhash"
,
txhashstr
,
"ExecWithdraw error "
,
err
)
return
nil
,
err
...
...
@@ -55,9 +59,7 @@ func (p *privacy) Exec_Public2Privacy(payload *ty.Public2Privacy, tx *types.Tran
// Exec_Privacy2Privacy execute privacy to privacy transaction
func
(
p
*
privacy
)
Exec_Privacy2Privacy
(
payload
*
ty
.
Privacy2Privacy
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
if
payload
.
Tokenname
!=
types
.
BTY
{
return
nil
,
types
.
ErrNotSupport
}
txhashstr
:=
hex
.
EncodeToString
(
tx
.
Hash
())
receipt
:=
&
types
.
Receipt
{
KV
:
make
([]
*
types
.
KeyValue
,
0
)}
privacyInput
:=
payload
.
Input
...
...
@@ -97,12 +99,13 @@ func (p *privacy) Exec_Privacy2Privacy(payload *ty.Privacy2Privacy, tx *types.Tr
// Exec_Privacy2Public execute privacy to public transaction
func
(
p
*
privacy
)
Exec_Privacy2Public
(
payload
*
ty
.
Privacy2Public
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
if
payload
.
Tokenname
!=
types
.
BTY
{
return
nil
,
types
.
ErrNotSupport
accDB
,
err
:=
p
.
createAccountDB
(
payload
.
GetAssetExec
(),
payload
.
GetTokenname
())
if
err
!=
nil
{
privacylog
.
Error
(
"Exec_pub2priv_newAccountDB"
,
"exec"
,
payload
.
GetAssetExec
(),
"symbol"
,
payload
.
GetTokenname
(),
"err"
,
err
)
}
txhashstr
:=
hex
.
EncodeToString
(
tx
.
Hash
())
coinsAccount
:=
p
.
GetCoinsAccount
()
receipt
,
err
:=
coinsAccount
.
ExecDeposit
(
payload
.
To
,
address
.
ExecAddress
(
string
(
tx
.
Execer
)),
payload
.
Amount
)
receipt
,
err
:=
accDB
.
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
...
...
@@ -141,3 +144,12 @@ func (p *privacy) Exec_Privacy2Public(payload *ty.Privacy2Public, tx *types.Tran
//////////////////debug code end///////////////
return
receipt
,
nil
}
func
(
p
*
privacy
)
createAccountDB
(
exec
,
symbol
string
)
(
*
account
.
DB
,
error
)
{
if
exec
==
"coins"
{
return
p
.
GetCoinsAccount
(),
nil
}
return
account
.
NewAccountDB
(
exec
,
symbol
,
p
.
GetStateDB
())
}
plugin/dapp/privacy/executor/privacy.go
View file @
6a6fefbe
...
...
@@ -220,8 +220,13 @@ func (p *privacy) CheckTx(tx *types.Transaction, index int) error {
//如果是私到私 或者私到公,交易费扣除则需要utxo实现,交易费并不生成真正的UTXO,也是即时燃烧掉而已
var
amount
int64
keyinput
:=
input
.
Keyinput
keyOutput
:=
output
.
Keyoutput
assertExec
:=
action
.
GetAssertExec
()
token
:=
action
.
GetTokenName
()
if
assertExec
==
""
||
token
==
""
{
return
types
.
ErrInvalidParam
}
if
action
.
Ty
==
pty
.
ActionPrivacy2Public
&&
action
.
GetPrivacy2Public
()
!=
nil
{
amount
=
action
.
GetPrivacy2Public
()
.
Amount
}
...
...
@@ -264,13 +269,12 @@ func (p *privacy) CheckTx(tx *types.Transaction, index int) error {
return
pty
.
ErrPubkeysOfUTXO
}
for
_
,
output
:=
range
keyOutput
{
totalOutput
+=
output
.
Amount
}
//平行链下的隐私交易,utxo不需要燃烧,fee只收取主链的bty,和utxo无关联
if
!
types
.
IsPara
()
{
if
assertExec
==
"coins"
&&
types
.
IsPara
()
{
for
_
,
output
:=
range
output
.
Keyoutput
{
totalOutput
+=
output
.
Amount
}
if
tx
.
Fee
<
pty
.
PrivacyTxFee
{
privacylog
.
Error
(
"PrivacyTrading CheckTx"
,
"txhash"
,
txhashstr
,
"fee set:"
,
tx
.
Fee
,
"required:"
,
pty
.
PrivacyTxFee
,
" error ErrPrivacyTxFeeNotEnough"
)
return
pty
.
ErrPrivacyTxFeeNotEnough
...
...
plugin/dapp/privacy/proto/privacy.proto
View file @
6a6fefbe
...
...
@@ -23,6 +23,7 @@ message Public2Privacy {
int64
amount
=
2
;
string
note
=
5
;
PrivacyOutput
output
=
7
;
string
assetExec
=
8
;
}
message
Privacy2Privacy
{
...
...
@@ -31,6 +32,7 @@ message Privacy2Privacy {
string
note
=
5
;
PrivacyInput
input
=
6
;
PrivacyOutput
output
=
7
;
string
assetExec
=
8
;
}
message
Privacy2Public
{
...
...
@@ -40,6 +42,7 @@ message Privacy2Public {
string
to
=
6
;
PrivacyInput
input
=
4
;
PrivacyOutput
output
=
5
;
string
assetExec
=
8
;
}
message
UTXOGlobalIndex
{
...
...
@@ -200,9 +203,9 @@ message ReqCreateUTXOs {
int64
amount
=
4
;
string
note
=
5
;
string
sender
=
6
;
//发送人地址
int32
count
=
7
;
string
pubkeypair
=
8
;
int64
expire
=
9
;
string
assetExec
=
10
;
}
message
ReplyPrivacyPkPair
{
...
...
@@ -425,6 +428,7 @@ message ReqCreatePrivacyTx {
string
pubkeypair
=
10
;
int32
mixcount
=
11
;
int64
expire
=
12
;
string
assetExec
=
13
;
}
service
privacy
{
...
...
plugin/dapp/privacy/rpc/rpc_channel_test.go
View file @
6a6fefbe
...
...
@@ -123,11 +123,11 @@ func testShowUTXOs4SpecifiedAmount(t *testing.T, jrpc *jsonclient.JSONClient) er
func
testCreateUTXOs
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
params
:=
&
pty
.
ReqCreateUTXOs
{
AssetExec
:
"coins"
,
Tokenname
:
types
.
BTY
,
Sender
:
"1JSRSwp16NvXiTjYBYK9iUQ9wqp3sCxz2p"
,
Pubkeypair
:
"92fe6cfec2e19cd15f203f83b5d440ddb63d0cb71559f96dc81208d819fea85886b08f6e874fca15108d244b40f9086d8c03260d4b954a40dfb3cbe41ebc7389"
,
Amount
:
123456
,
Count
:
12
,
Note
:
"for test"
,
Expire
:
int64
(
time
.
Hour
),
}
...
...
plugin/dapp/privacy/types/privacy.go
View file @
6a6fefbe
...
...
@@ -205,3 +205,15 @@ func (action *PrivacyAction) GetTokenName() string {
}
return
""
}
// GetAssertExec get assert exec
func
(
action
*
PrivacyAction
)
GetAssertExec
()
string
{
if
action
.
GetTy
()
==
ActionPublic2Privacy
&&
action
.
GetPublic2Privacy
()
!=
nil
{
return
action
.
GetPublic2Privacy
()
.
GetAssetExec
()
}
else
if
action
.
GetTy
()
==
ActionPrivacy2Privacy
&&
action
.
GetPrivacy2Privacy
()
!=
nil
{
return
action
.
GetPrivacy2Privacy
()
.
GetAssetExec
()
}
else
if
action
.
GetTy
()
==
ActionPrivacy2Public
&&
action
.
GetPrivacy2Public
()
!=
nil
{
return
action
.
GetPrivacy2Public
()
.
GetAssetExec
()
}
return
""
}
plugin/dapp/privacy/types/privacy.pb.go
View file @
6a6fefbe
This diff is collapsed.
Click to expand it.
plugin/dapp/privacy/wallet/exec.go
View file @
6a6fefbe
...
...
@@ -49,6 +49,18 @@ func (policy *privacyPolicy) On_CreateTransaction(req *privacytypes.ReqCreatePri
bizlog
.
Error
(
"createTransaction"
,
"isRescanUtxosFlagScaning cause error."
,
err
)
return
nil
,
err
}
//为空时增加自动设置
if
req
.
GetAssetExec
()
==
"coins"
&&
req
.
GetTokenname
()
==
""
{
req
.
Tokenname
=
types
.
GetCoinSymbol
()
}
if
req
.
AssetExec
==
""
||
req
.
Tokenname
==
""
{
bizlog
.
Error
(
"createTransaction"
,
"checkAssertExecSymbol err"
,
"empty assert exec or token name"
,
"assertExec"
,
req
.
GetAssetExec
(),
"assertSymbol"
,
req
.
GetTokenname
())
return
nil
,
types
.
ErrInvalidParam
}
if
!
checkAmountValid
(
req
.
Amount
)
{
err
=
types
.
ErrAmount
bizlog
.
Error
(
"createTransaction"
,
"isRescanUtxosFlagScaning cause error."
,
err
)
...
...
plugin/dapp/privacy/wallet/privacy.go
View file @
6a6fefbe
...
...
@@ -164,6 +164,7 @@ func (policy *privacyPolicy) createUTXOsByPub2Priv(priv crypto.PrivKey, reqCreat
Amount
:
reqCreateUTXOs
.
Amount
,
Note
:
reqCreateUTXOs
.
Note
,
Output
:
privacyOutput
,
AssetExec
:
reqCreateUTXOs
.
AssetExec
,
}
action
:=
&
privacytypes
.
PrivacyAction
{
Ty
:
privacytypes
.
ActionPublic2Privacy
,
...
...
@@ -594,6 +595,7 @@ func (policy *privacyPolicy) createPublic2PrivacyTx(req *privacytypes.ReqCreateP
Amount
:
amount
,
Note
:
req
.
GetNote
(),
Output
:
privacyOutput
,
AssetExec
:
req
.
GetAssetExec
(),
}
action
:=
&
privacytypes
.
PrivacyAction
{
...
...
@@ -624,10 +626,10 @@ func (policy *privacyPolicy) createPublic2PrivacyTx(req *privacytypes.ReqCreateP
func
(
policy
*
privacyPolicy
)
createPrivacy2PrivacyTx
(
req
*
privacytypes
.
ReqCreatePrivacyTx
)
(
*
types
.
Transaction
,
error
)
{
//需要燃烧的utxo
utxoBurnedAmount
:=
privacytypes
.
PrivacyTxFee
is
Para
:=
types
.
IsPara
(
)
if
is
Para
{
utxoBurnedAmount
=
0
var
utxoBurnedAmount
int64
is
MainetCoins
:=
!
types
.
IsPara
()
&&
(
req
.
AssetExec
==
"coins"
)
if
is
MainetCoins
{
utxoBurnedAmount
=
privacytypes
.
PrivacyTxFee
}
buildInfo
:=
&
buildInputInfo
{
tokenname
:
req
.
GetTokenname
(),
...
...
@@ -674,6 +676,7 @@ func (policy *privacyPolicy) createPrivacy2PrivacyTx(req *privacytypes.ReqCreate
Note
:
req
.
GetNote
(),
Input
:
privacyInput
,
Output
:
privacyOutput
,
AssetExec
:
req
.
GetAssetExec
(),
}
action
:=
&
privacytypes
.
PrivacyAction
{
Ty
:
privacytypes
.
ActionPrivacy2Privacy
,
...
...
@@ -688,7 +691,7 @@ func (policy *privacyPolicy) createPrivacy2PrivacyTx(req *privacytypes.ReqCreate
To
:
address
.
ExecAddress
(
types
.
ExecName
(
privacytypes
.
PrivacyX
)),
}
tx
.
SetExpire
(
time
.
Duration
(
req
.
Expire
))
if
isPara
{
if
!
isMainetCoins
{
tx
.
Fee
,
err
=
tx
.
GetRealFee
(
types
.
GInt
(
"MinFee"
))
if
err
!=
nil
{
bizlog
.
Error
(
"createPrivacy2PrivacyTx"
,
"calc fee failed"
,
err
)
...
...
@@ -697,7 +700,7 @@ func (policy *privacyPolicy) createPrivacy2PrivacyTx(req *privacytypes.ReqCreate
}
// 创建交易成功,将已经使用掉的UTXO冻结,需要注意此处获取的txHash和交易发送时的一致
policy
.
saveFTXOInfo
(
tx
.
GetExpire
(),
req
.
GetTokenname
()
,
req
.
GetFrom
(),
hex
.
EncodeToString
(
tx
.
Hash
()),
selectedUtxo
)
policy
.
saveFTXOInfo
(
tx
.
GetExpire
(),
req
.
Tokenname
,
req
.
GetFrom
(),
hex
.
EncodeToString
(
tx
.
Hash
()),
selectedUtxo
)
tx
.
Signature
=
&
types
.
Signature
{
Signature
:
types
.
Encode
(
&
privacytypes
.
PrivacySignatureParam
{
ActionType
:
action
.
Ty
,
...
...
@@ -711,10 +714,11 @@ func (policy *privacyPolicy) createPrivacy2PrivacyTx(req *privacytypes.ReqCreate
func
(
policy
*
privacyPolicy
)
createPrivacy2PublicTx
(
req
*
privacytypes
.
ReqCreatePrivacyTx
)
(
*
types
.
Transaction
,
error
)
{
//需要燃烧的utxo
utxoBurnedAmount
:=
privacytypes
.
PrivacyTxFee
isPara
:=
types
.
IsPara
()
if
isPara
{
utxoBurnedAmount
=
0
//需要燃烧的utxo
var
utxoBurnedAmount
int64
isMainetCoins
:=
!
types
.
IsPara
()
&&
(
req
.
AssetExec
==
"coins"
)
if
isMainetCoins
{
utxoBurnedAmount
=
privacytypes
.
PrivacyTxFee
}
buildInfo
:=
&
buildInputInfo
{
tokenname
:
req
.
GetTokenname
(),
...
...
@@ -760,6 +764,7 @@ func (policy *privacyPolicy) createPrivacy2PublicTx(req *privacytypes.ReqCreateP
Input
:
privacyInput
,
Output
:
privacyOutput
,
To
:
req
.
GetTo
(),
AssetExec
:
req
.
GetAssetExec
(),
}
action
:=
&
privacytypes
.
PrivacyAction
{
Ty
:
privacytypes
.
ActionPrivacy2Public
,
...
...
@@ -774,7 +779,7 @@ func (policy *privacyPolicy) createPrivacy2PublicTx(req *privacytypes.ReqCreateP
To
:
address
.
ExecAddress
(
types
.
ExecName
(
privacytypes
.
PrivacyX
)),
}
tx
.
SetExpire
(
time
.
Duration
(
req
.
Expire
))
if
isPara
{
if
!
isMainetCoins
{
tx
.
Fee
,
err
=
tx
.
GetRealFee
(
types
.
GInt
(
"MinFee"
))
if
err
!=
nil
{
bizlog
.
Error
(
"createPrivacy2PublicTx"
,
"calc fee failed"
,
err
)
...
...
@@ -782,7 +787,7 @@ func (policy *privacyPolicy) createPrivacy2PublicTx(req *privacytypes.ReqCreateP
}
}
// 创建交易成功,将已经使用掉的UTXO冻结,需要注意此处获取的txHash和交易发送时的一致
policy
.
saveFTXOInfo
(
tx
.
GetExpire
(),
req
.
GetTokenname
()
,
req
.
GetFrom
(),
hex
.
EncodeToString
(
tx
.
Hash
()),
selectedUtxo
)
policy
.
saveFTXOInfo
(
tx
.
GetExpire
(),
req
.
Tokenname
,
req
.
GetFrom
(),
hex
.
EncodeToString
(
tx
.
Hash
()),
selectedUtxo
)
tx
.
Signature
=
&
types
.
Signature
{
Signature
:
types
.
Encode
(
&
privacytypes
.
PrivacySignatureParam
{
ActionType
:
action
.
Ty
,
...
...
@@ -793,9 +798,9 @@ func (policy *privacyPolicy) createPrivacy2PublicTx(req *privacytypes.ReqCreateP
return
tx
,
nil
}
func
(
policy
*
privacyPolicy
)
saveFTXOInfo
(
expire
int64
,
token
,
sender
,
txhash
string
,
selectedUtxos
[]
*
txOutputInfo
)
{
func
(
policy
*
privacyPolicy
)
saveFTXOInfo
(
expire
int64
,
assertSymbol
,
sender
,
txhash
string
,
selectedUtxos
[]
*
txOutputInfo
)
{
//将已经作为本次交易输入的utxo进行冻结,防止产生双花交易
policy
.
store
.
moveUTXO2FTXO
(
expire
,
token
,
sender
,
txhash
,
selectedUtxos
)
policy
.
store
.
moveUTXO2FTXO
(
expire
,
assertSymbol
,
sender
,
txhash
,
selectedUtxos
)
//TODO:需要加入超时处理,需要将此处的txhash写入到数据库中,以免钱包瞬间奔溃后没有对该笔隐私交易的记录,
//TODO:然后当该交易得到执行之后,没法将FTXO转化为STXO,added by hezhengjun on 2018.6.5
}
...
...
@@ -878,7 +883,7 @@ func (policy *privacyPolicy) reqUtxosByAddr(addrs []string) {
}
policy
.
store
.
saveREscanUTXOsAddresses
(
storeAddrs
)
reqAddr
:=
address
.
ExecAddress
(
privacytypes
.
PrivacyX
)
reqAddr
:=
address
.
ExecAddress
(
types
.
ExecName
(
privacytypes
.
PrivacyX
)
)
var
txInfo
types
.
ReplyTxInfo
i
:=
0
operater
:=
policy
.
getWalletOperate
()
...
...
@@ -944,6 +949,7 @@ func (policy *privacyPolicy) reqUtxosByAddr(addrs []string) {
policy
.
store
.
saveREscanUTXOsAddresses
(
storeAddrs
)
}
//TODO:input也可能时混淆的utxo, 需要增加判定实际的utxo
func
(
policy
*
privacyPolicy
)
deleteScanPrivacyInputUtxo
()
{
maxUTXOsPerTime
:=
1000
for
{
...
...
@@ -1225,7 +1231,7 @@ func (policy *privacyPolicy) addDelPrivacyTxsFromBlock(tx *types.Transaction, in
}
//处理input,对于公对私的交易类型,只会出现在output类型处理中
//如果该隐私交易是本钱包中的地址发送出去的,则需要对相应的utxo进行处理
//如果该隐私交易是本钱包中的地址发送出去的,则需要对相应的utxo进行处理
TODO:处理其他节点构造并发起的隐私input(需要比较keyimage)
if
AddTx
==
addDelType
{
ftxos
,
keys
:=
policy
.
store
.
getFTXOlist
()
for
i
,
ftxo
:=
range
ftxos
{
...
...
plugin/dapp/privacy/wallet/privacy_test.go
View file @
6a6fefbe
...
...
@@ -120,6 +120,7 @@ func (mock *PrivacyMock) CreateUTXOs(sender string, pubkeypair string, amount in
dbbatch
:=
mock
.
store
.
NewBatch
(
true
)
for
n
:=
0
;
n
<
count
;
n
++
{
tx
:=
mock
.
createPublic2PrivacyTx
(
&
ty
.
ReqCreatePrivacyTx
{
AssetExec
:
"coins"
,
Tokenname
:
mock
.
tokenName
,
Type
:
1
,
Amount
:
amount
,
...
...
plugin/dapp/privacy/wallet/privacybizpolicy_test.go
View file @
6a6fefbe
...
...
@@ -343,10 +343,10 @@ func Test_CreateUTXOs(t *testing.T) {
},
{
req
:
&
ty
.
ReqCreateUTXOs
{
AssetExec
:
"coins"
,
Tokenname
:
types
.
BTY
,
Amount
:
10
*
types
.
Coin
,
Note
:
"say something"
,
Count
:
16
,
Sender
:
testAddrs
[
0
],
Pubkeypair
:
testPubkeyPairs
[
0
],
},
...
...
@@ -384,6 +384,7 @@ func Test_CreateTransaction(t *testing.T) {
},
{
// 公对私测试
req
:
&
ty
.
ReqCreatePrivacyTx
{
AssetExec
:
"coins"
,
Tokenname
:
types
.
BTY
,
Type
:
1
,
Amount
:
100
*
types
.
Coin
,
...
...
@@ -394,6 +395,7 @@ func Test_CreateTransaction(t *testing.T) {
},
{
// 私对私测试
req
:
&
ty
.
ReqCreatePrivacyTx
{
AssetExec
:
"coins"
,
Tokenname
:
types
.
BTY
,
Type
:
2
,
Amount
:
10
*
types
.
Coin
,
...
...
@@ -404,6 +406,7 @@ func Test_CreateTransaction(t *testing.T) {
},
{
// 私对公测试
req
:
&
ty
.
ReqCreatePrivacyTx
{
AssetExec
:
"coins"
,
Tokenname
:
types
.
BTY
,
Type
:
3
,
Amount
:
10
*
types
.
Coin
,
...
...
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