2021-02-02 19:20:31 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
2021-03-24 08:00:35 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/ledger"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/neo"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/roles"
|
2021-02-19 14:47:41 +00:00
|
|
|
)
|
2021-02-02 19:20:31 +00:00
|
|
|
|
2021-02-04 07:22:54 +00:00
|
|
|
type IRNode struct {
|
2021-03-04 19:21:49 +00:00
|
|
|
PublicKey interop.PublicKey
|
2021-02-04 07:22:54 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 11:56:51 +00:00
|
|
|
// InnerRingNodes return a list of inner ring nodes from state validator role
|
|
|
|
// in the sidechain.
|
2022-03-21 11:01:45 +00:00
|
|
|
func InnerRingNodes() []interop.PublicKey {
|
2021-03-24 08:00:35 +00:00
|
|
|
blockHeight := ledger.CurrentIndex()
|
2022-03-21 11:01:45 +00:00
|
|
|
return roles.GetDesignatedByRole(roles.NeoFSAlphabet, uint32(blockHeight+1))
|
2021-03-24 08:00:35 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 11:56:51 +00:00
|
|
|
// AlphabetNodes returns a list of alphabet nodes from committee in the sidechain.
|
2022-03-21 11:01:45 +00:00
|
|
|
func AlphabetNodes() []interop.PublicKey {
|
|
|
|
return neo.GetCommittee()
|
2021-03-24 08:00:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AlphabetAddress returns multi address of alphabet public keys.
|
2023-12-06 16:23:33 +00:00
|
|
|
func AlphabetAddress() interop.Hash160 {
|
2021-03-24 08:00:35 +00:00
|
|
|
alphabet := neo.GetCommittee()
|
|
|
|
return Multiaddress(alphabet, false)
|
|
|
|
}
|
|
|
|
|
2021-09-20 15:05:49 +00:00
|
|
|
// CommitteeAddress returns multi address of committee.
|
2023-12-06 16:23:33 +00:00
|
|
|
func CommitteeAddress() interop.Hash160 {
|
2021-09-20 15:05:49 +00:00
|
|
|
committee := neo.GetCommittee()
|
|
|
|
return Multiaddress(committee, true)
|
|
|
|
}
|
|
|
|
|
2022-04-14 11:56:51 +00:00
|
|
|
// Multiaddress returns default multisignature account address for N keys.
|
|
|
|
// If committee set to true, it is `M = N/2+1` committee account.
|
2023-12-06 16:23:33 +00:00
|
|
|
func Multiaddress(n []interop.PublicKey, committee bool) interop.Hash160 {
|
2021-03-25 17:57:46 +00:00
|
|
|
threshold := len(n)*2/3 + 1
|
2021-03-24 08:00:35 +00:00
|
|
|
if committee {
|
|
|
|
threshold = len(n)/2 + 1
|
|
|
|
}
|
|
|
|
|
2021-09-20 15:05:49 +00:00
|
|
|
return contract.CreateMultisigAccount(threshold, n)
|
2021-03-24 08:00:35 +00:00
|
|
|
}
|