From bd77c8aec960405fa1c0d37755de051a287dfded Mon Sep 17 00:00:00 2001 From: "Bjarte S. Karlsen" Date: Tue, 27 Apr 2021 11:12:24 +0200 Subject: [PATCH] do not panic but send money/nft to owner instead (#27) --- contracts/Auction.cdc | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/contracts/Auction.cdc b/contracts/Auction.cdc index 3eee73b..c1b5b84 100644 --- a/contracts/Auction.cdc +++ b/contracts/Auction.cdc @@ -159,7 +159,11 @@ pub contract Auction { collectionRef.deposit(token: <-NFT!) return } - panic("Could not send NFT to non existing capability") + if let ownerCollection=self.ownerCollectionCap.borrow() { + let NFT <- self.NFT <- nil + ownerCollection.deposit(token: <-NFT!) + return + } } // sendBidTokens sends the bid tokens to the Vault Receiver belonging to the provided Capability @@ -172,7 +176,14 @@ pub contract Auction { } return } - panic("Could not send tokens to non existant receiver") + + if let ownerRef= self.ownerVaultCap.borrow() { + let bidVaultRef = &self.bidVault as &FungibleToken.Vault + if(bidVaultRef.balance > 0.0) { + ownerRef.deposit(from: <-bidVaultRef.withdraw(amount: bidVaultRef.balance)) + } + return + } } pub fun releasePreviousBid() { @@ -185,7 +196,6 @@ pub contract Auction { //This method should probably use preconditions more pub fun settleAuction(cutPercentage: UFix64, cutVault:Capability<&{FungibleToken.Receiver}> ) { - pre { !self.auctionCompleted : "The auction is already settled" self.NFT != nil: "NFT in auction does not exist" @@ -286,11 +296,7 @@ pub contract Auction { if self.bidder() != bidderAddress { if self.bidVault.balance != 0.0 { - if let vaultCap = self.recipientVaultCap { - self.sendBidTokens(self.recipientVaultCap!) - } else { - panic("unable to get recipient Vault capability") - } + self.sendBidTokens(self.recipientVaultCap!) } }