public async Task <MessageOM> SignMessage(string address, string message) { AuthenticationHeaderValue authHeaderValue = null; RpcClient client = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json"); RpcRequest request = RpcRequest.WithParameterList("SignMessage", new List <object> { address, message }, 1); RpcResponse response = await client.SendRequestAsync(request); if (response.HasError) { throw new ApiCustomException(response.Error.Code, response.Error.Message); } MessageOM responseValue = response.GetResult <MessageOM>(); return(responseValue); }
public static async Task <ApiResponse> SignMessage(string address, string message) { ApiResponse response = new ApiResponse(); try { BlockChainEngine engine = new BlockChainEngine(); MessageOM result = await engine.SignMessage(address, message); Message entity = new Message(); entity.PublicKey = result.PublicKey; entity.Signature = result.Signature; if (result != null) { response.Result = Newtonsoft.Json.Linq.JToken.FromObject(entity); } else { response.Result = null; } return(response); } catch (ApiCustomException ex) { Logger.Singleton.Error(ex.ToString()); Logger.Singleton.Error("Api error code is:" + ex.ErrorCode.ToString()); Logger.Singleton.Error("Api error reason is:" + ex.InnerException.ToString()); response.Error = new ApiError(ex.ErrorCode, ex.ToString()); } catch (Exception ex) { Logger.Singleton.Error(ex.ToString()); Logger.Singleton.Error("Custom error code is:" + ex.HResult); Logger.Singleton.Error("Custom error reason is:" + ex.InnerException); response.Error = new ApiError(ex.HResult, ex.ToString()); } return(response); }