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

Simplify resolving NNS hashes via RPC binding #361

Merged
merged 4 commits into from
Sep 26, 2023
Merged

Conversation

roman-khimov
Copy link
Member

No description provided.

// names (like "container" or "netmap") and extracts the hash for the
// respective NNS record in any of the formats (of which historically there's
// been a few).
func (c *ContractReader) ResolveFSContract(name string) (util.Uint160, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be perfect to have some enum for "container", "netmap" and other possible contract names.
If it already exists, the reference in the comment will be useful

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't, at least not in some common space (various utilities like adm do know about them).

Copy link
Member

@carpawell carpawell Sep 22, 2023

Choose a reason for hiding this comment

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

cant we add some constants? as a user i would be more glad not to figure names out myself

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, let's try them this way.

rpc/nns/hashes.go Show resolved Hide resolved
rpc/nns/hashes.go Show resolved Hide resolved
smallhive
smallhive previously approved these changes Sep 22, 2023
rpc/nns/hashes.go Outdated Show resolved Hide resolved
Copy link
Contributor

@cthulhu-rider cthulhu-rider left a comment

Choose a reason for hiding this comment

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

good candidate to provide code example like

// Resolve addresses of the NeoFS smart contracts deployed in the particular
// NeoFS Sidechain by their NNS domain names.
func ExampleContractReader_ResolveFSContract() {
	const sidechainRPCEndpoint = "https://rpc1.morph.fs.neo.org:40341"

	c, err := rpcclient.New(context.Background(), sidechainRPCEndpoint, rpcclient.Options{})
	if err != nil {
		log.Fatal(err)
	}

	err = c.Init()
	if err != nil {
		log.Fatal(err)
	}

	nnsAddress, err := nns.InferHash(c)
	if err != nil {
		log.Fatal(err)
	}

	nnsContract := nns.NewReader(invoker.New(c, nil), nnsAddress)

	for _, name := range []string{
		nns.NameAudit,
		nns.NameBalance,
		nns.NameContainer,
		nns.NameNeoFSID,
		nns.NameNetmap,
		nns.NameProxy,
		nns.NameReputation,
	} {
		addr, err := nnsContract.ResolveFSContract(name)
		if err != nil {
			log.Fatal(err)
		}

		fmt.Printf("%s: %s\n", name, addr)
	}
}

rpc/nns/names.go Outdated Show resolved Hide resolved
@roman-khimov roman-khimov merged commit 86765df into master Sep 26, 2023
8 checks passed
@roman-khimov roman-khimov deleted the nns-contract-hash branch September 26, 2023 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants