forked from TrueCloudLab/frostfs-contract
[#60] netmap: Use interop to create multi signature account
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
9d36a33b9d
commit
2ef8c55562
1 changed files with 5 additions and 46 deletions
|
@ -2,8 +2,8 @@ package netmapcontract
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop"
|
"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/iterator"
|
"github.com/nspcc-dev/neo-go/pkg/interop/iterator"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/crypto"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/management"
|
"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/native/std"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||||
|
@ -431,52 +431,11 @@ func multiaddress(n []common.IRNode, committee bool) []byte {
|
||||||
threshold = len(n)/2 + 1
|
threshold = len(n)/2 + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = []byte{0x10 + uint8(threshold)} // m value = 5
|
keys := []interop.PublicKey{}
|
||||||
|
for _, node := range n {
|
||||||
sortedNodes := insertSort(n)
|
|
||||||
|
|
||||||
for _, node := range sortedNodes {
|
|
||||||
key := node.PublicKey
|
key := node.PublicKey
|
||||||
|
keys = append(keys, key)
|
||||||
result = append(result, []byte{0x0C, 0x21}...) // 33 byte array
|
|
||||||
result = append(result, key...) // public key
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ln := 0x10 + uint8(len(sortedNodes))
|
return contract.CreateMultisigAccount(threshold, keys)
|
||||||
result = append(result, ln) // n value = 7
|
|
||||||
|
|
||||||
result = append(result, []byte{0x41, 0x7B, 0xCE, 0x6C, 0xA5}...) // Neo.Crypto.CheckMultisig
|
|
||||||
|
|
||||||
shaHash := crypto.Sha256(result)
|
|
||||||
|
|
||||||
return crypto.Ripemd160(shaHash)
|
|
||||||
}
|
|
||||||
|
|
||||||
func insertSort(nodes []common.IRNode) []common.IRNode {
|
|
||||||
for i := 1; i < len(nodes); i++ {
|
|
||||||
v := nodes[i]
|
|
||||||
j := i - 1
|
|
||||||
for j >= 0 && more(nodes[j], v) {
|
|
||||||
nodes[j+1] = nodes[j]
|
|
||||||
j--
|
|
||||||
}
|
|
||||||
nodes[j+1] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
return nodes
|
|
||||||
}
|
|
||||||
|
|
||||||
func more(a, b common.IRNode) bool {
|
|
||||||
keyA := a.PublicKey
|
|
||||||
keyB := b.PublicKey
|
|
||||||
|
|
||||||
for i := 1; i < len(keyA); i++ { // start from 1 because we sort based on Xcoord of public key
|
|
||||||
if keyA[i] == keyB[i] {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
return keyA[i] > keyB[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue