-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functions to give information from the tickets. (#39)
* Add support to common resources * Update * Update * First draft * flow.json * Add tests as overflow.go * Add ways to get flow repayment address * Refine tests * Resolve conversation * Add info to helper struct * Add ci tests * pr * Amend struct * fix test * enhance ci tests * enhance tests per Austins comment * Add to mainnet * Update test/fungible-token.test.js Co-authored-by: Austin Kline <[email protected]> Co-authored-by: Hui Ben <[email protected]> Co-authored-by: Austin Kline <[email protected]>
- Loading branch information
1 parent
f9bff2f
commit ab82f74
Showing
17 changed files
with
2,507 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,27 @@ jobs: | |
run: npm ci | ||
- name: Run tests | ||
run: npm test -- --runInBand | ||
|
||
tests-overflow: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.18 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/go/pkg/mod | ||
~/.cache/go-build | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: run tests | ||
run: go test -timeout 30m -json ./... > test.json | ||
- name: Annotate tests | ||
if: always() | ||
uses: guyarb/[email protected] | ||
with: | ||
test-results: test.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import LostAndFound from "./LostAndFound.cdc" | ||
|
||
pub contract LostAndFoundHelper { | ||
|
||
pub struct Ticket { | ||
|
||
// An optional message to attach to this item. | ||
pub let memo: String? | ||
// The address that it allowed to withdraw the item fromt this ticket | ||
pub let redeemer: Address | ||
//The type of the resource (non-optional) so that bins can represent the true type of an item | ||
pub let type: Type | ||
pub let typeIdentifier: String | ||
// State maintained by LostAndFound | ||
pub let redeemed: Bool | ||
pub let name : String? | ||
pub let description : String? | ||
pub let thumbnail : String? | ||
pub let ticketID : UInt64? | ||
|
||
init(_ ticket: &LostAndFound.Ticket, id: UInt64?) { | ||
self.memo = ticket.memo | ||
self.redeemer = ticket.redeemer | ||
self.type = ticket.type | ||
self.typeIdentifier = ticket.type.identifier | ||
self.redeemed = ticket.redeemed | ||
self.name = ticket.display?.name | ||
self.description = ticket.display?.description | ||
self.thumbnail = ticket.display?.thumbnail?.uri() | ||
self.ticketID = id | ||
} | ||
|
||
} | ||
|
||
pub fun constructResult(_ ticket: &LostAndFound.Ticket?, id:UInt64?) : LostAndFoundHelper.Ticket? { | ||
if ticket != nil { | ||
return LostAndFoundHelper.Ticket(ticket!, id: id) | ||
} | ||
return nil | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
cadence/scripts/ExampleNFT/borrow_all_tickets_as_struct.cdc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import LostAndFound from "../../contracts/LostAndFound.cdc" | ||
import LostAndFoundHelper from "../../contracts/LostAndFoundHelper.cdc" | ||
|
||
pub fun main(addr: Address): [LostAndFoundHelper.Ticket] { | ||
|
||
let res : [LostAndFoundHelper.Ticket] = [] | ||
for ticket in LostAndFound.borrowAllTickets(addr: addr) { | ||
if let t = LostAndFoundHelper.constructResult(ticket, id: nil) { | ||
res.append(t) | ||
} | ||
} | ||
|
||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import ExampleNFT from "../../contracts/ExampleNFT.cdc" | ||
import LostAndFound from "../../contracts/LostAndFound.cdc" | ||
|
||
pub fun main(addr: Address, type: String): [UInt64] { | ||
let tickets = LostAndFound.borrowAllTicketsByType(addr: addr, type: CompositeType(type)!) | ||
let ids : [UInt64] = [] | ||
for ticket in tickets { | ||
if let id = ticket.getNonFungibleTokenID() { | ||
ids.append(id) | ||
} | ||
} | ||
return ids | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import FungibleToken from "../../contracts/FungibleToken.cdc" | ||
import ExampleToken from "../../contracts/ExampleToken.cdc" | ||
|
||
import LostAndFound from "../../contracts/LostAndFound.cdc" | ||
import LostAndFoundHelper from "../../contracts/LostAndFoundHelper.cdc" | ||
|
||
pub fun main(addr: Address, ticketID: UInt64): LostAndFoundHelper.Ticket? { | ||
let shelfManager = LostAndFound.borrowShelfManager() | ||
let shelf = shelfManager.borrowShelf(redeemer: addr) | ||
let bin = shelf!.borrowBin(type: Type<@ExampleToken.Vault>())! | ||
|
||
let ticket = bin.borrowTicket(id: ticketID) | ||
return LostAndFoundHelper.constructResult(ticket, id: ticketID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import FungibleToken from "../../contracts/FungibleToken.cdc" | ||
import LostAndFound from "../../contracts/LostAndFound.cdc" | ||
|
||
pub fun main(addr: Address, type: String): UFix64 { | ||
let tickets = LostAndFound.borrowAllTicketsByType(addr: addr, type: CompositeType(type)!) | ||
var balance : UFix64 = 0.0 | ||
for ticket in tickets { | ||
if let b = ticket.getFungibleTokenBalance() { | ||
balance = balance + b | ||
} | ||
} | ||
return balance | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import LostAndFound from "../contracts/LostAndFound.cdc" | ||
|
||
pub fun main(addr: Address, type: String, ticketID: UInt64): Address? { | ||
let shelfManager = LostAndFound.borrowShelfManager() | ||
if let shelf = shelfManager.borrowShelf(redeemer: addr) { | ||
if let bin = shelf.borrowBin(type: CompositeType(type)!) { | ||
if let ticket = bin.borrowTicket(id: ticketID) { | ||
return ticket.getFlowRepaymentAddress() | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
Oops, something went wrong.