[#60] netmap: Use interop to create multi signature account

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-03-17 11:10:23 +03:00 committed by Alex Vanin
parent 9d36a33b9d
commit 2ef8c55562

View file

@ -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
} }