Commit fe44a8a1 authored by jiangpeng's avatar jiangpeng

privacy:update code

* rename struct ReqCreatePricacyTx field "Type" to "ActionType" * move privacy constant reference in chain33 types to local types
parent 83b42f56
......@@ -127,7 +127,7 @@ func createPub2PrivTx(cmd *cobra.Command, args []string) {
params := pty.ReqCreatePrivacyTx{
Tokenname: tokenname,
Type: types.PrivacyTypePublic2Privacy,
ActionType: pty.ActionPublic2Privacy,
Amount: amount,
Note: note,
Pubkeypair: pubkeypair,
......@@ -192,7 +192,7 @@ func createPriv2PrivTx(cmd *cobra.Command, args []string) {
params := pty.ReqCreatePrivacyTx{
Tokenname: tokenname,
Type: types.PrivacyTypePrivacy2Privacy,
ActionType: pty.ActionPrivacy2Privacy,
Amount: amount,
Note: note,
Pubkeypair: pubkeypair,
......@@ -258,15 +258,15 @@ func createPriv2PubTx(cmd *cobra.Command, args []string) {
}
params := pty.ReqCreatePrivacyTx{
Tokenname: tokenname,
Type: types.PrivacyTypePrivacy2Public,
Amount: amount,
Note: note,
From: from,
To: to,
Mixcount: mixCount,
Expire: expire,
AssetExec: assetExec,
Tokenname: tokenname,
ActionType: pty.ActionPrivacy2Public,
Amount: amount,
Note: note,
From: from,
To: to,
Mixcount: mixCount,
Expire: expire,
AssetExec: assetExec,
}
ctx := jsonclient.NewRPCCtx(rpcLaddr, "privacy.CreateRawTransaction", params, nil)
ctx.RunWithoutMarshal()
......
......@@ -181,7 +181,7 @@ func TestPrivacy_Exec_Public2Privacy(t *testing.T) {
for _, tc := range tcArr {
req := tc.payload.(*pty.ReqCreatePrivacyTx)
req.Type = types.PrivacyTypePublic2Privacy
req.ActionType = pty.ActionPublic2Privacy
tc.testState = testStateExec
}
testExec(mock, tcArr, testPrivateKeys[0], t)
......@@ -196,7 +196,7 @@ func TestPrivacy_Exec_Privacy2Privacy(t *testing.T) {
{
index: 1,
payload: &pty.ReqCreatePrivacyTx{
Type: types.PrivacyTypePublic2Privacy,
ActionType: pty.ActionPublic2Privacy,
Amount: types.Coin * 9,
Pubkeypair: testPubkeyPairs[0],
},
......@@ -213,8 +213,8 @@ func TestPrivacy_Exec_Privacy2Privacy(t *testing.T) {
for _, tc := range tcArr {
req := tc.payload.(*pty.ReqCreatePrivacyTx)
if req.Type == 0 {
req.Type = types.PrivacyTypePrivacy2Privacy
if req.ActionType == 0 {
req.ActionType = pty.ActionPrivacy2Privacy
}
tc.testState = testStateExec
}
......@@ -230,7 +230,7 @@ func TestPrivacy_Exec_Privacy2Public(t *testing.T) {
{
index: 1,
payload: &pty.ReqCreatePrivacyTx{
Type: types.PrivacyTypePublic2Privacy,
ActionType: pty.ActionPublic2Privacy,
Amount: types.Coin * 9,
Pubkeypair: testPubkeyPairs[0],
},
......@@ -248,8 +248,8 @@ func TestPrivacy_Exec_Privacy2Public(t *testing.T) {
for _, tc := range tcArr {
req := tc.payload.(*pty.ReqCreatePrivacyTx)
if req.Type == 0 {
req.Type = types.PrivacyTypePrivacy2Public
if req.ActionType == 0 {
req.ActionType = pty.ActionPrivacy2Public
}
tc.testState = testStateExec
}
......@@ -265,7 +265,7 @@ func TestPrivacy_ExecLocal(t *testing.T) {
{
index: 1,
payload: &pty.ReqCreatePrivacyTx{
Type: types.PrivacyTypePublic2Privacy,
ActionType: pty.ActionPublic2Privacy,
Amount: types.Coin * 9,
Pubkeypair: testPubkeyPairs[0],
},
......@@ -273,7 +273,7 @@ func TestPrivacy_ExecLocal(t *testing.T) {
{
index: 2,
payload: &pty.ReqCreatePrivacyTx{
Type: types.PrivacyTypePrivacy2Privacy,
ActionType: pty.ActionPrivacy2Privacy,
Amount: types.Coin,
Pubkeypair: testPubkeyPairs[1],
From: testAddrs[0],
......@@ -282,7 +282,7 @@ func TestPrivacy_ExecLocal(t *testing.T) {
{
index: 3,
payload: &pty.ReqCreatePrivacyTx{
Type: types.PrivacyTypePrivacy2Public,
ActionType: pty.ActionPrivacy2Public,
Amount: types.Coin,
Pubkeypair: testPubkeyPairs[1],
From: testAddrs[0],
......@@ -306,7 +306,7 @@ func TestPrivacy_ExecDelLocal(t *testing.T) {
{
index: 1,
payload: &pty.ReqCreatePrivacyTx{
Type: types.PrivacyTypePublic2Privacy,
ActionType: pty.ActionPublic2Privacy,
Amount: types.Coin * 9,
Pubkeypair: testPubkeyPairs[0],
},
......@@ -314,7 +314,7 @@ func TestPrivacy_ExecDelLocal(t *testing.T) {
{
index: 2,
payload: &pty.ReqCreatePrivacyTx{
Type: types.PrivacyTypePrivacy2Privacy,
ActionType: pty.ActionPrivacy2Privacy,
Amount: types.Coin,
Pubkeypair: testPubkeyPairs[1],
From: testAddrs[0],
......@@ -323,7 +323,7 @@ func TestPrivacy_ExecDelLocal(t *testing.T) {
{
index: 3,
payload: &pty.ReqCreatePrivacyTx{
Type: types.PrivacyTypePrivacy2Public,
ActionType: pty.ActionPrivacy2Public,
Amount: types.Coin,
Pubkeypair: testPubkeyPairs[1],
From: testAddrs[0],
......
......@@ -103,14 +103,14 @@ func (p *privacy) getGlobalUtxoIndex(getUtxoIndexReq *pty.ReqUTXOGlobalIndex) (t
tokenName := getUtxoIndexReq.Tokenname
currentHeight := p.GetHeight()
for _, amount := range getUtxoIndexReq.Amount {
utxos, err := p.getUtxosByTokenAndAmount(tokenName, amount, types.UTXOCacheCount)
utxos, err := p.getUtxosByTokenAndAmount(tokenName, amount, pty.UTXOCacheCount)
if err != nil {
return utxoGlobalIndexResp, err
}
index := len(utxos) - 1
for ; index >= 0; index-- {
if utxos[index].GetHeight()+types.ConfirmedHeight <= currentHeight {
if utxos[index].GetHeight()+pty.ConfirmedHeight <= currentHeight {
break
}
}
......
......@@ -17,7 +17,7 @@ var (
{
index: 1,
payload: &pty.ReqCreatePrivacyTx{
Type: types.PrivacyTypePublic2Privacy,
ActionType: pty.ActionPublic2Privacy,
Amount: types.Coin,
Pubkeypair: testPubkeyPairs[0],
},
......
......@@ -237,5 +237,5 @@ type walletMock struct {
}
func (w *walletMock) GetBlockHeight() int64 {
return initHeight + types.PrivacyMaturityDegree
return initHeight + pty.UtxoMaturityDegree
}
File mode changed from 100644 to 100755
......@@ -402,10 +402,7 @@ message WalletAccountPrivacy {
message ReqCreatePrivacyTx {
string tokenname = 1;
// 构建交易类型
// 1:隐私交易 公开->隐私
// 2:隐私交易 隐私->隐私
// 3:隐私交易 隐私->公开
int32 type = 2;
int32 actionType = 2;
int64 amount = 3;
string note = 4;
// 普通交易的发送方
......
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package types
import "github.com/33cn/chain33/types"
const (
// InvalidAction invalid action type
InvalidAction = 0
//action type for privacy
// ActionPublic2Privacy public to privacy action type
ActionPublic2Privacy = iota + 100
// ActionPrivacy2Privacy privacy to privacy action type
ActionPrivacy2Privacy
// ActionPrivacy2Public privacy to public action type
ActionPrivacy2Public
// log for privacy
// TyLogPrivacyFee privacy fee log type
TyLogPrivacyFee = 500
// TyLogPrivacyInput privacy input type
TyLogPrivacyInput = 501
// TyLogPrivacyOutput privacy output type
TyLogPrivacyOutput = 502
)
const (
//SignNameOnetimeED25519 privacy name of crypto
SignNameOnetimeED25519 = "privacy.onetimeed25519"
// SignNameRing signature name ring
SignNameRing = "privacy.RingSignatue"
// OnetimeED25519 one time ED25519
OnetimeED25519 = 4
// RingBaseonED25519 ring raseon ED25519
RingBaseonED25519 = 5
// PrivacyMaxCount max mix utxo cout
PrivacyMaxCount = 16
// PrivacyTxFee privacy tx fee
PrivacyTxFee = types.Coin
)
const (
// utxo缓存数量
UTXOCacheCount = 256
// UtxoMaturityDegree utxo 成熟度
UtxoMaturityDegree = 12
BTYDustThreshold = types.Coin
ConfirmedHeight = 12
SignatureSize = (4 + 33 + 65)
// Size1Kshiftlen tx消息大小1k
Size1Kshiftlen = 10
)
......@@ -14,41 +14,6 @@ import (
// PrivacyX privacy executor name
var PrivacyX = "privacy"
const (
// InvalidAction invalid action type
InvalidAction = 0
//action type for privacy
// ActionPublic2Privacy public to privacy action type
ActionPublic2Privacy = iota + 100
// ActionPrivacy2Privacy privacy to privacy action type
ActionPrivacy2Privacy
// ActionPrivacy2Public privacy to public action type
ActionPrivacy2Public
// log for privacy
// TyLogPrivacyFee privacy fee log type
TyLogPrivacyFee = 500
// TyLogPrivacyInput privacy input type
TyLogPrivacyInput = 501
// TyLogPrivacyOutput privacy output type
TyLogPrivacyOutput = 502
//SignNameOnetimeED25519 privacy name of crypto
SignNameOnetimeED25519 = "privacy.onetimeed25519"
// SignNameRing signature name ring
SignNameRing = "privacy.RingSignatue"
// OnetimeED25519 one time ED25519
OnetimeED25519 = 4
// RingBaseonED25519 ring raseon ED25519
RingBaseonED25519 = 5
// PrivacyMaxCount max mix utxo cout
PrivacyMaxCount = 16
// PrivacyTxFee privacy tx fee
PrivacyTxFee = types.Coin
)
// RescanUtxoFlag
const (
UtxoFlagNoScan int32 = 0
......
This diff is collapsed.
......@@ -318,7 +318,7 @@ func (policy *privacyPolicy) selectUTXO(token, addr string, amount int64) ([]*tx
if curBlockHeight < wutxo.height {
continue
}
if curBlockHeight-wutxo.height > types.PrivacyMaturityDegree {
if curBlockHeight-wutxo.height > privacytypes.UtxoMaturityDegree {
balance += wutxo.outinfo.amount
confirmUTXOs = append(confirmUTXOs, wutxo)
} else {
......@@ -493,12 +493,12 @@ func (policy *privacyPolicy) buildInput(privacykeyParirs *privacy.Privacy, build
}
func (policy *privacyPolicy) createTransaction(req *privacytypes.ReqCreatePrivacyTx) (*types.Transaction, error) {
switch req.Type {
case types.PrivacyTypePublic2Privacy:
switch req.ActionType {
case privacytypes.ActionPublic2Privacy:
return policy.createPublic2PrivacyTx(req)
case types.PrivacyTypePrivacy2Privacy:
case privacytypes.ActionPrivacy2Privacy:
return policy.createPrivacy2PrivacyTx(req)
case types.PrivacyTypePrivacy2Public:
case privacytypes.ActionPrivacy2Public:
return policy.createPrivacy2PublicTx(req)
}
return nil, types.ErrInvalidParam
......
......@@ -122,7 +122,7 @@ func (mock *PrivacyMock) CreateUTXOs(sender string, pubkeypair string, amount in
tx := mock.createPublic2PrivacyTx(&ty.ReqCreatePrivacyTx{
AssetExec: "coins",
Tokenname: mock.tokenName,
Type: 1,
ActionType: 1,
Amount: amount,
From: sender,
Pubkeypair: pubkeypair,
......@@ -219,8 +219,8 @@ func (mock *PrivacyMock) createPublic2PrivacyTx(req *ty.ReqCreatePrivacyTx) *typ
To: address.ExecAddress(ty.PrivacyX),
}
cfg := mock.walletOp.GetAPI().GetConfig()
txSize := types.Size(tx) + types.SignatureSize
realFee := int64((txSize+1023)>>types.Size1Kshiftlen) * cfg.GetMinTxFeeRate()
txSize := types.Size(tx) + ty.SignatureSize
realFee := int64((txSize+1023)>>ty.Size1Kshiftlen) * cfg.GetMinTxFeeRate()
tx.Fee = realFee
tx.SetExpire(cfg, time.Hour)
return tx
......
......@@ -358,7 +358,7 @@ func Test_CreateTransaction(t *testing.T) {
req: &ty.ReqCreatePrivacyTx{
AssetExec: "coins",
Tokenname: types.BTY,
Type: 1,
ActionType: ty.ActionPublic2Privacy,
Amount: 100 * types.Coin,
From: testAddrs[0],
Pubkeypair: testPubkeyPairs[0],
......@@ -369,7 +369,7 @@ func Test_CreateTransaction(t *testing.T) {
req: &ty.ReqCreatePrivacyTx{
AssetExec: "coins",
Tokenname: types.BTY,
Type: 2,
ActionType: ty.ActionPrivacy2Privacy,
Amount: 10 * types.Coin,
From: testAddrs[0],
Pubkeypair: testPubkeyPairs[1],
......@@ -380,7 +380,7 @@ func Test_CreateTransaction(t *testing.T) {
req: &ty.ReqCreatePrivacyTx{
AssetExec: "coins",
Tokenname: types.BTY,
Type: 3,
ActionType: ty.ActionPrivacy2Public,
Amount: 10 * types.Coin,
From: testAddrs[0],
Pubkeypair: testPubkeyPairs[0],
......
......@@ -161,12 +161,12 @@ func parseViewSpendPubKeyPair(in string) (viewPubKey, spendPubKey []byte, err er
//1.进行实际转账utxo
//2.进行找零转账utxo
func generateOuts(viewpubTo, spendpubto, viewpubChangeto, spendpubChangeto *[32]byte, transAmount, selectedAmount, fee int64) (*privacytypes.PrivacyOutput, error) {
decomDigit := decomposeAmount2digits(transAmount, types.BTYDustThreshold)
decomDigit := decomposeAmount2digits(transAmount, privacytypes.BTYDustThreshold)
//计算找零
changeAmount := selectedAmount - transAmount - fee
var decomChange []int64
if 0 < changeAmount {
decomChange = decomposeAmount2digits(changeAmount, types.BTYDustThreshold)
decomChange = decomposeAmount2digits(changeAmount, privacytypes.BTYDustThreshold)
}
bizlog.Info("generateOuts", "decompose digit for amount", selectedAmount-fee, "decomDigit", decomDigit)
......
......@@ -9,6 +9,7 @@ import (
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/types"
pty "github.com/33cn/plugin/plugin/dapp/privacy/types"
"github.com/stretchr/testify/require"
)
......@@ -119,7 +120,7 @@ func Test_decomposeAmount2digits(t *testing.T) {
},
{
amount: 62387455827,
dustThreshold: types.BTYDustThreshold,
dustThreshold: pty.BTYDustThreshold,
actual: []int64{87455827, 1e8, 2e8, 2e9, 5e10, 1e10},
},
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment