Skip to content

Commit

Permalink
Reversing the repository organization (#26)
Browse files Browse the repository at this point in the history
* reorganizing the repository

* makefile test update

* go mod tidy

* make fix
  • Loading branch information
joshuahannan authored Jun 25, 2020
1 parent 5b27dd1 commit c4c920e
Show file tree
Hide file tree
Showing 31 changed files with 818 additions and 412 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.PHONY: ci
ci:
$(MAKE) -C test ci
$(MAKE) -C contracts ci
$(MAKE) -C lib/go/contracts ci
$(MAKE) -C lib/go/test ci

32 changes: 6 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ The feedback we are looking for is:

## Basics of the Standard:

The code for the standard is in `src/contracts/FungibleToken.cdc`. An example implementation of the standard that simulates what a simple token would be like is in `src/contracts/ExampleToken.cdc`.
The code for the standard is in `contracts/FungibleToken.cdc`. An example implementation of the standard that simulates what a simple token would be like is in `contracts/ExampleToken.cdc`.

The exact smart contract that is used for the official Flow Network Token is in `src/contracts/FlowToken.cdc`
The exact smart contract that is used for the official Flow Network Token is in `contracts/FlowToken.cdc`

Example transactions that users could use to interact with fungible tokens are located in the `src/transactions/` directory.
Go transaction templates are in the `test/templates.go` file. These templates are mostly generic and can be used with any fungible token implementation by providing the correct addresses, names, and values.
Example transactions that users could use to interact with fungible tokens are located in the `transactions/` directory. These templates are mostly generic and can be used with any fungible token implementation by providing the correct addresses, names, and values.

The standard consists of a contract interface called `FungibleToken` that requires implementing contracts to define a `Vault` resource that represents the tokens that an account owns. Each account that owns tokens will have a `Vault` stored in its account storage. Users call functions on each other's `Vault`s to send and receive tokens.

Expand Down Expand Up @@ -179,8 +178,8 @@ A standard for token metadata is still an unsolved problem in the general blockc

To use the Flow Token contract as is, you need to follow these steps:

1. Deploy the `FungibleToken` definition to account `0x02`
2. Deploy the `ExampleToken` definition to account `0x03`
1. Import the `FungibleToken` definition from account `0xee82856bf20e2aa6`. This is a predeployed interface in the emulator, testnet, and mainnet.
2. Deploy the `ExampleToken` definition
3. You can use the `get_balance.cdc` or `get_supply.cdc` scripts to read the
balance of a user's `Vault` or the total supply of all tokens, respectively.
4. Use the `setupAccount.cdc` on any account to set up the account to be able to
Expand All @@ -195,26 +194,7 @@ To use the Flow Token contract as is, you need to follow these steps:

# Running Automated Tests

You can find automated tests in the `fungible_token_test.go` file. It uses the transaction templates that are contained in the `fungible_templates.go` file. Currently, these rely on a dependency from a private dapper labs repository to run, so external users will not be able to run them. We are working on making all of this public so anyone can run tests, but haven't completed this work yet.


# Payment ID solution for Custodial Deposits

We have included a simple example of a contract and resource that could
be used by custodial services to be able to accept deposits from their customers.
This is included in `src/contracts/CustodialDeposit.cdc`. The service would deploy the
contract to their account, which stores the special `DepositResource`
into their storage and published a reference, then users could use transactions
like `src/transactions/custodial_deposit.cdc` to deposit their tokens into the account.
Each deposit has to include a payment ID, or tag as we call it in the contract, to
indicate which account it corresponds to. The resource emits an event that the
service can watch for to see which user's account to credit.

To test, if you have already deployed `FungibleToken.cdc` and `FlowToken.cdc` to
accounts 1 and 2, respectively:

1. Deploy `CustodialDeposit.cdc` to account `0x04`
2. Switch to Account `0x03` and submit the `custodial_deposit.cdc` transaction.
You can find automated tests in the `lib/go/test/token_test.go` file. It uses the transaction templates that are contained in the `lib/go/templates/transaction_templates.go` file. Currently, these rely on a dependency from a private dapper labs repository to run, so external users will not be able to run them. We are working on making all of this public so anyone can run tests, but haven't completed this work yet.

## License

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion contracts/Makefile → lib/go/contracts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ check-generated:
git diff --exit-code

.PHONY: ci
ci: generate check-generated test
ci: generate test
19 changes: 2 additions & 17 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/onflow/flow-ft/contracts/internal/assets"
"github.com/onflow/flow-ft/lib/go/contracts/internal/assets"
)

const (
Expand All @@ -21,21 +21,6 @@ func FungibleToken() []byte {
return assets.MustAsset(fungibleTokenFilename)
}

// FlowToken returns the FlowToken contract.
//
// The returned contract will import the FungibleToken interface from the specified address.
func FlowToken(fungibleTokenAddr string) []byte {
code := assets.MustAssetString(flowTokenFilename)

code = strings.ReplaceAll(
code,
"0x"+defaultFungibleTokenAddress,
"0x"+fungibleTokenAddr,
)

return []byte(code)
}

// ExampleToken returns the ExampleToken contract.
//
// The returned contract will import the FungibleToken interface from the specified address.
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/onflow/flow-ft/contracts"
"github.com/onflow/flow-ft/lib/go/contracts"
)

var addrA = flow.HexToAddress("0A")
Expand All @@ -16,12 +16,6 @@ func TestFungibleTokenContract(t *testing.T) {
assert.NotNil(t, contract)
}

func TestFlowTokenContract(t *testing.T) {
contract := contracts.FlowToken(addrA.Hex())
assert.NotNil(t, contract)
assert.Contains(t, string(contract), addrA.Hex())
}

func TestExampleTokenContract(t *testing.T) {
contract := contracts.ExampleToken(addrA.Hex())
assert.NotNil(t, contract)
Expand Down
12 changes: 12 additions & 0 deletions lib/go/contracts/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/onflow/flow-ft/lib/go/contracts

go 1.14

require (
github.com/kevinburke/go-bindata v3.21.0+incompatible // indirect
github.com/onflow/flow-ft/contracts v0.1.3
github.com/onflow/flow-go-sdk v0.4.0
github.com/stretchr/testify v1.5.1
)

replace github.com/onflow/flow-ft/lib/go/contracts => ../contracts
2 changes: 1 addition & 1 deletion contracts/go.sum → lib/go/contracts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/julienschmidt/httprouter v1.1.1-0.20170430222011-975b5c4c7c21/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU=
github.com/kevinburke/go-bindata v3.21.0+incompatible h1:baK7hwFJDlAHrOqmE9U3u8tow1Uc5ihN9E/b7djcK2g=
github.com/kevinburke/go-bindata v3.21.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
Expand Down Expand Up @@ -132,6 +131,7 @@ github.com/onflow/cadence v0.4.0-beta1 h1:0f4CMnddT++5OYY53OPFuv5JTb85qDg/nygLV4
github.com/onflow/cadence v0.4.0-beta1/go.mod h1:gaPtSctdMzT5NAoJgzsRuwUkdgRswVHsRXFNNmCTn3I=
github.com/onflow/cadence v0.4.0 h1:oAKY/HclZZhc5wJgJwdPjWXJuC5IjuuHHVAAq3S7AHI=
github.com/onflow/cadence v0.4.0/go.mod h1:gaPtSctdMzT5NAoJgzsRuwUkdgRswVHsRXFNNmCTn3I=
github.com/onflow/flow-ft/contracts v0.1.3/go.mod h1:IKe3yEurEKpg/J15q5WBlHkuMmt1iRECSHgnIa1gvRw=
github.com/onflow/flow-go-sdk v0.4.0 h1:ZNEE8HQ6xTyr4+RmlxZ2+U/BjKtQDsAB54I+D8AJpZA=
github.com/onflow/flow-go-sdk v0.4.0/go.mod h1:MHn8oQCkBNcl2rXdYSm9VYYK4ogwEpyrdM/XK/czdlM=
github.com/onflow/flow/protobuf/go/flow v0.1.5-0.20200601215056-34a11def1d6b/go.mod h1:kRugbzZjwQqvevJhrnnCFMJZNmoSJmxlKt6hTGXZojM=
Expand Down

Large diffs are not rendered by default.

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
4 changes: 3 additions & 1 deletion contracts/go.mod → lib/go/templates/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/onflow/flow-ft/contracts
module github.com/onflow/flow-ft/lib/go/templates

go 1.14

Expand All @@ -15,3 +15,5 @@ require (
golang.org/x/tools v0.0.0-20200323144430-8dcfad9e016e // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)

replace github.com/onflow/flow-ft/lib/go/templates => ../templates
Loading

0 comments on commit c4c920e

Please sign in to comment.