## privacy 隐私交易合约  

目前主网不支持privacy合约，可在平行链运行。  
`cli privacy -h`  
```
Available Commands:
  enable      enable privacy address in wallet
  list_txs    List privacy transactions in wallet
  priv2priv   Create a privacy to privacy transaction
  priv2pub    Create a privacy to public transaction
  pub2priv    Create a public to privacy transaction
  rescanOpt   rescan Utxos in wallet and query rescan utxos status
  showau      Show Amount of UTXO
  showpai     Show privacy account information
  showpas     Show privacy account spend command
  showpk      Show privacy key by address
  showutxo4a  Show specified amount UTXOs
```
隐私交易合约不同于BTY主网账户体系，采用UTXO账户体系。  
***
## 前置操作 

## enable 使能钱包中的地址  
对于需要进行隐私交易的地址，需要先对其使能。  
`cli privacy enable -a "17mFjHjMHdtTU31QhFsLGcjNWxvGaVZcPH"-"1JeVN3q938vx8Pqcg7Kodmih8sWT5eQHHs"`  
```
{
    "results": [
        {
            "addr": "17mFjHjMHdtTU31QhFsLGcjNWxvGaVZcPH",
            "IsOK": true,
            "msg": ""
        },
        {
            "addr": "1JeVN3q938vx8Pqcg7Kodmih8sWT5eQHHs",
            "IsOK": true,
            "msg": ""
        }
    ]
}
```
-a后对多个地址操作时，以-分隔；或用all来使能本地钱包中所有的地址。  

需要向隐私合约转入供操作的代币：  
`cli token send_exec -e privacy -s COC -a 10000`   
签名并发送。  

## showpk 根据钱包地址查询隐私公钥   
`cli privacy showpk -a "1KoiQmaFg3DoZr84JehxrEWiR7SorSgbUx"`  
```
{
    "showSuccessful": true,
    "pubkeypair": "f52b540136a5c52cf032618627948773b94969a5ea994277fdcc3d9530003099e9dd7fb7cb4460172447b890e6e5a41319c4955462fbca65abfb373d5763aaf0"
}
```
***
## 交易相关  
## pub2priv 公开到隐私的交易  
本质是创建了一笔UTXO的交易。  
`cli privacy pub2priv -a 100 -e token -s COC -p 0065aa7868353e745990395e5c3519edc18cfb44541afcdd1188a585abc69590c2d0cdf0b94abe1ea7ded23efc92f11c4964a64505cfe3c6e7e5fb6dd62970ef`  
-p为目标隐私地址的公钥。  
**该交易使目标地址获得了指定数额的UTXO，可供后续花费。**  


## priv2priv 隐私到隐私的交易
`cli privacy priv2priv -a 15 -e coins -f 1KoiQmaFg3DoZr84JehxrEWiR7SorSgbUx -m 16 -p 241c7a688def4703b7e9cd3b7a89fba133ab350c608fb9aaa06eb328f1162b1deb441c2b435c3433715176191ccf9278b7d18fc175325065831c2e4c9f2f1b22 -s BTY`    
-m为UTXO混淆数量，默认为16  
-p为目标隐私地址的公钥。  
该交易需消耗1BTY为手续费。  

**该交易使目标地址获得了指定数额的UTXO，可供后续花费。**  

## priv2pub 隐私到公开的交易  
`cli privacy priv2pub -a 17 -e coins -f 1KoiQmaFg3DoZr84JehxrEWiR7SorSgbUx -m 17 -s BTY -t "1JeVN3q938vx8Pqcg7Kodmih8sWT5eQHHs" `  
由发送地址签名并发送。  
该交易需消耗1BTY为手续费。  

**该交易使目标地址的privacy合约中获得指定数额的代币。**  

可使用withdraw命令将这部分代币取回。  
`cli coins withdraw -a 17 -e privacy`
*** 
## 查询相关  

## showpai 根据地址查询隐私账户的信息  
`cli privacy showpai -a 1KoiQmaFg3DoZr84JehxrEWiR7SorSgbUx -s BTY -d 3`  
```
{
    "AvailableDetail": [
        {
            "Txhash": "0xef6269240bdae5bcdc8399844ab1791a5fead4441f3492e7c735f8ded359e32b",
            "Amount": "100.0000"
        }
    ],
    "AvailableAmount": "100.0000",
    "FrozenAmount": "0.0000",
    "TotalAmount": "100.0000"
}
```
-d为可选配置项：display mode.(0: display collect. 1:display available detail. 2:display frozen detail. 3:display all)  

## showau 查询UTOX的数量  
`cli privacy showau`  
```
{
    "amountDetail": [
        {
            "amount": 10,
            "count": 1
        },
        {
            "amount": 100,
            "count": 1
        }
    ]
}
```
## showutxo4a 根据指定金额查询钱包地址中的UTXO  

`cli privacy showutxo4a -a 100`  
```
[
    {
        "Txhash": "0xef6269240bdae5bcdc8399844ab1791a5fead4441f3492e7c735f8ded359e32b",
        "OnetimePubKey": "a0ca5d2d82233361ac82a3098d61e378069e134df5018827e8f138a4c0ba250d"
    }
]
```
  

## list_txs 查询钱包中指定地址的隐私交易  
`cli privacy list_txs  -a 1KoiQmaFg3DoZr84JehxrEWiR7SorSgbUx -c 1 -d 1`  
```
{
    "txDetails": [
        {
            "tx": {
                "execer": "privacy",
                "payload": {
                    "privacy2public": {
                        "tokenname": "BTY",
                        "amount": "1700000000",
                        "note": "",
                        "to": "1JeVN3q938vx8Pqcg7Kodmih8sWT5eQHHs",
                        "input": {
                            "keyinput": [
                                {
                                    "amount": "200000000",
                                    "utxoGlobalIndex": [
                                        {
                                            "txhash": "0xcc439a6049f44146522dad7dd8943d6b1d63ecef68d41497fa5dc9c323dc5b25",
                                            "outindex": 3
                                        },
                                        {
                                            "txhash": "0xcc439a6049f44146522dad7dd8943d6b1d63ecef68d41497fa5dc9c323dc5b25",
                                            "outindex": 2
                                        }
                                    ],
                                    "keyImage": "0xd1dcfeb83be78d4d6918a5cdceabdb1c11b9e9e10139c79a9b24c92879555f61"
                                },
                                {
                                    "amount": "1000000000",
                                    "utxoGlobalIndex": [
                                        {
                                            "txhash": "0xcc439a6049f44146522dad7dd8943d6b1d63ecef68d41497fa5dc9c323dc5b25",
                                            "outindex": 1
                                        },
                                        {
                                            "txhash": "0xcc439a6049f44146522dad7dd8943d6b1d63ecef68d41497fa5dc9c323dc5b25",
                                            "outindex": 6
                                        },
                                        {
                                            "txhash": "0x4bb6b0e7aee5edc559130ae261dd8523ccbd5ed87ccc65aa9b58bb90b2d4fe69",
                                            "outindex": 0
                                        }
                                    ],
                                    "keyImage": "0x8cf1bcde57e9a64b339f67d778f14da88581ddf4cb1bd180dd5c07645bf6cd68"
                                },
                                {
                                    "amount": "2000000000",
                                    "utxoGlobalIndex": [
                                        {
                                            "txhash": "0xcc439a6049f44146522dad7dd8943d6b1d63ecef68d41497fa5dc9c323dc5b25",
                                            "outindex": 5
                                        }
                                    ],
                                    "keyImage": "0x6199ac3df223f5b22f54326655b6f2d38db0d62ba09f3fc4590e643643d4ac8e"
                                }
                            ]
                        },
                        "output": {
                            "RpubKeytx": "0x04283fcf89fd6319bc8c7c14bc907b71a2e4d11d07effd5703ab2e47bb7fb23c",
                            "keyoutput": [
                                {
                                    "amount": "200000000",
                                    "onetimepubkey": "0x662c7df1a596aa9018986d946be3e9984c6188fc2620ffad622669c11280839c"
                                },
                                {
                                    "amount": "200000000",
                                    "onetimepubkey": "0xb3c2a28ac20f875bc2cc889c36b1e513f86c3b47d15cf3e9eb55de4f48814828"
                                },
                                {
                                    "amount": "1000000000",
                                    "onetimepubkey": "0x1236cbfd485981589752b20d30aa3c699203916cb4af34b147ff1b5e19f899d5"
                                }
                            ]
                        },
                        "assetExec": "coins"
                    },
                    "ty": 103
                },
                "rawpayload": " ",
                "signature": {
                    "ty": 5,
                    "pubkey": "0x731fb3ab7e47a046c3f927815d89497a93bf1d1e0631a35f1d1adfd3f9cff843",
                    "signature": " "
                },
                "fee": "1.0000",
                "expire": 1565601399,
                "nonce": 2234700166825889400,
                "to": "1FeyE6VDZ4FYgpK1n2okWMDAtPkwBuooQd",
                "from": "1FeyE6VDZ4FYgpK1n2okWMDAtPkwBuooQd",
                "hash": "0x6656dce3ef5a3ebcd012addc52bb1d6662f1581048989e291d6559c53f0b6d53"
            },
            "receipt": {
                "ty": 2,
                "tyName": "ExecOk",
                "logs": [
                    {
                        "ty": 2,
                        "tyName": "LogFee",
                        "log": {
                            "prev": {
                                "currency": 0,
                                "balance": "241300000000",
                                "frozen": "0",
                                "addr": "1FeyE6VDZ4FYgpK1n2okWMDAtPkwBuooQd"
                            },
                            "current": {
                                "currency": 0,
                                "balance": "241200000000",
                                "frozen": "0",
                                "addr": "1FeyE6VDZ4FYgpK1n2okWMDAtPkwBuooQd"
                            }
                        },
                        "rawLog": "0x0a2b10809ae7f48207222231466579453656445a34465967704b316e326f6b574d444174506b7742756f6f5164122b1080d88fc58207222231466579453656445a34465967704b316e326f6b574d444174506b7742756f6f5164"
                    },
                    {
                        "ty": 8,
                        "tyName": "LogExecDeposit",
                        "log": {
                            "execAddr": "1FeyE6VDZ4FYgpK1n2okWMDAtPkwBuooQd",
                            "prev": {
                                "currency": 0,
                                "balance": "0",
                                "frozen": "0",
                                "addr": "1JeVN3q938vx8Pqcg7Kodmih8sWT5eQHHs"
                            },
                            "current": {
                                "currency": 0,
                                "balance": "1700000000",
                                "frozen": "0",
                                "addr": "1JeVN3q938vx8Pqcg7Kodmih8sWT5eQHHs"
                            }
                        },
                        "rawLog": "0x0a2231466579453656445a34465967704b316e326f6b574d444174506b7742756f6f516412242222314a65564e337139333876783850716367374b6f646d6968387357543565514848731a2a1080e2cfaa062222314a65564e337139333876783850716367374b6f646d696838735754356551484873"
                    },
                    {
                        "ty": 501,
                        "tyName": "LogPrivacyInput",
                        "log": {
                            "keyinput": [
                                {
                                    "amount": "200000000",
                                    "utxoGlobalIndex": [
                                        {
                                            "txhash": "0xcc439a6049f44146522dad7dd8943d6b1d63ecef68d41497fa5dc9c323dc5b25",
                                            "outindex": 3
                                        },
                                        {
                                            "txhash": "0xcc439a6049f44146522dad7dd8943d6b1d63ecef68d41497fa5dc9c323dc5b25",
                                            "outindex": 2
                                        }
                                    ],
                                    "keyImage": "0xd1dcfeb83be78d4d6918a5cdceabdb1c11b9e9e10139c79a9b24c92879555f61"
                                },
                                {
                                    "amount": "1000000000",
                                    "utxoGlobalIndex": [
                                        {
                                            "txhash": "0xcc439a6049f44146522dad7dd8943d6b1d63ecef68d41497fa5dc9c323dc5b25",
                                            "outindex": 1
                                        },
                                        {
                                            "txhash": "0xcc439a6049f44146522dad7dd8943d6b1d63ecef68d41497fa5dc9c323dc5b25",
                                            "outindex": 6
                                        },
                                        {
                                            "txhash": "0x4bb6b0e7aee5edc559130ae261dd8523ccbd5ed87ccc65aa9b58bb90b2d4fe69",
                                            "outindex": 0
                                        }
                                    ],
                                    "keyImage": "0x8cf1bcde57e9a64b339f67d778f14da88581ddf4cb1bd180dd5c07645bf6cd68"
                                },
                                {
                                    "amount": "2000000000",
                                    "utxoGlobalIndex": [
                                        {
                                            "txhash": "0xcc439a6049f44146522dad7dd8943d6b1d63ecef68d41497fa5dc9c323dc5b25",
                                            "outindex": 5
                                        }
                                    ],
                                    "keyImage": "0x6199ac3df223f5b22f54326655b6f2d38db0d62ba09f3fc4590e643643d4ac8e"
                                }
                            ]
                        },
                        "rawLog": " "
                    },
                    {
                        "ty": 502,
                        "tyName": "LogPrivacyOutput",
                        "log": {
                            "RpubKeytx": "0x425459",
                            "keyoutput": [
                                {
                                    "amount": "200000000",
                                    "onetimepubkey": "0x662c7df1a596aa9018986d946be3e9984c6188fc2620ffad622669c11280839c"
                                },
                                {
                                    "amount": "200000000",
                                    "onetimepubkey": "0xb3c2a28ac20f875bc2cc889c36b1e513f86c3b47d15cf3e9eb55de4f48814828"
                                },
                                {
                                    "amount": "1000000000",
                                    "onetimepubkey": "0x1236cbfd485981589752b20d30aa3c699203916cb4af34b147ff1b5e19f899d5"
                                }
                            ]
                        },
                        "rawLog": "0x0a034254591227088084af5f1220662c7df1a596aa9018986d946be3e9984c6188fc2620ffad622669c11280839c1227088084af5f1220b3c2a28ac20f875bc2cc889c36b1e513f86c3b47d15cf3e9eb55de4f488148281228088094ebdc0312201236cbfd485981589752b20d30aa3c699203916cb4af34b147ff1b5e19f899d5"
                    }
                ]
            },
            "height": 2995030,
            "index": 1,
            "blocktime": 1565600804,
            "amount": "0.0000",
            "fromaddr": "1KoiQmaFg3DoZr84JehxrEWiR7SorSgbUx",
            "txhash": "0x6656dce3ef5a3ebcd012addc52bb1d6662f1581048989e291d6559c53f0b6d53",
            "actionname": "Privacy2Public"
        }
    ]
}
```
部分可选参数：  
`cli privacy list_txs -h`  
```
Flags:
  -a, --addr string         account address
  -c, --count int32         number of transactions, default 10 (default 10)
  -d, --direction int32     query direction (0: pre page, 1: next page), valid with seedtxhash param (default 1)
  -h, --help                help for list_txs
      --seedtxhash string   seed trasnaction hash
      --sendrecv int32      send or recv flag (0: send, 1: recv), default 0
      --token string        token name.(BTY supported) (default "BTY")
```
提供了-c查询数量，-d查询方向，指定起始查询哈希，指定发送或接收，指定查询symbol等配置项。  
该命令需有UTXO花费产生后可用。  


## showpas 查询指定地址的UTXO花费情况  
`cli privacy showpas -a "1KoiQmaFg3DoZr84JehxrEWiR7SorSgbUx" -s BTY`  
```
Total Privacy spend amount is 132.0000
[
    {
        "Txhash": "6656dce3ef5a3ebcd012addc52bb1d6662f1581048989e291d6559c53f0b6d53",
        "Spend": [
            {
                "Txhash": "0xcc439a6049f44146522dad7dd8943d6b1d63ecef68d41497fa5dc9c323dc5b25",
                "OutIndex": 3,
                "Amount": "2.0000"
            },
            {
                "Txhash": "0xcc439a6049f44146522dad7dd8943d6b1d63ecef68d41497fa5dc9c323dc5b25",
                "OutIndex": 6,
                "Amount": "10.0000"
            },
            {
                "Txhash": "0xcc439a6049f44146522dad7dd8943d6b1d63ecef68d41497fa5dc9c323dc5b25",
                "OutIndex": 5,
                "Amount": "20.0000"
            }
        ]
    },
    {
        "Txhash": "cc439a6049f44146522dad7dd8943d6b1d63ecef68d41497fa5dc9c323dc5b25",
        "Spend": [
            {
                "Txhash": "0xef6269240bdae5bcdc8399844ab1791a5fead4441f3492e7c735f8ded359e32b",
                "Amount": "100.0000"
            }
        ]
    }
]
```
该命令需有UTXO花费产生后可用。  

## rescanOpt 指定地址加载隐私UTXO  
`cli privacy rescanOpt -a all -f 0`  
```
"start rescan UTXO"  
```  
-f为0，指定地址开始加载导入地址的UTXO  
`cli privacy rescanOpt -a all -f 1`  
```
{
    "ShowRescanResults": [
        {
            "addr": "19S9wG9wgS2RhtZm1B5Zr24vexGYYK6QC7",
            "FlagString": "UtxoFlagNoScan"
        },
        {
            "addr": "1F5VPf3w2L3HEYoXP9g7TJNqyhCTUZZPmQ",
            "FlagString": "UtxoFlagNoScan"
        },
        {
            "addr": "1KoiQmaFg3DoZr84JehxrEWiR7SorSgbUx",
            "FlagString": "UtxoFlagNoScan"
        }
    ]
}
```
-f为1，显示目前地址的加载情况。