From be6c2800327fc00a136b0c43772c53d67320ba5a Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 20 Apr 2021 17:27:15 +0300 Subject: [PATCH] [#74] neofs: Add `AlphabetAddress` method This method returns multi signature address of alphabet nodes in NeoFS contract. Signed-off-by: Alex Vanin --- neofs/config.yml | 2 +- neofs/neofs_contract.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/neofs/config.yml b/neofs/config.yml index 9fc400a..b22aa29 100644 --- a/neofs/config.yml +++ b/neofs/config.yml @@ -1,5 +1,5 @@ name: "NeoFS" -safemethods: ["alphabetList", "innerRingCandidates", "config", "listConfig", "version"] +safemethods: ["alphabetList", "alphabetAddress", "innerRingCandidates", "config", "listConfig", "version"] events: - name: Deposit parameters: diff --git a/neofs/neofs_contract.go b/neofs/neofs_contract.go index c617002..b036993 100644 --- a/neofs/neofs_contract.go +++ b/neofs/neofs_contract.go @@ -15,6 +15,7 @@ package smart_contract Inner ring list related methods: - AlphabetList + - AlphabetAddress - InnerRingCandidates - InnerRingCandidateAdd - InnerRingCandidateRemove @@ -26,6 +27,7 @@ package smart_contract - SetConfig Other utility methods: + - Migrate - Version - Cheque */ @@ -127,6 +129,12 @@ func AlphabetList() []common.IRNode { return getNodes(ctx, alphabetKey) } +// AlphabetAddress returns 2\3n+1 multi signature address of alphabet nodes. +func AlphabetAddress() interop.Hash160 { + ctx := storage.GetReadOnlyContext() + return multiaddress(getNodes(ctx, alphabetKey)) +} + // InnerRingCandidates returns array of inner ring candidate node keys. func InnerRingCandidates() []common.IRNode { ctx := storage.GetReadOnlyContext() @@ -534,3 +542,17 @@ func rmNodeByKey(lst, add []common.IRNode, k []byte) ([]common.IRNode, []common. return newLst, add, flag } + +// multiaddress returns multi signature address from list of IRNode structures +// with m = 2/3n+1. +func multiaddress(n []common.IRNode) []byte { + threshold := len(n)*2/3 + 1 + + keys := []interop.PublicKey{} + for _, node := range n { + key := node.PublicKey + keys = append(keys, key) + } + + return contract.CreateMultisigAccount(threshold, keys) +}