@flowtyio/flow-contracts 0.1.2 → 0.1.4

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.
@@ -6,8 +6,13 @@ access(all) contract ContractManager {
6
6
  access(all) let StoragePath: StoragePath
7
7
  access(all) let PublicPath: PublicPath
8
8
 
9
+ access(all) let OwnerStoragePath: StoragePath
10
+ access(all) let OwnerPublicPath: PublicPath
11
+
9
12
  access(all) entitlement Manage
10
13
 
14
+ access(all) event ManagerSaved(uuid: UInt64, contractAddress: Address, ownerAddress: Address)
15
+
11
16
  access(all) resource Manager {
12
17
  access(self) let acct: Capability<auth(Storage, Contracts, Keys, Inbox, Capabilities) &Account>
13
18
  access(self) let routerCap: Capability<auth(FungibleTokenRouter.Owner) &FungibleTokenRouter.Router>
@@ -36,6 +41,26 @@ access(all) contract ContractManager {
36
41
  return getAccount(self.acct.address)
37
42
  }
38
43
 
44
+ // Should be called after saving a ContractManager resource to signal that a new address stores (and therefore "owns")
45
+ // this manager resource's acct capability. Without this, it is not possible to track the original creator of a contract
46
+ // when using the ContractManager
47
+ access(Manage) fun onSave() {
48
+ let acct = self.acct.borrow()!
49
+
50
+ acct.storage.load<Address>(from: ContractManager.OwnerStoragePath)
51
+ acct.storage.save(self.owner!.address, to: ContractManager.OwnerStoragePath)
52
+
53
+ if !acct.capabilities.get<&Address>(ContractManager.OwnerPublicPath).check() {
54
+ acct.capabilities.unpublish(ContractManager.OwnerPublicPath)
55
+ acct.capabilities.publish(
56
+ acct.capabilities.storage.issue<&Address>(ContractManager.OwnerStoragePath),
57
+ at: ContractManager.OwnerPublicPath
58
+ )
59
+ }
60
+
61
+ emit ManagerSaved(uuid: self.uuid, contractAddress: self.acct.address, ownerAddress: self.owner!.address)
62
+ }
63
+
39
64
  init(tokens: @FlowToken.Vault, defaultRouterAddress: Address) {
40
65
  pre {
41
66
  tokens.balance >= 0.001: "minimum balance of 0.001 required for initialization"
@@ -69,5 +94,9 @@ access(all) contract ContractManager {
69
94
  let identifier = "ContractManager_".concat(self.account.address.toString())
70
95
  self.StoragePath = StoragePath(identifier: identifier)!
71
96
  self.PublicPath = PublicPath(identifier: identifier)!
97
+
98
+ let ownerIdentifier = "ContractManager_Owner_".concat(self.account.address.toString())
99
+ self.OwnerStoragePath = StoragePath(identifier: ownerIdentifier)!
100
+ self.OwnerPublicPath = PublicPath(identifier: ownerIdentifier)!
72
101
  }
73
102
  }
@@ -2,6 +2,7 @@ import "FlowtyDrops"
2
2
  import "MetadataViews"
3
3
  import "ViewResolver"
4
4
  import "AddressUtils"
5
+ import "ContractManager"
5
6
 
6
7
  access(all) contract DropTypes {
7
8
  access(all) struct Display {
@@ -34,6 +35,7 @@ access(all) contract DropTypes {
34
35
  access(all) let minterCount: Int
35
36
  access(all) let commissionRate: UFix64
36
37
  access(all) let nftType: String
38
+ access(all) let creator: Address?
37
39
 
38
40
  access(all) let address: Address?
39
41
  access(all) let mintedByAddress: Int?
@@ -55,10 +57,12 @@ access(all) contract DropTypes {
55
57
  nftType: Type,
56
58
  address: Address?,
57
59
  phases: [PhaseSummary],
58
- royaltyRate: UFix64
60
+ royaltyRate: UFix64,
61
+ creator: Address?
59
62
  ) {
60
63
  self.id = id
61
64
  self.display = Display(display)
65
+ self.creator = creator
62
66
 
63
67
  self.medias = []
64
68
  for m in medias?.items ?? [] {
@@ -169,6 +173,8 @@ access(all) contract DropTypes {
169
173
  let contractAddress = AddressUtils.parseAddress(nftType)!
170
174
  let contractName = segments[2]
171
175
 
176
+ let creator = self.getCreatorAddress(contractAddress)
177
+
172
178
  let resolver = getAccount(contractAddress).contracts.borrow<&{ViewResolver}>(name: contractName)
173
179
  if resolver == nil {
174
180
  return nil
@@ -224,7 +230,8 @@ access(all) contract DropTypes {
224
230
  nftType: CompositeType(dropDetails.nftType)!,
225
231
  address: minter,
226
232
  phases: phaseSummaries,
227
- royaltyRate: royaltyRate
233
+ royaltyRate: royaltyRate,
234
+ creator: creator
228
235
  )
229
236
 
230
237
  return dropSummary
@@ -235,6 +242,8 @@ access(all) contract DropTypes {
235
242
  let segments = nftTypeIdentifier.split(separator: ".")
236
243
  let contractAddress = AddressUtils.parseAddress(nftType)!
237
244
  let contractName = segments[2]
245
+
246
+ let creator = self.getCreatorAddress(contractAddress)
238
247
 
239
248
  let resolver = getAccount(contractAddress).contracts.borrow<&{ViewResolver}>(name: contractName)
240
249
  if resolver == nil {
@@ -297,10 +306,37 @@ access(all) contract DropTypes {
297
306
  nftType: CompositeType(dropDetails.nftType)!,
298
307
  address: minter,
299
308
  phases: phaseSummaries,
300
- royaltyRate: royaltyRate
309
+ royaltyRate: royaltyRate,
310
+ creator: creator
301
311
  ))
302
312
  }
303
313
 
304
314
  return summaries
305
315
  }
316
+
317
+ access(all) fun getCreatorAddress(_ contractAddress: Address): Address? {
318
+ // We look for a two-way relationship between creator and collection. A contract can expose an address at ContractManager.OwnerPublicPath
319
+ // specifying the owning account. If found, we will check that same account for a &ContractManager.Manager resource at ContractManager.PublicPath,
320
+ // which, when borrowed, can return its underlying account address using &Manager.getAccount().
321
+ //
322
+ // If the addresses match, we consider this account to be the creator of a drop
323
+ let tmp = getAccount(contractAddress).capabilities.borrow<&Address>(ContractManager.OwnerPublicPath)
324
+ if tmp == nil {
325
+ return nil
326
+ }
327
+
328
+ let creator = *(tmp!)
329
+ let manager = getAccount(creator).capabilities.borrow<&ContractManager.Manager>(ContractManager.PublicPath)
330
+ if manager == nil {
331
+ return nil
332
+ }
333
+
334
+ let contractManagerAccount = manager!.getAccount()
335
+
336
+ if contractManagerAccount.address != contractAddress {
337
+ return nil
338
+ }
339
+
340
+ return creator
341
+ }
306
342
  }
package/flow.json CHANGED
@@ -359,7 +359,7 @@
359
359
  "source": "./contracts/flowty-drops/ContractManager.cdc",
360
360
  "aliases": {
361
361
  "testing": "0x0000000000000006",
362
- "testnet": "0x772a10c786851a1b",
362
+ "testnet": "0x155bce6ac93f3e00",
363
363
  "emulator": "0xf8d6e0586b0a20c7"
364
364
  }
365
365
  },
@@ -367,7 +367,7 @@
367
367
  "source": "./contracts/flowty-drops/initializers/ContractInitializer.cdc",
368
368
  "aliases": {
369
369
  "testing": "0x0000000000000006",
370
- "testnet": "0x772a10c786851a1b",
370
+ "testnet": "0x155bce6ac93f3e00",
371
371
  "emulator": "0xf8d6e0586b0a20c7"
372
372
  }
373
373
  },
@@ -375,7 +375,7 @@
375
375
  "source": "./contracts/flowty-drops/initializers/ContractBorrower.cdc",
376
376
  "aliases": {
377
377
  "testing": "0x0000000000000006",
378
- "testnet": "0x772a10c786851a1b",
378
+ "testnet": "0x155bce6ac93f3e00",
379
379
  "emulator": "0xf8d6e0586b0a20c7"
380
380
  }
381
381
  },
@@ -383,7 +383,7 @@
383
383
  "source": "./contracts/flowty-drops/initializers/OpenEditionInitializer.cdc",
384
384
  "aliases": {
385
385
  "testing": "0x0000000000000006",
386
- "testnet": "0x772a10c786851a1b",
386
+ "testnet": "0x155bce6ac93f3e00",
387
387
  "emulator": "0xf8d6e0586b0a20c7"
388
388
  }
389
389
  },
@@ -391,7 +391,7 @@
391
391
  "source": "./contracts/flowty-drops/nft/BaseCollection.cdc",
392
392
  "aliases": {
393
393
  "testing": "0x0000000000000006",
394
- "testnet": "0x772a10c786851a1b",
394
+ "testnet": "0x155bce6ac93f3e00",
395
395
  "emulator": "0xf8d6e0586b0a20c7"
396
396
  }
397
397
  },
@@ -399,7 +399,7 @@
399
399
  "source": "./contracts/flowty-drops/nft/ContractFactoryTemplate.cdc",
400
400
  "aliases": {
401
401
  "testing": "0x0000000000000006",
402
- "testnet": "0x772a10c786851a1b",
402
+ "testnet": "0x155bce6ac93f3e00",
403
403
  "emulator": "0xf8d6e0586b0a20c7"
404
404
  }
405
405
  },
@@ -407,7 +407,7 @@
407
407
  "source": "./contracts/flowty-drops/nft/ContractFactory.cdc",
408
408
  "aliases": {
409
409
  "testing": "0x0000000000000006",
410
- "testnet": "0x772a10c786851a1b",
410
+ "testnet": "0x155bce6ac93f3e00",
411
411
  "emulator": "0xf8d6e0586b0a20c7"
412
412
  }
413
413
  },
@@ -415,7 +415,7 @@
415
415
  "source": "./contracts/flowty-drops/nft/OpenEditionTemplate.cdc",
416
416
  "aliases": {
417
417
  "testing": "0x0000000000000006",
418
- "testnet": "0x772a10c786851a1b",
418
+ "testnet": "0x155bce6ac93f3e00",
419
419
  "emulator": "0xf8d6e0586b0a20c7"
420
420
  }
421
421
  },
@@ -423,7 +423,7 @@
423
423
  "source": "./contracts/flowty-drops/nft/UniversalCollection.cdc",
424
424
  "aliases": {
425
425
  "testing": "0x0000000000000006",
426
- "testnet": "0x772a10c786851a1b",
426
+ "testnet": "0x155bce6ac93f3e00",
427
427
  "emulator": "0xf8d6e0586b0a20c7"
428
428
  }
429
429
  },
@@ -431,7 +431,7 @@
431
431
  "source": "./contracts/flowty-drops/nft/BaseNFT.cdc",
432
432
  "aliases": {
433
433
  "testing": "0x0000000000000006",
434
- "testnet": "0x772a10c786851a1b",
434
+ "testnet": "0x155bce6ac93f3e00",
435
435
  "emulator": "0xf8d6e0586b0a20c7"
436
436
  }
437
437
  },
@@ -439,7 +439,7 @@
439
439
  "source": "./contracts/flowty-drops/nft/NFTMetadata.cdc",
440
440
  "aliases": {
441
441
  "testing": "0x0000000000000006",
442
- "testnet": "0x772a10c786851a1b",
442
+ "testnet": "0x155bce6ac93f3e00",
443
443
  "emulator": "0xf8d6e0586b0a20c7"
444
444
  }
445
445
  },
@@ -447,7 +447,7 @@
447
447
  "source": "./contracts/flowty-drops/FlowtyDrops.cdc",
448
448
  "aliases": {
449
449
  "testing": "0x0000000000000006",
450
- "testnet": "0x772a10c786851a1b",
450
+ "testnet": "0x155bce6ac93f3e00",
451
451
  "emulator": "0xf8d6e0586b0a20c7"
452
452
  }
453
453
  },
@@ -455,7 +455,7 @@
455
455
  "source": "./contracts/flowty-drops/DropFactory.cdc",
456
456
  "aliases": {
457
457
  "testing": "0x0000000000000006",
458
- "testnet": "0x772a10c786851a1b",
458
+ "testnet": "0x155bce6ac93f3e00",
459
459
  "emulator": "0xf8d6e0586b0a20c7"
460
460
  }
461
461
  },
@@ -463,7 +463,7 @@
463
463
  "source": "./contracts/flowty-drops/FlowtyActiveCheckers.cdc",
464
464
  "aliases": {
465
465
  "testing": "0x0000000000000006",
466
- "testnet": "0x772a10c786851a1b",
466
+ "testnet": "0x155bce6ac93f3e00",
467
467
  "emulator": "0xf8d6e0586b0a20c7"
468
468
  }
469
469
  },
@@ -471,7 +471,7 @@
471
471
  "source": "./contracts/flowty-drops/FlowtyPricers.cdc",
472
472
  "aliases": {
473
473
  "testing": "0x0000000000000006",
474
- "testnet": "0x772a10c786851a1b",
474
+ "testnet": "0x155bce6ac93f3e00",
475
475
  "emulator": "0xf8d6e0586b0a20c7"
476
476
  }
477
477
  },
@@ -479,7 +479,7 @@
479
479
  "source": "./contracts/flowty-drops/FlowtyAddressVerifiers.cdc",
480
480
  "aliases": {
481
481
  "testing": "0x0000000000000006",
482
- "testnet": "0x772a10c786851a1b",
482
+ "testnet": "0x155bce6ac93f3e00",
483
483
  "emulator": "0xf8d6e0586b0a20c7"
484
484
  }
485
485
  },
@@ -487,7 +487,7 @@
487
487
  "source": "./contracts/flowty-drops/DropTypes.cdc",
488
488
  "aliases": {
489
489
  "testing": "0x0000000000000006",
490
- "testnet": "0x934da91a977f1ac4",
490
+ "testnet": "0x53ff16309e318ae2",
491
491
  "emulator": "0xf8d6e0586b0a20c7"
492
492
  }
493
493
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowtyio/flow-contracts",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "main": "index.json",
5
5
  "description": "An NPM package for common flow contracts",
6
6
  "author": "flowtyio",