@flowtyio/flow-contracts 0.1.0-beta.8 → 0.1.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/contracts/TokenForwarding.cdc +19 -11
- package/package.json +1 -1
|
@@ -16,29 +16,37 @@ their tokens to.
|
|
|
16
16
|
|
|
17
17
|
import "FungibleToken"
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
access(all) contract TokenForwarding {
|
|
20
20
|
|
|
21
21
|
// Event that is emitted when tokens are deposited to the target receiver
|
|
22
|
-
|
|
22
|
+
access(all) event ForwardedDeposit(amount: UFix64, from: Address?)
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
access(all) resource interface ForwarderPublic {
|
|
25
|
+
access(all) fun check(): Bool
|
|
26
|
+
access(all) fun safeBorrow(): &{FungibleToken.Receiver}?
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
access(all) resource Forwarder: FungibleToken.Receiver, ForwarderPublic {
|
|
30
30
|
|
|
31
31
|
// This is where the deposited tokens will be sent.
|
|
32
32
|
// The type indicates that it is a reference to a receiver
|
|
33
33
|
//
|
|
34
34
|
access(self) var recipient: Capability
|
|
35
35
|
|
|
36
|
+
access(all) view fun getSupportedVaultTypes(): {Type: Bool} {
|
|
37
|
+
return {}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
access(all) view fun isSupportedVaultType(type: Type): Bool {
|
|
41
|
+
return true
|
|
42
|
+
}
|
|
43
|
+
|
|
36
44
|
// deposit
|
|
37
45
|
//
|
|
38
46
|
// Function that takes a Vault object as an argument and forwards
|
|
39
47
|
// it to the recipient's Vault using the stored reference
|
|
40
48
|
//
|
|
41
|
-
|
|
49
|
+
access(all) fun deposit(from: @{FungibleToken.Vault}) {
|
|
42
50
|
let receiverRef = self.recipient.borrow<&{FungibleToken.Receiver}>()!
|
|
43
51
|
|
|
44
52
|
let balance = from.balance
|
|
@@ -48,17 +56,17 @@ pub contract TokenForwarding {
|
|
|
48
56
|
emit ForwardedDeposit(amount: balance, from: self.owner?.address)
|
|
49
57
|
}
|
|
50
58
|
|
|
51
|
-
|
|
59
|
+
access(all) fun check(): Bool {
|
|
52
60
|
return self.recipient.check<&{FungibleToken.Receiver}>()
|
|
53
61
|
}
|
|
54
62
|
|
|
55
|
-
|
|
63
|
+
access(all) fun safeBorrow(): &{FungibleToken.Receiver}? {
|
|
56
64
|
return self.recipient.borrow<&{FungibleToken.Receiver}>()
|
|
57
65
|
}
|
|
58
66
|
|
|
59
67
|
// changeRecipient changes the recipient of the forwarder to the provided recipient
|
|
60
68
|
//
|
|
61
|
-
|
|
69
|
+
access(all) fun changeRecipient(_ newRecipient: Capability) {
|
|
62
70
|
pre {
|
|
63
71
|
newRecipient.borrow<&{FungibleToken.Receiver}>() != nil: "Could not borrow Receiver reference from the Capability"
|
|
64
72
|
}
|
|
@@ -75,7 +83,7 @@ pub contract TokenForwarding {
|
|
|
75
83
|
|
|
76
84
|
// createNewForwarder creates a new Forwarder reference with the provided recipient
|
|
77
85
|
//
|
|
78
|
-
|
|
86
|
+
access(all) fun createNewForwarder(recipient: Capability): @Forwarder {
|
|
79
87
|
return <-create Forwarder(recipient: recipient)
|
|
80
88
|
}
|
|
81
89
|
}
|