Skip to content

Commit

Permalink
adjust entitlements, address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
austinkline committed May 21, 2024
1 parent b297a0c commit 602e6bb
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 25 deletions.
26 changes: 15 additions & 11 deletions contracts/LostAndFound.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,28 @@ access(all) contract LostAndFound {
access(all) event DepositorTokensAdded(uuid: UInt64, tokens: UFix64, balance: UFix64)
access(all) event DepositorTokensWithdrawn(uuid: UInt64, tokens: UFix64, balance: UFix64)

// Used by the @Depositor resource and controls whether the depositor can be used
// or not to send resources to the LostAndFound
access(all) entitlement Deposit
access(all) entitlement Withdraw

// Used by the @Depositor resource to manage settings such as low token threshold
access(all) entitlement Owner

// Placeholder receiver so that any resource can be supported, not just FT and NFT Receivers
access(all) resource interface AnyResourceReceiver {
access(Deposit) fun deposit(item: @AnyResource)
}

access(all) resource DepositEstimate {
access(Withdraw) var item: @AnyResource?
access(self) var item: @AnyResource?
access(all) let storageFee: UFix64

init(item: @AnyResource, storageFee: UFix64) {
self.item <- item
self.storageFee = storageFee
}

access(Withdraw) fun withdraw(): @AnyResource {
access(all) fun withdraw(): @AnyResource {
let item <- self.item <- nil
return <-item!
}
Expand Down Expand Up @@ -140,7 +144,7 @@ access(all) contract LostAndFound {
return nil
}

access(Withdraw) fun withdraw(receiver: Capability) {
access(contract) fun withdraw(receiver: Capability) {
pre {
receiver.address == self.redeemer: "receiver address and redeemer must match"
!self.redeemed: "already redeemed"
Expand Down Expand Up @@ -344,7 +348,7 @@ access(all) contract LostAndFound {
}

// Redeem a specific ticket instead of all of a certain type.
access(Withdraw) fun redeem(type: Type, ticketID: UInt64, receiver: Capability) {
access(all) fun redeem(type: Type, ticketID: UInt64, receiver: Capability) {
pre {
receiver.address == self.redeemer: "receiver must match the redeemer of this shelf"
self.bins.containsKey(type.identifier): "no bin for provided type"
Expand Down Expand Up @@ -430,7 +434,7 @@ access(all) contract LostAndFound {
storagePayment.getType() == Type<@FlowToken.Vault>(): "storage payment must be in flow tokens"
}
let receiver = LostAndFound.account
.capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver)!
.capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver)
.borrow()!


Expand Down Expand Up @@ -513,11 +517,11 @@ access(all) contract LostAndFound {
return false
}

access(Mutate) fun setLowBalanceThreshold(threshold: UFix64?) {
access(Owner) fun setLowBalanceThreshold(threshold: UFix64?) {
self.lowBalanceThreshold = threshold
}

access(Mutate) fun getLowBalanceThreshold(): UFix64? {
access(Owner) fun getLowBalanceThreshold(): UFix64? {
return self.lowBalanceThreshold
}

Expand All @@ -528,7 +532,7 @@ access(all) contract LostAndFound {
display: MetadataViews.Display?
) : UInt64 {
let receiver = LostAndFound.account
.capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver)!
.capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver)
.borrow()!

let storageBeforeShelf = LostAndFound.account.storage.used
Expand Down Expand Up @@ -577,7 +581,7 @@ access(all) contract LostAndFound {
}
}

access(Mutate) fun withdrawTokens(amount: UFix64): @{FungibleToken.Vault} {
access(Owner) fun withdrawTokens(amount: UFix64): @{FungibleToken.Vault} {
let tokens <-self.flowTokenVault.withdraw(amount: amount)
emit DepositorTokensWithdrawn(uuid: self.uuid, tokens: amount, balance: self.flowTokenVault.balance)
self.checkForLowBalance()
Expand Down Expand Up @@ -617,7 +621,7 @@ access(all) contract LostAndFound {
}

access(all) fun borrowShelfManager(): &LostAndFound.ShelfManager {
return self.account.capabilities.get<&LostAndFound.ShelfManager>(LostAndFound.LostAndFoundPublicPath)!.borrow()!
return self.account.capabilities.get<&LostAndFound.ShelfManager>(LostAndFound.LostAndFoundPublicPath).borrow()!
}

access(all) fun borrowAllTicketsByType(addr: Address, type: Type): [&LostAndFound.Ticket] {
Expand Down
4 changes: 2 additions & 2 deletions contracts/standard/ExampleNFT.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ access(all) contract ExampleNFT: ViewResolver {

// dictionary of NFT conforming tokens
// NFT is a resource type with an `UInt64` ID field
access(self) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}
access(all) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}

init () {
self.ownedNFTs <- {}
Expand Down Expand Up @@ -197,7 +197,7 @@ access(all) contract ExampleNFT: ViewResolver {
}

// withdraw removes an NFT from the collection and moves it to the caller
access(NonFungibleToken.Withdraw | NonFungibleToken.Owner) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
access(NonFungibleToken.Withdraw) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
let token <- self.ownedNFTs.remove(key: withdrawID) ?? panic("missing NFT")

emit Withdraw(id: token.id, from: self.owner?.address)
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
},
"homepage": "https://github.com/Flowtyio/lost-and-found#readme",
"dependencies": {
"@flowtyio/flow-contracts": "^0.1.0-beta.6"
"@flowtyio/flow-contracts": "^0.1.0-beta.21"
}
}
1 change: 0 additions & 1 deletion transactions/depositor/setup_depositor.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ transaction(lowBalanceThreshold: UFix64?) {
prepare(acct: auth(Storage, Capabilities) &Account) {
if acct.storage.borrow<&LostAndFound.Depositor>(from: LostAndFound.DepositorStoragePath) == nil {
let flowTokenRepayment = acct.capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver)
?? panic("flow token repayment capability not found")
let depositor <- LostAndFound.createDepositor(flowTokenRepayment, lowBalanceThreshold: lowBalanceThreshold)
acct.storage.save(<-depositor, to: LostAndFound.DepositorStoragePath)

Expand Down
2 changes: 1 addition & 1 deletion transactions/depositor/withdraw_below_threshold.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "FlowToken"
transaction(lowBalanceThreshold: UFix64) {
prepare(acct: auth(Storage, Capabilities) &Account) {
if acct.storage.borrow<&LostAndFound.Depositor>(from: LostAndFound.DepositorStoragePath) == nil {
let flowTokenRepayment = acct.capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver)!
let flowTokenRepayment = acct.capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver)
let depositor <- LostAndFound.createDepositor(flowTokenRepayment, lowBalanceThreshold: lowBalanceThreshold)
acct.storage.save(<-depositor, to: LostAndFound.DepositorStoragePath)

Expand Down
2 changes: 1 addition & 1 deletion transactions/depositor/withdraw_to_threshold.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "FlowToken"
transaction(lowBalanceThreshold: UFix64) {
prepare(acct: auth(Storage, Capabilities) &Account) {
if acct.storage.borrow<&LostAndFound.Depositor>(from: LostAndFound.DepositorStoragePath) == nil {
let flowTokenRepayment = acct.capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver)!
let flowTokenRepayment = acct.capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver)
let depositor <- LostAndFound.createDepositor(flowTokenRepayment, lowBalanceThreshold: lowBalanceThreshold)
acct.storage.save(<-depositor, to: LostAndFound.DepositorStoragePath)

Expand Down
1 change: 0 additions & 1 deletion transactions/example-nft/mint_example_nft.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ transaction(recipient: Address, num: Int) {

execute {
let cap = getAccount(recipient).capabilities.get<&{NonFungibleToken.Collection}>(ExampleNFT.CollectionPublicPath)
?? panic("receiver not found")
let receiver = cap.borrow() ?? panic("unable to borrow collection")

var count = 0
Expand Down

0 comments on commit 602e6bb

Please sign in to comment.