-
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.
netmap: Make
NewEpoch
callback mechanism more generic
Do not hardcode container and balance contract as a `NewEpoch` events receivers in the netmap contract. Use the netmap's registration method on a deploy stage instead. Closes #327. Signed-off-by: Pavel Karpy <[email protected]>
- Loading branch information
Showing
8 changed files
with
162 additions
and
8 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
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,39 @@ | ||
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/convert" | ||
"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" | ||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime" | ||
) | ||
|
||
// RegisterNewEpochHook registers calling contract as a NewEpoch | ||
// callback requester. Netmap contract's address is taken from the | ||
// NNS contract, therefore, it must be presented and filled with | ||
// netmap information for correct RegisterNewEpochHook call; otherwise | ||
// successive call is not guaranteed. | ||
// Caller must have `NewEpoch` method with a single numeric argument. | ||
func RegisterNewEpochHook() { | ||
nnsContract := management.GetContractByID(1) | ||
if nnsContract == nil { | ||
panic("missing NNS contract") | ||
} | ||
|
||
resolveRes := contract.Call(nnsContract.Hash, "resolve", contract.ReadOnly, "netmap.neofs", 16) | ||
records := resolveRes.([]string) | ||
if len(records) == 0 { | ||
panic("did not find a record of the Proxy contract in the NNS") | ||
} | ||
|
||
var netmapContract interop.Hash160 | ||
if len(records[0]) == 2*interop.Hash160Len { | ||
netmapContract = convert.ToBytes(std.Atoi(records[0], 16)) | ||
} else { | ||
netmapContract = address.ToHash160(records[0]) | ||
} | ||
|
||
contract.Call(netmapContract, "registerNewEpochRecipient", contract.All, runtime.GetExecutingScriptHash()) | ||
} |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.