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(examples): Ivan's registry, home realm #3354

Merged
merged 31 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
241eb1d
Created registry, home real in progress
Dec 17, 2024
452ced8
I have now added my home realm files, still need to add functionaliti…
Dec 18, 2024
0e75031
Merge branch 'master' of github.com:Ursulovic/gno into home-page
Dec 18, 2024
f81e4eb
Merge branch 'master' into home-page
Ursulovic Dec 19, 2024
65d4777
Finished all home realm functionalities, added tests aswell
Dec 19, 2024
5308289
Merge branch 'gnolang:master' into home-page
Ursulovic Dec 19, 2024
7e8de8c
Merge branch 'gnolang:master' into home-page
Ursulovic Dec 20, 2024
2f45a55
Minor updates to renderAboutMe function
Dec 20, 2024
7533f05
Merge branch 'gnolang:master' into home-page
Ursulovic Dec 20, 2024
b3ceda8
Fixed tests
Dec 20, 2024
92cfaea
Updated bio and fixed tests
Dec 20, 2024
1cf5070
Merge branch 'gnolang:master' into home-page
Ursulovic Dec 20, 2024
c907258
Merge branch 'gnolang:master' into home-page
Ursulovic Dec 23, 2024
2213227
Merge branch 'gnolang:master' into home-page
Ursulovic Jan 10, 2025
4e114b5
Created new home page, almost done
Jan 12, 2025
a122b2e
Finished home realm and tests
Jan 13, 2025
8805496
Merge branch 'gnolang:master' into home-page
Ursulovic Jan 13, 2025
4163ec7
Merge branch 'gnolang:master' into home-page
Ursulovic Jan 13, 2025
87c0f85
Almost implemented all suggestions
Jan 13, 2025
4f98afd
Home realm refactoring done
Jan 13, 2025
ec85925
Update home.gno
Ursulovic Jan 13, 2025
773ae0e
Merge branch 'gnolang:master' into home-page
Ursulovic Jan 14, 2025
706784e
Ran make fmt command in order to format all files
Jan 14, 2025
2808eaa
Merge branch 'master' into home-page
thehowl Jan 14, 2025
b610cd3
Merge branch 'gnolang:master' into home-page
Ursulovic Jan 14, 2025
1065ad2
I have removed initIsValidURL function and instead created new defaul…
Jan 14, 2025
5b182e8
I realised I have forgotten to make an url to connect studio dynamic,…
Jan 14, 2025
0bfa81e
I have now renamed owner variable to Ownable. Now it expored and Owna…
Jan 14, 2025
bb7676a
Renamed variable studioConnectUrl to connectUrl and function for upda…
Jan 14, 2025
f31ec47
Removed variable for url and update function for it and have set url …
Jan 14, 2025
c3b7f67
Ran fmt
Jan 14, 2025
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
1 change: 1 addition & 0 deletions examples/gno.land/r/ursulovic/home/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/ursulovic/home
90 changes: 90 additions & 0 deletions examples/gno.land/r/ursulovic/home/home.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package home

import (
"std"
"strings"

"gno.land/p/moul/md"
"gno.land/r/leon/hof"
"gno.land/p/demo/ownable"

"gno.land/r/ursulovic/registry"
)

var (
phrases [10]string
aboutMe string
pfp string
pfpCaption string
owner *ownable.Ownable
)

func init() {
owner = ownable.NewWithAddress(registry.MainAddress())

phrases[0] = "Why did the blockchain go to therapy? It had a lot of unprocessed transactions."
phrases[1] = "Why don’t blockchains ever tell secrets? They use smart contracts – always open and never closed!"
phrases[2] = "In Gnoland, we don’t worry about bugs – they’re just features waiting to be integrated!"
phrases[3] = "Why did the smart contract break up with traditional finance? It was a long-term contract – no longer sustainable."
phrases[4] = "Why do blockchains make great comedians? They always deliver the punchline at just the right time!"
phrases[5] = "Why did the blockchain apply for a job? It wanted to become the most reliable ledger around!"
phrases[6] = "Why did the blockchain file a police report? It had a case of identity theft – someone stole its private keys!"
phrases[7] = "In Gnoland, our smart contracts aren’t just written in code – they’re also written in poetry!"
phrases[8] = "Why did the blockchain join a gym? To get a better hash rate!"
phrases[9] = "Why did the blockchain break up with traditional finance? It was looking for a more transparent relationship."

aboutMe = "Hi, I’m Ivan Ursulovic, a computer engineering graduate, blockchain enthusiast, and backend developer specializing in ASP.NET. I love learning new things and taking on challenges."
pfp = "https://i.ibb.co/W28NPkw/beograd.webp"
pfpCaption = "Belgrade, the city I come from"
hof.Register()
}

//Update
leohhhn marked this conversation as resolved.
Show resolved Hide resolved
func UpdatePfp(url string, caption string) {
owner.AssertCallerIsOwner()
pfp = url
pfpCaption = caption
}

func UpdateAboutMe(abtMe string) {
owner.AssertCallerIsOwner()
aboutMe = abtMe
}

func UpdatePhrase(index int, newPhrase string) {
owner.AssertCallerIsOwner()
if index < 0 || index >= len(phrases) {
panic("index out of boundaries")
}
phrases[index] = newPhrase
}


//Rendering
func Render(path string) string {
var out strings.Builder
out.WriteString(renderAboutMe())
out.WriteString(renderPhrase())
out.WriteString(md.Image(pfpCaption, pfp))
out.WriteString(md.Italic("Belgrade, the city I come from"))
return out.String()
}

func renderAboutMe() string {
var out strings.Builder
out.WriteString(md.H3("About me"))

out.WriteString(md.Paragraph(aboutMe))

return out.String()
}


func renderPhrase() string {
var out strings.Builder
phrase := phrases[int(std.GetHeight())%len(phrases)]

out.WriteString(md.H3(`Randomly selected blockchain wisdom:`) + md.Bold(phrase))

return out.String()
}
49 changes: 49 additions & 0 deletions examples/gno.land/r/ursulovic/home/home_test.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package home

import (
"std"
"strings"
"testing"
)

func TestUpdatePfp(t *testing.T) {
owner := std.Address("g1d24j8fwnc0w5q427fauyey4gdd30qgu69k6n0x")
std.TestSetOrigCaller(owner)

pfp = "abc"

UpdatePfp("https://i.ibb.co/W28NPkw/beograd.webp", "Test caption")

if pfp != "https://i.ibb.co/W28NPkw/beograd.webp" {
t.Fatalf("Expected result: https://i.ibb.co/W28NPkw/beograd.webp, got %s", pfp)
}
}

func TestUpdateAboutMe(t *testing.T) {
owner := std.Address("g1d24j8fwnc0w5q427fauyey4gdd30qgu69k6n0x")
std.TestSetOrigCaller(owner)

aboutMe = ""

excpected := "Testing about me..."

UpdateAboutMe(excpected)

if aboutMe != excpected {
t.Fatalf("Excpected about me to be %s, got %s", excpected, aboutMe)
}
}

func TestUpdatePhrase(t *testing.T) {
owner := std.Address("g1d24j8fwnc0w5q427fauyey4gdd30qgu69k6n0x")
std.TestSetOrigCaller(owner)

index := 0
newPhrase := "New test phrase"

UpdatePhrase(index, newPhrase)

if phrases[index] != newPhrase {
t.Fatalf("Expected phrase at index %d to be %s, got %s", index, newPhrase, phrases[index])
}
}
1 change: 1 addition & 0 deletions examples/gno.land/r/ursulovic/registry/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/ursulovic/registry
59 changes: 59 additions & 0 deletions examples/gno.land/r/ursulovic/registry/registry.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package registry

import (
"errors"
"std"
)

var (
mainAddress std.Address
backupAddress std.Address

ErrInvalidAddr = errors.New("Ivan's registry: Invalid address")
ErrUnauthorized = errors.New("Ivan's registry: Unauthorized")
)

func init() {
mainAddress = "g1d24j8fwnc0w5q427fauyey4gdd30qgu69k6n0x"
backupAddress = "g1mw2xft3eava9kfhqw3fjj3kkf3pkammty0mtv7"
}


func MainAddress() std.Address {
return mainAddress
}

func BackupAddress() std.Address {
return backupAddress
}

func SetMainAddress(addr std.Address) error {
assertAuthorized()

if !addr.IsValid() {
return ErrInvalidAddr
}

mainAddress = addr
return nil
}

func SetBackupAddress(addr std.Address) error {
assertAuthorized()

if !addr.IsValid() {
return ErrInvalidAddr
}

backupAddress = addr
return nil
}
// It will stay here for now, might be useful later
func assertAuthorized() {
Ursulovic marked this conversation as resolved.
Show resolved Hide resolved
caller := std.PrevRealm().Addr()
isAuthorized := caller == mainAddress || caller == backupAddress

if !isAuthorized {
panic(ErrUnauthorized)
}
}
Loading