public static bool OnGetBlockById(JToken id, string method, JArray parameters, out JToken result) { result = new JObject(); if (parameters == null || parameters.Count != 1) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, "Invalid parameters"); return(false); } try { SHA256Hash hash = SHA256Hash.Wrap(parameters[0].ToString().HexToBytes()); BlockCapsule block = Manager.Instance.DBManager.GetBlockById(hash); BlockExtention block_extention = RpcApiService.CreateBlockExtention(block); result = JToken.FromObject(block_extention.ToByteArray()); } catch (System.Exception e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.UNKNOWN_ERROR, e.Message); return(false); } return(true); }
public static bool OnGetBlockByLimitNext(JToken id, string method, JArray parameters, out JToken result) { result = new JObject(); if (parameters == null || parameters.Count != 1) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, "Invalid parameters"); return(false); } try { BlockLimit limit = BlockLimit.Parser.ParseFrom(parameters[0].ToObject <byte[]>()); BlockListExtention blocks = new BlockListExtention(); Manager.Instance.DBManager.Block.GetLimitNumber(limit.StartNum, limit.EndNum - limit.StartNum).ForEach(block => { blocks.Block.Add(RpcApiService.CreateBlockExtention(block)); }); result = JToken.FromObject(blocks.ToByteArray()); } catch (System.Exception e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.UNKNOWN_ERROR, e.Message); return(false); } return(true); }
public static bool OnGetBlock(JToken id, string method, JArray parameters, out JToken result) { result = new JObject(); if (parameters == null || parameters.Count != 1) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, "Invalid parameters"); return(false); } try { BlockCapsule block = Manager.Instance.DBManager.GetBlockByNum(parameters[0].Value <long>()); result = JToken.FromObject(RpcApiService.CreateBlockExtention(block).ToByteArray()); } catch (InvalidCastException e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, e.Message); return(false); } catch (System.Exception e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.UNKNOWN_ERROR, e.Message); return(false); } return(true); }
public static bool OnGetBlockByLatestNum(JToken id, string method, JArray parameters, out JToken result) { result = new JObject(); if (parameters == null || parameters.Count != 0) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, "Invalid parameters"); return(false); } try { List <BlockCapsule> blocks = Manager.Instance.DBManager.Block.GetBlockByLatestNum(1); if (blocks == null || blocks.Count == 0) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INTERNAL_ERROR, "Can not load latest block."); } BlockExtention block_extention = RpcApiService.CreateBlockExtention(blocks[0]); result = JToken.FromObject(block_extention.ToByteArray()); } catch (InvalidCastException e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, e.Message); return(false); } catch (System.Exception e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.UNKNOWN_ERROR, e.Message); return(false); } return(true); }
public static bool OnAssetIssueListByName(JToken id, string method, JArray parameters, out JToken result) { result = new JObject(); if (parameters == null || parameters.Count != 1) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, "Invalid parameters"); return(false); } try { byte[] name = Encoding.UTF8.GetBytes(parameters[0].ToString()); AssetIssueList asset_issue_list = RpcApiService.GetAssetIssueListByName(name); result = JToken.FromObject(asset_issue_list.ToByteArray()); } catch (NonUniqueObjectException e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INTERNAL_ERROR, e.Message); return(false); } catch (ArgumentException e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, e.Message); return(false); } catch (System.Exception e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.UNKNOWN_ERROR, e.Message); return(false); } return(true); }
public static bool OnListExchangePaginated(JToken id, string method, JArray parameters, out JToken result) { result = new JObject(); if (parameters == null || parameters.Count != 2) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, "Invalid parameters"); return(false); } try { int offset = parameters[0].ToObject <int>(); int limit = parameters[1].ToObject <int>(); ExchangeList exchanges = RpcApiService.GetListExchangePaginated(offset, limit); result = JToken.FromObject(exchanges.ToByteArray()); } catch (ArgumentException e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, e.Message); return(false); } catch (System.Exception e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.UNKNOWN_ERROR, e.Message); return(false); } return(true); }
public static bool OnGetTransactionInfoById(JToken id, string method, JArray parameters, out JToken result) { result = new JObject(); if (parameters == null || parameters.Count != 1) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, "Invalid parameters"); return(false); } try { SHA256Hash hash = SHA256Hash.Wrap(parameters[0].ToString().HexToBytes()); TransactionInfo transaction = RpcApiService.GetTransactionInfoById(hash); result = JToken.FromObject(transaction.ToByteArray()); } catch (ItemNotFoundException e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.NOT_FOUN_ITEM, e.Message); return(false); } catch (System.Exception e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.UNKNOWN_ERROR, e.Message); return(false); } return(true); }
public static bool OnAssetIssueByAccount(JToken id, string method, JArray parameters, out JToken result) { result = new JObject(); if (parameters == null || parameters.Count != 1) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, "Invalid parameters"); return(false); } try { byte[] address = Wallet.Base58ToAddress(parameters[0].ToString()); AssetIssueList asset_issue_list = RpcApiService.GetAssetIssueListByAddress(address); result = JToken.FromObject(asset_issue_list); } catch (ArgumentException e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, e.Message); return(false); } catch (System.Exception e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.UNKNOWN_ERROR, e.Message); return(false); } return(true); }
public static bool OnGetTransactionCountByBlockNum(JToken id, string method, JArray parameters, out JToken result) { result = new JObject(); if (parameters == null || parameters.Count != 1) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, "Invalid parameters"); return(false); } try { long block_num = parameters[0].ToObject <long>(); int count = RpcApiService.GetTransactionCountByBlockNum(block_num); NumberMessage message = new NumberMessage() { Num = count }; result = JToken.FromObject(message.ToByteArray()); } catch (ItemNotFoundException e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.NOT_FOUN_ITEM, e.Message); return(false); } catch (System.Exception e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.UNKNOWN_ERROR, e.Message); return(false); } return(true); }
public static bool OnGetTransactionApprovedList(JToken id, string method, JArray parameters, out JToken result) { result = new JObject(); if (parameters == null || parameters.Count != 1) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, "Invalid parameters"); return(false); } try { Transaction transaction = Transaction.Parser.ParseFrom(parameters[0].ToObject <byte[]>()); TransactionApprovedList approved = RpcApiService.GetTransactionApprovedList(transaction); result = JToken.FromObject(approved.ToByteArray()); } catch (System.Exception e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.UNKNOWN_ERROR, e.Message); return(false); } return(true); }
public static bool OnListWitness(JToken id, string method, JArray parameters, out JToken result) { result = new JObject(); if (parameters == null || parameters.Count != 0) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, "Invalid parameters"); return(false); } try { result = JToken.FromObject(RpcApiService.GetListWitness().ToByteArray()); } catch (InvalidCastException e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, e.Message); return(false); } catch (FormatException e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, e.Message); return(false); } catch (System.Exception e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.UNKNOWN_ERROR, e.Message); return(false); } return(true); }
public static bool OnGetAccount(JToken id, string method, JArray parameters, out JToken result) { result = new JObject(); if (parameters == null || parameters.Count != 1) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, "Invalid parameters"); return(false); } try { byte[] address = Wallet.Base58ToAddress(parameters[0].Value <string>()); Account account = RpcApiService.GetAccount(address); result = (account != null) ? JToken.FromObject(account.ToByteArray()) : null; } catch (InvalidCastException e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, e.Message); return(false); } catch (FormatException e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, e.Message); return(false); } catch (System.Exception e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.UNKNOWN_ERROR, e.Message); return(false); } return(true); }
public static bool OnBroadcastTransaction(JToken id, string method, JArray parameters, out JToken result) { result = new JObject(); if (parameters == null || parameters.Count != 1) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, "Invalid parameters"); return(false); } Transaction transaction = Transaction.Parser.ParseFrom(parameters[0].ToObject <byte[]>()); Return ret = RpcApiService.BroadcastTransaction(transaction); result = JToken.FromObject(ret.ToByteArray()); return(true); }
public static bool OnGetTotalTransaction(JToken id, string method, JArray parameters, out JToken result) { result = new JObject(); if (parameters == null || parameters.Count != 0) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, "Invalid parameters"); return(false); } try { NumberMessage message = RpcApiService.GetTotalTransaction(); result = JToken.FromObject(message.ToByteArray()); } catch (System.Exception e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.UNKNOWN_ERROR, e.Message); return(false); } return(true); }
public static bool OnCreateContract(JToken id, string method, JArray parameters, out JToken result) { result = new JObject(); if (parameters == null || parameters.Count != 2) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, "Invalid parameters"); return(false); } try { IMessage contract = null; ContractType contract_type = (ContractType)parameters[0].ToObject <int>(); switch (contract_type) { case ContractType.AccountCreateContract: contract = AccountCreateContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.TransferContract: contract = TransferContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.TransferAssetContract: contract = TransferAssetContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.VoteAssetContract: contract = VoteAssetContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.VoteWitnessContract: contract = VoteWitnessContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.WitnessCreateContract: contract = WitnessCreateContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.AssetIssueContract: contract = AssetIssueContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.WitnessUpdateContract: contract = WitnessUpdateContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.ParticipateAssetIssueContract: contract = ParticipateAssetIssueContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.AccountUpdateContract: contract = AccountUpdateContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.FreezeBalanceContract: contract = FreezeBalanceContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.UnfreezeBalanceContract: contract = UnfreezeBalanceContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.WithdrawBalanceContract: contract = WithdrawBalanceContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.UnfreezeAssetContract: contract = UnfreezeAssetContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.UpdateAssetContract: contract = UpdateAssetContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.ProposalCreateContract: contract = ProposalCreateContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.ProposalApproveContract: contract = ProposalApproveContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.ProposalDeleteContract: contract = ProposalDeleteContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.SetAccountIdContract: contract = SetAccountIdContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.CreateSmartContract: contract = CreateSmartContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.TriggerSmartContract: contract = TriggerSmartContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.UpdateSettingContract: contract = UpdateSettingContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.ExchangeCreateContract: contract = ExchangeCreateContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.ExchangeInjectContract: contract = ExchangeInjectContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.ExchangeWithdrawContract: contract = ExchangeWithdrawContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.ExchangeTransactionContract: contract = ExchangeTransactionContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.UpdateEnergyLimitContract: contract = UpdateEnergyLimitContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.AccountPermissionUpdateContract: contract = AccountPermissionUpdateContract.Parser.ParseFrom(parameters[1].ToObject <byte[]>()); break; case ContractType.CustomContract: case ContractType.GetContract: case ContractType.ClearAbicontract: default: break; } TransactionExtention transaction_extention = RpcApiService.CreateTransactionExtention(contract, contract_type); result = JToken.FromObject(transaction_extention.ToByteArray()); } catch (System.Exception e) { result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, e.Message); return(false); } return(true); }