From c5a4cfaebeb32ce10e5e67cdf189c3c8e7103e89 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 10 Oct 2019 18:22:06 +0300 Subject: [PATCH] smartcontract: add CreateSignatureRedeemScript() It's very similar to the CreateMultiSigRedeemScript() and it will be used in interop functions. --- pkg/smartcontract/contract.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/smartcontract/contract.go b/pkg/smartcontract/contract.go index 7e978bfd3..095f9f8e9 100644 --- a/pkg/smartcontract/contract.go +++ b/pkg/smartcontract/contract.go @@ -9,6 +9,21 @@ import ( "github.com/CityOfZion/neo-go/pkg/vm" ) +// CreateSignatureRedeemScript creates a check signature script runnable by VM. +func CreateSignatureRedeemScript(key *keys.PublicKey) ([]byte, error) { + buf := new(bytes.Buffer) + err := vm.EmitBytes(buf, key.Bytes()) + if err != nil { + return nil, err + } + err = vm.EmitOpcode(buf, vm.CHECKSIG) + if err != nil { + return nil, err + } + + return buf.Bytes(), nil +} + // CreateMultiSigRedeemScript will create a script runnable by the VM. func CreateMultiSigRedeemScript(m int, publicKeys keys.PublicKeys) ([]byte, error) { if m <= 1 {