Skip to content

Commit 27c18d6

Browse files
Merge pull request #743 from pastelnetwork/PSL-1031_checkSNBalance
[PSL-1031] check SN balance before reg ops
2 parents 4c4416e + e3c2b0d commit 27c18d6

File tree

20 files changed

+1070
-483
lines changed

20 files changed

+1070
-483
lines changed

dupedetection/dd-server.pb.go

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

dupedetection/dd-server_grpc.pb.go

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

pastel/client.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/base64"
66
"fmt"
7+
"math"
78
"net"
89
"strconv"
910
"strings"
@@ -806,6 +807,30 @@ func (client *client) MasterNodesExtra(ctx context.Context) (MasterNodes, error)
806807
return masterNodes, nil
807808
}
808809

810+
// ZGetTotalBalance returns total balance
811+
// Command `z_gettotalbalance`
812+
func (client *client) ZGetTotalBalance(ctx context.Context) (*GetTotalBalanceResponse, error) {
813+
resp := &GetTotalBalanceResponse{}
814+
815+
if err := client.callFor(ctx, &resp, "z_gettotalbalance"); err != nil {
816+
return nil, errors.Errorf("failed to get total balance: %w", err)
817+
}
818+
819+
return resp, nil
820+
}
821+
822+
// NFTStorageFee returns the fee of NFT storage
823+
// Command `tickets tools estimatenftstoragefee <sizeInMB>`
824+
func (client *client) NFTStorageFee(ctx context.Context, sizeInMB float64) (*NFTStorageFeeEstimate, error) {
825+
resp := &NFTStorageFeeEstimate{}
826+
827+
if err := client.callFor(ctx, &resp, "tickets", "tools", "estimatenftstoragefee", int(math.Ceil(sizeInMB))); err != nil {
828+
return nil, errors.Errorf("failed to get estimated nft storage: %w", err)
829+
}
830+
831+
return resp, nil
832+
}
833+
809834
// GetRawMempool returns the list of in-progress transaction ids
810835
func (client *client) GetRawMempool(ctx context.Context) ([]string, error) {
811836
var transactionIDs []string

pastel/common.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,17 @@ type GetActionFeesResult struct {
134134
SenseFee float64 `json:"sensefee"`
135135
CascadeFee float64 `json:"cascadefee"`
136136
}
137+
138+
// GetTotalBalanceResponse ...
139+
type GetTotalBalanceResponse struct {
140+
Transparent float64 `json:"transparent"`
141+
Private float64 `json:"private"`
142+
Total float64 `json:"total"`
143+
}
144+
145+
// NFTStorageFeeEstimate ...
146+
type NFTStorageFeeEstimate struct {
147+
EstimatedNftStorageFeeMin float64 `json:"estimatedNftStorageFeeMin"`
148+
EstimatedNftStorageFeeAverage float64 `json:"estimatedNftStorageFeeAverage"`
149+
EstimatedNftStorageFeeMax float64 `json:"estimatedNftStorageFeeMax"`
150+
}

pastel/pastel.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,12 @@ type Client interface {
231231

232232
// BurnAddress ...
233233
BurnAddress() string
234+
235+
//ZGetTotalBalance returns total balance
236+
//Command `z_gettotalbalance`
237+
ZGetTotalBalance(ctx context.Context) (*GetTotalBalanceResponse, error)
238+
239+
//NFTStorageFee returns the fee of NFT storage
240+
//Command `tickets tools estimatenftstoragefee <sizeInMB>`
241+
NFTStorageFee(ctx context.Context, sizeInMB float64) (*NFTStorageFeeEstimate, error)
234242
}

0 commit comments

Comments
 (0)