Ejemplo n.º 1
0
        public async Task <bool> InvokeContractTransfer(NETWORK_TYPE net, string wif, string fromSh, string toSh, int amount, int gasCost)
        {
            var res = await _nodeServices.InvokeExportAsync <bool>(
                GetScriptLocation(), "InvokeContractTransfer", GetNetwork(net), wif, CONTRACT_HASH, gasCost, fromSh, toSh, amount);

            return(res);
        }
Ejemplo n.º 2
0
        public async Task <bool> SendAsset(NETWORK_TYPE type, string wif, ASSET_NAME assetName, string addr, int amount)
        {
            var asset = (assetName == ASSET_NAME.NEO) ? "NEO" : "GAS";
            var res   = await nodeServices.InvokeExportAsync <bool>(GetScriptLocation(),
                                                                    "SendAsset", GetNetwork(type), wif, asset, addr, amount);

            return(res);
        }
Ejemplo n.º 3
0
        public async Task <bool> InvokeContractReplace(NETWORK_TYPE net, string wif,
                                                       string key, string data, int index, int gasCost)
        {
            var res = await _nodeServices.InvokeExportAsync <bool>(
                GetScriptLocation(), "InvokeContractReplace", GetNetwork(net), wif, CONTRACT_HASH, gasCost, key, data, index);

            return(res);
        }
Ejemplo n.º 4
0
    private void InitializeRPCClient()
    {
        m_kCLB = new IxMagnaChainBridge();
        string       strHost = "http://127.0.0.1";
        int          iPort   = 8332;
        string       strUser = "******";
        string       strPwd  = "pwd";
        NETWORK_TYPE eNT     = NETWORK_TYPE.MAIN;

        bool bRet = m_kCLB.Initialize(strHost, iPort, strUser, strPwd, eNT);
    }
Ejemplo n.º 5
0
        public async Task <string> GetStorage(NETWORK_TYPE type, string key)
        {
            try
            {
                var res = await _nodeServices
                          .InvokeExportAsync <string>(GetScriptLocation(), "GetStorage", GetNetwork(type), CONTRACT_HASH, key);

                return(res);
            }
            catch (Exception err) {
                return(null);
            }
        }
Ejemplo n.º 6
0
        public async Task <bool> InvokeContractRequestRefund(NETWORK_TYPE net, string wif, string userId, int value, int gasCost)
        {
            try
            {
                var res = await nodeServices.InvokeExportAsync <bool>(GetScriptLocation(),
                                                                      "InvokeContractRequestRefund", GetNetwork(net), wif, CONTRACT_HASH, gasCost, Helper.ReverseHex(userId), value);

                return(res);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 7
0
        public async Task <int> GetTokenBalance(NETWORK_TYPE net, string revSh)
        {
            try
            {
                var res = await _nodeServices.InvokeExportAsync <string>(GetScriptLocation(),
                                                                         "GetTokenBalance", GetNetwork(net), CONTRACT_HASH, revSh);

                var a = Int32.Parse(res);
                return(a);
            }
            catch (Exception err) {
                return(0);
            }
        }
Ejemplo n.º 8
0
        public async Task <bool> InvokeContractCleanUp(NETWORK_TYPE net, string wif, string id, int gasCost)
        {
            try
            {
                var res = await nodeServices.InvokeExportAsync <bool>(GetScriptLocation(),
                                                                      "InvokeContractCleanUp", GetNetwork(net), wif, CONTRACT_HASH, gasCost, Helper.Str2Hex(id));

                return(res);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 9
0
        public async Task <bool> InvokeContractMintToken(NETWORK_TYPE net, string wif, int neoAmount, int gasCost)
        {
            try
            {
                var res = await nodeServices.InvokeExportAsync <bool>(GetScriptLocation(),
                                                                      "InvokeContractMintToken", GetNetwork(net), wif, CONTRACT_HASH, gasCost, neoAmount);

                return(res);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 10
0
        public async Task <bool> InvokeContractTransfer(NETWORK_TYPE net, string wif, string from, string to, int amount, int gasCost)
        {
            try
            {
                var res = await nodeServices.InvokeExportAsync <bool>(GetScriptLocation(),
                                                                      "InvokeContractTransfer", GetNetwork(net), wif, CONTRACT_HASH, gasCost, Helper.ReverseHex(from), Helper.ReverseHex(to), amount);

                return(res);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 11
0
        /*RegisterTrip(byte[] id, byte[] driver, string way, BigInteger date,
         * BigInteger cancelDate, BigInteger seatsCount, BigInteger price,
         * BigInteger depositDriver)
         *
         * public static bool CancelTrip(byte[] id)
         *
         * public static bool ReserveSeat(byte[] id, byte[] passenger)
         * public static bool CancelSeat(byte[] id, byte[] passenger)
         * public static bool PayForTrip(byte[] id, byte[] passenger)
         * public static bool RequestRefund(byte[] user, BigInteger value)
         * public static bool CleanUp(byte[] id)*/


        public async Task <bool> InvokeContractRegisterTrip(NETWORK_TYPE net, string wif, Trip trip, int gasCost)
        {
            try
            {
                string revSh = Helper.ReverseHex(trip.DriverId);
                uint   a     = trip.Date.ToTimestamp();
                uint   b     = trip.CancelDate.ToTimestamp();
                var    res   = await nodeServices.InvokeExportAsync <bool>(GetScriptLocation(),
                                                                           "InvokeContractRegisterTrip", GetNetwork(net), wif, CONTRACT_HASH, gasCost, Helper.Str2Hex(trip.Id), revSh, Helper.Str2Hex(trip.From + trip.To),
                                                                           a, b, trip.SeatsCount, trip.Price, trip.Deposit);

                return(res);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 12
0
        public async Task <bool> SendAsset(NETWORK_TYPE type, ASSET_NAME assetName, string addr, int amount)
        {
            var user = await _userManager.GetUserAsync(User);

            if (assetName == ASSET_NAME.SC)
            {
                var toSh = await SmartPromiseConverter.GetScriptHashReversed(addr, _blockchain);

                var fromSh = await SmartPromiseConverter.GetScriptHashReversed(user.Address, _blockchain);

                var res = await _blockchain.InvokeContractTransfer(type, user.Wif, fromSh, toSh, amount, 1);

                return(res);
            }
            else
            {
                return(await _blockchain.SendAsset(type, user.Wif, assetName, addr, amount));
            }
        }
Ejemplo n.º 13
0
    private static void OpenRPCConsole()
    {
        string strKeyPrefix = Application.dataPath;

        RPC_HOST     = PlayerPrefs.GetString(strKeyPrefix + "#RPC_HOST", @"http://127.0.0.1");
        RPC_PORT     = PlayerPrefs.GetInt(strKeyPrefix + "#RPC_PORT", 8332);
        RPC_USERNAME = PlayerPrefs.GetString(strKeyPrefix + "#RPC_USERNAME", @"user");
        RPC_PASSWORD = PlayerPrefs.GetString(strKeyPrefix + "#RPC_PASSWORD", @"pwd");
        RPC_NET_TYPE = (NETWORK_TYPE)PlayerPrefs.GetInt(strKeyPrefix + "#RPC_NET_TYPE", (int)NETWORK_TYPE.TEST_NET);

        ms_strImportMasterKeyName = PlayerPrefs.GetString(strKeyPrefix + "#ms_strImportMasterKeyName", "");
        ms_strMasterKey           = PlayerPrefs.GetString(strKeyPrefix + "#ms_strMasterKey", "");

        ms_strContractAddress = PlayerPrefs.GetString(strKeyPrefix + "#ms_strContractAddress", "");

        ms_kSig          = GetWindow <RPCConsole>(false, "MagnaChain", true);
        ms_kSig.position = new Rect(400, 150, 760, 610);

        Initialize();
    }
Ejemplo n.º 14
0
    private void InitializeRPCClient()
    {
        m_kCLB = new IxMagnaChainBridge();
        string       strHost = "http://127.0.0.1";
        int          iPort   = 8332;
        string       strUser = "******";
        string       strPwd  = "pwd";
        NETWORK_TYPE eNT     = NETWORK_TYPE.MAIN;

        TextOut("Initialize RPC client: " + strHost + ":" + iPort.ToString());
        bool bRet = m_kCLB.Initialize(strHost, iPort, strUser, strPwd, eNT);

        if (bRet == false)
        {
            TextOut("Initialize RPC client failed!", "red");
        }
        else
        {
            TextOut("Initialize RPC client succeed.");
        }
    }
Ejemplo n.º 15
0
    private void DrawSettingsUI(float fYOffset)
    {
        if (m_bNeedResetFocus)
        {
            GUI.FocusControl(null);
            m_bNeedResetFocus = false;
        }

        GUILayout.Space(10);

        RPC_HOST = DrawFileChooser("RHLabe", "RHInput", "RHBtn", 20.0f, false, "Rpc Host:", 120.0f, RPC_HOST, 330.0f, "", false, true);
        GUILayout.Space(10);

        string strRpcPort = RPC_PORT.ToString();

        strRpcPort = DrawFileChooser("RPLabe", "RPInput", "RPBtn", 20.0f, false, "Rpc port:", 120.0f, strRpcPort, 330.0f, @"8332", false, true);
        try
        {
            RPC_PORT = Convert.ToInt32(strRpcPort);
        }
        catch (Exception e)
        {
            RPC_PORT = 8332;
        }
        GUILayout.Space(10);

        RPC_USERNAME = DrawFileChooser("RUNLabe", "RUNInput", "RUNBtn", 20.0f, false, "Rpc user name:", 120.0f, RPC_USERNAME, 330.0f, "", false, true);
        GUILayout.Space(10);

        RPC_PASSWORD = DrawFileChooser("RPSLabe", "RPSInput", "RPSBtn", 20.0f, false, "Rpc password:"******"", true, true);
        GUILayout.Space(10);

        GUILayout.BeginHorizontal();
        GUILayout.Space(20.0f);
        GUILayout.Label("Network:", GUILayout.Width(120.0f));
        //GUILayout.Space(10.0f);
        string[] arrNetType = new string[3];
        arrNetType[0] = "MAIN";
        arrNetType[1] = "TEST_NET";
        arrNetType[2] = "REG_TEST";
        RPC_NET_TYPE  = (NETWORK_TYPE)EditorGUILayout.Popup((int)RPC_NET_TYPE, arrNetType, GUILayout.Width(90));
        GUILayout.EndHorizontal();

        GUILayout.Space(25);

        GUILayout.BeginHorizontal();
        float fBtnWidth = 150.0f;
        float fX        = ms_kSig.position.width * 0.5f - fBtnWidth * 0.5f;

        GUILayout.Space(fX);
        GUILayoutOption[] arrLO = new GUILayoutOption[2];
        arrLO[0] = GUILayout.Width(fBtnWidth);
        arrLO[1] = GUILayout.Height(40);
        GUI.SetNextControlName("SaveBtn");
        if (GUILayout.Button("Save", arrLO))
        {
            string strKeyPrefix = Application.dataPath;
            if (!string.IsNullOrEmpty(RPC_HOST))
            {
                PlayerPrefs.SetString(strKeyPrefix + "#RPC_HOST", RPC_HOST);
            }

            if (RPC_PORT > 0)
            {
                PlayerPrefs.SetInt(strKeyPrefix + "#RPC_PORT", RPC_PORT);
            }


            if (!string.IsNullOrEmpty(RPC_USERNAME))
            {
                PlayerPrefs.SetString(strKeyPrefix + "#RPC_USERNAME", RPC_USERNAME);
            }


            if (!string.IsNullOrEmpty(RPC_PASSWORD))
            {
                PlayerPrefs.SetString(strKeyPrefix + "#RPC_PASSWORD", RPC_PASSWORD);
            }

            PlayerPrefs.SetInt(strKeyPrefix + "#RPC_NET_TYPE", (int)RPC_NET_TYPE);

            PlayerPrefs.Save();

            if (m_kCB != null)
            {
                m_kCB.Release();
                m_kCB = null;
            }

            m_kCB       = new IxMagnaChainBridge();
            m_bCBInited = m_kCB.Initialize(RPC_HOST, RPC_PORT, RPC_USERNAME, RPC_PASSWORD, RPC_NET_TYPE);
            if (m_bCBInited == false)
            {
                if (EditorUtility.DisplayDialog("Erorr", "Initialize RCP client failed.", "OK"))
                {
                    return;
                }
            }

            if (!string.IsNullOrEmpty(ms_strImportMasterKeyName) && !string.IsNullOrEmpty(ms_strMasterKey))
            {
                m_kCB.ImportMasterExtKey(ms_strImportMasterKeyName, ms_strMasterKey);
            }
        }
        //GUI.FocusControl("SaveBtn");
        GUILayout.EndHorizontal();

        GUILayout.Space(40);
        ms_strImportMasterKeyName = DrawFileChooser("IMKNLabe", "IMKNInput", "IMKNBtn", 20.0f, false, "Master key name:", 120.0f, ms_strImportMasterKeyName, 330.0f, "", false, true);

        GUILayout.Space(10);
        ms_strMasterKey = DrawFileChooser("MKLabe", "MKInput", "MKBtn", 20.0f, false, "Master key:", 120.0f, ms_strMasterKey, 330.0f, "", false, true);

        GUILayout.Space(20);

        GUILayout.BeginHorizontal();
        fBtnWidth = 180.0f;
        fX        = ms_kSig.position.width * 0.5f - fBtnWidth * 0.5f;
        GUILayout.Space(fX);
        arrLO[0] = GUILayout.Width(fBtnWidth);
        arrLO[1] = GUILayout.Height(30);
        GUI.SetNextControlName("ImportMasterKey");
        if (GUILayout.Button("Import Master Key", arrLO))
        {
            if (m_kCB == null)
            {
                if (EditorUtility.DisplayDialog("Prompt", "MagnaChain has not initialized.", "OK"))
                {
                    return;
                }
            }

            if (string.IsNullOrEmpty(ms_strImportMasterKeyName))
            {
                if (EditorUtility.DisplayDialog("Prompt", "Please input master key name.", "OK"))
                {
                    return;
                }
            }

            if (string.IsNullOrEmpty(ms_strMasterKey))
            {
                if (EditorUtility.DisplayDialog("Prompt", "Please input master key.", "OK"))
                {
                    return;
                }
            }

            if (m_kCB.IsMasterExtKeyExist(ms_strImportMasterKeyName))
            {
                if (EditorUtility.DisplayDialog("Prompt", "The master key has imported: " + ms_strImportMasterKeyName, "OK"))
                {
                    return;
                }
            }

            if (m_kCB.ImportMasterExtKey(ms_strImportMasterKeyName, ms_strMasterKey) == false)
            {
                if (EditorUtility.DisplayDialog("Error", "Import master key failed!", "OK"))
                {
                    return;
                }
            }
            else
            {
                string strKeyPrefix = Application.dataPath;

                PlayerPrefs.SetString(strKeyPrefix + "#ms_strImportMasterKeyName", ms_strImportMasterKeyName);
                PlayerPrefs.SetString(strKeyPrefix + "#ms_strMasterKey", ms_strMasterKey);
                PlayerPrefs.Save();

                if (EditorUtility.DisplayDialog("Done", "Import master key succeed.", "OK"))
                {
                    return;
                }
            }
        }
        GUILayout.EndHorizontal();
    }
 public virtual void OnNetworkTypeChanged(NETWORK_TYPE type)
 {
 }
Ejemplo n.º 17
0
 private string GetNetwork(NETWORK_TYPE type)
 {
     return((type == NETWORK_TYPE.MAINNET) ? "MainNet" : "TestNet");
 }
Ejemplo n.º 18
0
 public async Task <Balance> GetBalance(NETWORK_TYPE network, string addr)
 {
     return(await _blockchain.GetBalance(network, addr));
 }
Ejemplo n.º 19
0
 public async Task <IEnumerable <TransactionHistoryItem> > GetTransactionHistory(
     NETWORK_TYPE type, string addr)
 {
     return(await nodeServices.InvokeExportAsync <
                IEnumerable <TransactionHistoryItem> >(GetScriptLocation(), "GetTransactionHistory", GetNetwork(type), addr));
 }
Ejemplo n.º 20
0
 public async Task <Balance> GetBalance(NETWORK_TYPE type, string addr)
 {
     return(await nodeServices.InvokeExportAsync <Balance>(GetScriptLocation(), "GetBalance", GetNetwork(type), addr));
 }
Ejemplo n.º 21
0
 public void Init(Data.NETWORK_TYPE newNetworkType)
 {
     NetworkType = newNetworkType;
     LoadData();
 }
Ejemplo n.º 22
0
 public async Task <IEnumerable <TransactionHistoryItem> > GetTransactionHistory(NETWORK_TYPE network, string addr)
 {
     return(await _blockchain.GetTransactionHistory(network, addr));
 }
Ejemplo n.º 23
0
 public async Task <string> GetStorage(NETWORK_TYPE network, string scriptHash, string key)
 {
     return(await _blockchain.GetStorage(network, key));
 }
Ejemplo n.º 24
0
 void AgoraRtcEventHandler.OnNetworkTypeChanged(NETWORK_TYPE type)
 {
     OnNetworkTypeChanged?.Invoke(type);
 }
Ejemplo n.º 25
0
    // Use this for initialization
    void Start()
    {
        // 追加1126 システムの初期化をする(WinMainのInitApp)
        oulSystem.Initialize();

        // ネットワークメッセージ初期化
        MessageManager.Start(SelectData.isNetworkBattle);
        MessageManager.SetNetworkScene(this);

        // ネットワークオブジェクト取得
        networkManager = GameObject.Find("NetworkManager").GetComponent <oulNetwork>();
        networkManager.Restart();

        networkType = SelectData.networkType;

        // ホストかクライアントかを起動
        if (networkType == NETWORK_TYPE.HOST)
        {
            // ホストウィンドウのプレイヤー名設定
            hostWindow.SetPlayerName(PlayerDataManager.GetPlayerData().playerName);
            // ホストウィンドウにプレイヤー表示
            hostWindow.SetPlayerActive(true);
            // IPアドレス表示
            TextIP.gameObject.SetActive(true);
            TextIP.text = "";
            {
                // ホスト名を取得する
                string hostname = Dns.GetHostName();

                // ホスト名からIPアドレスを取得する
                IPAddress[] adrList = Dns.GetHostAddresses(hostname);
                foreach (IPAddress address in adrList)
                {
                    // IPv4 のみを追加する
                    if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        TextIP.text += address.ToString() + "\r\n";
                    }
                }
            }

            // ネットワーク開始
            if (!networkManager.isNetworkActive)
            {
                client = networkManager.StartHost();
            }
        }
        if (networkType == NETWORK_TYPE.CLIENT)
        {
            // クライアントウィンドウのプレイヤー名設定
            clientWindow.SetPlayerName(PlayerDataManager.GetPlayerData().playerName);
            // クライアントウィンドウにプレイヤー表示
            clientWindow.SetPlayerActive(true);

            // ネットワーク開始
            if (!networkManager.isNetworkActive)
            {
                client = networkManager.StartClient2(PlayerDataManager.GetPlayerData().ip);
            }
        }

        // ステート初期化
        // ステートマシンの初期化や切り替えは最後に行う
        stateMachine = new BaseEntityStateMachine <SceneLobby>(this);

        stateMachine.globalState = SceneLobbyState.Global.GetInstance();
        stateMachine.ChangeState(SceneLobbyState.WaitConnection.GetInstance());
    }