예제 #1
0
        public static ReadOnlyMemory <byte> CreateMultiSigRedeemScript(IEnumerable <ECPoint> publicKeys, int count)
        {
            var comparer = new ECPointComparer();

            var buffer = new ArrayBufferWriter <byte>();
            var writer = new BufferWriter <byte>(buffer);

            writer.EmitPush(count);

            foreach (var key in publicKeys.OrderBy(pk => pk, comparer))
            {
                if (!EncodedPublicKey.TryEncode(key, true, out var encodedKey))
                {
                    throw new ArgumentException(nameof(publicKeys));
                }

                writer.EmitPush(encodedKey.Key.AsSpan());
            }
            writer.EmitPush(publicKeys.Count());
            writer.EmitOpCode(OpCode.CHECKMULTISIG);
            writer.Commit();

            return(buffer.WrittenMemory);
        }