Skip to content

获取共识人公钥

tanyuan edited this page Aug 1, 2017 · 2 revisions

using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Services.Neo;

class A : FunctionCode
{
        public static string Main()
        {
            uint height0 = Blockchain.GetHeight();
            Header head = Blockchain.GetHeader(59);   //ok 3162

            byte[] programHash = { 0x5c, 0x63, 0x2b, 0x9d, 0xfe, 0x78, 0x8a, 0x7f, 0x88, 0x1a, 0x33, 0xc3, 0xcc, 0xa3, 0x14, 0x38, 0x86, 0x10, 0xb6, 0x6f };
            byte[] assetid = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            string[] list = new string[120];
            int i = 0;


             byte[][] validators = Blockchain.GetValidators();
                   list[i++] = "GetValidators: \n";
            foreach (byte[] v in validators)
            {
                list[i++] = BytesToHexStr(v) + ",\n";
            }

            return Strcat(list);
        }
       
        public static string Strcat(string[] list)
        {
            string str = "";
            foreach (string item in list)
            {
                str = str + item;
            }
            return str;
        }
        public static string BytesToHexStr(byte[] bys)
        {
            int highByte, lowByte;
            string str = "";
            for (int i = 0; i < bys.Length; i++)
            {
                highByte = bys[i] >> 4;
                lowByte = bys[i] & 0x0f;

                highByte += 0x30;

                if (highByte > 0x39)
                {
                    int var = highByte + 0x27;
                    str = str + var;
                }
                else
                    str = str + highByte;

                lowByte += 0x30;
                if (lowByte > 0x39)
                {
                    int val = lowByte + 0x27;
                    str = str + val;
                }
                else
                    str = str + lowByte;
            }
            return str;
        }
        public static string IntTostring(int input)
        {
            int tmp = input;
            int n = 0;
            while (tmp > 0)
            {
                n++;
                tmp = tmp / 10;
            }
            tmp = input;
            string str = "";
            for (int i = n - 1; i > 0; i--)
            {
                int mul = 1;
                int j = i;
                while (j-- > 0)
                {
                    mul = mul * 10;
                }
                int val = tmp / mul + '0';
                tmp = input % mul;
                str = str + val;
            }
            int last = tmp % 10 + '0';
            str = str + last;
            return str;
        }
}

执行码:

参数:空

结果: GetValidators: 02186B95CF941D4AC5340F83431402BF32C7642FD6BD852A7A13F2488D72E8F487, 0234ACDBF93C61F66D1343FE2695BB5DE9FFFFAAEEEA8120EA9C6098E7BFF0F1F1, 0262AE58D62E9A24C4C7F3EB2049C43EB97AFF1B962047C5FF8D0AABCCF82D3B72, 02D1708024559A9A83028C25C7F0BF12B0A01EA8EA9CFF077748BC54D624F62F65,

作者:周喜

Clone this wiki locally