Exemple #1
0
    static MyJson.IJsonNode UnPackJsonNumber(System.IO.Stream stream, byte tagfirst)
    {
        MyJson.JsonNode_ValueNumber number = new MyJson.JsonNode_ValueNumber();
        bool isFloat = (tagfirst & 32) > 0;
        bool isBool  = (tagfirst & 16) > 0;
        bool isNull  = (tagfirst & 8) > 0;
        int  blen    = tagfirst % 8 + 1;

        byte[] buf = new byte[4];
        for (int i = 0; i < 4; i++)
        {
            buf[i] = 0;
        }
        if (isBool)
        {
            number.SetBool(isNull);
        }
        else if (isNull)
        {
            number.SetNull();
        }
        else if (isFloat)
        {
            stream.Read(buf, 0, blen);
            number.value = BitConverter.ToSingle(buf, 0);
        }
        else
        {
            stream.Read(buf, 0, blen);
            number.value = BitConverter.ToInt32(buf, 0);
        }

        return(number);
    }
    void onCLick_wallet_creat2()
    {
        string passward1 = m_panel.FindChild("wallet_create/wallet_password1").GetComponent <InputField>().text;
        string passward2 = m_panel.FindChild("wallet_create/wallet_password2").GetComponent <InputField>().text;

        if (passward1 == "")
        {
            testtool.showNotice("请输入密码");
            return;
        }
        if (passward2 == "")
        {
            testtool.showNotice("请确认密码");
            return;
        }
        if (passward1 != passward2)
        {
            testtool.showNotice("密码不一致");
            return;
        }

        try
        {
            //创建一个钱包
            ThinNeo.NEP6.NEP6Wallet wallet = new ThinNeo.NEP6.NEP6Wallet("");
            byte[] privateKey         = new byte[32];
            RandomNumberGenerator rng = RandomNumberGenerator.Create();
            rng.GetBytes(privateKey);
            wallet.CreateAccount(privateKey, passward1);
            MyJson.JsonNode_Object wallet_json = new MyJson.JsonNode_Object();
            var n = new MyJson.JsonNode_ValueNumber();
            n.SetNull();
            wallet_json["name"]     = n;
            wallet_json["version"]  = new MyJson.JsonNode_ValueString("1.0");
            wallet_json["scrypt"]   = wallet.scrypt.ToJson();
            wallet_json["accounts"] = new MyJson.JsonNode_Array();
            foreach (var ac in wallet.accounts.Values)
            {
                var jnot = ac.ToJson();
                wallet_json["accounts"].AsList().Add(jnot);
            }
            wallet_json["extra"] = n;

            var wif = ThinNeo.Helper.GetWifFromPrivateKey(privateKey);
            roleInfo.getInstance().set_storage(wif);

            m_panel.FindChild("wallet_create").gameObject.SetActive(false);
            api_tool._instance.bindWallet(roleInfo.getInstance().uid, roleInfo.getInstance().token, wallet_json.ToString(), on_wallet_bind);
        }
        catch
        {
            testtool.showNotice("创建钱包错误");
        }
    }
Exemple #3
0
        public MyJson.JsonNode_Object ToJson()
        {
            MyJson.JsonNode_Object account = new MyJson.JsonNode_Object();
            byte[] shash = (ScriptHash);
            var    addr  = Helper.GetAddressFromScriptHash(shash);

            account["address"] = new MyJson.JsonNode_ValueString(addr);
            var _null = new MyJson.JsonNode_ValueNumber();

            _null.SetNull();
            account["label"]     = _null;
            account["isDefault"] = new MyJson.JsonNode_ValueNumber(false);
            account["lock"]      = new MyJson.JsonNode_ValueNumber(false);
            account["key"]       = new MyJson.JsonNode_ValueString(nep2key);
            account["contract"]  = ((NEP6Contract)Contract)?.ToJson();
            account["extra"]     = _null;
            return(account);
        }
        public void Save()
        {
            MyJson.JsonNode_Object wallet = new MyJson.JsonNode_Object();
            var n = new MyJson.JsonNode_ValueNumber();

            n.SetNull();
            wallet["name"]     = n;
            wallet["version"]  = new MyJson.JsonNode_ValueString("1.0");
            wallet["scrypt"]   = scrypt.ToJson();
            wallet["accounts"] = new MyJson.JsonNode_Array();
            foreach (var ac in accounts.Values)
            {
                var jnot = ac.ToJson();
                wallet["accounts"].AsList().Add(jnot);
            }
            wallet["extra"] = n;
            File.WriteAllText(path, wallet.ToString());
        }
Exemple #5
0
        public MyJson.JsonNode_Object GetWallet()
        {
            MyJson.JsonNode_Object wallet = new MyJson.JsonNode_Object();
            var n = new MyJson.JsonNode_ValueNumber();

            n.SetNull();
            wallet["name"]     = n;
            wallet["version"]  = new MyJson.JsonNode_ValueString("1.0");
            wallet["scrypt"]   = scrypt.ToJson();
            wallet["accounts"] = new MyJson.JsonNode_Array();
            foreach (var ac in accounts.Values)
            {
                var jnot = ac.ToJson();
                wallet["accounts"].AsList().Add(jnot);
            }
            wallet["extra"] = n;
            return(wallet);
        }
Exemple #6
0
    static MyJson.IJsonNode UnPackJsonNumber(System.IO.Stream stream, byte tagfirst)
    {
        MyJson.JsonNode_ValueNumber number = new MyJson.JsonNode_ValueNumber();
        bool isFloat = (tagfirst & 32) > 0;
        bool isBool = (tagfirst & 16) > 0;
        bool isNull = (tagfirst & 8) > 0;
        int blen = tagfirst % 8 + 1;
        byte[] buf = new byte[4];
        for (int i = 0; i < 4; i++)
        {
            buf[i] = 0;
        }
        if (isBool)
        {
            number.SetBool(isNull);
        }
        else if (isNull)
        {
            number.SetNull();
        }
        else if (isFloat)
        {
            stream.Read(buf, 0, blen);
            number.value = BitConverter.ToSingle(buf, 0);
        }
        else
        {
            stream.Read(buf, 0, blen);
            number.value = BitConverter.ToInt32(buf, 0);
        }

        return number;
    }