-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*: make address params optional, take them from NNS
They're still there to override/keep compatibility, but they're not mandatory now. Closes #325. Signed-off-by: Roman Khimov <roman@nspcc.ru>
- Loading branch information
1 parent
238986e
commit 41e483f
Showing
10 changed files
with
220 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package common | ||
|
||
import ( | ||
"github.com/nspcc-dev/neo-go/pkg/interop" | ||
"github.com/nspcc-dev/neo-go/pkg/interop/contract" | ||
"github.com/nspcc-dev/neo-go/pkg/interop/lib/address" | ||
"github.com/nspcc-dev/neo-go/pkg/interop/native/management" | ||
"github.com/nspcc-dev/neo-go/pkg/interop/native/std" | ||
) | ||
|
||
// 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 its well-known ID or panics if | ||
// it can't be resolved. | ||
func InferNNSHash() interop.Hash160 { | ||
var nns = management.GetContractByID(1) | ||
if nns == nil { | ||
panic("no NNS contract") | ||
} | ||
return nns.Hash | ||
} | ||
|
||
// ResolveFSContract returns contract hash by name as registered in NNS or | ||
// panics if it can't be resolved. | ||
func ResolveFSContract(name string) interop.Hash160 { | ||
var nns = InferNNSHash() | ||
res := contract.Call(nns, "resolve", contract.ReadOnly, name+"."+ContractTLD, 16 /*TXT*/) | ||
strs := res.([]string) | ||
for _, str := range strs { | ||
if len(str) == interop.Hash160Len*2 { | ||
var h = make([]byte, interop.Hash160Len) | ||
for i := 0; i < interop.Hash160Len; i++ { | ||
ii := (interop.Hash160Len - i - 1) * 2 | ||
h[i] = byte(std.Atoi(str[ii:ii+2], 16)) | ||
} | ||
return h | ||
} else { | ||
return address.ToHash160(str) | ||
} | ||
} | ||
panic("failed to resolve contract") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.