forked from gnolang/gno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/TERITORI/gno
- Loading branch information
Showing
16 changed files
with
399 additions
and
25 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 |
---|---|---|
|
@@ -31,7 +31,7 @@ jobs: | |
uses: coursier/[email protected] | ||
|
||
- name: Set up JDK 17 | ||
uses: coursier/[email protected].5 | ||
uses: coursier/[email protected].6 | ||
with: | ||
jvm: temurin:1.17 | ||
|
||
|
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,25 @@ | ||
# Start a local faucet | ||
|
||
## Step1: | ||
|
||
Make sure you have started gnoland | ||
|
||
../../gno.land/build/gnoland start -lazy | ||
|
||
## Step2: | ||
|
||
Start the faucet. | ||
|
||
./build/gnofaucet serve -chain-id dev -mnemonic "source bonus chronic canvas draft south burst lottery vacant surface solve popular case indicate oppose farm nothing bullet exhibit title speed wink action roast" | ||
|
||
By default, the faucet sends out 10,000,000ugnot (10gnot) per request. | ||
|
||
## Step3: | ||
|
||
Make sure you have started website | ||
|
||
../../gno.land/build/gnoweb | ||
|
||
Request testing tokens from following URL, Have fun! | ||
|
||
http://localhost:8888/faucet |
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,72 @@ | ||
// Package fqname provides utilities for handling fully qualified identifiers in | ||
// Gno. A fully qualified identifier typically includes a package path followed | ||
// by a dot (.) and then the name of a variable, function, type, or other | ||
// package-level declaration. | ||
package fqname | ||
|
||
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. | ||
// | ||
// pkgpath, name := fqname.Parse("gno.land/p/demo/avl.Tree") | ||
// ufmt.Sprintf("Package: %s, Name: %s\n", id.Package, id.Name) | ||
// // Output: Package: gno.land/p/demo/avl, Name: Tree | ||
func Parse(fqname string) (pkgpath, name string) { | ||
// Find the index of the last slash. | ||
lastSlashIndex := strings.LastIndex(fqname, "/") | ||
if lastSlashIndex == -1 { | ||
// No slash found, handle it as a simple package name with dot notation. | ||
dotIndex := strings.LastIndex(fqname, ".") | ||
if dotIndex == -1 { | ||
return fqname, "" | ||
} | ||
return fqname[:dotIndex], fqname[dotIndex+1:] | ||
} | ||
|
||
// Get the part after the last slash. | ||
afterSlash := fqname[lastSlashIndex+1:] | ||
|
||
// Check for a dot in the substring after the last slash. | ||
dotIndex := strings.Index(afterSlash, ".") | ||
if dotIndex == -1 { | ||
// No dot found after the last slash | ||
return fqname, "" | ||
} | ||
|
||
// Split at the dot to separate the base and the suffix. | ||
base := fqname[:lastSlashIndex+1+dotIndex] | ||
suffix := afterSlash[dotIndex+1:] | ||
|
||
return base, suffix | ||
} | ||
|
||
// Construct a qualified identifier. | ||
// | ||
// fqName := fqname.Construct("gno.land/r/demo/foo20", "GRC20") | ||
// fmt.Println("Fully Qualified Name:", fqName) | ||
// // Output: gno.land/r/demo/foo20.GRC20 | ||
func Construct(pkgpath, name string) string { | ||
// TODO: ensure pkgpath is valid - and as such last part does not contain a dot. | ||
if name == "" { | ||
return pkgpath | ||
} | ||
return pkgpath + "." + name | ||
} | ||
|
||
// RenderLink creates a formatted link for a fully qualified identifier. | ||
// If the package path starts with "gno.land", it converts it to a markdown link. | ||
// If the domain is different or missing, it returns the input as is. | ||
func RenderLink(pkgPath, slug string) string { | ||
if strings.HasPrefix(pkgPath, "gno.land") { | ||
pkgLink := strings.TrimPrefix(pkgPath, "gno.land") | ||
if slug != "" { | ||
return "[" + pkgPath + "](" + pkgLink + ")." + slug | ||
} | ||
return "[" + pkgPath + "](" + pkgLink + ")" | ||
} | ||
if slug != "" { | ||
return pkgPath + "." + slug | ||
} | ||
return pkgPath | ||
} |
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,74 @@ | ||
package fqname | ||
|
||
import ( | ||
"testing" | ||
|
||
"gno.land/p/demo/uassert" | ||
) | ||
|
||
func TestParse(t *testing.T) { | ||
tests := []struct { | ||
input string | ||
expectedPkgPath string | ||
expectedName string | ||
}{ | ||
{"gno.land/p/demo/avl.Tree", "gno.land/p/demo/avl", "Tree"}, | ||
{"gno.land/p/demo/avl", "gno.land/p/demo/avl", ""}, | ||
{"gno.land/p/demo/avl.Tree.Node", "gno.land/p/demo/avl", "Tree.Node"}, | ||
{"gno.land/p/demo/avl/nested.Package.Func", "gno.land/p/demo/avl/nested", "Package.Func"}, | ||
{"path/filepath.Split", "path/filepath", "Split"}, | ||
{"path.Split", "path", "Split"}, | ||
{"path/filepath", "path/filepath", ""}, | ||
{"path", "path", ""}, | ||
{"", "", ""}, | ||
} | ||
|
||
for _, tt := range tests { | ||
pkgpath, name := Parse(tt.input) | ||
uassert.Equal(t, tt.expectedPkgPath, pkgpath, "Package path did not match") | ||
uassert.Equal(t, tt.expectedName, name, "Name did not match") | ||
} | ||
} | ||
|
||
func TestConstruct(t *testing.T) { | ||
tests := []struct { | ||
pkgpath string | ||
name string | ||
expected string | ||
}{ | ||
{"gno.land/r/demo/foo20", "GRC20", "gno.land/r/demo/foo20.GRC20"}, | ||
{"gno.land/r/demo/foo20", "", "gno.land/r/demo/foo20"}, | ||
{"path", "", "path"}, | ||
{"path", "Split", "path.Split"}, | ||
{"path/filepath", "", "path/filepath"}, | ||
{"path/filepath", "Split", "path/filepath.Split"}, | ||
{"", "JustName", ".JustName"}, | ||
{"", "", ""}, | ||
} | ||
|
||
for _, tt := range tests { | ||
result := Construct(tt.pkgpath, tt.name) | ||
uassert.Equal(t, tt.expected, result, "Constructed FQName did not match expected") | ||
} | ||
} | ||
|
||
func TestRenderLink(t *testing.T) { | ||
tests := []struct { | ||
pkgPath string | ||
slug string | ||
expected string | ||
}{ | ||
{"gno.land/p/demo/avl", "Tree", "[gno.land/p/demo/avl](/p/demo/avl).Tree"}, | ||
{"gno.land/p/demo/avl", "", "[gno.land/p/demo/avl](/p/demo/avl)"}, | ||
{"github.com/a/b", "C", "github.com/a/b.C"}, | ||
{"example.com/pkg", "Func", "example.com/pkg.Func"}, | ||
{"gno.land/r/demo/foo20", "GRC20", "[gno.land/r/demo/foo20](/r/demo/foo20).GRC20"}, | ||
{"gno.land/r/demo/foo20", "", "[gno.land/r/demo/foo20](/r/demo/foo20)"}, | ||
{"", "", ""}, | ||
} | ||
|
||
for _, tt := range tests { | ||
result := RenderLink(tt.pkgPath, tt.slug) | ||
uassert.Equal(t, tt.expected, result, "Rendered link did not match expected") | ||
} | ||
} |
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,3 @@ | ||
module gno.land/p/demo/fqname | ||
|
||
require gno.land/p/demo/uassert v0.0.0-latest |
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,81 @@ | ||
package printfdebugging | ||
|
||
// consts copied from https://github.com/fatih/color/blob/main/color.go | ||
|
||
// Attribute defines a single SGR Code | ||
type Attribute int | ||
|
||
const Escape = "\x1b" | ||
|
||
// Base attributes | ||
const ( | ||
Reset Attribute = iota | ||
Bold | ||
Faint | ||
Italic | ||
Underline | ||
BlinkSlow | ||
BlinkRapid | ||
ReverseVideo | ||
Concealed | ||
CrossedOut | ||
) | ||
|
||
const ( | ||
ResetBold Attribute = iota + 22 | ||
ResetItalic | ||
ResetUnderline | ||
ResetBlinking | ||
_ | ||
ResetReversed | ||
ResetConcealed | ||
ResetCrossedOut | ||
) | ||
|
||
// Foreground text colors | ||
const ( | ||
FgBlack Attribute = iota + 30 | ||
FgRed | ||
FgGreen | ||
FgYellow | ||
FgBlue | ||
FgMagenta | ||
FgCyan | ||
FgWhite | ||
) | ||
|
||
// Foreground Hi-Intensity text colors | ||
const ( | ||
FgHiBlack Attribute = iota + 90 | ||
FgHiRed | ||
FgHiGreen | ||
FgHiYellow | ||
FgHiBlue | ||
FgHiMagenta | ||
FgHiCyan | ||
FgHiWhite | ||
) | ||
|
||
// Background text colors | ||
const ( | ||
BgBlack Attribute = iota + 40 | ||
BgRed | ||
BgGreen | ||
BgYellow | ||
BgBlue | ||
BgMagenta | ||
BgCyan | ||
BgWhite | ||
) | ||
|
||
// Background Hi-Intensity text colors | ||
const ( | ||
BgHiBlack Attribute = iota + 100 | ||
BgHiRed | ||
BgHiGreen | ||
BgHiYellow | ||
BgHiBlue | ||
BgHiMagenta | ||
BgHiCyan | ||
BgHiWhite | ||
) |
Oops, something went wrong.