Commit ded031ee authored by jiangpeng's avatar jiangpeng Committed by vipwzw

privacy:support fork in test net

parent 4ea2a651
......@@ -149,7 +149,7 @@ func (p *privacy) Exec_Privacy2Public(payload *ty.Privacy2Public, tx *types.Tran
func (p *privacy) createAccountDB(exec, symbol string) (*account.DB, error) {
if exec == "coins" {
if exec == "" || exec == "coins" {
return p.GetCoinsAccount(), nil
}
......
......@@ -20,14 +20,23 @@ const (
invalidIndex = -1
)
//计算隐私资产utxo的前缀, 和exec,token相关
func calcUtxoAssetPrefix(exec, token string) string {
//只有coins资产的key不加exec前缀, 主要考虑是不加分叉兼容历史隐私交易
if exec == "" || exec == "coins" {
return token
}
return exec + ":" + token
}
//CalcPrivacyOutputKey 该key对应的是types.KeyOutput
//该kv会在store中设置
func CalcPrivacyOutputKey(exec, token string, amount int64, txhash string, outindex int) (key []byte) {
return []byte(fmt.Sprintf(privacyOutputKeyPrefix+"-%s-%s-%d-%s-%d", exec, token, amount, txhash, outindex))
return []byte(fmt.Sprintf(privacyOutputKeyPrefix+"-%s-%d-%s-%d", calcUtxoAssetPrefix(exec, token), amount, txhash, outindex))
}
func calcPrivacyKeyImageKey(exec, token string, keyimage []byte) []byte {
return []byte(fmt.Sprintf(privacyKeyImagePrefix+"-%s-%s-%s", exec, token, common.ToHex(keyimage)))
return []byte(fmt.Sprintf(privacyKeyImagePrefix+"-%s-%s", calcUtxoAssetPrefix(exec, token), common.ToHex(keyimage)))
}
//CalcPrivacyUTXOkeyHeight 在本地数据库中设置一条可以找到对应amount的对应的utxo的global index
......
......@@ -208,6 +208,11 @@ func (p *privacy) CheckTx(tx *types.Transaction, index int) error {
return err
}
privacylog.Debug("PrivacyTrading CheckTx", "txhash", txhashstr, "action type ", action.Ty)
assertExec := action.GetAssertExec()
token := action.GetTokenName()
if token == "" {
return types.ErrInvalidParam
}
if pty.ActionPublic2Privacy == action.Ty {
return nil
}
......@@ -220,12 +225,6 @@ func (p *privacy) CheckTx(tx *types.Transaction, index int) error {
//如果是私到私 或者私到公,交易费扣除则需要utxo实现,交易费并不生成真正的UTXO,也是即时燃烧掉而已
var amount int64
keyinput := input.Keyinput
assertExec := action.GetAssertExec()
token := action.GetTokenName()
if assertExec == "" || token == "" {
return types.ErrInvalidParam
}
if action.Ty == pty.ActionPrivacy2Public && action.GetPrivacy2Public() != nil {
amount = action.GetPrivacy2Public().Amount
......@@ -269,8 +268,8 @@ func (p *privacy) CheckTx(tx *types.Transaction, index int) error {
return pty.ErrPubkeysOfUTXO
}
//平行链下的隐私交易,utxo不需要燃烧,fee只收取主链的bty,和utxo无关联
if assertExec == "coins" && !types.IsPara() {
//只有主链coins隐私转账才收取特殊交易费, assertExec空情况适配老版本
if !types.IsPara() && (assertExec == "" || assertExec == "coins") {
for _, output := range output.Keyoutput {
totalOutput += output.Amount
......
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