Skip to content

Commit c0b1f2f

Browse files
committed
:refactor: call methods to use PublicKey type parameter
1 parent 6c1b1b9 commit c0b1f2f

17 files changed

+146
-139
lines changed

build/runtime.wasm

3.67 KB
Binary file not shown.

frame/balances/call_force_free.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import (
1010
primitives "github.com/LimeChain/gosemble/primitives/types"
1111
)
1212

13-
type callForceFree struct {
13+
type callForceFree[T primitives.PublicKey] struct {
1414
primitives.Callable
1515
transfer
1616
}
1717

18-
func newCallForceFree(moduleId sc.U8, functionId sc.U8, storedMap primitives.StoredMap, constants *consts, mutator accountMutator) primitives.Call {
19-
call := callForceFree{
18+
func newCallForceFree[T primitives.PublicKey](moduleId sc.U8, functionId sc.U8, storedMap primitives.StoredMap, constants *consts, mutator accountMutator) primitives.Call {
19+
call := callForceFree[T]{
2020
Callable: primitives.Callable{
2121
ModuleId: moduleId,
2222
FunctionId: functionId,
@@ -27,8 +27,8 @@ func newCallForceFree(moduleId sc.U8, functionId sc.U8, storedMap primitives.Sto
2727
return call
2828
}
2929

30-
func (c callForceFree) DecodeArgs(buffer *bytes.Buffer) (primitives.Call, error) {
31-
who, err := types.DecodeMultiAddress[testPublicKeyType](buffer)
30+
func (c callForceFree[T]) DecodeArgs(buffer *bytes.Buffer) (primitives.Call, error) {
31+
who, err := types.DecodeMultiAddress[T](buffer)
3232
if err != nil {
3333
return nil, err
3434
}
@@ -43,27 +43,27 @@ func (c callForceFree) DecodeArgs(buffer *bytes.Buffer) (primitives.Call, error)
4343
return c, nil
4444
}
4545

46-
func (c callForceFree) Encode(buffer *bytes.Buffer) error {
46+
func (c callForceFree[T]) Encode(buffer *bytes.Buffer) error {
4747
return c.Callable.Encode(buffer)
4848
}
4949

50-
func (c callForceFree) Bytes() []byte {
50+
func (c callForceFree[T]) Bytes() []byte {
5151
return c.Callable.Bytes()
5252
}
5353

54-
func (c callForceFree) ModuleIndex() sc.U8 {
54+
func (c callForceFree[T]) ModuleIndex() sc.U8 {
5555
return c.Callable.ModuleIndex()
5656
}
5757

58-
func (c callForceFree) FunctionIndex() sc.U8 {
58+
func (c callForceFree[T]) FunctionIndex() sc.U8 {
5959
return c.Callable.FunctionIndex()
6060
}
6161

62-
func (c callForceFree) Args() sc.VaryingData {
62+
func (c callForceFree[T]) Args() sc.VaryingData {
6363
return c.Callable.Args()
6464
}
6565

66-
func (c callForceFree) BaseWeight() types.Weight {
66+
func (c callForceFree[T]) BaseWeight() types.Weight {
6767
// Proof Size summary in bytes:
6868
// Measured: `206`
6969
// Estimated: `3593`
@@ -77,19 +77,19 @@ func (c callForceFree) BaseWeight() types.Weight {
7777
SaturatingAdd(w)
7878
}
7979

80-
func (_ callForceFree) WeighData(baseWeight types.Weight) types.Weight {
80+
func (_ callForceFree[T]) WeighData(baseWeight types.Weight) types.Weight {
8181
return types.WeightFromParts(baseWeight.RefTime, 0)
8282
}
8383

84-
func (_ callForceFree) ClassifyDispatch(baseWeight types.Weight) types.DispatchClass {
84+
func (_ callForceFree[T]) ClassifyDispatch(baseWeight types.Weight) types.DispatchClass {
8585
return types.NewDispatchClassNormal()
8686
}
8787

88-
func (_ callForceFree) PaysFee(baseWeight types.Weight) types.Pays {
88+
func (_ callForceFree[T]) PaysFee(baseWeight types.Weight) types.Pays {
8989
return types.NewPaysYes()
9090
}
9191

92-
func (c callForceFree) Dispatch(origin types.RuntimeOrigin, args sc.VaryingData) types.DispatchResultWithPostInfo[types.PostDispatchInfo] {
92+
func (c callForceFree[T]) Dispatch(origin types.RuntimeOrigin, args sc.VaryingData) types.DispatchResultWithPostInfo[types.PostDispatchInfo] {
9393
amount := args[1].(sc.U128)
9494

9595
err := c.forceFree(origin, args[0].(types.MultiAddress), amount)
@@ -111,7 +111,7 @@ func (c callForceFree) Dispatch(origin types.RuntimeOrigin, args sc.VaryingData)
111111
// forceFree frees some balance from a user by force.
112112
// Can only be called by ROOT.
113113
// Consider Substrate fn force_unreserve
114-
func (c callForceFree) forceFree(origin types.RawOrigin, who types.MultiAddress, amount sc.U128) types.DispatchError {
114+
func (c callForceFree[T]) forceFree(origin types.RawOrigin, who types.MultiAddress, amount sc.U128) types.DispatchError {
115115
if !origin.IsRootOrigin() {
116116
return types.NewDispatchErrorBadOrigin()
117117
}
@@ -130,7 +130,7 @@ func (c callForceFree) forceFree(origin types.RawOrigin, who types.MultiAddress,
130130
}
131131

132132
// forceFree frees funds, returning the amount that has not been freed.
133-
func (c callForceFree) force(who primitives.AccountId[types.PublicKey], value sc.U128) (sc.U128, error) {
133+
func (c callForceFree[T]) force(who primitives.AccountId[types.PublicKey], value sc.U128) (sc.U128, error) {
134134
if value.Eq(constants.Zero) {
135135
return constants.Zero, nil
136136
}

frame/balances/call_force_free_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var (
3838

3939
func Test_Call_ForceFree_new(t *testing.T) {
4040
target := setupCallForceFree()
41-
expected := callForceFree{
41+
expected := callForceFree[testPublicKeyType]{
4242
Callable: primitives.Callable{
4343
ModuleId: moduleId,
4444
FunctionId: functionForceFreeIndex,
@@ -267,9 +267,9 @@ func Test_removeReserveAndFree(t *testing.T) {
267267
assert.Equal(t, sc.NewU128(5), accountData.Free)
268268
}
269269

270-
func setupCallForceFree() callForceFree {
270+
func setupCallForceFree() primitives.Call {
271271
mockStoredMap = new(mocks.StoredMap)
272272
mockMutator = new(mockAccountMutator)
273273

274-
return newCallForceFree(moduleId, sc.U8(functionForceFreeIndex), mockStoredMap, testConstants, mockMutator).(callForceFree)
274+
return newCallForceFree[testPublicKeyType](moduleId, sc.U8(functionForceFreeIndex), mockStoredMap, testConstants, mockMutator)
275275
}

frame/balances/call_force_transfer.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import (
1010

1111
type testPublicKeyType = primitives.Ed25519PublicKey
1212

13-
type callForceTransfer struct {
13+
type callForceTransfer[T primitives.PublicKey] struct {
1414
primitives.Callable
1515
transfer
1616
}
1717

18-
func newCallForceTransfer(moduleId sc.U8, functionId sc.U8, storedMap primitives.StoredMap, constants *consts, mutator accountMutator) primitives.Call {
19-
call := callForceTransfer{
18+
func newCallForceTransfer[T primitives.PublicKey](moduleId sc.U8, functionId sc.U8, storedMap primitives.StoredMap, constants *consts, mutator accountMutator) primitives.Call {
19+
call := callForceTransfer[T]{
2020
Callable: primitives.Callable{
2121
ModuleId: moduleId,
2222
FunctionId: functionId,
@@ -27,12 +27,12 @@ func newCallForceTransfer(moduleId sc.U8, functionId sc.U8, storedMap primitives
2727
return call
2828
}
2929

30-
func (c callForceTransfer) DecodeArgs(buffer *bytes.Buffer) (primitives.Call, error) {
31-
source, err := types.DecodeMultiAddress[testPublicKeyType](buffer)
30+
func (c callForceTransfer[T]) DecodeArgs(buffer *bytes.Buffer) (primitives.Call, error) {
31+
source, err := types.DecodeMultiAddress[T](buffer)
3232
if err != nil {
3333
return nil, err
3434
}
35-
dest, err := types.DecodeMultiAddress[testPublicKeyType](buffer)
35+
dest, err := types.DecodeMultiAddress[T](buffer)
3636
if err != nil {
3737
return nil, err
3838
}
@@ -48,27 +48,27 @@ func (c callForceTransfer) DecodeArgs(buffer *bytes.Buffer) (primitives.Call, er
4848
return c, nil
4949
}
5050

51-
func (c callForceTransfer) Encode(buffer *bytes.Buffer) error {
51+
func (c callForceTransfer[T]) Encode(buffer *bytes.Buffer) error {
5252
return c.Callable.Encode(buffer)
5353
}
5454

55-
func (c callForceTransfer) Bytes() []byte {
55+
func (c callForceTransfer[T]) Bytes() []byte {
5656
return c.Callable.Bytes()
5757
}
5858

59-
func (c callForceTransfer) ModuleIndex() sc.U8 {
59+
func (c callForceTransfer[T]) ModuleIndex() sc.U8 {
6060
return c.Callable.ModuleIndex()
6161
}
6262

63-
func (c callForceTransfer) FunctionIndex() sc.U8 {
63+
func (c callForceTransfer[T]) FunctionIndex() sc.U8 {
6464
return c.Callable.FunctionIndex()
6565
}
6666

67-
func (c callForceTransfer) Args() sc.VaryingData {
67+
func (c callForceTransfer[T]) Args() sc.VaryingData {
6868
return c.Callable.Args()
6969
}
7070

71-
func (c callForceTransfer) BaseWeight() types.Weight {
71+
func (c callForceTransfer[T]) BaseWeight() types.Weight {
7272
// Proof Size summary in bytes:
7373
// Measured: `135`
7474
// Estimated: `6196`
@@ -82,19 +82,19 @@ func (c callForceTransfer) BaseWeight() types.Weight {
8282
SaturatingAdd(w)
8383
}
8484

85-
func (_ callForceTransfer) WeighData(baseWeight types.Weight) types.Weight {
85+
func (_ callForceTransfer[T]) WeighData(baseWeight types.Weight) types.Weight {
8686
return types.WeightFromParts(baseWeight.RefTime, 0)
8787
}
8888

89-
func (_ callForceTransfer) ClassifyDispatch(baseWeight types.Weight) types.DispatchClass {
89+
func (_ callForceTransfer[T]) ClassifyDispatch(baseWeight types.Weight) types.DispatchClass {
9090
return types.NewDispatchClassNormal()
9191
}
9292

93-
func (_ callForceTransfer) PaysFee(baseWeight types.Weight) types.Pays {
93+
func (_ callForceTransfer[T]) PaysFee(baseWeight types.Weight) types.Pays {
9494
return types.NewPaysYes()
9595
}
9696

97-
func (c callForceTransfer) Dispatch(origin types.RuntimeOrigin, args sc.VaryingData) types.DispatchResultWithPostInfo[types.PostDispatchInfo] {
97+
func (c callForceTransfer[T]) Dispatch(origin types.RuntimeOrigin, args sc.VaryingData) types.DispatchResultWithPostInfo[types.PostDispatchInfo] {
9898
value := sc.U128(args[2].(sc.Compact))
9999

100100
err := c.forceTransfer(origin, args[0].(types.MultiAddress), args[1].(types.MultiAddress), value)
@@ -115,7 +115,7 @@ func (c callForceTransfer) Dispatch(origin types.RuntimeOrigin, args sc.VaryingD
115115

116116
// forceTransfer transfers liquid free balance from `source` to `dest`.
117117
// Can only be called by ROOT.
118-
func (c callForceTransfer) forceTransfer(origin types.RawOrigin, source types.MultiAddress, dest types.MultiAddress, value sc.U128) types.DispatchError {
118+
func (c callForceTransfer[T]) forceTransfer(origin types.RawOrigin, source types.MultiAddress, dest types.MultiAddress, value sc.U128) types.DispatchError {
119119
if !origin.IsRootOrigin() {
120120
return types.NewDispatchErrorBadOrigin()
121121
}

frame/balances/call_force_transfer_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
func Test_Call_ForceTransfer_new(t *testing.T) {
1515
target := setupCallForceTransfer()
16-
expected := callForceTransfer{
16+
expected := callForceTransfer[testPublicKeyType]{
1717
Callable: primitives.Callable{
1818
ModuleId: moduleId,
1919
FunctionId: functionForceTransferIndex,
@@ -192,9 +192,9 @@ func Test_Call_ForceTransfer_Dispatch_CannotLookup_Dest(t *testing.T) {
192192
mockStoredMap.AssertNotCalled(t, "DepositEvent", mock.Anything)
193193
}
194194

195-
func setupCallForceTransfer() callForceTransfer {
195+
func setupCallForceTransfer() primitives.Call {
196196
mockStoredMap = new(mocks.StoredMap)
197197
mockMutator = new(mockAccountMutator)
198198

199-
return newCallForceTransfer(moduleId, functionForceTransferIndex, mockStoredMap, testConstants, mockMutator).(callForceTransfer)
199+
return newCallForceTransfer[testPublicKeyType](moduleId, functionForceTransferIndex, mockStoredMap, testConstants, mockMutator)
200200
}

frame/balances/call_set_balance.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import (
88
"github.com/LimeChain/gosemble/primitives/types"
99
)
1010

11-
type callSetBalance struct {
11+
type callSetBalance[T types.PublicKey] struct {
1212
types.Callable
1313
constants *consts
1414
storedMap types.StoredMap
1515
accountMutator accountMutator
1616
issuance support.StorageValue[sc.U128]
1717
}
1818

19-
func newCallSetBalance(moduleId sc.U8, functionId sc.U8, storedMap types.StoredMap, constants *consts, mutator accountMutator, issuance support.StorageValue[sc.U128]) types.Call {
20-
call := callSetBalance{
19+
func newCallSetBalance[T types.PublicKey](moduleId sc.U8, functionId sc.U8, storedMap types.StoredMap, constants *consts, mutator accountMutator, issuance support.StorageValue[sc.U128]) types.Call {
20+
call := callSetBalance[T]{
2121
Callable: types.Callable{
2222
ModuleId: moduleId,
2323
FunctionId: functionId,
@@ -31,8 +31,8 @@ func newCallSetBalance(moduleId sc.U8, functionId sc.U8, storedMap types.StoredM
3131
return call
3232
}
3333

34-
func (c callSetBalance) DecodeArgs(buffer *bytes.Buffer) (types.Call, error) {
35-
targetAddress, err := types.DecodeMultiAddress[testPublicKeyType](buffer)
34+
func (c callSetBalance[T]) DecodeArgs(buffer *bytes.Buffer) (types.Call, error) {
35+
targetAddress, err := types.DecodeMultiAddress[T](buffer)
3636
if err != nil {
3737
return nil, err
3838
}
@@ -53,27 +53,27 @@ func (c callSetBalance) DecodeArgs(buffer *bytes.Buffer) (types.Call, error) {
5353
return c, nil
5454
}
5555

56-
func (c callSetBalance) Encode(buffer *bytes.Buffer) error {
56+
func (c callSetBalance[T]) Encode(buffer *bytes.Buffer) error {
5757
return c.Callable.Encode(buffer)
5858
}
5959

60-
func (c callSetBalance) Bytes() []byte {
60+
func (c callSetBalance[T]) Bytes() []byte {
6161
return c.Callable.Bytes()
6262
}
6363

64-
func (c callSetBalance) ModuleIndex() sc.U8 {
64+
func (c callSetBalance[T]) ModuleIndex() sc.U8 {
6565
return c.Callable.ModuleIndex()
6666
}
6767

68-
func (c callSetBalance) FunctionIndex() sc.U8 {
68+
func (c callSetBalance[T]) FunctionIndex() sc.U8 {
6969
return c.Callable.FunctionIndex()
7070
}
7171

72-
func (c callSetBalance) Args() sc.VaryingData {
72+
func (c callSetBalance[T]) Args() sc.VaryingData {
7373
return c.Callable.Args()
7474
}
7575

76-
func (c callSetBalance) BaseWeight() types.Weight {
76+
func (c callSetBalance[T]) BaseWeight() types.Weight {
7777
// Proof Size summary in bytes:
7878
// Measured: `206`
7979
// Estimated: `3593`
@@ -87,23 +87,23 @@ func (c callSetBalance) BaseWeight() types.Weight {
8787
SaturatingAdd(w)
8888
}
8989

90-
func (_ callSetBalance) IsInherent() bool {
90+
func (_ callSetBalance[T]) IsInherent() bool {
9191
return false
9292
}
9393

94-
func (_ callSetBalance) WeighData(baseWeight types.Weight) types.Weight {
94+
func (_ callSetBalance[T]) WeighData(baseWeight types.Weight) types.Weight {
9595
return types.WeightFromParts(baseWeight.RefTime, 0)
9696
}
9797

98-
func (_ callSetBalance) ClassifyDispatch(baseWeight types.Weight) types.DispatchClass {
98+
func (_ callSetBalance[T]) ClassifyDispatch(baseWeight types.Weight) types.DispatchClass {
9999
return types.NewDispatchClassNormal()
100100
}
101101

102-
func (_ callSetBalance) PaysFee(baseWeight types.Weight) types.Pays {
102+
func (_ callSetBalance[T]) PaysFee(baseWeight types.Weight) types.Pays {
103103
return types.NewPaysYes()
104104
}
105105

106-
func (c callSetBalance) Dispatch(origin types.RuntimeOrigin, args sc.VaryingData) types.DispatchResultWithPostInfo[types.PostDispatchInfo] {
106+
func (c callSetBalance[T]) Dispatch(origin types.RuntimeOrigin, args sc.VaryingData) types.DispatchResultWithPostInfo[types.PostDispatchInfo] {
107107
newFree := sc.U128(args[1].(sc.Compact))
108108
newReserved := sc.U128(args[2].(sc.Compact))
109109

@@ -127,7 +127,7 @@ func (c callSetBalance) Dispatch(origin types.RuntimeOrigin, args sc.VaryingData
127127
// Changes free and reserve balance of `who`,
128128
// including the total issuance.
129129
// Can only be called by ROOT.
130-
func (c callSetBalance) setBalance(origin types.RawOrigin, who types.MultiAddress, newFree sc.U128, newReserved sc.U128) types.DispatchError {
130+
func (c callSetBalance[T]) setBalance(origin types.RawOrigin, who types.MultiAddress, newFree sc.U128, newReserved sc.U128) types.DispatchError {
131131
if !origin.IsRootOrigin() {
132132
return types.NewDispatchErrorBadOrigin()
133133
}

0 commit comments

Comments
 (0)