Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public static RpcApiResult GetTransactionApprovedList(Transaction transaction, out TransactionApprovedList transaction_list)
        {
            transaction_list = null;

            try
            {
                JObject receive = SendCommand(RpcCommand.Transaction.GetTransactionApprovedList, new JArray()
                {
                    transaction.ToByteArray()
                });
                if (receive.TryGetValue("error", out JToken value))
                {
                    return(new RpcApiResult(false, value["code"].ToObject <int>(), value["message"].ToObject <string>()));
                }

                transaction_list = TransactionApprovedList.Parser.ParseFrom(receive["result"].ToObject <byte[]>());
            }
            catch (System.Exception e)
            {
                throw e;
            }

            return(RpcApiResult.Success);
        }
Ejemplo n.º 3
0
        public static TransactionApprovedList GetTransactionApprovedList(Transaction transaction)
        {
            TransactionExtention transaction_extention = new TransactionExtention()
            {
                Transaction = transaction,
                Txid        = ByteString.CopyFrom(SHA256Hash.ToHash(transaction.RawData.ToByteArray())),
                Result      = new Return()
                {
                    Result = true,
                    Code   = Return.Types.response_code.Success
                }
            };

            TransactionApprovedList approved = new TransactionApprovedList()
            {
                Transaction = transaction_extention
            };

            try
            {
                Contract       contract      = transaction.RawData.Contract[0];
                byte[]         owner_address = TransactionCapsule.GetOwner(contract);
                AccountCapsule account       = Manager.Instance.DBManager.Account.Get(owner_address);
                if (account == null)
                {
                    throw new PermissionException("Account is not exist.");
                }

                if (transaction.Signature.Count > 0)
                {
                    byte[] hash = SHA256Hash.ToHash(transaction.RawData.ToByteArray());
                    foreach (var signature in transaction.Signature)
                    {
                        if (signature.Count() < 65)
                        {
                            throw new SignatureFormatException("Signature size is " + signature.Count());
                        }

                        byte[] signature_address = ECKey.SignatureToAddress(hash, ECDSASignature.ExtractECDSASignature(signature.ToByteArray()));
                        approved.ApprovedList.Add(ByteString.CopyFrom(signature_address));
                    }
                }
                approved.Result = new TransactionApprovedList.Types.Result()
                {
                    Code = TransactionApprovedList.Types.Result.Types.response_code.Success
                };
            }
            catch (SignatureFormatException e)
            {
                approved.Result = new TransactionApprovedList.Types.Result()
                {
                    Code    = TransactionApprovedList.Types.Result.Types.response_code.SignatureFormatError,
                    Message = e.Message
                };
            }
            catch (SignatureException e)
            {
                approved.Result = new TransactionApprovedList.Types.Result()
                {
                    Code    = TransactionApprovedList.Types.Result.Types.response_code.ComputeAddressError,
                    Message = e.Message
                };
            }
            catch (System.Exception e)
            {
                approved.Result = new TransactionApprovedList.Types.Result()
                {
                    Code    = TransactionApprovedList.Types.Result.Types.response_code.OtherError,
                    Message = e.Message
                };
            }

            return(approved);
        }