Commit 2c40966f authored by jiangpeng's avatar jiangpeng Committed by vipwzw

adapting parachain privacy

parent bd063a54
......@@ -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), tx.Execer) {
if err := types.Decode(msg, tx); err != nil || !bytes.Equal([]byte(privacytypes.PrivacyX), types.GetRealExecName(tx.Execer)) {
// 目前只有隐私交易用到了环签名
return false
}
......
......@@ -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
......
......@@ -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
}
......
......@@ -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) {}
// 使能隐私账户
......
This diff is collapsed.
......@@ -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()
......
This diff is collapsed.
......@@ -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,
......
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