Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: official documentation #1046

Merged
merged 74 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 72 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
d8f1599
Add base Docusaurus setup
zivkovicmilos Aug 9, 2023
0c84b03
Remove docs README
zivkovicmilos Aug 9, 2023
b473202
Add content for the Overview
zivkovicmilos Aug 10, 2023
b4e3f7c
Update Installation doc
zivkovicmilos Aug 10, 2023
57a9e7b
Update the Create a private key section
zivkovicmilos Aug 10, 2023
a10d126
Update the Create a private key section
zivkovicmilos Aug 10, 2023
955042a
Update the Premining Balances tutorial
zivkovicmilos Aug 11, 2023
630be8f
Update the Running a Faucet tutorial
zivkovicmilos Aug 11, 2023
badb5d9
Update the Setting up a Local Chain doc
zivkovicmilos Aug 15, 2023
c7f611d
Update the Browsing Gno Source code doc
zivkovicmilos Aug 15, 2023
8845314
Add guide on creating a simple Realm
zivkovicmilos Sep 4, 2023
e93b74b
Add guide on creating a simple Package
zivkovicmilos Sep 4, 2023
019650a
Add guide on running tests
zivkovicmilos Sep 4, 2023
3a40dd4
Merge branch 'master' into feature/official-docs
zivkovicmilos Oct 3, 2023
da1fe7b
feat: add grc20 + grc721 guides (#16)
waymobetta Oct 8, 2023
c940c2c
feat: index from dev portal (#18)
r3v4s Oct 10, 2023
e2343c6
feat: add contents from portal (#19)
dongwon8247 Oct 10, 2023
a324ce5
feat: add howto - deploy & write-simple-dapp (#17)
leohhhn Oct 10, 2023
ab9c39a
initial explaination doc for gno modules (#20)
harry-hov Oct 11, 2023
db983b9
style: customize doc styles (#21)
alexiscolin Oct 12, 2023
22c0cde
Drop some docs temporarily
zivkovicmilos Oct 12, 2023
23a747f
Reorganize the docs, so they are framework agnostic
zivkovicmilos Oct 12, 2023
cfc4459
Clean up config
zivkovicmilos Oct 12, 2023
38d9a12
Merge branch 'master' into feature/official-docs
zivkovicmilos Oct 12, 2023
679fa08
Update docs/explanation/gno-language.md
zivkovicmilos Oct 17, 2023
7842672
Update docs/explanation/gno-language.md
zivkovicmilos Oct 17, 2023
4ec69ee
Update docs/explanation/gno-modules.md
zivkovicmilos Oct 17, 2023
7ae2920
Update docs/explanation/gno-modules.md
zivkovicmilos Oct 17, 2023
9f7ab77
Update docs/explanation/gno-test.md
zivkovicmilos Oct 17, 2023
4ba996d
Update docs/explanation/gno-tooling/cli/gnofaucet.md
zivkovicmilos Oct 17, 2023
67f73b8
Update docs/how-to-guides/Interact-with-gnoland.md
zivkovicmilos Oct 17, 2023
21283a8
Update docs/explanation/realms.md
zivkovicmilos Oct 17, 2023
35942e6
Update docs/explanation/realms.md
zivkovicmilos Oct 17, 2023
cd33a9c
Update docs/getting-started/working-with-key-pairs.md
zivkovicmilos Oct 17, 2023
ee0a7ff
Update docs/explanation/tendermint2.md
zivkovicmilos Oct 17, 2023
acaf2aa
Update docs/explanation/realms.md
zivkovicmilos Oct 17, 2023
d004bb1
Merge branch 'master' into feature/official-docs
zivkovicmilos Oct 21, 2023
6d3e57c
Rephrase sentence
zivkovicmilos Oct 21, 2023
531642c
Rephase Ethereum section
zivkovicmilos Oct 21, 2023
db5eda0
Fix typo
zivkovicmilos Oct 21, 2023
e4ee8a0
Update docs/explanation/gno-language.md
leohhhn Oct 31, 2023
43384c5
Update docs/explanation/gno-language.md
leohhhn Oct 31, 2023
b6089ba
Update docs/explanation/gno-language.md
leohhhn Oct 31, 2023
458598d
Update docs/explanation/gno-modules.md
leohhhn Oct 31, 2023
40fa990
Rephrase gno-language.md sentence
zivkovicmilos Nov 8, 2023
00cbe6d
Drop common params doc
zivkovicmilos Nov 8, 2023
6bf83af
Improve gnofaucet.md
zivkovicmilos Nov 8, 2023
3603681
Add disclaimer for Adena
zivkovicmilos Nov 8, 2023
7254544
Swap test3 for staging
zivkovicmilos Nov 8, 2023
72e20b1
Update docs/getting-started/setting-up-a-local-chain.md
zivkovicmilos Nov 8, 2023
ecdb870
Merge branch 'feature/official-docs' of https://github.com/zivkovicmi…
zivkovicmilos Nov 8, 2023
969e914
Add form GUI explanation
zivkovicmilos Nov 8, 2023
e89d450
Rename file
zivkovicmilos Nov 8, 2023
1e627ef
Rename installation to local setup
zivkovicmilos Nov 8, 2023
fba2029
Add link to Gnolang
zivkovicmilos Nov 8, 2023
824816e
Rename Packages to Pure Packages
zivkovicmilos Nov 8, 2023
ef941e0
Add disclaimer for chain id
zivkovicmilos Nov 8, 2023
e8f1460
Update tm2 doc
zivkovicmilos Nov 8, 2023
d6ee4da
Add code embed support
zivkovicmilos Nov 8, 2023
43d4dba
Rename lang shorthand
zivkovicmilos Nov 8, 2023
b949947
Update docs/explanation/gno-modules.md
zivkovicmilos Nov 8, 2023
7da892e
Update docs/explanation/gno-modules.md
zivkovicmilos Nov 8, 2023
2206eac
Rephrase
zivkovicmilos Nov 8, 2023
4b6fa24
Update docs/explanation/gno-modules.md
zivkovicmilos Nov 8, 2023
3c67978
Update docs/explanation/gno-modules.md
zivkovicmilos Nov 8, 2023
f888653
Update docs/explanation/gno-modules.md
zivkovicmilos Nov 8, 2023
b1ac173
Remove duplicate compatibility doc
zivkovicmilos Nov 8, 2023
6b68949
Merge branch 'master' into feature/official-docs
zivkovicmilos Nov 8, 2023
8ba08b8
Add devrels to own the docs
zivkovicmilos Nov 8, 2023
90922f5
Fix hanging references
zivkovicmilos Nov 9, 2023
408f0fa
Update docs/explanation/gnovm.md
zivkovicmilos Nov 9, 2023
9073308
Update docs/explanation/gnovm.md
zivkovicmilos Nov 9, 2023
34de86c
Merge branch 'master' into feature/official-docs
zivkovicmilos Nov 9, 2023
5e9b9d2
Merge branch 'feature/official-docs' of https://github.com/zivkovicmi…
zivkovicmilos Nov 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ PHILOSOPHY.md @jaekwon @moul
CONTRIBUTING.md @jaekwon @moul
LICENSE.md @jaekwon @moul
.github/CODEOWNERS @jaekwon @moul

# Documentation.
docs/* @gnolang/devrels
6 changes: 6 additions & 0 deletions docs/assets/explanation/packages/pkg-1.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
func TotalSupply() uint64
func BalanceOf(account std.Address) uint64
func Transfer(to std.Address, amount uint64)
func Approve(spender std.Address, amount uint64)
func TransferFrom(from, to std.Address, amount uint64)
func Allowance(owner, spender std.Address) uint64
11 changes: 11 additions & 0 deletions docs/assets/explanation/packages/pkg-2.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// functions that work similarly to those of grc20
func BalanceOf(owner std.Address) (uint64, error)
func Approve(approved std.Address, tid TokenID) error
func TransferFrom(from, to std.Address, tid TokenID) error

// functions unique to grc721
func OwnerOf(tid TokenID) (std.Address, error)
func SafeTransferFrom(from, to std.Address, tid TokenID) error
func SetApprovalForAll(operator std.Address, approved bool) error
func GetApproved(tid TokenID) (std.Address, error)
func IsApprovedForAll(owner, operator std.Address) bool
12 changes: 12 additions & 0 deletions docs/assets/explanation/packages/pkg-3.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
func TestAddress(name string) std.Address {
if len(name) > std.RawAddressSize {
panic("address name cannot be greater than std.AddressSize bytes")
}
addr := std.RawAddress{}
// TODO: use strings.RepeatString or similar.
// NOTE: I miss python's "".Join().
blanks := "____________________"
copy(addr[:], []byte(blanks))
copy(addr[:], []byte(name))
return std.Address(std.EncodeBech32("g", addr))
}
8 changes: 8 additions & 0 deletions docs/assets/explanation/packages/pkg-4.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
admin := users.AddressOrName("g1tntwtvzrkt2gex69f0pttan0fp05zmeg5yykv8")
test2 := users.AddressOrName(testutils.TestAddress("test2"))
recv := users.AddressOrName(testutils.TestAddress("recv"))
normal := users.AddressOrName(testutils.TestAddress("normal"))
owner := users.AddressOrName(testutils.TestAddress("owner"))
spender := users.AddressOrName(testutils.TestAddress("spender"))
recv2 := users.AddressOrName(testutils.TestAddress("recv2"))
mibu := users.AddressOrName(testutils.TestAddress("mint_burn"))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions docs/assets/how-to-guides/creating-grc20/mytoken-1.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package mytoken

import (
"std"

"gno.land/p/demo/grc/grc20"
)

var (
mytoken *grc20.AdminToken
admin std.Address = "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj" // set admin account
)

// init is a constructor function that runs only once (at time of deployment)
func init() {
// provision the token's name, symbol and number of decimals
mytoken = grc20.NewAdminToken("Mytoken", "MTKN", 4)

// set the total supply
mytoken.Mint(admin, 1000000*10000) // @administrator (supply = 1 million)
}
83 changes: 83 additions & 0 deletions docs/assets/how-to-guides/creating-grc20/mytoken-2.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
func TotalSupply() uint64 {
return mytoken.TotalSupply()
}

func BalanceOf(owner users.AddressOrName) uint64 {
balance, err := mytoken.BalanceOf(owner.Resolve())
if err != nil {
panic(err)
}
return balance
}

func Allowance(owner, spender users.AddressOrName) uint64 {
allowance, err := mytoken.Allowance(owner.Resolve(), spender.Resolve())
if err != nil {
panic(err)
}
return allowance
}

func Transfer(to users.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
err := mytoken.Transfer(caller, to.Resolve(), amount)
if err != nil {
panic(err)
}
}

func Approve(spender users.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
err := mytoken.Approve(caller, spender.Resolve(), amount)
if err != nil {
panic(err)
}
}

func TransferFrom(from, to users.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
err := mytoken.TransferFrom(caller, from.Resolve(), to.Resolve(), amount)
if err != nil {
panic(err)
}
}

func Mint(address users.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
assertIsAdmin(caller)
err := mytoken.Mint(address.Resolve(), amount)
if err != nil {
panic(err)
}
}

func Burn(address users.AddressOrName, amount uint64) {
caller := std.PrevRealm().Addr()
assertIsAdmin(caller)
err := mytoken.Burn(address.Resolve(), amount)
if err != nil {
panic(err)
}
}

func Render(path string) string {
parts := strings.Split(path, "/")
c := len(parts)

switch {
case path == "":
return mytoken.RenderHome()
case c == 2 && parts[0] == "balance":
owner := users.AddressOrName(parts[1])
balance, _ := mytoken.BalanceOf(owner.Resolve())
return ufmt.Sprintf("%d\n", balance)
default:
return "404\n"
}
}

func assertIsAdmin(address std.Address) {
if address != admin {
panic("restricted access")
}
}
17 changes: 17 additions & 0 deletions docs/assets/how-to-guides/creating-grc721/mynonfungibletoken-1.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package mynonfungibletoken

import (
"std"

"gno.land/p/demo/grc/grc721"
)

var (
admin std.Address = "g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj" // set admin account
// provision the token's name and symbol
mynonfungibletoken = grc721.NewBasicNFT("mynonfungibletoken", "MNFT")
)

func init() {
mintNNFT(admin, 10) // @administrator (supply = 10)
}
102 changes: 102 additions & 0 deletions docs/assets/how-to-guides/creating-grc721/mynonfungibletoken-2.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
func mintNNFT(owner std.Address, n uint64) {
count := my.TokenCount()
for i := count; i < count+n; i++ {
tid := grc721.TokenID(ufmt.Sprintf("%d", i))
mynonfungibletoken.Mint(owner, tid)
}
}

// Getters

func BalanceOf(user users.AddressOrName) uint64 {
balance, err := mynonfungibletoken.BalanceOf(user.Resolve())
if err != nil {
panic(err)
}

return balance
}

func OwnerOf(tid grc721.TokenID) std.Address {
owner, err := mynonfungibletoken.OwnerOf(tid)
if err != nil {
panic(err)
}

return owner
}

func IsApprovedForAll(owner, user users.AddressOrName) bool {
return mynonfungibletoken.IsApprovedForAll(owner.Resolve(), user.Resolve())
}

func GetApproved(tid grc721.TokenID) std.Address {
addr, err := mynonfungibletoken.GetApproved(tid)
if err != nil {
panic(err)
}

return addr
}

// Setters

func Approve(user users.AddressOrName, tid grc721.TokenID) {
err := mynonfungibletoken.Approve(user.Resolve(), tid)
if err != nil {
panic(err)
}
}

func SetApprovalForAll(user users.AddressOrName, approved bool) {
err := mynonfungibletoken.SetApprovalForAll(user.Resolve(), approved)
if err != nil {
panic(err)
}
}

func TransferFrom(from, to users.AddressOrName, tid grc721.TokenID) {
err := mynonfungibletoken.TransferFrom(from.Resolve(), to.Resolve(), tid)
if err != nil {
panic(err)
}
}

// Admin

func Mint(to users.AddressOrName, tid grc721.TokenID) {
caller := std.PrevRealm().Addr()
assertIsAdmin(caller)
err := mynonfungibletoken.Mint(to.Resolve(), tid)
if err != nil {
panic(err)
}
}

func Burn(tid grc721.TokenID) {
caller := std.PrevRealm().Addr()
assertIsAdmin(caller)
err := mynonfungibletoken.Burn(tid)
if err != nil {
panic(err)
}
}

// Render

func Render(path string) string {
switch {
case path == "":
return mynonfungibletoken.RenderHome()
default:
return "404\n"
}
}

// Util

func assertIsAdmin(address std.Address) {
if address != admin {
panic("restricted access")
}
}
39 changes: 39 additions & 0 deletions docs/assets/how-to-guides/porting-solidity-to-gno/porting-1.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
func shouldEqual(t *testing.T, got interface{}, expected interface{}) {
t.Helper()

if got != expected {
t.Errorf("expected %v(%T), got %v(%T)", expected, expected, got, got)
}
}

func shouldErr(t *testing.T, err error) {
t.Helper()
if err == nil {
t.Errorf("expected an error, but got nil.")
}
}

func shouldNoErr(t *testing.T, err error) {
t.Helper()
if err != nil {
t.Errorf("expected no error, but got err: %s.", err.Error())
}
}

func shouldPanic(t *testing.T, f func()) {
defer func() {
if r := recover(); r == nil {
t.Errorf("should have panic")
}
}()
f()
}

func shouldNoPanic(t *testing.T, f func()) {
defer func() {
if r := recover(); r != nil {
t.Errorf("should not have panic")
}
}()
f()
}
29 changes: 29 additions & 0 deletions docs/assets/how-to-guides/porting-solidity-to-gno/porting-10.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/// End the auction and send the highest bid
/// to the beneficiary.
function auctionEnd() external {
// It is a good guideline to structure functions that interact
// with other contracts (i.e. they call functions or send Ether)
// into three phases:
// 1. checking conditions
// 2. performing actions (potentially changing conditions)
// 3. interacting with other contracts
// If these phases are mixed up, the other contract could call
// back into the current contract and modify the state or cause
// effects (ether payout) to be performed multiple times.
// If functions called internally include interaction with external
// contracts, they also have to be considered interaction with
// external contracts.

// 1. Conditions
if (block.timestamp < auctionEndTime)
revert AuctionNotYetEnded();
if (ended)
revert AuctionEndAlreadyCalled();

// 2. Effects
ended = true;
emit AuctionEnded(highestBidder, highestBid);

// 3. Interaction
beneficiary.transfer(highestBid);
}
17 changes: 17 additions & 0 deletions docs/assets/how-to-guides/porting-solidity-to-gno/porting-11.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
func AuctionEnd() {
if std.GetHeight() < auctionEndBlock {
panic("Auction hasn't ended")
}

if ended {
panic("Auction has ended")

}
ended = true

// Send the highest bid to the recipient
banker := std.GetBanker(std.BankerTypeRealmSend)
pkgAddr := std.GetOrigPkgAddr()

banker.SendCoins(pkgAddr, receiver, std.Coins{{"ugnot", int64(highestBid)}})
}
18 changes: 18 additions & 0 deletions docs/assets/how-to-guides/porting-solidity-to-gno/porting-12.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// AuctionEnd() Function Test
func TestAuctionEnd(t *testing.T) {
// Auction is ongoing
shouldPanic(t, AuctionEnd)

// Auction ends
highestBid = 3
std.TestSkipHeights(500)
shouldNoPanic(t, AuctionEnd)
shouldEqual(t, ended, true)

banker := std.GetBanker(std.BankerTypeRealmSend)
shouldEqual(t, banker.GetCoins(receiver).String(), "3ugnot")

// Auction has already ended
shouldPanic(t, AuctionEnd)
shouldEqual(t, ended, true)
}
Loading
Loading