Skip to content

Commit 6bac746

Browse files
authored
support ecosystem 'utxo_fee' parameter settings (#2058)
1 parent 5aed384 commit 6bac746

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

packages/smart/smart_p.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,9 @@ func UtxoToken(sc *SmartContract, toID int64, value string) (flag bool, err erro
912912
var money2 = decimal.Zero
913913
var fuelRate2 = decimal.Zero
914914
var taxes2 = decimal.Zero
915-
if ret, ok := fuels[ecosystem2]; ok {
915+
ret, ok := fuels[ecosystem2]
916+
percent, hasPercent := comPercents[ecosystem2]
917+
if ok && hasPercent {
916918

917919
fuelRate2, err = decimal.NewFromString(ret)
918920
if err != nil {
@@ -925,7 +927,7 @@ func UtxoToken(sc *SmartContract, toID int64, value string) (flag bool, err erro
925927
money2 = totalAmount
926928
}
927929
percentMoney2 := decimal.Zero
928-
if percent, hasPercent := comPercents[ecosystem2]; hasPercent && percent > 0 && money2.GreaterThan(decimal.Zero) {
930+
if percent > 0 && money2.GreaterThan(decimal.Zero) {
929931
percentMoney2 = money2.Mul(decimal.NewFromInt(percent)).Div(decimal.New(100, 0)).Floor()
930932
if percentMoney2.GreaterThan(decimal.Zero) {
931933
txOutputs = append(txOutputs, sqldb.SpentInfo{OutputIndex: outputIndex, OutputKeyId: 0, OutputValue: percentMoney2.String(), BlockId: blockId, Ecosystem: ecosystem2, Type: consts.UTXO_Type_Combustion})

packages/storage/sqldb/ecosystem.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,13 @@ func GetAllSystemStatesIDs() ([]int64, []string, error) {
8585

8686
// GetCombustionPercents is ecosystem combustion percent
8787
func GetCombustionPercents(db *DbTransaction, ids []int64) (map[int64]int64, error) {
88-
//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
89-
//select id,(fee_mode_info -> 'combustion' ->> 'percent')::int as percent from "1_ecosystems" where (fee_mode_info -> 'combustion' ->> 'flag')::int = 2 and id in
9088
query :=
9189
`
92-
select id,(fee_mode_info::json#>>'{combustion,percent}')::int as percent
93-
from "1_ecosystems"
94-
where (fee_mode_info::json#>>'{combustion,flag}')::int=2 and id IN ?
95-
`
90+
SELECT eco.id,(eco.fee_mode_info::json#>>'{combustion,percent}')::int as percent
91+
FROM "1_parameters" as par
92+
LEFT JOIN "1_ecosystems" as eco ON par.ecosystem = eco.id
93+
WHERE par.name = 'utxo_fee' and par.value = '1' and par.ecosystem IN ?
94+
`
9695

9796
type Combustion struct {
9897
Id int64

packages/transaction/smart_contract.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func (s *SmartTransactionParser) Action(in *InToCxt, out *OutCtx) (err error) {
9494
}
9595
out.Apply(
9696
WithOutCtxTxResult(ret),
97+
WithOutCtxSysUpdate(s.SysUpdate),
9798
WithOutCtxRollBackTx(s.RollBackTx),
9899
)
99100
if err != nil || s.Penalty {
@@ -109,7 +110,6 @@ func (s *SmartTransactionParser) Action(in *InToCxt, out *OutCtx) (err error) {
109110
ret.BlockId = s.BlockHeader.BlockId
110111
out.Apply(
111112
WithOutCtxTxResult(ret),
112-
WithOutCtxSysUpdate(s.SysUpdate),
113113
WithOutCtxTxOutputs(s.TxOutputsMap),
114114
WithOutCtxTxInputs(s.TxInputsMap),
115115
)

packages/types/custom_tx.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package types
66

77
import (
8+
"errors"
89
"fmt"
910
"regexp"
1011
"strings"
@@ -142,14 +143,20 @@ func (txSmart *SmartTransaction) Validate() error {
142143
if txSmart.NetworkID != conf.Config.LocalConf.NetworkID {
143144
return fmt.Errorf("error networkid invalid")
144145
}
145-
if txSmart.UTXO != nil && len(txSmart.UTXO.Value) > 0 {
146+
if txSmart.UTXO != nil {
146147
if ok, _ := regexp.MatchString("^\\d+$", txSmart.UTXO.Value); !ok {
147-
return fmt.Errorf("error UTXO %s must integer", txSmart.UTXO.Value)
148+
return errors.New("error UTXO Value must be a positive integer")
149+
}
150+
if value, err := decimal.NewFromString(txSmart.UTXO.Value); err != nil || value.LessThanOrEqual(decimal.Zero) {
151+
return errors.New("error UTXO Value must be greater than zero")
148152
}
149153
}
150-
if txSmart.TransferSelf != nil && len(txSmart.TransferSelf.Value) > 0 {
154+
if txSmart.TransferSelf != nil {
151155
if ok, _ := regexp.MatchString("^\\d+$", txSmart.TransferSelf.Value); !ok {
152-
return fmt.Errorf("error TransferSelf %s must integer", txSmart.TransferSelf.Value)
156+
return errors.New("error TransferSelf Value must be a positive integer")
157+
}
158+
if value, err := decimal.NewFromString(txSmart.TransferSelf.Value); err != nil || value.LessThanOrEqual(decimal.Zero) {
159+
return errors.New("error TransferSelf Value must be greater than zero")
153160
}
154161
}
155162

0 commit comments

Comments
 (0)