@@ -11,49 +11,41 @@ import "FlowToken"
11
11
12
12
Consumers of this contract would then need to pop the resource out of the DepositEstimate resource to get it back
13
13
*/
14
- pub contract FeeEstimator {
15
- pub resource DepositEstimate {
16
- pub var item : @AnyResource ?
17
- pub var storageFee : UFix64
14
+ access (all) contract FeeEstimator {
15
+ access (all) resource DepositEstimate {
16
+ access (all) var item : @AnyResource ?
17
+ access (all) var storageFee : UFix64
18
18
19
19
init (item : @AnyResource , storageFee : UFix64 ) {
20
20
self .item <- item
21
21
self .storageFee = storageFee
22
22
}
23
23
24
- pub fun withdraw (): @AnyResource {
25
- let resource <- self .item <- nil
26
- return <- resource!
27
- }
28
-
29
- destroy () {
30
- pre {
31
- self .item == nil : " cannot destroy with non-null item"
32
- }
33
-
34
- destroy self .item
24
+ access (all) fun withdraw (): @AnyResource {
25
+ let r <- self .item <- nil
26
+ return <- r!
35
27
}
36
28
}
37
29
38
- pub fun hasStorageCapacity (_ addr : Address , _ storageFee : UFix64 ): Bool {
30
+ access (all) fun hasStorageCapacity (_ addr : Address , _ storageFee : UFix64 ): Bool {
39
31
return FlowStorageFees.defaultTokenAvailableBalance (addr) > storageFee
40
32
}
41
33
42
- pub fun estimateDeposit (
34
+ access (all) fun estimateDeposit (
43
35
item : @AnyResource ,
44
36
): @DepositEstimate {
45
- let storageUsedBefore = FeeEstimator.account.storageUsed
46
- FeeEstimator.account.save (<- item, to : / storage/ temp)
47
- let storageUsedAfter = FeeEstimator.account.storageUsed
37
+ let storageUsedBefore = FeeEstimator.account.storage.used
38
+ FeeEstimator.account.storage. save (<- item, to : / storage/ temp)
39
+ let storageUsedAfter = FeeEstimator.account.storage.used
48
40
49
41
let storageDiff = storageUsedAfter - storageUsedBefore
50
42
let storageFee = FeeEstimator.storageUsedToFlowAmount (storageDiff)
51
- let loadedItem <- FeeEstimator.account.load< @AnyResource> (from : / storage/ temp)!
43
+ let loadedItem <- FeeEstimator.account.storage. load< @AnyResource> (from : / storage/ temp)!
52
44
let estimate <- create DepositEstimate (item : <- loadedItem, storageFee : storageFee)
53
45
return <- estimate
54
46
}
55
47
56
- pub fun storageUsedToFlowAmount (_ storageUsed : UInt64 ): UFix64 {
48
+ access (all) fun storageUsedToFlowAmount (_ storageUsed : UInt64 ): UFix64 {
57
49
let storageMB = FlowStorageFees.convertUInt64StorageBytesToUFix64Megabytes (storageUsed)
58
50
return FlowStorageFees.storageCapacityToFlow (storageMB)
59
51
}
0 commit comments