Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support ecosystem 'utxo_fee' parameter settings #2058

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/smart/smart_p.go
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,9 @@ func UtxoToken(sc *SmartContract, toID int64, value string) (flag bool, err erro
var money2 = decimal.Zero
var fuelRate2 = decimal.Zero
var taxes2 = decimal.Zero
if ret, ok := fuels[ecosystem2]; ok {
ret, ok := fuels[ecosystem2]
percent, hasPercent := comPercents[ecosystem2]
if ok && hasPercent {

fuelRate2, err = decimal.NewFromString(ret)
if err != nil {
Expand All @@ -925,7 +927,7 @@ func UtxoToken(sc *SmartContract, toID int64, value string) (flag bool, err erro
money2 = totalAmount
}
percentMoney2 := decimal.Zero
if percent, hasPercent := comPercents[ecosystem2]; hasPercent && percent > 0 && money2.GreaterThan(decimal.Zero) {
if percent > 0 && money2.GreaterThan(decimal.Zero) {
percentMoney2 = money2.Mul(decimal.NewFromInt(percent)).Div(decimal.New(100, 0)).Floor()
if percentMoney2.GreaterThan(decimal.Zero) {
txOutputs = append(txOutputs, sqldb.SpentInfo{OutputIndex: outputIndex, OutputKeyId: 0, OutputValue: percentMoney2.String(), BlockId: blockId, Ecosystem: ecosystem2, Type: consts.UTXO_Type_Combustion})
Expand Down
11 changes: 5 additions & 6 deletions packages/storage/sqldb/ecosystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,13 @@ func GetAllSystemStatesIDs() ([]int64, []string, error) {

// GetCombustionPercents is ecosystem combustion percent
func GetCombustionPercents(db *DbTransaction, ids []int64) (map[int64]int64, error) {
//select id, (fee_mode_info::json #>> '{combustion,percent}')::int as percent from "1_ecosystems" where (fee_mode_info::json #>> '{combustion,flag}')::int = 2 and id in
//select id,(fee_mode_info -> 'combustion' ->> 'percent')::int as percent from "1_ecosystems" where (fee_mode_info -> 'combustion' ->> 'flag')::int = 2 and id in
query :=
`
select id,(fee_mode_info::json#>>'{combustion,percent}')::int as percent
from "1_ecosystems"
where (fee_mode_info::json#>>'{combustion,flag}')::int=2 and id IN ?
`
SELECT eco.id,(eco.fee_mode_info::json#>>'{combustion,percent}')::int as percent
FROM "1_parameters" as par
LEFT JOIN "1_ecosystems" as eco ON par.ecosystem = eco.id
WHERE par.name = 'utxo_fee' and par.value = '1' and par.ecosystem IN ?
`

type Combustion struct {
Id int64
Expand Down
2 changes: 1 addition & 1 deletion packages/transaction/smart_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (s *SmartTransactionParser) Action(in *InToCxt, out *OutCtx) (err error) {
}
out.Apply(
WithOutCtxTxResult(ret),
WithOutCtxSysUpdate(s.SysUpdate),
WithOutCtxRollBackTx(s.RollBackTx),
)
if err != nil || s.Penalty {
Expand All @@ -109,7 +110,6 @@ func (s *SmartTransactionParser) Action(in *InToCxt, out *OutCtx) (err error) {
ret.BlockId = s.BlockHeader.BlockId
out.Apply(
WithOutCtxTxResult(ret),
WithOutCtxSysUpdate(s.SysUpdate),
WithOutCtxTxOutputs(s.TxOutputsMap),
WithOutCtxTxInputs(s.TxInputsMap),
)
Expand Down
15 changes: 11 additions & 4 deletions packages/types/custom_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package types

import (
"errors"
"fmt"
"regexp"
"strings"
Expand Down Expand Up @@ -142,14 +143,20 @@ func (txSmart *SmartTransaction) Validate() error {
if txSmart.NetworkID != conf.Config.LocalConf.NetworkID {
return fmt.Errorf("error networkid invalid")
}
if txSmart.UTXO != nil && len(txSmart.UTXO.Value) > 0 {
if txSmart.UTXO != nil {
if ok, _ := regexp.MatchString("^\\d+$", txSmart.UTXO.Value); !ok {
return fmt.Errorf("error UTXO %s must integer", txSmart.UTXO.Value)
return errors.New("error UTXO Value must be a positive integer")
}
if value, err := decimal.NewFromString(txSmart.UTXO.Value); err != nil || value.LessThanOrEqual(decimal.Zero) {
return errors.New("error UTXO Value must be greater than zero")
}
}
if txSmart.TransferSelf != nil && len(txSmart.TransferSelf.Value) > 0 {
if txSmart.TransferSelf != nil {
if ok, _ := regexp.MatchString("^\\d+$", txSmart.TransferSelf.Value); !ok {
return fmt.Errorf("error TransferSelf %s must integer", txSmart.TransferSelf.Value)
return errors.New("error TransferSelf Value must be a positive integer")
}
if value, err := decimal.NewFromString(txSmart.TransferSelf.Value); err != nil || value.LessThanOrEqual(decimal.Zero) {
return errors.New("error TransferSelf Value must be greater than zero")
}
}

Expand Down