Skip to content

Commit

Permalink
Merge pull request #67 from dapperlabs/josh/reorg
Browse files Browse the repository at this point in the history
Reorganizing the repo
  • Loading branch information
joshuahannan authored Jun 24, 2020
2 parents 0253ddc + bd3151b commit d02e043
Show file tree
Hide file tree
Showing 42 changed files with 448 additions and 97 deletions.
58 changes: 17 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,18 @@ The first step for using any smart contract is deploying it to the blockchain,
or emulator in our case. Do these commands in vscode

1. Start the emulator with the `Run emulator` vscode command.
2. Open the `NonFungibleToken.cdc` file and the `TopShot.cdc` file. Feel free to read as much as you want to
2. Open the `NonFungibleToken.cdc` file from the [flow-nft repo](https://github.com/onflow/flow-nft/blob/master/src/contracts/NonFungibleToken.cdc) and the `TopShot.cdc` file. Feel free to read as much as you want to
familiarize yourself with the contract
3. The Marketplace smart contract implements the fungible token interface in `fungible-token.cdc`, so you need
to open that first and click the `deploy contract to account 0x01` button
that appears above the `FlowToken` contract. This will deploy the interface definition and contract
to account 1.
4. Run the `switch account` command from the vscode comman palette. Switch to account 2.
5. In `NonFungibleToken.cdc`, click the `deploy contract to account` to deploy to account 2.
6. Switch to account 3.
6. In `topshot.cdc`, click the `deploy contract to account` button that appears over the
`TopShot` contract declaration to deploy to account 3.

This deploys the contract code to account 3. It also runs the contracts
3. In `NonFungibleToken.cdc`, click the `deploy contract to account` to deploy it.
4. Switch to a different account
5. In `TopShot.cdc`, make sure it imports `NonFungibleToken` from the account you deployed it to
6. click the `deploy contract to account` button that appears over the
`TopShot` contract declaration to deploy it to a new account

This deploys the contract code. It also runs the contracts
`init` function, which initializes the contract storage variables,
stores the `Collection` and `Admin` resources
in account storage, and stores references to `Collection`.
in account storage, and creates links to the `Collection`.

As you can see, whenever we want to call a function, read a field,
or use a type that is defined in a smart contract, we simply import
Expand Down Expand Up @@ -133,7 +129,9 @@ is a list of events that can be emitted, and what each event means.

## Directory Structure

The directories here are organized into scripts and transactions.
The directories here are organized into contrats, scripts, and transactions.

Contracts contain the source code for the topshot contracts that are deployed to Flow.

Scripts contain read-only transactions to get information about
the state of someones Collection or about the state of the TopShot contract.
Expand All @@ -146,51 +144,29 @@ minting moments, and transfering moments.
- `scripts/` : This contains all the read-only Cadence scripts
that are used to read information from the smart contract
or from a resource in account storage
- `collections/`: Used to read information about a user's Moment collection
- `market/`: Used to read information about the market smart contract and about a user's Moment sales.
- `plays/`: Used to read information related to play data and IDs.
- `sets/`: Used to read various information about set names and IDs
- `test/` : This contains special transactions and scripts that are used
to quickly test the functionality of the smart contracts. They are not all
working now and will be updated to be extensive when the contracts
are updated with the new storage interface changes.
- `transactions/` : This directory contains all the state-changing transactions
that are associated with the TopShot smart contracts.
- `collections/`: Transactions for a user to interact with their Moment collection
- `market/`: Transactions for users to buy and sell moments using
the market smart contract.
- `plays/`: Transactions for an Admin to add and modify play data and IDs.
- `sets/`: Transactions for an Admin to take all
the actions associated wit sets, like adding plays, minting moments,
locking sets, and more.

### Marketplace

The `topshot_market.cdc` contract allows users to create a marketplace object in their account to sell their moments.

1. Make sure you have followed the steps to get topshot set up.
2. Deploy `fungible-token.cdc` to account 1
3. Deploy `NonFungibleToken.cdc` to account 2 and `TopShot.cdc` to account 3.
4. Deploy `MarketTopShot.cdc` to account 4. Feel free to look at the various
fields and functions in the smart contract.
### Marketplace

There currently aren't many example transactions for the market but they will be added soon once we have a better idea of exactly how it will function.
The `MarketTopShot.cdc` contract allows users to create a marketplace object in their account to sell their moments.

#### Events for Market-related actions

- `pub event MomentListed(id: UInt64, price: UFix64, seller: Address?)`

Emitted when a user lists a moment for sale in their SaleCollection.

- `pub event PriceChanged(id: UInt64, newPrice: UFix64, seller: Address?)`
- `pub event MomentPriceChanged(id: UInt64, newPrice: UFix64, seller: Address?)`

Emitted when a user changes the price of their moment.

- `pub event TokenPurchased(id: UInt64, price: UFix64, seller: Address?)`
- `pub event MomentPurchased(id: UInt64, price: UFix64, seller: Address?)`

Emitted when a user purchases a moment that is for sale.

- `pub event SaleWithdrawn(id: UInt64, owner: Address?)`
- `pub event MomentWithdrawn(id: UInt64, owner: Address?)`

Emitted when a seller withdraws their moment from their SaleCollection

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 0 additions & 10 deletions contracts/go.mod

This file was deleted.

File renamed without changes.
4 changes: 2 additions & 2 deletions contracts/contracts.go → lib/go/contracts/contracts.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package contracts

//go:generate go run github.com/kevinburke/go-bindata/go-bindata -prefix ../src/contracts -o internal/assets/assets.go -pkg assets -nometadata -nomemcopy ../src/contracts
//go:generate go run github.com/kevinburke/go-bindata/go-bindata -prefix ../../../contracts -o internal/assets/assets.go -pkg assets -nometadata -nomemcopy ../../../contracts

import (
"strings"

"github.com/dapperlabs/nba-smart-contracts/contracts/internal/assets"
"github.com/dapperlabs/nba-smart-contracts/lib/go/contracts/internal/assets"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/onflow/flow-go-sdk"
"github.com/stretchr/testify/assert"

"github.com/dapperlabs/nba-smart-contracts/contracts"
"github.com/dapperlabs/nba-smart-contracts/lib/go/contracts"
)

var addrA = flow.HexToAddress("0A")
Expand Down
13 changes: 13 additions & 0 deletions lib/go/contracts/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module github.com/dapperlabs/nba-smart-contracts/lib/go/contracts

go 1.14

require (
github.com/dapperlabs/nba-smart-contracts/contracts v0.1.9
github.com/onflow/flow-ft v0.1.2 // indirect
github.com/onflow/flow-ft/contracts v0.1.3 // indirect
github.com/onflow/flow-go-sdk v0.4.0
github.com/stretchr/testify v1.5.1
)

replace github.com/dapperlabs/nba-smart-contracts/lib/go/contracts => ../contracts
3 changes: 3 additions & 0 deletions contracts/go.sum → lib/go/contracts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cloudflare/cloudflare-go v0.10.2-0.20190916151808-a80f83b9add9/go.mod h1:1MxXX1Ux4x6mqPmjkUgTP1CdXIBXKX7T+Jk9Gxrmx+U=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/dapperlabs/nba-smart-contracts v0.1.4 h1:DKtQ1olSEdrKI91fJiIKM6DtU/58NXPrkNfATFEIllw=
github.com/dapperlabs/nba-smart-contracts/contracts v0.1.9 h1:4YGqDeEU/pRD/k3q6YlbIUrEyLfxBRnFgp/CDbm3LNE=
github.com/dapperlabs/nba-smart-contracts/contracts v0.1.9/go.mod h1:IfJM8GfN/DiN39E0B8VZE/nlKe/ITUlASFUa1UEWDRY=
github.com/dapperlabs/nba-smart-contracts/templates v0.1.6 h1:QPbM2ElXUno5vKabSprwLMimvaWrrzAqwR9j6Gx8UqA=
github.com/dapperlabs/nba-smart-contracts/templates v0.1.6/go.mod h1:fnX9SVlV+1pguQZ5wNMP8Tm0aRSkbaP6pv6iOEJdR0c=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down

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

File renamed without changes.
2 changes: 1 addition & 1 deletion events/go.mod → lib/go/events/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/dapperlabs/nba-smart-contracts/events
module github.com/dapperlabs/nba-smart-contracts/lib/go/events

go 1.14

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions lib/go/templates/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.PHONY: test
test:
go test ./...

.PHONY: generate
generate:
go generate

.PHONY: check-generated
check-generated:
git diff --exit-code

.PHONY: ci
ci: generate check-generated test
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions lib/go/templates/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module github.com/dapperlabs/nba-smart-contracts/lib/go/templates

go 1.14

require (
github.com/dapperlabs/nba-smart-contracts/templates v0.1.10
github.com/ethereum/go-ethereum v1.9.13 // indirect
github.com/kevinburke/go-bindata v3.21.0+incompatible // indirect
github.com/onflow/cadence v0.4.0 // indirect
github.com/onflow/flow-go-sdk v0.4.0
github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/testify v1.5.1
golang.org/x/crypto v0.0.0-20200429183012-4b2356b1ed79 // indirect
golang.org/x/lint v0.0.0-20200130185559-910be7a94367 // indirect
golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3 // indirect
golang.org/x/tools v0.0.0-20200323144430-8dcfad9e016e // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)

replace github.com/dapperlabs/nba-smart-contracts/lib/go/templates => ../templates
Loading

0 comments on commit d02e043

Please sign in to comment.