neo-go/pkg/smartcontract/contract.go
Anthony De Meulemeester 94672cb9cc
Persistance (#53)
* added publish TX for backwards compat.

* lowered the prototick for faster block syncing

* print useragent on startup

* added createMultiRedeemScript for genesis block generation.

* building genesis block from scratch.

* implemented merkle tree.

* starting blockhain with generated genesis hash

* Fixed bug in unspent coin state.

* fixed broken tests after genesis block.

* removed log line.

* bumped version -> 0.34.0
2018-03-25 12:45:54 +02:00

34 lines
900 B
Go

package smartcontract
import (
"bytes"
"fmt"
"sort"
"github.com/CityOfZion/neo-go/pkg/crypto"
"github.com/CityOfZion/neo-go/pkg/vm"
)
// CreateMultiSigRedeemScript will create a script runnable by the VM.
func CreateMultiSigRedeemScript(m int, publicKeys crypto.PublicKeys) ([]byte, error) {
if m <= 1 {
return nil, fmt.Errorf("param m cannot be smaller or equal to 1 got %d", m)
}
if m > len(publicKeys) {
return nil, fmt.Errorf("length of the signatures (%d) is higher then the number of public keys", m)
}
if m > 1024 {
return nil, fmt.Errorf("public key count %d exceeds maximum of length 1024", len(publicKeys))
}
buf := new(bytes.Buffer)
vm.EmitInt(buf, int64(m))
sort.Sort(publicKeys)
for _, pubKey := range publicKeys {
vm.EmitBytes(buf, pubKey.Bytes())
}
vm.EmitInt(buf, int64(len(publicKeys)))
vm.EmitOpcode(buf, vm.Ocheckmultisig)
return buf.Bytes(), nil
}