Skip to content

Commit

Permalink
fix: user sui name.
Browse files Browse the repository at this point in the history
Zhangguiguang committed Dec 15, 2023

Verified

This commit was signed with the committer’s verified signature.
Zhangguiguang 张贵广
1 parent d5d2273 commit 82037ee
Showing 4 changed files with 11 additions and 23 deletions.
20 changes: 4 additions & 16 deletions dmens/fetch_nft.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ package dmens
import (
"context"
"fmt"
"strings"

"github.com/coming-chat/go-sui/v2/sui_types"
"github.com/coming-chat/go-sui/v2/types"
@@ -145,23 +144,12 @@ func (p *Poster) QuerySuiNameByAddress(address string) (name *base.OptionalStrin
if err != nil {
return
}
options := types.SuiObjectDataOptions{
ShowType: true,
ShowDisplay: true}
objs, err := client.BatchGetFilteredObjectsOwnedByAddress(context.Background(), *addr, options, func(oi *types.SuiObjectData) bool {
if strings.HasSuffix(*oi.Type, "::registrar::RegistrationNFT") {
return true
}
return false
})
namePage, err := client.ResolveNameServiceNames(context.Background(), *addr, nil, nil)
if err != nil {
return
}
for _, obj := range objs {
nft := mapToNFTAvatar(obj)
if nft != nil {
return &base.OptionalString{Value: nft.Name}, nil
}
if len(namePage.Data) > 0 {
return base.NewOptionalString(namePage.Data[0]), nil
}
return nil, fmt.Errorf("sui name by address `%v` not found", address)
return nil, fmt.Errorf("user does not own sui name")
}
2 changes: 1 addition & 1 deletion dmens/fetch_nft_test.go
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ func TestQuerySuiNameByAddress(t *testing.T) {
name, err := poster.QuerySuiNameByAddress(owner)
require.Error(t, err)

owner = "0x7e875ea78ee09f08d72e2676cf84e0f1c8ac61d94fa339cc8e37cace85bebc6e"
owner = "0x57188743983628b3474648d8aa4a9ee8abebe8f6816243773d7e8ed4fd833a28"
name, err = poster.QuerySuiNameByAddress(owner)
require.NoError(t, err)
t.Log(name.Value)
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@ module github.com/coming-chat/go-dmens-sdk
go 1.19

require (
github.com/coming-chat/go-sui/v2 v2.0.1-0.20230518103936-ac853f583e8f
github.com/coming-chat/wallet-SDK v0.2.7-0.20231206082848-5a4be8706de3
github.com/coming-chat/go-sui/v2 v2.0.1
github.com/coming-chat/wallet-SDK v0.2.7-0.20231215091548-05619f7757eb
github.com/stretchr/testify v1.8.2
)

8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -51,10 +51,10 @@ github.com/cloudflare/cloudflare-go v0.10.2-0.20190916151808-a80f83b9add9/go.mod
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/coming-chat/go-aptos v0.0.0-20230626110140-8331b0e6cdd4 h1:q7Nw6EKABaQ1F9GpybXL58fmpD9ZupRlitP/XZjrOhc=
github.com/coming-chat/go-aptos v0.0.0-20230626110140-8331b0e6cdd4/go.mod h1:byZxzNOokbO5/mGYTztPhKMUwBnFjn0Tj0bpieocv6I=
github.com/coming-chat/go-sui/v2 v2.0.1-0.20230518103936-ac853f583e8f h1:KPOGMdQH9cOt+ZMC/BJy8P3SzjOA0TL0zXgs4Pd4fnA=
github.com/coming-chat/go-sui/v2 v2.0.1-0.20230518103936-ac853f583e8f/go.mod h1:0/cgsi6HcHEfPFC05mY/ovzWuxxpmKxiY0NIEFgMP4g=
github.com/coming-chat/wallet-SDK v0.2.7-0.20231206082848-5a4be8706de3 h1:B/pqM+Ba0hTEPp5gK00cQBzJiLEonuDvTnMIv7u7H/I=
github.com/coming-chat/wallet-SDK v0.2.7-0.20231206082848-5a4be8706de3/go.mod h1:5CO6WOFxlKiavmIoSq2wPqsL48htcS1/4CcqPg5VQDY=
github.com/coming-chat/go-sui/v2 v2.0.1 h1:Mi7IGUvKd8OLP5zA3YhfDN/L5AJTXHsSsJnLb9WX9+4=
github.com/coming-chat/go-sui/v2 v2.0.1/go.mod h1:0/cgsi6HcHEfPFC05mY/ovzWuxxpmKxiY0NIEFgMP4g=
github.com/coming-chat/wallet-SDK v0.2.7-0.20231215091548-05619f7757eb h1:l7wx8VRkG7qh4Q4gTI2U5Xbb30RTuV9Y3soaU7wzPII=
github.com/coming-chat/wallet-SDK v0.2.7-0.20231215091548-05619f7757eb/go.mod h1:HzJmU6XoraQf7f8deMWExGvEwqsXwDE0OBKuK3NYIwI=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=

0 comments on commit 82037ee

Please sign in to comment.