Skip to content

Commit

Permalink
Merge branch 'feat/sync-assignstmt-valuedecl-1958' of https://github.…
Browse files Browse the repository at this point in the history
…com/hthieu1110/gno into feat/sync-assignstmt-valuedecl-1958
  • Loading branch information
hthieu1110 committed Nov 20, 2024
2 parents 8317775 + 6600d7d commit ed58ab1
Show file tree
Hide file tree
Showing 49 changed files with 985 additions and 106 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/BUG-REPORT.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
name: Bug Report Template
about: Create a bug report
labels: "🐞 bug"
# NOTE: keep in sync with gnovm/cmd/gno/bug.go
---

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fossa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: coursier/[email protected]

- name: Set up JDK 17
uses: coursier/[email protected].6
uses: coursier/[email protected].8
with:
jvm: temurin:1.17

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/releaser-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
cache: true

- uses: sigstore/[email protected]
- uses: anchore/sbom-action/[email protected].5
- uses: anchore/sbom-action/[email protected].7

- uses: docker/login-action@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/releaser-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
cache: true

- uses: sigstore/[email protected]
- uses: anchore/sbom-action/[email protected].5
- uses: anchore/sbom-action/[email protected].7

- uses: docker/login-action@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
cache: true

- uses: sigstore/[email protected]
- uses: anchore/sbom-action/[email protected].5
- uses: anchore/sbom-action/[email protected].7

- uses: docker/login-action@v3
with:
Expand Down
32 changes: 32 additions & 0 deletions docs/reference/gno-js-client/gno-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,38 @@ id: gno-js-provider
The `Gno Provider` is an extension on the `tm2-js-client` `Provider`,
outlined [here](../tm2-js-client/Provider/provider.md). Both JSON-RPC and WS providers are included with the package.

## Instantiation

### new GnoWSProvider

Creates a new instance of the Gno WebSocket Provider, based on [`tm2-js-client` `WSProvider`](../tm2-js-client/Provider/ws-provider.md).

#### Parameters

Same as [`tm2-js-client` `WSProvider`](../tm2-js-client/Provider/ws-provider.md).

#### Usage

```ts
new GnoWSProvider('ws://staging.gno.land:26657/ws');
// provider with WS connection is created
```

### new GnoJSONRPCProvider

Creates a new instance of the Gno JSON-RPC Provider, based on [`tm2-js-client` `JSONRPCProvider`](../tm2-js-client/Provider/json-rpc-provider.md).

#### Parameters

Same as [`tm2-js-client` `JSONRPCProvider`](../tm2-js-client/Provider/json-rpc-provider.md).

#### Usage

```ts
new GnoJSONRPCProvider('http://staging.gno.land:36657');
// provider is created
```

## Realm Methods

### getRenderOutput
Expand Down
46 changes: 31 additions & 15 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
# Gnolang examples
# Examples

This folder showcases Gnolang realms and library demos. These examples not only aid in engine testing but also provide a glimpse into the potential of Gnolang's capabilities.
This folder showcases example Gno realms (smart contracts) and pure packages (libraries).
These examples provide a glimpse into the potential of gno.land and the capabilities of Gno,
while also serving as a test suite for the GnoVM.

While sharing contracts here can enhance engine testing, it's not mandatory. If considering a separate repository for contracts, be aware that this might restrict the experience due to the continuous efforts around `gno mod` support. A key point to note is that the main repository cannot reference separate code, which might pose developmental challenges.
Pure packages and realms in this folder are pre-deployed to gno.land testnets,
making them readily available for on-chain use. However, **there is no guarantee
that the code is bug-free, so it should be used with caution and an understanding of potential risks.**

## Personal Realms & Shared Content

**Prioritizing Shared Content:** As we expand our examples and use-cases, it's essential to prioritize shared content that benefits the broader community. These examples serve as a foundation and reference for all users.

**Personal Realms Inclusion:** We're open to personal realms, but they must exemplify best practices and inspire others. To maintain our repository's organization, we may decline some realms. If so, consider uploading onchain and keeping source code separately. For higher acceptance odds, offer useful or original examples.
## Structure

**Recommended Approach:**
- Use `r/demo` and `p/demo` for generic examples and components that can be imported by others. These are meant to be easily referenced and utilized by the community.
- Personal realms are welcomed if they are easily maintainable with the Continuous Integration (CI) system. If a personal realm becomes cumbersome to maintain or doesn't align with the CI's checks, it might be relocated to a less prominent location or even removed.
This folder mimics the gno.land package path system; the "root" of the system is
the `gno.land` folder. Next, it branches out to `p/` and `r/`, which contain
pure packages and realms, respectively.

## Usage

Our recommendation is to use the [gno](../gnovm/cmd/gno) utility to develop contracts locally before publishing them on-chain. This approach offers a faster and streamlined workflow, along with additional debugging features. Simply fork or create new contracts and refer to the Makefile. Once everything looks good locally, you can then publish it on a localnet or testnet.
## Personal Realms & Shared Content

For further guidance and insights, please refer to the [`awesome-gno` tutorials](https://github.com/gnolang/awesome-gno#tutorials).
**Prioritizing Shared Content:** As we expand our examples and use-cases, it's
essential to prioritize shared content that benefits the broader community.
These examples serve as a foundation and reference for all users.

**Personal Realms & Pure Packages:** We welcome personal realms that
exemplify best practices and inspire others. To maintain the organization
of the monorepo, some submissions may be declined. If so, consider uploading
[permissionlessly](../docs/gno-tooling/cli/gnokey/state-changing-calls.md#addpackage)
and storing the source code in a separate repo. For higher
acceptance odds, offer useful and original examples.

**Recommended Approach:**
- Use `r/demo` and `p/demo` for generic examples and components that can be
imported by others. These are meant to be easily referenced and utilized by the
community.
- Packages under personal namespaces, such as in [r/leon](./gno.land/r/leon),
are welcome if they are easily maintainable with the Continuous Integration (CI)
system. If a personal realm becomes cumbersome to maintain or doesn't align with
the CI's checks, it might be relocated to a less prominent location or even removed.
7 changes: 6 additions & 1 deletion examples/gno.land/p/demo/fqname/fqname.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
// package-level declaration.
package fqname

import "strings"
import (
"strings"
)

// Parse splits a fully qualified identifier into its package path and name
// components. It handles cases with and without slashes in the package path.
Expand Down Expand Up @@ -63,10 +65,13 @@ func RenderLink(pkgPath, slug string) string {
if slug != "" {
return "[" + pkgPath + "](" + pkgLink + ")." + slug
}

return "[" + pkgPath + "](" + pkgLink + ")"
}

if slug != "" {
return pkgPath + "." + slug
}

return pkgPath
}
6 changes: 3 additions & 3 deletions examples/gno.land/p/demo/ownable/ownable.gno
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func (o *Ownable) TransferOwnership(newOwner std.Address) error {
o.owner = newOwner
std.Emit(
OwnershipTransferEvent,
"from", string(prevOwner),
"to", string(newOwner),
"from", prevOwner.String(),
"to", newOwner.String(),
)

return nil
Expand All @@ -58,7 +58,7 @@ func (o *Ownable) DropOwnership() error {

std.Emit(
OwnershipTransferEvent,
"from", string(prevOwner),
"from", prevOwner.String(),
"to", "",
)

Expand Down
10 changes: 9 additions & 1 deletion examples/gno.land/p/demo/pausable/pausable.gno
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package pausable

import "gno.land/p/demo/ownable"
import (
"std"

"gno.land/p/demo/ownable"
)

type Pausable struct {
*ownable.Ownable
Expand Down Expand Up @@ -35,6 +39,8 @@ func (p *Pausable) Pause() error {
}

p.paused = true
std.Emit("Paused", "account", p.Owner().String())

return nil
}

Expand All @@ -45,5 +51,7 @@ func (p *Pausable) Unpause() error {
}

p.paused = false
std.Emit("Unpaused", "account", p.Owner().String())

return nil
}
3 changes: 3 additions & 0 deletions examples/gno.land/p/moul/mdtable/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module gno.land/p/moul/mdtable

require gno.land/p/demo/urequire v0.0.0-latest
66 changes: 66 additions & 0 deletions examples/gno.land/p/moul/mdtable/mdtable.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Package mdtable provides a simple way to create Markdown tables.
//
// Example usage:
//
// import "gno.land/p/moul/mdtable"
//
// func Render(path string) string {
// table := mdtable.Table{
// Headers: []string{"ID", "Title", "Status", "Date"},
// }
// table.Append([]string{"#1", "Add a new validator", "succeed", "2024-01-01"})
// table.Append([]string{"#2", "Change parameter", "timed out", "2024-01-02"})
// return table.String()
// }
//
// Output:
//
// | ID | Title | Status | Date |
// | --- | --- | --- | --- |
// | #1 | Add a new validator | succeed | 2024-01-01 |
// | #2 | Change parameter | timed out | 2024-01-02 |
package mdtable

import (
"strings"
)

type Table struct {
Headers []string
Rows [][]string
// XXX: optional headers alignment.
}

func (t *Table) Append(row []string) {
t.Rows = append(t.Rows, row)
}

func (t Table) String() string {
// XXX: switch to using text/tabwriter when porting to Gno to support
// better-formatted raw Markdown output.

if len(t.Headers) == 0 && len(t.Rows) == 0 {
return ""
}

var sb strings.Builder

if len(t.Headers) == 0 {
t.Headers = make([]string, len(t.Rows[0]))
}

// Print header.
sb.WriteString("| " + strings.Join(t.Headers, " | ") + " |\n")
sb.WriteString("|" + strings.Repeat(" --- |", len(t.Headers)) + "\n")

// Print rows.
for _, row := range t.Rows {
escapedRow := make([]string, len(row))
for i, cell := range row {
escapedRow[i] = strings.ReplaceAll(cell, "|", "|") // Escape pipe characters.
}
sb.WriteString("| " + strings.Join(escapedRow, " | ") + " |\n")
}

return sb.String()
}
Loading

0 comments on commit ed58ab1

Please sign in to comment.