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
7a535e84
Commit
7a535e84
authored
Jan 22, 2019
by
jiangpeng
Committed by
vipwzw
Jan 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加隐私三步构建命令
parent
f78f3e57
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
92 deletions
+81
-92
privacy.go
plugin/dapp/privacy/commands/privacy.go
+81
-92
No files found.
plugin/dapp/privacy/commands/privacy.go
View file @
7a535e84
...
@@ -36,9 +36,9 @@ func PrivacyCmd() *cobra.Command {
...
@@ -36,9 +36,9 @@ func PrivacyCmd() *cobra.Command {
cmd
.
AddCommand
(
cmd
.
AddCommand
(
showPrivacyKeyCmd
(),
showPrivacyKeyCmd
(),
showPrivacyAccountSpendCmd
(),
showPrivacyAccountSpendCmd
(),
public2Privacy
Cmd
(),
createPub2PrivTx
Cmd
(),
privacy2Privacy
Cmd
(),
createPriv2PrivTx
Cmd
(),
privacy2Public
Cmd
(),
createPriv2PubTx
Cmd
(),
showAmountsOfUTXOCmd
(),
showAmountsOfUTXOCmd
(),
showUTXOs4SpecifiedAmountCmd
(),
showUTXOs4SpecifiedAmountCmd
(),
createUTXOsCmd
(),
createUTXOsCmd
(),
...
@@ -79,38 +79,35 @@ func showPrivacyKey(cmd *cobra.Command, args []string) {
...
@@ -79,38 +79,35 @@ func showPrivacyKey(cmd *cobra.Command, args []string) {
ctx
.
Run
()
ctx
.
Run
()
}
}
// public2PrivacyCmd public address to privacy address
func
public2PrivacyCmd
()
*
cobra
.
Command
{
// CreatePub2PrivTxCmd create a public to privacy transaction
func
createPub2PrivTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"pub2priv"
,
Use
:
"pub2priv"
,
Short
:
"
Public to privacy from pubkeypair amout note
"
,
Short
:
"
Create a public to privacy transaction
"
,
Run
:
public2Privacy
,
Run
:
createPub2PrivTx
,
}
}
public2PrivacyFlag
(
cmd
)
createPub2PrivTxFlags
(
cmd
)
return
cmd
return
cmd
}
}
func
public2PrivacyFlag
(
cmd
*
cobra
.
Command
)
{
func
createPub2PrivTxFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"from"
,
"f"
,
""
,
"from account address"
)
cmd
.
Flags
()
.
StringP
(
"pubkeypair"
,
"p"
,
""
,
"public key pair"
)
cmd
.
MarkFlagRequired
(
"from"
)
cmd
.
Flags
()
.
StringP
(
"pubkeypair"
,
"p"
,
""
,
"to view spend public key pair"
)
cmd
.
MarkFlagRequired
(
"pubkeypair"
)
cmd
.
MarkFlagRequired
(
"pubkeypair"
)
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"a"
,
0.0
,
"transfer amount, at most 4 decimal places"
)
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"a"
,
0
,
"transfer amount"
)
cmd
.
MarkFlagRequired
(
"amount"
)
cmd
.
MarkFlagRequired
(
"amount"
)
cmd
.
Flags
()
.
StringP
(
"note"
,
"n"
,
""
,
"transfer note"
)
cmd
.
Flags
()
.
StringP
(
"symbol"
,
"s"
,
"BTY"
,
"token symbol"
)
cmd
.
Flags
()
.
StringP
(
"note"
,
"n"
,
""
,
"note for transaction"
)
cmd
.
Flags
()
.
Int64P
(
"expire"
,
""
,
0
,
"transfer expire, default one hour"
)
cmd
.
Flags
()
.
Int64P
(
"expire"
,
""
,
0
,
"transfer expire, default one hour"
)
cmd
.
Flags
()
.
IntP
(
"expiretype"
,
""
,
1
,
"0: height 1: time default is 1"
)
cmd
.
Flags
()
.
IntP
(
"expiretype"
,
""
,
1
,
"0: height 1: time default is 1"
)
}
}
func
public2Privacy
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
createPub2PrivTx
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
from
,
_
:=
cmd
.
Flags
()
.
GetString
(
"from"
)
pubkeypair
,
_
:=
cmd
.
Flags
()
.
GetString
(
"pubkeypair"
)
pubkeypair
,
_
:=
cmd
.
Flags
()
.
GetString
(
"pubkeypair"
)
amount
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"amount"
)
amount
:=
cmdtypes
.
GetAmountValue
(
cmd
,
"amount"
)
tokenname
,
_
:=
cmd
.
Flags
()
.
GetString
(
"symbol"
)
note
,
_
:=
cmd
.
Flags
()
.
GetString
(
"note"
)
note
,
_
:=
cmd
.
Flags
()
.
GetString
(
"note"
)
expire
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"expire"
)
expire
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"expire"
)
expiretype
,
_
:=
cmd
.
Flags
()
.
GetInt
(
"expiretype"
)
expiretype
,
_
:=
cmd
.
Flags
()
.
GetInt
(
"expiretype"
)
...
@@ -121,62 +118,59 @@ func public2Privacy(cmd *cobra.Command, args []string) {
...
@@ -121,62 +118,59 @@ func public2Privacy(cmd *cobra.Command, args []string) {
}
}
}
else
if
expiretype
==
1
{
}
else
if
expiretype
==
1
{
if
expire
<=
0
{
if
expire
<=
0
{
expire
=
int64
(
time
.
Hour
)
expire
=
int64
(
time
.
Hour
/
time
.
Second
)
}
}
}
else
{
}
else
{
fmt
.
Println
(
"Invalid expiretype"
,
expiretype
)
fmt
.
Println
(
"Invalid expiretype"
,
expiretype
)
return
return
}
}
amountInt64
:=
int64
(
amount
*
types
.
InputPrecision
)
*
types
.
Multiple1E4
//支持4位小数输入,多余的输入将被截断
params
:=
types
.
ReqCreateTransaction
{
params
:=
pty
.
ReqPub2Pri
{
Tokenname
:
tokenname
,
Sender
:
from
,
Type
:
types
.
PrivacyTypePublic2Privacy
,
Amount
:
amount
,
Note
:
[]
byte
(
note
),
Pubkeypair
:
pubkeypair
,
Pubkeypair
:
pubkeypair
,
Amount
:
amountInt64
,
Note
:
note
,
Tokenname
:
types
.
BTY
,
Expire
:
expire
,
Expire
:
expire
,
}
}
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"privacy.CreateRawTransaction"
,
params
,
nil
)
var
res
rpctypes
.
ReplyHash
ctx
.
RunWithoutMarshal
()
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"privacy.MakeTxPublic2privacy"
,
params
,
&
res
)
ctx
.
Run
()
}
}
//
privacy address to privacy address
//
CreatePriv2PrivTxCmd create a privacy to privacy transaction
func
privacy2Privacy
Cmd
()
*
cobra
.
Command
{
func
createPriv2PrivTx
Cmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"priv2priv"
,
Use
:
"priv2priv"
,
Short
:
"
Privacy to privacy from toviewpubkey tospendpubkey amout note
"
,
Short
:
"
Create a privacy to privacy transaction
"
,
Run
:
privacy2Privacy
,
Run
:
createPriv2PrivTx
,
}
}
privacy2PrivacyFlag
(
cmd
)
createPriv2PrivTxFlags
(
cmd
)
return
cmd
return
cmd
}
}
func
privacy2PrivacyFlag
(
cmd
*
cobra
.
Command
)
{
func
createPriv2PrivTxFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"from"
,
"f"
,
""
,
"from account address"
)
cmd
.
Flags
()
.
StringP
(
"pubkeypair"
,
"p"
,
""
,
"public key pair"
)
cmd
.
MarkFlagRequired
(
"from"
)
cmd
.
Flags
()
.
StringP
(
"pubkeypair"
,
"p"
,
""
,
"to view spend public key pair"
)
cmd
.
MarkFlagRequired
(
"pubkeypair"
)
cmd
.
MarkFlagRequired
(
"pubkeypair"
)
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"a"
,
0.0
,
"transfer amount, at most 4 decimal places"
)
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"a"
,
0.0
,
"transfer amount"
)
cmd
.
MarkFlagRequired
(
"amount"
)
cmd
.
MarkFlagRequired
(
"amount"
)
cmd
.
Flags
()
.
StringP
(
"from"
,
"f"
,
""
,
"from address"
)
cmd
.
MarkFlagRequired
(
"from"
)
cmd
.
Flags
()
.
StringP
(
"note"
,
"n"
,
""
,
"transfer note"
)
cmd
.
Flags
()
.
Int32P
(
"mixcount"
,
"m"
,
defMixCount
,
"utxo mix count"
)
cmd
.
Flags
()
.
Int32P
(
"mixcount"
,
"m"
,
defMixCount
,
"transfer note"
)
cmd
.
Flags
()
.
StringP
(
"symbol"
,
"s"
,
"BTY"
,
"token symbol"
)
cmd
.
Flags
()
.
StringP
(
"note"
,
"n"
,
""
,
"note for transaction"
)
cmd
.
Flags
()
.
Int64P
(
"expire"
,
""
,
0
,
"transfer expire, default one hour"
)
cmd
.
Flags
()
.
Int64P
(
"expire"
,
""
,
0
,
"transfer expire, default one hour"
)
cmd
.
Flags
()
.
IntP
(
"expiretype"
,
""
,
1
,
"0: height 1: time default is 1"
)
cmd
.
Flags
()
.
IntP
(
"expiretype"
,
""
,
1
,
"0: height 1: time default is 1"
)
}
}
func
privacy2Privacy
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
createPriv2PrivTx
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
from
,
_
:=
cmd
.
Flags
()
.
GetString
(
"from"
)
pubkeypair
,
_
:=
cmd
.
Flags
()
.
GetString
(
"pubkeypair"
)
pubkeypair
,
_
:=
cmd
.
Flags
()
.
GetString
(
"pubkeypair"
)
amount
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"amount"
)
amount
:=
cmdtypes
.
GetAmountValue
(
cmd
,
"amount"
)
mixcount
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"mixcount"
)
mixCount
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"mixcount"
)
tokenname
,
_
:=
cmd
.
Flags
()
.
GetString
(
"symbol"
)
note
,
_
:=
cmd
.
Flags
()
.
GetString
(
"note"
)
note
,
_
:=
cmd
.
Flags
()
.
GetString
(
"note"
)
sender
,
_
:=
cmd
.
Flags
()
.
GetString
(
"from"
)
expire
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"expire"
)
expire
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"expire"
)
expiretype
,
_
:=
cmd
.
Flags
()
.
GetInt
(
"expiretype"
)
expiretype
,
_
:=
cmd
.
Flags
()
.
GetInt
(
"expiretype"
)
if
expiretype
==
0
{
if
expiretype
==
0
{
...
@@ -186,63 +180,60 @@ func privacy2Privacy(cmd *cobra.Command, args []string) {
...
@@ -186,63 +180,60 @@ func privacy2Privacy(cmd *cobra.Command, args []string) {
}
}
}
else
if
expiretype
==
1
{
}
else
if
expiretype
==
1
{
if
expire
<=
0
{
if
expire
<=
0
{
expire
=
int64
(
time
.
Hour
)
expire
=
int64
(
time
.
Hour
/
time
.
Second
)
}
}
}
else
{
}
else
{
fmt
.
Println
(
"Invalid expiretype"
,
expiretype
)
fmt
.
Println
(
"Invalid expiretype"
,
expiretype
)
return
return
}
}
amountInt64
:=
int64
(
amount
*
types
.
InputPrecision
)
*
types
.
Multiple1E4
//支持4位小数输入,多余的输入将被截断
params
:=
types
.
ReqCreateTransaction
{
params
:=
pty
.
ReqPri2Pri
{
Tokenname
:
tokenname
,
Sender
:
from
,
Type
:
types
.
PrivacyTypePrivacy2Privacy
,
Amount
:
amount
,
Note
:
[]
byte
(
note
),
Pubkeypair
:
pubkeypair
,
Pubkeypair
:
pubkeypair
,
Amount
:
amountInt64
,
From
:
sender
,
Mixin
:
mixcount
,
Mixcount
:
mixCount
,
Note
:
note
,
Tokenname
:
types
.
BTY
,
Expire
:
expire
,
Expire
:
expire
,
}
}
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"privacy.CreateRawTransaction"
,
params
,
nil
)
var
res
rpctypes
.
ReplyHash
ctx
.
RunWithoutMarshal
()
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"privacy.MakeTxPrivacy2privacy"
,
params
,
&
res
)
ctx
.
Run
()
}
}
//
privacy address to public address
//
CreatePriv2PubTxCmd create a privacy to public transaction
func
privacy2Public
Cmd
()
*
cobra
.
Command
{
func
createPriv2PubTx
Cmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"priv2pub"
,
Use
:
"priv2pub"
,
Short
:
"
Public to privacy from toviewpubkey tospendpubkey amout note
"
,
Short
:
"
Create a privacy to public transaction
"
,
Run
:
privacy2Public
,
Run
:
createPriv2PubTx
,
}
}
privacy2Publiclag
(
cmd
)
createPriv2PubTxFlags
(
cmd
)
return
cmd
return
cmd
}
}
func
privacy2Publiclag
(
cmd
*
cobra
.
Command
)
{
func
createPriv2PubTxFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"from"
,
"f"
,
""
,
"from account address"
)
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"a"
,
0.0
,
"transfer amount, at most 4 decimal places"
)
cmd
.
MarkFlagRequired
(
"amount"
)
cmd
.
Flags
()
.
StringP
(
"from"
,
"f"
,
""
,
"from address"
)
cmd
.
MarkFlagRequired
(
"from"
)
cmd
.
MarkFlagRequired
(
"from"
)
cmd
.
Flags
()
.
StringP
(
"to"
,
"t"
,
""
,
"to address"
)
cmd
.
Flags
()
.
StringP
(
"to"
,
"t"
,
""
,
"to account address"
)
cmd
.
MarkFlagRequired
(
"to"
)
cmd
.
MarkFlagRequired
(
"to"
)
cmd
.
Flags
()
.
Float64P
(
"amount"
,
"a"
,
0.0
,
"transfer amount"
)
cmd
.
Flags
()
.
Int32P
(
"mixcount"
,
"m"
,
defMixCount
,
"utxo mix count"
)
cmd
.
MarkFlagRequired
(
"amount"
)
cmd
.
Flags
()
.
StringP
(
"symbol"
,
"s"
,
"BTY"
,
"token symbol"
)
cmd
.
Flags
()
.
StringP
(
"note"
,
"n"
,
""
,
"note for transaction"
)
cmd
.
Flags
()
.
StringP
(
"note"
,
"n"
,
""
,
"transfer note"
)
cmd
.
Flags
()
.
Int32P
(
"mixcount"
,
"m"
,
defMixCount
,
"transfer note"
)
cmd
.
Flags
()
.
Int64P
(
"expire"
,
""
,
0
,
"transfer expire, default one hour"
)
cmd
.
Flags
()
.
Int64P
(
"expire"
,
""
,
0
,
"transfer expire, default one hour"
)
cmd
.
Flags
()
.
IntP
(
"expiretype"
,
""
,
1
,
"0: height 1: time default is 1"
)
cmd
.
Flags
()
.
IntP
(
"expiretype"
,
""
,
1
,
"0: height 1: time default is 1"
)
}
}
func
privacy2Public
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
createPriv2PubTx
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
amount
:=
cmdtypes
.
GetAmountValue
(
cmd
,
"amount"
)
mixCount
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"mixcount"
)
tokenname
,
_
:=
cmd
.
Flags
()
.
GetString
(
"symbol"
)
from
,
_
:=
cmd
.
Flags
()
.
GetString
(
"from"
)
from
,
_
:=
cmd
.
Flags
()
.
GetString
(
"from"
)
to
,
_
:=
cmd
.
Flags
()
.
GetString
(
"to"
)
to
,
_
:=
cmd
.
Flags
()
.
GetString
(
"to"
)
amount
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"amount"
)
mixcount
,
_
:=
cmd
.
Flags
()
.
GetInt32
(
"mixcount"
)
note
,
_
:=
cmd
.
Flags
()
.
GetString
(
"note"
)
note
,
_
:=
cmd
.
Flags
()
.
GetString
(
"note"
)
expire
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"expire"
)
expire
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"expire"
)
expiretype
,
_
:=
cmd
.
Flags
()
.
GetInt
(
"expiretype"
)
expiretype
,
_
:=
cmd
.
Flags
()
.
GetInt
(
"expiretype"
)
...
@@ -253,27 +244,25 @@ func privacy2Public(cmd *cobra.Command, args []string) {
...
@@ -253,27 +244,25 @@ func privacy2Public(cmd *cobra.Command, args []string) {
}
}
}
else
if
expiretype
==
1
{
}
else
if
expiretype
==
1
{
if
expire
<=
0
{
if
expire
<=
0
{
expire
=
int64
(
time
.
Hour
)
expire
=
int64
(
time
.
Hour
/
time
.
Second
)
}
}
}
else
{
}
else
{
fmt
.
Println
(
"Invalid expiretype"
,
expiretype
)
fmt
.
Println
(
"Invalid expiretype"
,
expiretype
)
return
return
}
}
amountInt64
:=
int64
(
amount
*
types
.
InputPrecision
)
*
types
.
Multiple1E4
//支持4位小数输入,多余的输入将被截断
params
:=
types
.
ReqCreateTransaction
{
params
:=
pty
.
ReqPri2Pub
{
Tokenname
:
tokenname
,
Sender
:
from
,
Type
:
types
.
PrivacyTypePrivacy2Public
,
Receiver
:
to
,
Amount
:
amount
,
Amount
:
amountInt64
,
Note
:
[]
byte
(
note
)
,
Note
:
note
,
From
:
from
,
To
kenname
:
types
.
BTY
,
To
:
to
,
Mix
in
:
mixc
ount
,
Mix
count
:
mixC
ount
,
Expire
:
expire
,
Expire
:
expire
,
}
}
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"privacy.CreateRawTransaction"
,
params
,
nil
)
var
res
rpctypes
.
ReplyHash
ctx
.
RunWithoutMarshal
()
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"privacy.MakeTxPrivacy2public"
,
params
,
&
res
)
ctx
.
Run
()
}
}
func
showPrivacyAccountSpendCmd
()
*
cobra
.
Command
{
func
showPrivacyAccountSpendCmd
()
*
cobra
.
Command
{
...
...
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