Unverified Commit 556879c1 authored by vipwzw's avatar vipwzw Committed by GitHub

Merge pull request #265 from bysomeone/modify-privacy-txFee

modify privacy tx fee
parents 12653f8f 16afdc44
......@@ -224,12 +224,6 @@ func (p *privacy) CheckTx(tx *types.Transaction, index int) error {
if action.Ty == pty.ActionPrivacy2Public && action.GetPrivacy2Public() != nil {
amount = action.GetPrivacy2Public().Amount
}
if tx.Fee < pty.PrivacyTxFee {
privacylog.Error("PrivacyTrading CheckTx", "txhash", txhashstr, "fee set:", tx.Fee, "required:", pty.PrivacyTxFee, " error ErrPrivacyTxFeeNotEnough")
return pty.ErrPrivacyTxFeeNotEnough
}
var ringSignature types.RingSignature
if err := types.Decode(tx.Signature.Signature, &ringSignature); err != nil {
privacylog.Error("PrivacyTrading CheckTx", "txhash", txhashstr, "Decode tx.Signature.Signature error ", err)
......@@ -276,6 +270,10 @@ func (p *privacy) CheckTx(tx *types.Transaction, index int) error {
//平行链下的隐私交易,utxo不需要燃烧,fee只收取主链的bty,和utxo无关联
if !types.IsPara() {
if tx.Fee < pty.PrivacyTxFee {
privacylog.Error("PrivacyTrading CheckTx", "txhash", txhashstr, "fee set:", tx.Fee, "required:", pty.PrivacyTxFee, " error ErrPrivacyTxFeeNotEnough")
return pty.ErrPrivacyTxFeeNotEnough
}
var feeAmount int64
if action.Ty == pty.ActionPrivacy2Privacy {
feeAmount = totalInput - totalOutput
......
......@@ -577,7 +577,7 @@ func (policy *privacyPolicy) createTransaction(req *types.ReqCreateTransaction)
func (policy *privacyPolicy) createPublic2PrivacyTx(req *types.ReqCreateTransaction) (*types.Transaction, error) {
viewPubSlice, spendPubSlice, err := parseViewSpendPubKeyPair(req.GetPubkeypair())
if err != nil {
bizlog.Error("parse view spend public key pair failed. err ", err)
bizlog.Error("createPublic2PrivacyTx", "parse view spend public key pair failed. err ", err)
return nil, err
}
amount := req.GetAmount()
......@@ -585,7 +585,7 @@ func (policy *privacyPolicy) createPublic2PrivacyTx(req *types.ReqCreateTransact
spendPublic := (*[32]byte)(unsafe.Pointer(&spendPubSlice[0]))
privacyOutput, err := generateOuts(viewPublic, spendPublic, nil, nil, amount, amount, 0)
if err != nil {
bizlog.Error("generate output failed. err ", err)
bizlog.Error("createPublic2PrivacyTx", "generate output failed. err ", err)
return nil, err
}
......@@ -606,15 +606,18 @@ func (policy *privacyPolicy) createPublic2PrivacyTx(req *types.ReqCreateTransact
Nonce: policy.getWalletOperate().Nonce(),
To: address.ExecAddress(types.ExecName(privacytypes.PrivacyX)),
}
tx.SetExpire(time.Duration(req.Expire))
tx.Signature = &types.Signature{
Signature: types.Encode(&privacytypes.PrivacySignatureParam{
ActionType: action.Ty,
}),
}
tx.Fee, err = tx.GetRealFee(types.GInt("MinFee"))
if err != nil {
bizlog.Error("createPublic2PrivacyTx", "calc fee failed", err)
return nil, err
}
txSize := types.Size(tx) + types.SignatureSize
realFee := int64((txSize+1023)>>types.Size1Kshiftlen) * types.GInt("MinFee")
tx.Fee = realFee
return tx, nil
}
......@@ -622,7 +625,8 @@ func (policy *privacyPolicy) createPrivacy2PrivacyTx(req *types.ReqCreateTransac
//需要燃烧的utxo
utxoBurnedAmount := privacytypes.PrivacyTxFee
if types.IsPara() {
isPara := types.IsPara()
if isPara {
utxoBurnedAmount = 0
}
buildInfo := &buildInputInfo{
......@@ -683,7 +687,16 @@ func (policy *privacyPolicy) createPrivacy2PrivacyTx(req *types.ReqCreateTransac
Nonce: policy.getWalletOperate().Nonce(),
To: address.ExecAddress(types.ExecName(privacytypes.PrivacyX)),
}
// 创建交易成功,将已经使用掉的UTXO冻结
tx.SetExpire(time.Duration(req.Expire))
if isPara {
tx.Fee, err = tx.GetRealFee(types.GInt("MinFee"))
if err != nil {
bizlog.Error("createPrivacy2PrivacyTx", "calc fee failed", err)
return nil, err
}
}
// 创建交易成功,将已经使用掉的UTXO冻结,需要注意此处获取的txHash和交易发送时的一致
policy.saveFTXOInfo(tx, req.GetTokenname(), req.GetFrom(), hex.EncodeToString(tx.Hash()), selectedUtxo)
tx.Signature = &types.Signature{
Signature: types.Encode(&privacytypes.PrivacySignatureParam{
......@@ -699,7 +712,8 @@ func (policy *privacyPolicy) createPrivacy2PublicTx(req *types.ReqCreateTransact
//需要燃烧的utxo
utxoBurnedAmount := privacytypes.PrivacyTxFee
if types.IsPara() {
isPara := types.IsPara()
if isPara {
utxoBurnedAmount = 0
}
buildInfo := &buildInputInfo{
......@@ -759,7 +773,15 @@ func (policy *privacyPolicy) createPrivacy2PublicTx(req *types.ReqCreateTransact
Nonce: policy.getWalletOperate().Nonce(),
To: address.ExecAddress(types.ExecName(privacytypes.PrivacyX)),
}
// 创建交易成功,将已经使用掉的UTXO冻结
tx.SetExpire(time.Duration(req.Expire))
if isPara {
tx.Fee, err = tx.GetRealFee(types.GInt("MinFee"))
if err != nil {
bizlog.Error("createPrivacy2PublicTx", "calc fee failed", err)
return nil, err
}
}
// 创建交易成功,将已经使用掉的UTXO冻结,需要注意此处获取的txHash和交易发送时的一致
policy.saveFTXOInfo(tx, req.GetTokenname(), req.GetFrom(), hex.EncodeToString(tx.Hash()), selectedUtxo)
tx.Signature = &types.Signature{
Signature: types.Encode(&privacytypes.PrivacySignatureParam{
......
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