示例#1
0
文件: CCMC.cs 项目: neo-ngd/n3-asset
        public static bool changeBookKeeper(byte[] rawHeader, byte[] pubKeyList, byte[] signList)
        {
            Header header = deserializHeader(rawHeader);

            if (header.height == 0)
            {
                return(initGenesisBlock(header, pubKeyList));
            }
            BigInteger latestHeight = new BigInteger(((byte[])Storage.Get(Storage.CurrentContext, currentEpochHeightPrefix)).Concat(new byte[] { 0x00 }));

            if (latestHeight > header.height)
            {
                notify("The height of header illegal");
                return(false);
            }
            ECPoint[] keepers = (ECPoint[])StdLib.Deserialize(Storage.Get(Storage.CurrentContext, mCKeeperPubKeysPrefix));
            if (!verifySigWithOrder(rawHeader, signList, keepers))
            {
                notify("Verify signature failed");
                return(false);
            }
            BookKeeper bookKeeper = verifyPubkey(pubKeyList);

            if ((ByteString)header.nextBookKeeper != (ByteString)bookKeeper.nextBookKeeper)
            {
                notify("bookKeeper not match");
                throw new Exception();
            }
            Storage.Put(Storage.CurrentContext, currentEpochHeightPrefix, header.height);
            Storage.Put(Storage.CurrentContext, mCKeeperPubKeysPrefix, StdLib.Serialize(bookKeeper.keepers));
            ChangeBookKeeperEvent(header.height, rawHeader);
            return(true);
        }
示例#2
0
文件: CCMC.cs 项目: neo-ngd/n3-asset
        public static bool initGenesisBlock(Header header, byte[] pubKeyList)
        {
            if (isGenesised())
            {
                return(false);
            }
            if (pubKeyList.Length % MCCHAIN_PUBKEY_LEN != 0)
            {
                notify("Length of pubKeyList is illegal");
                throw new ArgumentException();
            }
            BookKeeper bookKeeper = verifyPubkey(pubKeyList);

            Storage.Put(Storage.CurrentContext, currentEpochHeightPrefix, header.height);
            Storage.Put(Storage.CurrentContext, isGenesisedKey, 1);
            Storage.Put(Storage.CurrentContext, mCKeeperPubKeysPrefix, StdLib.Serialize(bookKeeper.keepers));
            return(true);
        }
示例#3
0
文件: CCMC.cs 项目: neo-ngd/n3-asset
        /// <summary>
        /// Tested, 根据给定的有效签名数与公钥数生成BookKeeper
        /// </summary>
        /// <param name="keyLength"></param>
        /// <param name="m"></param>
        /// <param name="pubKeyList"></param>
        /// <returns></returns>
        private static BookKeeper getBookKeeper(int keyLength, int m, byte[] pubKeyList)
        {
            BookKeeper bookKeeper = new BookKeeper();

            byte[] buff = new byte[] { };
            buff = writeUint16(buff, keyLength);
            ECPoint[] keepers = new ECPoint[keyLength];
            for (int i = 0; i < keyLength; i++)
            {
                var compressPubKey = compressMCPubKey(pubKeyList.Range(i * MCCHAIN_PUBKEY_LEN, MCCHAIN_PUBKEY_LEN));
                buff = writeVarBytes(buff, compressPubKey);
                ECPoint hash = getCompressPubKey(compressPubKey);
                keepers[i] = hash;
            }
            buff = writeUint16(buff, m);
            bookKeeper.nextBookKeeper = bytesToBytes20(Hash160(buff));
            bookKeeper.keepers        = keepers;
            return(bookKeeper);
        }