-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathaddRelatedAccount.cdc
28 lines (21 loc) · 1.2 KB
/
addRelatedAccount.cdc
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
import FindRelatedAccounts from "../contracts/FindRelatedAccounts.cdc"
transaction(name: String, network: String, address: String) {
var relatedAccounts : &FindRelatedAccounts.Accounts?
prepare(account: AuthAccount) {
self.relatedAccounts= account.borrow<&FindRelatedAccounts.Accounts>(from:FindRelatedAccounts.storagePath)
if self.relatedAccounts == nil {
let relatedAccounts <- FindRelatedAccounts.createEmptyAccounts()
account.save(<- relatedAccounts, to: FindRelatedAccounts.storagePath)
account.link<&FindRelatedAccounts.Accounts{FindRelatedAccounts.Public}>(FindRelatedAccounts.publicPath, target: FindRelatedAccounts.storagePath)
self.relatedAccounts = account.borrow<&FindRelatedAccounts.Accounts>(from:FindRelatedAccounts.storagePath)
}
let cap = account.getCapability<&FindRelatedAccounts.Accounts{FindRelatedAccounts.Public}>(FindRelatedAccounts.publicPath)
if !cap.check() {
account.unlink(FindRelatedAccounts.publicPath)
account.link<&FindRelatedAccounts.Accounts{FindRelatedAccounts.Public}>(FindRelatedAccounts.publicPath, target: FindRelatedAccounts.storagePath)
}
}
execute {
self.relatedAccounts!.addRelatedAccount(name:name, network:network, address: address)
}
}