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/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/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..49c350f 100644 --- a/flow.json +++ b/flow.json @@ -1,5 +1,6 @@ { "contracts": { + "DapperWalletCollections": "./contracts/DapperWalletCollections.cdc", "DapperWalletRestrictions": "./contracts/DapperWalletRestrictions.cdc" }, "networks": { @@ -8,6 +9,23 @@ "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-collection-allowlist-mainnet": { + "address": "42a54b4f70e7dc81", + "key": { + "type": "file", + "hashAlgorithm": "SHA3_256", + "index": 2, + "location": "dapper-wallet-collections-mainnet.key" + } + }, "dapper-wallet-restrictions-testnet": { "address": "a7d10afc50b14991", "key": { @@ -15,12 +33,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,14 +51,21 @@ "DapperWalletRestrictions" ] }, - "testnet": { - "dapper-wallet-restrictions-testnet": [ + "mainnet": { + "dapper-wallet-restrictions-mainnet": [ "DapperWalletRestrictions" + ], + "dapper-collection-allowlist-mainnet": [ + "DapperWalletCollections" ] }, - "mainnet": { - "dapper-wallet-restrictions-mainnet": [ + "testnet": { + "dapper-wallet-restrictions-testnet": [ "DapperWalletRestrictions" + ], + "dapper-wallet-restrictions-testnet-2": [ + "DapperWalletRestrictions", + "DapperWalletCollections" ] } } 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) + } +}