Skip to content

Commit e4f37e6

Browse files
authored
Return utxo/vtxo amount limits in GetInfo (#531)
* Make utxo/vtxo amount limit disabled by default and return params in GetInfo * Add comments * Fix comments * Update sdk
1 parent ada8a77 commit e4f37e6

File tree

14 files changed

+173
-12
lines changed

14 files changed

+173
-12
lines changed

api-spec/openapi/swagger/ark/v1/service.swagger.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,26 @@
548548
},
549549
"version": {
550550
"type": "string"
551+
},
552+
"utxoMinAmount": {
553+
"type": "string",
554+
"format": "int64",
555+
"title": "-1 means native dust limit (default)"
556+
},
557+
"utxoMaxAmount": {
558+
"type": "string",
559+
"format": "int64",
560+
"title": "-1 means no limit (default), 0 means boarding not allowed"
561+
},
562+
"vtxoMinAmount": {
563+
"type": "string",
564+
"format": "int64",
565+
"title": "-1 means native dust limit (default)"
566+
},
567+
"vtxoMaxAmount": {
568+
"type": "string",
569+
"format": "int64",
570+
"title": "-1 means no limit (default)"
551571
}
552572
}
553573
},

api-spec/protobuf/ark/v1/service.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ message GetInfoResponse {
104104
string forfeit_address = 9;
105105
MarketHour market_hour = 10;
106106
string version = 11;
107+
int64 utxo_min_amount = 12; // -1 means native dust limit (default)
108+
int64 utxo_max_amount = 13; // -1 means no limit (default), 0 means boarding not allowed
109+
int64 vtxo_min_amount = 14; // -1 means native dust limit (default)
110+
int64 vtxo_max_amount = 15; // -1 means no limit (default)
107111
}
108112

109113
message GetBoardingAddressRequest {

api-spec/protobuf/gen/ark/v1/service.pb.go

Lines changed: 44 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/client-sdk/client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ func (a *arkClient) initWithWallet(
256256
MarketHourPeriod: info.MarketHourPeriod,
257257
MarketHourRoundInterval: info.MarketHourRoundInterval,
258258
ExplorerURL: explorerSvc.BaseUrl(),
259+
UtxoMinAmount: info.UtxoMinAmount,
260+
UtxoMaxAmount: info.UtxoMaxAmount,
261+
VtxoMinAmount: info.VtxoMinAmount,
262+
VtxoMaxAmount: info.VtxoMaxAmount,
259263
}
260264
if err := a.store.ConfigStore().AddData(ctx, storeData); err != nil {
261265
return err
@@ -338,6 +342,10 @@ func (a *arkClient) init(
338342
MarketHourEndTime: info.MarketHourEndTime,
339343
MarketHourPeriod: info.MarketHourPeriod,
340344
MarketHourRoundInterval: info.MarketHourRoundInterval,
345+
UtxoMinAmount: info.UtxoMinAmount,
346+
UtxoMaxAmount: info.UtxoMaxAmount,
347+
VtxoMinAmount: info.VtxoMinAmount,
348+
VtxoMaxAmount: info.VtxoMaxAmount,
341349
}
342350
walletSvc, err := getWallet(a.store.ConfigStore(), &cfgData, supportedWallets)
343351
if err != nil {

pkg/client-sdk/client/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ type Info struct {
7878
MarketHourEndTime int64
7979
MarketHourPeriod int64
8080
MarketHourRoundInterval int64
81+
UtxoMinAmount int64
82+
UtxoMaxAmount int64
83+
VtxoMinAmount int64
84+
VtxoMaxAmount int64
8185
}
8286

8387
type RoundEventChannel struct {

pkg/client-sdk/client/grpc/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ func (a *grpcClient) GetInfo(ctx context.Context) (*client.Info, error) {
8080
MarketHourEndTime: resp.GetMarketHour().GetNextEndTime(),
8181
MarketHourPeriod: resp.GetMarketHour().GetPeriod(),
8282
MarketHourRoundInterval: resp.GetMarketHour().GetRoundInterval(),
83+
UtxoMinAmount: resp.GetUtxoMinAmount(),
84+
UtxoMaxAmount: resp.GetUtxoMaxAmount(),
85+
VtxoMinAmount: resp.GetVtxoMinAmount(),
86+
VtxoMaxAmount: resp.GetVtxoMaxAmount(),
8387
}, nil
8488
}
8589

pkg/client-sdk/client/rest/client.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,22 @@ func (a *restClient) GetInfo(
9595
if err != nil {
9696
return nil, err
9797
}
98+
utxoMinAmount, err := strconv.Atoi(resp.Payload.UtxoMinAmount)
99+
if err != nil {
100+
return nil, err
101+
}
102+
utxoMaxAmount, err := strconv.Atoi(resp.Payload.UtxoMaxAmount)
103+
if err != nil {
104+
return nil, err
105+
}
106+
vtxoMinAmount, err := strconv.Atoi(resp.Payload.VtxoMinAmount)
107+
if err != nil {
108+
return nil, err
109+
}
110+
vtxoMaxAmount, err := strconv.Atoi(resp.Payload.VtxoMaxAmount)
111+
if err != nil {
112+
return nil, err
113+
}
98114

99115
return &client.Info{
100116
PubKey: resp.Payload.Pubkey,
@@ -110,6 +126,10 @@ func (a *restClient) GetInfo(
110126
MarketHourEndTime: int64(nextEndTime),
111127
MarketHourPeriod: int64(period),
112128
MarketHourRoundInterval: int64(mhRoundInterval),
129+
UtxoMinAmount: int64(utxoMinAmount),
130+
UtxoMaxAmount: int64(utxoMaxAmount),
131+
VtxoMinAmount: int64(vtxoMinAmount),
132+
VtxoMaxAmount: int64(vtxoMaxAmount),
113133
}, nil
114134
}
115135

pkg/client-sdk/client/rest/service/models/v1_get_info_response.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/client-sdk/store/file/types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ type storeData struct {
2828
MarketHourEndTime string `json:"market_hour_end_time"`
2929
MarketHourPeriod string `json:"market_hour_period"`
3030
MarketHourRoundInterval string `json:"market_hour_round_interval"`
31+
UtxoMinAmount string `json:"utxo_min_amount"`
32+
UtxoMaxAmount string `json:"utxo_max_amount"`
33+
VtxoMinAmount string `json:"vtxo_min_amount"`
34+
VtxoMaxAmount string `json:"vtxo_max_amount"`
3135
}
3236

3337
func (d storeData) isEmpty() bool {
@@ -53,6 +57,10 @@ func (d storeData) decode() types.Config {
5357
nextEndTime, _ := strconv.Atoi(d.MarketHourEndTime)
5458
period, _ := strconv.Atoi(d.MarketHourPeriod)
5559
mhRoundInterval, _ := strconv.Atoi(d.MarketHourRoundInterval)
60+
utxoMinAmount, _ := strconv.Atoi(d.UtxoMinAmount)
61+
utxoMaxAmount, _ := strconv.Atoi(d.UtxoMaxAmount)
62+
vtxoMinAmount, _ := strconv.Atoi(d.VtxoMinAmount)
63+
vtxoMaxAmount, _ := strconv.Atoi(d.VtxoMaxAmount)
5664

5765
vtxoTreeExpiryType := common.LocktimeTypeBlock
5866
if vtxoTreeExpiry >= 512 {
@@ -82,6 +90,10 @@ func (d storeData) decode() types.Config {
8290
MarketHourEndTime: int64(nextEndTime),
8391
MarketHourPeriod: int64(period),
8492
MarketHourRoundInterval: int64(mhRoundInterval),
93+
UtxoMinAmount: int64(utxoMinAmount),
94+
UtxoMaxAmount: int64(utxoMaxAmount),
95+
VtxoMinAmount: int64(vtxoMinAmount),
96+
VtxoMaxAmount: int64(vtxoMaxAmount),
8597
}
8698
}
8799

@@ -104,5 +116,9 @@ func (d storeData) asMap() map[string]string {
104116
"market_hour_end_time": d.MarketHourEndTime,
105117
"market_hour_period": d.MarketHourPeriod,
106118
"market_hour_round_interval": d.MarketHourRoundInterval,
119+
"utxo_min_amount": d.UtxoMinAmount,
120+
"utxo_max_amount": d.UtxoMaxAmount,
121+
"vtxo_min_amount": d.VtxoMinAmount,
122+
"vtxo_max_amount": d.VtxoMaxAmount,
107123
}
108124
}

pkg/client-sdk/types/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ type Config struct {
3434
MarketHourEndTime int64
3535
MarketHourPeriod int64
3636
MarketHourRoundInterval int64
37+
UtxoMinAmount int64
38+
UtxoMaxAmount int64
39+
VtxoMinAmount int64
40+
VtxoMaxAmount int64
3741
}
3842

3943
type VtxoKey struct {

server/internal/config/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ var (
184184
defaultMarketHourEndTime = defaultMarketHourStartTime.Add(time.Hour)
185185
defaultMarketHourPeriod = 24 * time.Hour
186186
defaultMarketHourInterval = time.Duration(defaultRoundInterval) * time.Second
187+
defaultUtxoMaxAmount = -1 // -1 means no limit (default), 0 means boarding not allowed
188+
defaultUtxoMinAmount = -1 // -1 means native dust limit (default)
189+
defaultVtxoMinAmount = -1 // -1 means native dust limit (default)
190+
defaultVtxoMaxAmount = -1 // -1 means no limit (default)
187191

188192
defaultAllowZeroFees = false
189193
defaultRoundMaxParticipantsCount = 128
@@ -215,6 +219,11 @@ func LoadConfig() (*Config, error) {
215219
viper.SetDefault(MarketHourRoundInterval, defaultMarketHourInterval)
216220
viper.SetDefault(AllowZeroFees, defaultAllowZeroFees)
217221
viper.SetDefault(RoundMaxParticipantsCount, defaultRoundMaxParticipantsCount)
222+
viper.SetDefault(UtxoMaxAmount, defaultUtxoMaxAmount)
223+
viper.SetDefault(UtxoMinAmount, defaultUtxoMinAmount)
224+
viper.SetDefault(VtxoMaxAmount, defaultVtxoMaxAmount)
225+
viper.SetDefault(VtxoMinAmount, defaultVtxoMinAmount)
226+
218227
net, err := getNetwork()
219228
if err != nil {
220229
return nil, fmt.Errorf("error while getting network: %s", err)

server/internal/core/application/covenantless.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -459,13 +459,15 @@ func (s *covenantlessService) SubmitRedeemTx(
459459
return "", "", fmt.Errorf("output value is less than dust threshold")
460460
}
461461

462-
if s.vtxoMaxAmount > 0 {
462+
if s.vtxoMaxAmount >= 0 {
463463
if out.Value > s.vtxoMaxAmount {
464464
return "", "", fmt.Errorf("output amount is higher than max vtxo amount:%d", s.vtxoMaxAmount)
465465
}
466466
}
467-
if out.Value < s.vtxoMinAmount {
468-
return "", "", fmt.Errorf("output amount is lower than min utxo amount:%d", s.vtxoMinAmount)
467+
if s.vtxoMinAmount >= 0 {
468+
if out.Value < s.vtxoMinAmount {
469+
return "", "", fmt.Errorf("output amount is lower than min utxo amount:%d", s.vtxoMinAmount)
470+
}
469471
}
470472
}
471473

@@ -698,13 +700,15 @@ func (s *covenantlessService) SpendVtxos(ctx context.Context, inputs []ports.Inp
698700
return "", fmt.Errorf("tx %s expired", input.Txid)
699701
}
700702

701-
if s.utxoMaxAmount > 0 {
703+
if s.utxoMaxAmount >= 0 {
702704
if tx.TxOut[input.VOut].Value > s.utxoMaxAmount {
703705
return "", fmt.Errorf("boarding input amount is higher than max utxo amount:%d", s.utxoMaxAmount)
704706
}
705707
}
706-
if tx.TxOut[input.VOut].Value < s.utxoMinAmount {
707-
return "", fmt.Errorf("boarding input amount is lower than min utxo amount:%d", s.utxoMinAmount)
708+
if s.utxoMinAmount >= 0 {
709+
if tx.TxOut[input.VOut].Value < s.utxoMinAmount {
710+
return "", fmt.Errorf("boarding input amount is lower than min utxo amount:%d", s.utxoMinAmount)
711+
}
708712
}
709713

710714
boardingTxs[input.Txid] = tx
@@ -826,13 +830,15 @@ func (s *covenantlessService) ClaimVtxos(ctx context.Context, creds string, rece
826830
return fmt.Errorf("receiver amount must be greater than dust amount %d", dustAmount)
827831
}
828832

829-
if s.vtxoMaxAmount > 0 {
833+
if s.vtxoMaxAmount >= 0 {
830834
if rcv.Amount > uint64(s.vtxoMaxAmount) {
831835
return fmt.Errorf("receiver amount is higher than max vtxo amount:%d", s.vtxoMaxAmount)
832836
}
833837
}
834-
if rcv.Amount < uint64(s.vtxoMinAmount) {
835-
return fmt.Errorf("receiver amount is lower than min vtxo amount:%d", s.vtxoMinAmount)
838+
if s.vtxoMinAmount >= 0 {
839+
if rcv.Amount < uint64(s.vtxoMinAmount) {
840+
return fmt.Errorf("receiver amount is lower than min vtxo amount:%d", s.vtxoMinAmount)
841+
}
836842
}
837843

838844
if !rcv.IsOnchain() {
@@ -1021,6 +1027,10 @@ func (s *covenantlessService) GetInfo(ctx context.Context) (*ServiceInfo, error)
10211027
Period: marketHourConfig.Period,
10221028
RoundInterval: marketHourConfig.RoundInterval,
10231029
},
1030+
UtxoMinAmount: s.utxoMinAmount,
1031+
UtxoMaxAmount: s.utxoMaxAmount,
1032+
VtxoMinAmount: s.vtxoMinAmount,
1033+
VtxoMaxAmount: s.vtxoMaxAmount,
10241034
}, nil
10251035
}
10261036

server/internal/core/application/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ type ServiceInfo struct {
5959
Dust uint64
6060
ForfeitAddress string
6161
NextMarketHour *NextMarketHour
62+
UtxoMinAmount int64
63+
UtxoMaxAmount int64
64+
VtxoMinAmount int64
65+
VtxoMaxAmount int64
6266
}
6367

6468
type NextMarketHour struct {

server/internal/interface/grpc/handlers/arkservice.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ func (h *handler) GetInfo(
9292
Period: int64(info.NextMarketHour.Period.Seconds()),
9393
RoundInterval: int64(info.NextMarketHour.RoundInterval.Seconds()),
9494
},
95-
Version: h.version,
95+
Version: h.version,
96+
UtxoMinAmount: info.UtxoMinAmount,
97+
UtxoMaxAmount: info.UtxoMaxAmount,
98+
VtxoMinAmount: info.VtxoMinAmount,
99+
VtxoMaxAmount: info.VtxoMaxAmount,
96100
}, nil
97101
}
98102

0 commit comments

Comments
 (0)