コード例 #1
0
        public static void ValidContractProto(List <Transaction> transactions)
        {
            List <Task <bool> > tasks = new List <Task <bool> >();

            transactions.ForEach(tx =>
            {
                Task <bool> task = Task.Run(() =>
                {
                    try
                    {
                        ValidContractProto(tx.RawData.Contract[0]);
                        return(true);
                    }
                    catch (System.Exception e)
                    {
                        Logger.Error(e.Message);
                    }
                    return(false);
                });
                tasks.Add(task);
            });

            foreach (Task <bool> task in tasks)
            {
                if (!task.Result)
                {
                    throw new P2pException(
                              P2pException.ErrorType.PROTOBUF_ERROR,
                              P2pException.GetDescription(P2pException.ErrorType.PROTOBUF_ERROR));
                }
            }
        }
コード例 #2
0
 public static void CompareBytes(byte[] src, byte[] dst)
 {
     if (src.Length != dst.Length)
     {
         throw new P2pException(
                   P2pException.ErrorType.PROTOBUF_ERROR,
                   P2pException.GetDescription(P2pException.ErrorType.PROTOBUF_ERROR)
                   );
     }
 }
コード例 #3
0
        public static void ValidContractProto(Transaction.Types.Contract contract)
        {
            System.Type type = null;
            Any         contract_parameter = contract.Parameter;

            Google.Protobuf.IMessage src = null;
            Google.Protobuf.IMessage contract_message = null;

            switch (contract.Type)
            {
            case ContractType.AccountCreateContract:
                src = contract_parameter.Unpack <AccountCreateContract>();
                contract_message = Parse <AccountCreateContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.TransferContract:
                src = contract_parameter.Unpack <TransferContract>();
                contract_message = Parse <TransferContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.TransferAssetContract:
                src = contract_parameter.Unpack <TransferAssetContract>();
                contract_message = Parse <TransferAssetContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.VoteAssetContract:
                src = contract_parameter.Unpack <VoteAssetContract>();
                contract_message = Parse <VoteAssetContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.VoteWitnessContract:
                src = contract_parameter.Unpack <VoteWitnessContract>();
                contract_message = Parse <VoteWitnessContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.WitnessCreateContract:
                src = contract_parameter.Unpack <WitnessCreateContract>();
                contract_message = Parse <WitnessCreateContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.AssetIssueContract:
                src = contract_parameter.Unpack <AssetIssueContract>();
                contract_message = Parse <AssetIssueContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.WitnessUpdateContract:
                src = contract_parameter.Unpack <WitnessUpdateContract>();
                contract_message = Parse <WitnessUpdateContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.ParticipateAssetIssueContract:
                src = contract_parameter.Unpack <ParticipateAssetIssueContract>();
                contract_message = Parse <ParticipateAssetIssueContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.AccountUpdateContract:
                src = contract_parameter.Unpack <AccountUpdateContract>();
                contract_message = Parse <AccountUpdateContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.FreezeBalanceContract:
                src = contract_parameter.Unpack <FreezeBalanceContract>();
                contract_message = Parse <FreezeBalanceContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.UnfreezeBalanceContract:
                src = contract_parameter.Unpack <UnfreezeBalanceContract>();
                contract_message = Parse <UnfreezeBalanceContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.UnfreezeAssetContract:
                src = contract_parameter.Unpack <UnfreezeAssetContract>();
                contract_message = Parse <UnfreezeAssetContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.WithdrawBalanceContract:
                src = contract_parameter.Unpack <WithdrawBalanceContract>();
                contract_message = Parse <WithdrawBalanceContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.CreateSmartContract:
                src = contract_parameter.Unpack <CreateSmartContract>();
                contract_message = Parse <CreateSmartContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.TriggerSmartContract:
                src = contract_parameter.Unpack <TriggerSmartContract>();
                contract_message = Parse <TriggerSmartContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.UpdateAssetContract:
                src = contract_parameter.Unpack <UpdateAssetContract>();
                contract_message = Parse <UpdateAssetContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.ProposalCreateContract:
                src = contract_parameter.Unpack <ProposalCreateContract>();
                contract_message = Parse <ProposalCreateContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.ProposalApproveContract:
                src = contract_parameter.Unpack <ProposalApproveContract>();
                contract_message = Parse <ProposalApproveContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.ProposalDeleteContract:
                src = contract_parameter.Unpack <ProposalDeleteContract>();
                contract_message = Parse <ProposalDeleteContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.SetAccountIdContract:
                src = contract_parameter.Unpack <SetAccountIdContract>();
                contract_message = Parse <SetAccountIdContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.UpdateSettingContract:
                src = contract_parameter.Unpack <UpdateSettingContract>();
                contract_message = Parse <UpdateSettingContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.UpdateEnergyLimitContract:
                src = contract_parameter.Unpack <UpdateEnergyLimitContract>();
                contract_message = Parse <UpdateEnergyLimitContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.ClearAbicontract:
                src = contract_parameter.Unpack <ClearABIContract>();
                contract_message = Parse <ClearABIContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.ExchangeCreateContract:
                src = contract_parameter.Unpack <ExchangeCreateContract>();
                contract_message = Parse <ExchangeCreateContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.ExchangeInjectContract:
                src = contract_parameter.Unpack <ExchangeInjectContract>();
                contract_message = Parse <ExchangeInjectContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.ExchangeWithdrawContract:
                src = contract_parameter.Unpack <ExchangeWithdrawContract>();
                contract_message = Parse <ExchangeWithdrawContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.ExchangeTransactionContract:
                src = contract_parameter.Unpack <ExchangeTransactionContract>();
                contract_message = Parse <ExchangeTransactionContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            case ContractType.AccountPermissionUpdateContract:
                src = contract_parameter.Unpack <AccountPermissionUpdateContract>();
                contract_message = Parse <AccountPermissionUpdateContract>(Message.GetCodedInputStream(src.ToByteArray()));
                break;

            default:
                break;
            }

            if (type == null)
            {
                throw new P2pException(P2pException.ErrorType.PROTOBUF_ERROR, P2pException.GetDescription(P2pException.ErrorType.PROTOBUF_ERROR));
            }

            Message.CompareBytes(src.ToByteArray(), contract_message.ToByteArray());
        }