From 9f8acaa4b08432e63e0e0a0cd51267944a100060 Mon Sep 17 00:00:00 2001 From: jacksonfoley Date: Thu, 22 Aug 2024 14:45:45 -0600 Subject: [PATCH 1/4] migrate DapperWalletRestrictions.cdc to cadence 1.0 --- contracts/DapperWalletRestrictions.cdc | 37 +++++++++++++------------- flow.json | 26 ++++++++++++------ 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/contracts/DapperWalletRestrictions.cdc b/contracts/DapperWalletRestrictions.cdc index 273f1de..e23e49e 100644 --- a/contracts/DapperWalletRestrictions.cdc +++ b/contracts/DapperWalletRestrictions.cdc @@ -1,11 +1,10 @@ -pub contract DapperWalletRestrictions { -// - pub let StoragePath: StoragePath +access(all) contract DapperWalletRestrictions { + access(all) let StoragePath: StoragePath - pub event TypeChanged(identifier: Type, newConfig: TypeConfig) - pub event TypeRemoved(identifier: Type) + access(all) event TypeChanged(identifier: Type, newConfig: TypeConfig) + access(all) event TypeRemoved(identifier: Type) - pub fun GetConfigFlags(): {String: String} { + access(all) view fun GetConfigFlags(): {String: String} { return { "CAN_INIT": "Can initialize collection in Dapper Custodial Wallet", "CAN_WITHDRAW": "Can withdraw NFT out of Dapper Custodial space", @@ -16,10 +15,10 @@ pub contract DapperWalletRestrictions { } } - pub struct TypeConfig{ - pub let flags: {String: Bool} + access(all) struct TypeConfig { + access(all) let flags: {String: Bool} - pub fun setFlag(_ flag: String, _ value: Bool) { + access(all) fun setFlag(_ flag: String, _ value: Bool) { if DapperWalletRestrictions.GetConfigFlags()[flag] == nil { panic("Invalid flag") } @@ -27,12 +26,12 @@ pub contract DapperWalletRestrictions { self.flags[flag] = value } - pub fun getFlag(_ flag: String): Bool { + access(all) view fun getFlag(_ flag: String): Bool { return self.flags[flag] ?? false } init () { - self.flags= {} + self.flags = {} } } @@ -40,28 +39,28 @@ pub contract DapperWalletRestrictions { access(self) let ext: {String: AnyStruct} - pub resource Admin { - pub fun addType(_ t: Type, conf: TypeConfig) { + access(all) resource Admin { + access(all) fun addType(_ t: Type, conf: TypeConfig) { DapperWalletRestrictions.types.insert(key: t, conf) emit TypeChanged(identifier: t, newConfig: conf) } - pub fun updateType(_ t: Type, conf: TypeConfig) { + access(all) fun updateType(_ t: Type, conf: TypeConfig) { DapperWalletRestrictions.types[t] = conf emit TypeChanged(identifier: t, newConfig: conf) } - pub fun removeType( _ t: Type) { + access(all) fun removeType( _ t: Type) { DapperWalletRestrictions.types.remove(key: t) emit TypeRemoved(identifier: t) } } - pub fun getTypes(): {Type:TypeConfig} { + access(all) view fun getTypes(): {Type:TypeConfig} { return self.types } - pub fun getConfig(_ t: Type): TypeConfig? { + access(all) view fun getConfig(_ t: Type): TypeConfig? { return self.types[t] } @@ -70,6 +69,6 @@ pub contract DapperWalletRestrictions { self.ext = {} self.StoragePath = /storage/dapperWalletCollections - self.account.save(<- create Admin(), to: self.StoragePath) + self.account.storage.save(<- create Admin(), to: self.StoragePath) } -} +} \ No newline at end of file diff --git a/flow.json b/flow.json index bc87c2d..c96da8f 100644 --- a/flow.json +++ b/flow.json @@ -8,6 +8,14 @@ "testnet": "access.devnet.nodes.onflow.org:9000" }, "accounts": { + "dapper-wallet-restrictions-mainnet": { + "address": "2d4cebdb9eca6f49", + "key": { + "type": "file", + "hashAlgorithm": "SHA2_256", + "location": "dapper-wallet-restrictions-mainnet.key" + } + }, "dapper-wallet-restrictions-testnet": { "address": "a7d10afc50b14991", "key": { @@ -15,12 +23,11 @@ "location": "dapper-wallet-restrictions-testnet.key" } }, - "dapper-wallet-restrictions-mainnet": { - "address": "2d4cebdb9eca6f49", + "dapper-wallet-restrictions-testnet-2": { + "address": "b67c471ade6fdbea", "key": { "type": "file", - "hashAlgorithm": "SHA2_256", - "location": "dapper-wallet-restrictions-mainnet.key" + "location": "dapper-wallet-restrictions-testnet.key" } }, "emulator-account": { @@ -34,13 +41,16 @@ "DapperWalletRestrictions" ] }, - "testnet": { - "dapper-wallet-restrictions-testnet": [ + "mainnet": { + "dapper-wallet-restrictions-mainnet": [ "DapperWalletRestrictions" ] }, - "mainnet": { - "dapper-wallet-restrictions-mainnet": [ + "testnet": { + "dapper-wallet-restrictions-testnet": [ + "DapperWalletRestrictions" + ], + "dapper-wallet-restrictions-testnet-2": [ "DapperWalletRestrictions" ] } From 67e8a515a463963d4c1f180ab1e3ff82668bdba0 Mon Sep 17 00:00:00 2001 From: jacksonfoley Date: Thu, 22 Aug 2024 15:01:52 -0600 Subject: [PATCH 2/4] add DapperWalletCollections contract to this repo as well. unclear if its being used --- contracts/DapperWalletCollections.cdc | 30 +++++++++++++++++++++++++++ flow.json | 4 +++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 contracts/DapperWalletCollections.cdc diff --git a/contracts/DapperWalletCollections.cdc b/contracts/DapperWalletCollections.cdc new file mode 100644 index 0000000..2cc76b1 --- /dev/null +++ b/contracts/DapperWalletCollections.cdc @@ -0,0 +1,30 @@ +access(all) contract DapperWalletCollections { + access(all) let StoragePath: StoragePath + + access(all) event TypeChanged(identifier: String, added: Bool) + + access(self) let types: {Type: Bool} + + access(all) resource Admin { + access(all) fun addType(_ t: Type) { + DapperWalletCollections.types.insert(key: t, true) + emit TypeChanged(identifier: t.identifier, added: true) + } + + access(all) fun removeType( _ t: Type) { + DapperWalletCollections.types.remove(key: t) + emit TypeChanged(identifier: t.identifier, added: false) + } + } + + access(all) view fun containsType(_ t: Type): Bool { + return self.types.containsKey(t) + } + + init () { + self.types = {} + + self.StoragePath = /storage/dapperWalletAllowlistCollections + self.account.storage.save(<- create Admin(), to: self.StoragePath) + } +} diff --git a/flow.json b/flow.json index c96da8f..8f2292f 100644 --- a/flow.json +++ b/flow.json @@ -1,5 +1,6 @@ { "contracts": { + "DapperWalletCollections": "./contracts/DapperWalletCollections.cdc", "DapperWalletRestrictions": "./contracts/DapperWalletRestrictions.cdc" }, "networks": { @@ -51,7 +52,8 @@ "DapperWalletRestrictions" ], "dapper-wallet-restrictions-testnet-2": [ - "DapperWalletRestrictions" + "DapperWalletRestrictions", + "DapperWalletCollections" ] } } From d702cbca692b4649153565a32631a9648edbd365 Mon Sep 17 00:00:00 2001 From: jacksonfoley Date: Thu, 22 Aug 2024 15:51:49 -0600 Subject: [PATCH 3/4] update flow.json --- .gitignore | 2 ++ flow.json | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/.gitignore b/.gitignore index e61344e..578a5e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ dapper-wallet-restrictions-testnet.key dapper-wallet-restrictions-mainnet.key +dapper-wallet-collections-testnet.key +dapper-wallet-collections-mainnet.key coverage.json \ No newline at end of file diff --git a/flow.json b/flow.json index 8f2292f..010326c 100644 --- a/flow.json +++ b/flow.json @@ -17,6 +17,14 @@ "location": "dapper-wallet-restrictions-mainnet.key" } }, + "dapper-collection-allowlist-mainnet": { + "address": "42a54b4f70e7dc81", + "key": { + "type": "file", + "hashAlgorithm": "SHA2_256", + "location": "dapper-wallet-collections-mainnet.key" + } + }, "dapper-wallet-restrictions-testnet": { "address": "a7d10afc50b14991", "key": { From 1abd98a1276c73404f09179dfd2b17eda5ba33f3 Mon Sep 17 00:00:00 2001 From: jacksonfoley Date: Fri, 23 Aug 2024 10:30:54 -0600 Subject: [PATCH 4/4] update key, transactions --- flow.json | 6 +++++- scripts/collections_contains_type.cdc | 6 ++++++ scripts/get_all_types.cdc | 2 +- transactions/add_collection_restriction.cdc | 11 +++++++++++ transactions/add_restriction.cdc | 6 +++--- transactions/update_restriction.cdc | 15 +++++++++++++++ 6 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 scripts/collections_contains_type.cdc create mode 100644 transactions/add_collection_restriction.cdc create mode 100644 transactions/update_restriction.cdc diff --git a/flow.json b/flow.json index 010326c..49c350f 100644 --- a/flow.json +++ b/flow.json @@ -21,7 +21,8 @@ "address": "42a54b4f70e7dc81", "key": { "type": "file", - "hashAlgorithm": "SHA2_256", + "hashAlgorithm": "SHA3_256", + "index": 2, "location": "dapper-wallet-collections-mainnet.key" } }, @@ -53,6 +54,9 @@ "mainnet": { "dapper-wallet-restrictions-mainnet": [ "DapperWalletRestrictions" + ], + "dapper-collection-allowlist-mainnet": [ + "DapperWalletCollections" ] }, "testnet": { diff --git a/scripts/collections_contains_type.cdc b/scripts/collections_contains_type.cdc new file mode 100644 index 0000000..bd6fa37 --- /dev/null +++ b/scripts/collections_contains_type.cdc @@ -0,0 +1,6 @@ +import "DapperWalletCollections" + +access(all) fun main(typeIdentifier: String): Bool { + let t = CompositeType(typeIdentifier)! + return DapperWalletCollections.containsType(t) +} \ No newline at end of file diff --git a/scripts/get_all_types.cdc b/scripts/get_all_types.cdc index e5c7554..a218ec9 100644 --- a/scripts/get_all_types.cdc +++ b/scripts/get_all_types.cdc @@ -1,5 +1,5 @@ import "DapperWalletRestrictions" -pub fun main(): {Type: DapperWalletRestrictions.TypeConfig} { +access(all) fun main(): {Type: DapperWalletRestrictions.TypeConfig} { return DapperWalletRestrictions.getTypes() } \ No newline at end of file diff --git a/transactions/add_collection_restriction.cdc b/transactions/add_collection_restriction.cdc new file mode 100644 index 0000000..aac262f --- /dev/null +++ b/transactions/add_collection_restriction.cdc @@ -0,0 +1,11 @@ +import DapperWalletCollections from "DapperWalletCollections" + +transaction(typeIdentifier: String) { + prepare(acct: auth(BorrowValue) &Account) { + let ref = acct.storage.borrow<&DapperWalletCollections.Admin>(from: DapperWalletCollections.StoragePath) + ?? panic("admin not found") + + let t = CompositeType(typeIdentifier)! + ref.addType(t) + } +} diff --git a/transactions/add_restriction.cdc b/transactions/add_restriction.cdc index eabf0cd..75ea478 100644 --- a/transactions/add_restriction.cdc +++ b/transactions/add_restriction.cdc @@ -1,8 +1,8 @@ import DapperWalletRestrictions from "DapperWalletRestrictions" transaction(typeIdentifier: String, flags: {String:Bool}) { - prepare(acct: AuthAccount) { - let ref = acct.borrow<&DapperWalletRestrictions.Admin>(from: DapperWalletRestrictions.StoragePath) + prepare(acct: auth(BorrowValue) &Account) { + let ref = acct.storage.borrow<&DapperWalletRestrictions.Admin>(from: DapperWalletRestrictions.StoragePath) ?? panic("admin not found") let conf = DapperWalletRestrictions.TypeConfig() @@ -12,4 +12,4 @@ transaction(typeIdentifier: String, flags: {String:Bool}) { let t = CompositeType(typeIdentifier)! ref.addType(t, conf: conf) } -} \ No newline at end of file +} diff --git a/transactions/update_restriction.cdc b/transactions/update_restriction.cdc new file mode 100644 index 0000000..f2d695f --- /dev/null +++ b/transactions/update_restriction.cdc @@ -0,0 +1,15 @@ +import DapperWalletRestrictions from "DapperWalletRestrictions" + +transaction(typeIdentifier: String, flags: {String:Bool}) { + prepare(acct: auth(BorrowValue) &Account) { + let ref = acct.storage.borrow<&DapperWalletRestrictions.Admin>(from: DapperWalletRestrictions.StoragePath) + ?? panic("admin not found") + + let conf = DapperWalletRestrictions.TypeConfig() + for k in flags.keys { + conf.setFlag(k, flags[k]!) + } + let t = CompositeType(typeIdentifier)! + ref.updateType(t, conf: conf) + } +}