/// <summary> API call. </summary> /// /// <remarks> Paul, 19/10/2015. </remarks> /// /// <typeparam name="T"> Generic type parameter. </typeparam> /// <param name="method"> The method. </param> /// <param name="args"> A variable-length parameters list containing arguments. </param> /// /// <returns> A Task<T> </returns> async public Task <T> ApiCall <T>(GrapheneMethods method, GrapheneApi api, params object[] args) { TaskCompletionSource <T> task = new TaskCompletionSource <T>(); EventHandler <string> onMessage = null; int id = -1; onMessage = (object sender, string message) => { GrapheneSocketResponse <T> decoded = JsonSerializer.DeserializeFromString <GrapheneSocketResponse <T> >(message); if (decoded.id == id) { m_socket.OnMessage -= onMessage; if (decoded.error != null) { task.SetException(new GrapheneRpcException(new GrapheneError { message = decoded.error })); } else { task.SetResult(decoded.result); } } }; m_socket.OnMessage += onMessage; id = m_socket.Send(method, m_apiMap[api], args); return(await task.Task); }
public GrapheneRequest(GrapheneMethods method, params object[] @params) { this.jsonrpc = 2; this.id = 1; this.method = method; this.@params = @params; }
public int Send(GrapheneMethods method, int api, params object[] args) { GrapheneSocketRequest r = new GrapheneSocketRequest(method, m_id++, api, args); string request = JsonSerializer.SerializeToString<GrapheneSocketRequest>(r); m_socket.Send(request); return m_id - 1; }
public GrapheneSocketRequest(GrapheneMethods method, int id, int api, params object[] @params) { this.id = id; this.method = "call"; object[] fudgeParams = { api, method, @params }; this.@params = fudgeParams; }
public int Send(GrapheneMethods method, int api, params object[] args) { GrapheneSocketRequest r = new GrapheneSocketRequest(method, m_id++, api, args); string request = JsonSerializer.SerializeToString <GrapheneSocketRequest>(r); m_socket.Send(request); return(m_id - 1); }
/// <summary> API call synchronise. </summary> /// /// <remarks> Paul, 23/10/2015. </remarks> /// /// <typeparam name="T"> Generic type parameter. </typeparam> /// <param name="method"> The method. </param> /// <param name="args"> A variable-length parameters list containing arguments. </param> /// /// <returns> A T. </returns> public T ApiCallSync <T>(GrapheneMethods method, GrapheneApi api, params object[] args) { int outer = System.Threading.Thread.CurrentThread.ManagedThreadId; Task <T> t = Task.Run <T>(() => { if (System.Threading.Thread.CurrentThread.ManagedThreadId == outer) { throw new NotImplementedException(); } return(ApiCall <T>(method, api, args)); }); bool sucesss = t.Wait(kTimeoutSeconds * 1000); if (!sucesss) { throw new TimeoutException(); } return(t.Result); }
/// <summary> API call. </summary> /// /// <remarks> Paul, 20/10/2015. </remarks> /// /// <param name="method"> The method. </param> /// <param name="args"> A variable-length parameters list containing arguments. </param> /// /// <returns> A T. </returns> public T ApiCall <T>(GrapheneMethods method, GrapheneApi api, params object[] args) { return(m_cliWallet.ApiCallSync <T>(method, api, args)); }
/// <summary> API call. </summary> /// /// <remarks> Paul, 20/10/2015. </remarks> /// /// <param name="method"> The method. </param> /// <param name="args"> A variable-length parameters list containing arguments. </param> /// /// <returns> A T. </returns> public async Task <T> ApiCallAsync <T>(GrapheneMethods method, GrapheneApi api, params object[] args) { return(await m_cliWallet.ApiCall <T>(method, api, args)); }
/// <summary> API call blockchain. </summary> /// /// <remarks> Paul, 23/10/2015. </remarks> /// /// <typeparam name="T"> Generic type parameter. </typeparam> /// <param name="method"> The method. </param> /// <param name="args"> A variable-length parameters list containing arguments. </param> /// /// <returns> A T. </returns> public T ApiCallBlockchain <T>(GrapheneMethods method, GrapheneApi api, params object[] args) { return(m_blockchain.ApiCallSync <T>(method, api, args)); }