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

Drop most of deploy configs #370

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion alphabet/alphabet_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func switchToNotary(ctx storage.Context, args []any) {
panic("address of the Proxy contract is missing or invalid")
}
} else {
proxyContract = common.ResolveContractHash("proxy")
proxyContract = common.ResolveFSContract("proxy")
}

if !common.TryPurgeVotes(ctx) {
Expand Down
2 changes: 1 addition & 1 deletion common/netmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ import (
// a successive call is not guaranteed.
// Caller must have `NewEpoch` method with a single numeric argument.
func SubscribeForNewEpoch() {
netmapContract := ResolveContractHash("netmap")
netmapContract := ResolveFSContract("netmap")
contract.Call(netmapContract, "subscribeForNewEpoch", contract.All, runtime.GetExecutingScriptHash())
}
47 changes: 25 additions & 22 deletions common/nns.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,38 @@ import (
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
)

// ResolveContractHash resolves contract hash by its well-known NeoFS name.
// Contract name should be lowercased, should not include `.neofs` TLD. Example
// values: "netmap", "container", etc.
// Relies on some NeoFS specifics:
// 1. NNS contract should be deployed first (and should have `1` contract ID)
// 2. It should be prefilled with contract hashes by their names (no
// capitalized chars; no `neofs` TLD)
func ResolveContractHash(contractName string) interop.Hash160 {
// get NNS contract (it always has ID=1 in the NeoFS Sidechain)
nnsContract := management.GetContractByID(1)
if nnsContract == nil {
panic("missing NNS contract")
// NNSID is the ID of the NNS contract in NeoFS networks. It's always deployed
// first.
const NNSID = 1

// ContractTLD is the default domain used by NeoFS contracts.
const ContractTLD = "neofs"

// InferNNSHash returns NNS contract hash by [NNSID] or panics if
// it can't be resolved.
func InferNNSHash() interop.Hash160 {
carpawell marked this conversation as resolved.
Show resolved Hide resolved
var nns = management.GetContractByID(NNSID)
if nns == nil {
panic("no NNS contract")
}
return nns.Hash
}

resResolve := contract.Call(nnsContract.Hash, "resolve", contract.ReadOnly,
contractName+".neofs", 16, // TXT
)
// ResolveFSContract resolves contract hash by its well-known NeoFS name.
// Contract name should be lowercased, should not include [ContractTLD]. Example
// values: "netmap", "container", etc. Relies on NeoFS-specific NNS setup, see
// [NNSID].
func ResolveFSContract(contractName string) interop.Hash160 {
Copy link
Member

Choose a reason for hiding this comment

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

what does FS stand for here?

Copy link
Member Author

Choose a reason for hiding this comment

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

NeoFS.

Copy link
Member

Choose a reason for hiding this comment

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

but there is no Neo in the method's name. i can understand and accept it but do not think it is a good name

var nns = InferNNSHash()

resResolve := contract.Call(nns, "resolve", contract.ReadOnly, contractName+"."+ContractTLD, 16 /*TXT*/)
records := resResolve.([]string)

carpawell marked this conversation as resolved.
Show resolved Hide resolved
if len(records) == 0 {
panic("did not find a record of the " + contractName + " contract in the NNS")
}

var hash interop.Hash160
if len(records[0]) == 2*interop.Hash160Len {
hash = convert.ToBytes(std.Atoi(records[0], 16))
} else {
hash = address.ToHash160(records[0])
return convert.ToBytes(std.Atoi(records[0], 16))
}

return hash
return address.ToHash160(records[0])
}