-
Notifications
You must be signed in to change notification settings - Fork 38
/
fee.go
52 lines (42 loc) · 1.44 KB
/
fee.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package client
import "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
// customFees represents source of customized per-operation fees.
// Can be initialized using var declaration.
//
// Instances are not thread-safe, so they mean initially filling, and then only reading.
type customFees map[string]fixedn.Fixed8
// setFeeForMethod sets fee for the operation executed using specified contract method.
func (x *customFees) setFeeForMethod(method string, fee fixedn.Fixed8) {
m := *x
if m == nil {
m = make(map[string]fixedn.Fixed8, 1)
*x = m
}
m[method] = fee
}
// returns customized for the operation executed using specified contract method.
// Returns false if fee is not customized.
func (x customFees) feeForMethod(method string) (fixedn.Fixed8, bool) {
v, ok := x[method]
return v, ok
}
// fees represents source of per-operation fees.
// Can be initialized using var declaration.
//
// Instances are not thread-safe, so they mean initially filling, and then only reading.
type fees struct {
defaultFee fixedn.Fixed8
customFees
}
// sets default fee for all operations.
func (x *fees) setDefault(fee fixedn.Fixed8) {
x.defaultFee = fee
}
// returns fee for the operation executed using specified contract method.
// Returns customized value if it is set. Otherwise, returns default value.
func (x fees) feeForMethod(method string) fixedn.Fixed8 {
if fee, ok := x.customFees.feeForMethod(method); ok {
return fee
}
return x.defaultFee
}