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: token hub #3479

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
6b9ceb7
initial commit
matijamarjanovic Jan 10, 2025
7ec4dc7
-add getter to basic nft and igrc721 interface
matijamarjanovic Jan 10, 2025
7970e42
fix fmt
matijamarjanovic Jan 10, 2025
9c397a5
- add iterate function to grc20reg to be able to get all registered t…
matijamarjanovic Jan 11, 2025
a02b955
remove unused var
matijamarjanovic Jan 11, 2025
0931341
add getter to grc1155
matijamarjanovic Jan 11, 2025
04ee40e
-add support for grc1155 (not perfect)
matijamarjanovic Jan 11, 2025
af1631f
display different token types on different pages
matijamarjanovic Jan 12, 2025
42152f4
add pagination for grc20 (this includes adding 1 more iteration funct…
matijamarjanovic Jan 12, 2025
c07116f
add pagination to grc721 page as well
matijamarjanovic Jan 12, 2025
c6ea858
add pagination for grc1155
matijamarjanovic Jan 12, 2025
b5967e4
add a getter function for tokens with non zero balances
matijamarjanovic Jan 12, 2025
8727cc6
-update saving grc1155 so it makes most sense
matijamarjanovic Jan 12, 2025
0186c2d
add get and must get for all token types
matijamarjanovic Jan 12, 2025
3181a38
fix fmt
matijamarjanovic Jan 12, 2025
1d7a4bf
Merge branch 'master' into feat/token-hub
matijamarjanovic Jan 13, 2025
3978697
add namespace support
matijamarjanovic Jan 13, 2025
fadc509
fix fmt
matijamarjanovic Jan 13, 2025
d3af61c
add testing
matijamarjanovic Jan 14, 2025
ad2b368
fix up test
matijamarjanovic Jan 14, 2025
2770485
fix fmt
matijamarjanovic Jan 14, 2025
99a5ca7
add getAll tokens + get tokens by type
matijamarjanovic Jan 14, 2025
2ab9221
add tests and remove (fake) test file
matijamarjanovic Jan 14, 2025
f084ceb
remove test realm
matijamarjanovic Jan 14, 2025
c484774
fix fmt
matijamarjanovic Jan 14, 2025
48c6cd1
more fix fmt
matijamarjanovic Jan 14, 2025
c0ca4a5
Merge branch 'master' into feat/token-hub
matijamarjanovic Jan 17, 2025
87aac01
update so nft doesn't allow optional slug, but has to include tokenid
matijamarjanovic Jan 17, 2025
8ab9a26
fix nft registration, now each minted can be registered
matijamarjanovic Jan 17, 2025
b107e7d
fix: show only nfts and grc1155 owner has, because there could be who…
matijamarjanovic Jan 17, 2025
936f181
write only key for nfts, no need for balance
matijamarjanovic Jan 17, 2025
dabf342
- add get all tokens without nfts
matijamarjanovic Jan 17, 2025
c333c42
add different funcs for prevrealm and orig caller
matijamarjanovic Jan 18, 2025
038cb50
- add seing anyones balances
matijamarjanovic Jan 20, 2025
d538723
Merge branch 'master' into feat/token-hub
matijamarjanovic Jan 20, 2025
5ed07c2
Merge branch 'master' into feat/token-hub
matijamarjanovic Jan 20, 2025
be510bc
Merge branch 'master' into feat/token-hub
matijamarjanovic Jan 21, 2025
8c09725
fix page size, remove test
matijamarjanovic Jan 21, 2025
88b0a7e
make errors start with lowercase
matijamarjanovic Jan 21, 2025
1c4b72a
remove not needed new lines
matijamarjanovic Jan 21, 2025
005e64b
- change slugs to slug
matijamarjanovic Jan 21, 2025
7ac568f
- remove getorigcaller use function
matijamarjanovic Jan 21, 2025
35fa7e2
remove get my balacnces - does the same as getuserbalances for the ca…
matijamarjanovic Jan 21, 2025
3b94b2e
fix naming
matijamarjanovic Jan 21, 2025
0a63572
return the tokens themselves instead of getters
matijamarjanovic Jan 21, 2025
99b44ac
implement return tokens themselves instead of getters in grc1155 too …
matijamarjanovic Jan 21, 2025
3f8bb51
update naming to be consistent
matijamarjanovic Jan 21, 2025
b5a8206
remove fqname and just use concat
matijamarjanovic Jan 21, 2025
3c5d8dc
divide realm into multiple files for better readability
matijamarjanovic Jan 21, 2025
43b4b52
render refactor; new functions for each case, use string concat inst…
matijamarjanovic Jan 21, 2025
59586e5
- change the pagination implement pager from p/demo/avl
matijamarjanovic Jan 21, 2025
f48d034
-refactor private getter
matijamarjanovic Jan 21, 2025
9b9767f
optimization so each token types should be gettable separately to red…
matijamarjanovic Jan 21, 2025
385fdf9
add get non zero balances
matijamarjanovic Jan 21, 2025
c9edff9
add formatting, fix ufmt print
matijamarjanovic Jan 21, 2025
1c598a3
move errors in separate file for better readability
matijamarjanovic Jan 21, 2025
a946cc4
add documentation
matijamarjanovic Jan 21, 2025
92305e9
Merge branch 'master' into feat/token-hub
matijamarjanovic Jan 21, 2025
93075f3
add working tests
matijamarjanovic Jan 21, 2025
387ebd9
\n placement
matijamarjanovic Jan 21, 2025
7be170b
fix fmt
matijamarjanovic Jan 21, 2025
1e0f60c
fix fmt again
matijamarjanovic Jan 21, 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
6 changes: 6 additions & 0 deletions examples/gno.land/p/demo/grc/grc1155/basic_grc1155_token.gno
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,9 @@ func (s *basicGRC1155Token) RenderHome() (str string) {

return
}

func (mt *basicGRC1155Token) Getter() MultiTokenGetter {
return func() IGRC1155 {
return mt
}
}
2 changes: 2 additions & 0 deletions examples/gno.land/p/demo/grc/grc1155/igrc1155.gno
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ type ApprovalForAllEvent struct {
type UpdateURIEvent struct {
URI string
}

type MultiTokenGetter func() IGRC1155
7 changes: 7 additions & 0 deletions examples/gno.land/p/demo/grc/grc721/basic_nft.gno
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,10 @@ func (s *basicNFT) RenderHome() (str string) {

return
}

// Then add the Getter method to your NFT types
func (n *basicNFT) Getter() NFTGetter {
return func() IGRC721 {
return n
}
}
2 changes: 2 additions & 0 deletions examples/gno.land/p/demo/grc/grc721/igrc721.gno
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ const (
ApprovalEvent = "Approval"
ApprovalForAllEvent = "ApprovalForAll"
)

type NFTGetter func() IGRC721
27 changes: 27 additions & 0 deletions examples/gno.land/r/demo/grc20reg/grc20reg.gno
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,31 @@ func Render(path string) string {
}
}

func Iterate(callback func(key string, token grc20.TokenGetter) bool) {
registry.Iterate("", "", func(key string, tokenI interface{}) bool {
tokenGetter := tokenI.(grc20.TokenGetter)
return callback(key, tokenGetter)
})
}

// iterate through n items starting from the startKey (pagination)
func IterateN(startKey string, n int, callback func(key string, token grc20.TokenGetter) bool) string {
var lastKey string
count := 0

registry.Iterate(startKey, "", func(key string, tokenI interface{}) bool {
if count >= n {
return true
}

tokenGetter := tokenI.(grc20.TokenGetter)
lastKey = key
count++

return callback(key, tokenGetter)
})

return lastKey
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this. Make a readonly tree getter instead (check avl folder), and use the avl/pager library in your smart contract.

Copy link
Contributor Author

@matijamarjanovic matijamarjanovic Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the advice, the code looks much better now and I can imagine the performance is better as well. See changes 59586e5

const registerEvent = "register"
1 change: 1 addition & 0 deletions examples/gno.land/r/matijamarjanovic/tokenhub/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/matijamarjanovic/tokenhub
Loading
Loading