/
transfer_keep_alive.go
122 lines (99 loc) 路 3.19 KB
/
transfer_keep_alive.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package dispatchables
import (
"bytes"
sc "github.com/LimeChain/goscale"
"github.com/LimeChain/gosemble/constants"
"github.com/LimeChain/gosemble/constants/balances"
"github.com/LimeChain/gosemble/primitives/types"
primitives "github.com/LimeChain/gosemble/primitives/types"
)
type TransferKeepAliveCall struct {
primitives.Callable
}
func NewTransferKeepAliveCall(args sc.VaryingData) TransferKeepAliveCall {
call := TransferKeepAliveCall{
Callable: primitives.Callable{
ModuleId: balances.ModuleIndex,
FunctionId: balances.FunctionTransferKeepAliveIndex,
},
}
if len(args) != 0 {
call.Arguments = args
}
return call
}
func (c TransferKeepAliveCall) DecodeArgs(buffer *bytes.Buffer) primitives.Call {
c.Arguments = sc.NewVaryingData(
types.DecodeMultiAddress(buffer),
sc.DecodeCompact(buffer),
)
return c
}
func (c TransferKeepAliveCall) Encode(buffer *bytes.Buffer) {
c.Callable.Encode(buffer)
}
func (c TransferKeepAliveCall) Bytes() []byte {
return c.Callable.Bytes()
}
func (c TransferKeepAliveCall) ModuleIndex() sc.U8 {
return c.Callable.ModuleIndex()
}
func (c TransferKeepAliveCall) FunctionIndex() sc.U8 {
return c.Callable.FunctionIndex()
}
func (c TransferKeepAliveCall) Args() sc.VaryingData {
return c.Callable.Args()
}
func (_ TransferKeepAliveCall) IsInherent() bool {
return false
}
func (_ TransferKeepAliveCall) BaseWeight(b ...any) types.Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `3593`
// Minimum execution time: 28_184 nanoseconds.
r := constants.DbWeight.Reads(1)
w := constants.DbWeight.Writes(1)
e := types.WeightFromParts(0, 3593)
return types.WeightFromParts(49_250_000, 0).
SaturatingAdd(e).
SaturatingAdd(r).
SaturatingAdd(w)
}
func (_ TransferKeepAliveCall) WeightInfo(baseWeight types.Weight) types.Weight {
return types.WeightFromParts(baseWeight.RefTime, 0)
}
func (_ TransferKeepAliveCall) ClassifyDispatch(baseWeight types.Weight) types.DispatchClass {
return types.NewDispatchClassNormal()
}
func (_ TransferKeepAliveCall) PaysFee(baseWeight types.Weight) types.Pays {
return types.NewPaysYes()
}
func (_ TransferKeepAliveCall) Dispatch(origin types.RuntimeOrigin, args sc.VaryingData) types.DispatchResultWithPostInfo[types.PostDispatchInfo] {
value := sc.U128(args[1].(sc.Compact))
err := transferKeepAlive(origin, args[0].(types.MultiAddress), value)
if err != nil {
return types.DispatchResultWithPostInfo[types.PostDispatchInfo]{
HasError: true,
Err: types.DispatchErrorWithPostInfo[types.PostDispatchInfo]{
Error: err,
},
}
}
return types.DispatchResultWithPostInfo[types.PostDispatchInfo]{
HasError: false,
Ok: types.PostDispatchInfo{},
}
}
// transferKeepAlive is similar to transfer, but includes a check that the origin transactor will not be "killed".
func transferKeepAlive(origin types.RawOrigin, dest types.MultiAddress, value sc.U128) types.DispatchError {
if !origin.IsSignedOrigin() {
return types.NewDispatchErrorBadOrigin()
}
transactor := origin.AsSigned()
address, err := types.DefaultAccountIdLookup().Lookup(dest)
if err != nil {
return types.NewDispatchErrorCannotLookup()
}
return trans(transactor, address, value, types.ExistenceRequirementKeepAlive)
}