示例#1
0
        private void PassParametersCheckbox_CheckedChanged(object sender, EventArgs e)
        {
            Engine.AutomationEngineInstance currentScriptEngine = new Engine.AutomationEngineInstance();
            var startFile = v_taskPath.ConvertToUserVariable(currentScriptEngine);

            var Sender = (CheckBox)sender;

            AssignmentsGridViewHelper.Visible = Sender.Checked;

            //load variables if selected and file exists
            if ((Sender.Checked) && (System.IO.File.Exists(startFile)))
            {
                Script.Script deserializedScript = Core.Script.Script.DeserializeFile(startFile);

                foreach (var variable in deserializedScript.Variables)
                {
                    DataRow[] foundVariables = v_VariableAssignments.Select("VariableName = '" + variable.VariableName + "'");
                    if (foundVariables.Length == 0)
                    {
                        v_VariableAssignments.Rows.Add(variable.VariableName, variable.VariableValue);
                    }
                }

                AssignmentsGridViewHelper.DataSource = v_VariableAssignments;


                for (int i = 0; i < AssignmentsGridViewHelper.Rows.Count - 1; i++)
                {
                    DataGridViewComboBoxCell returnComboBox = new DataGridViewComboBoxCell();
                    returnComboBox.Items.Add("Yes");
                    returnComboBox.Items.Add("No");
                    AssignmentsGridViewHelper.Rows[i].Cells[2] = returnComboBox;
                }
            }
        }
示例#2
0
        public ScriptEditorDialog(KeyObject keyObject, Script.Script script)
        {
            _ori_keyObject = keyObject;
            KeyObject      = keyObject.Clone();
            Script         = script;

            InitializeComponent();
            InitializeForm();
            InitializeMenu();
            RefreshView();
        }
示例#3
0
 public static void ValidateSLPScriptHeader(Script.Script script)
 {
     // validate SLP format
     Token.ValidateSLPScriptHeader(script);
     // check version number
     if (script.DataChunks[1].Length != 1 || script.DataChunks[1][0] != 1)
     {
         throw new InvalidSLPScriptException("SLP version violates spec - expected 1 or 2 bytes, but received " +
                                             script.DataChunks[1].Length + ".");
     }
 }
示例#4
0
 public static bool DoesScriptHaveValidHeader(Script.Script script)
 {
     try
     {
         ValidateSLPScriptHeader(script);
         return(true);
     }
     catch (InvalidSLPScriptException)
     {
         return(false);
     }
 }
示例#5
0
        public void Initialize(Service service)
        {
            Script = service.GetScript();
            var runtimes = Script.GetRuntimes();

            for (int i = 0; i < runtimes.Count; i++)
            {
                if (runtimes[i].GetType() == typeof(VirtualInputRuntime))
                {
                    Runtime = (VirtualInputRuntime)runtimes[i];
                }
            }
        }
示例#6
0
        /// <summary>
        ///     ReadScript
        /// </summary>
        /// <param name="script"></param>
        /// <exception cref="InvalidSLPScriptException"></exception>
        public static void ValidateSLPScriptHeader(Script.Script script)
        {
            /*
             *  <lokad_id: 'SLP\x00'> (4 bytes, ascii)
             *  <token_type: 1> (1 to 2 byte integer)
             */
            if (script.OpCodes.Count < 1 || !script.OpCodes[0].Equals(OpCodeType.OP_RETURN))
            {
                throw new InvalidSLPScriptException("Script is not an op_return");
            }

            if (script.OpCodes.Count < 2 || !script.OpCodes[1].Equals(OpCodeType.OP_DATA) ||
                script.DataChunks.Count < 1)
            {
                throw new InvalidSLPScriptException(
                          "Script is not an SLP op_return. Header is missing.");
            }

            if (script.DataChunks[0].Length != 4)
            {
                throw new InvalidSLPScriptException(
                          "Script is not an SLP op_return. Wrong header - expected 4 bytes, but received " +
                          script.DataChunks[0].Length + ".");
            }

            if (!script.DataChunks[0].SequenceEqual(OpReturnPrefix))
            {
                throw new InvalidSLPScriptException(
                          "Script is not an SLP op_return. Wrong header - expected 0x504c5300, but received " +
                          ByteHexConverter.ByteArrayToHex(script.DataChunks[0]) + ".");
            }

            if (script.DataChunks.Count == 1)
            {
                throw new InvalidSLPScriptException("Script is missing SLP token_type.");
            }


            if (script.DataChunks[1].Length != 1 && script.DataChunks[1].Length != 2)
            {
                throw new InvalidSLPScriptException("SLP version violates spec - expected 1 or 2 bytes, but received " +
                                                    script.DataChunks[1].Length + ".");
            }

            // make sure the script contains only push opcodes, data, and the op_return
            if (script.OpCodes.Where(x => x != OpCodeType.OP_DATA).Count() > 1)
            {
                throw new InvalidSLPScriptException("Script contains invalid op_codes! Invalid codes found: " +
                                                    string.Join(", ", script.OpCodes.Where(x => x != OpCodeType.OP_DATA)));
            }
        }
示例#7
0
        private void PassParametersCheckbox_CheckedChanged(object sender, EventArgs e)
        {
            var Sender = (CheckBox)sender;

            AssignmentsGridViewHelper.Visible = Sender.Checked;

            //load variables if selected and file exists
            if ((Sender.Checked) && (System.IO.File.Exists(v_taskPath)))
            {
                Script.Script deserializedScript = Core.Script.Script.DeserializeFile(v_taskPath);

                foreach (var variable in deserializedScript.Variables)
                {
                    DataRow[] foundVariables = v_VariableAssignments.Select("VariableName = '" + variable.VariableName + "'");
                    if (foundVariables.Length == 0)
                    {
                        v_VariableAssignments.Rows.Add(variable.VariableName, variable.VariableValue);
                    }
                }


                AssignmentsGridViewHelper.DataSource = v_VariableAssignments;
            }
        }
示例#8
0
        /// <summary>
        ///     ReadScript
        /// </summary>
        /// <param name="script"></param>
        /// <exception cref="InvalidSLPScriptException"></exception>
        public static TokenType1Message ReadSLPScript(Script.Script script)
        {
            /*
             *  <lokad_id: 'SLP\x00'> (4 bytes, ascii)
             *  <token_type: 1> (1 to 2 byte integer)
             */
            ValidateSLPScriptHeader(script);

            if (script.DataChunks.Count == 2)
            {
                throw new InvalidSLPScriptException("Script is missing an SLP command in the 3rd data chunk.");
            }


            if (!new[] { 4, 6, 7 }.Contains(script.DataChunks[2].Length))
            {
                throw new InvalidSLPScriptException(
                          "SLP command is invalid length. Excepted 4, 6, or 7 ASCII characters, but received " +
                          script.DataChunks[2].Length);
            }

            if (!IsValidAscii(script.DataChunks[2]))
            {
                throw new InvalidSLPScriptException(
                          "SLP command is invalid. Excepted ASCII, but received non-ASCII characters.");
            }

            TransactionType type;

            if (!Enum.TryParse(Encoding.ASCII.GetString(script.DataChunks[2]), out type))
            {
                throw new InvalidSLPScriptException("SLP command is invalid. Excepted " +
                                                    string.Join(", ", Enum.GetNames(typeof(TransactionType))) +
                                                    "; but received " + Encoding.ASCII.GetString(script.DataChunks[2]) +
                                                    ".");
            }

            switch (type)
            {
            case TransactionType.GENESIS:
                if (script.DataChunks.Count != 10)
                {
                    throw new InvalidSLPScriptException(
                              "Script contains incorrect number of data chunks for GENESIS operations. Expected 10, but received " +
                              script.DataChunks.Count + ".");
                }

                // first 3 params after header (first 5 params) require no validation:
                // token_ticker, token_name, token_document_url can be any value of any length

                // token_document_hash must be 0 or 32 bytes
                if (script.DataChunks[6].Length != 0 && script.DataChunks[6].Length != 32)
                {
                    throw new InvalidSLPScriptException(
                              "Invalid GENESIS Message. Expected TokenDocumentHash with 0 or 32 bytes, but received " +
                              script.DataChunks[6].Length);
                }
                // decimals must be between 0 and 9
                if (script.DataChunks[7].Length != 1)
                {
                    throw new ArgumentException("Invalid digits after decimal! Expected 1 byte but received " +
                                                script.DataChunks[7].Length + " bytes.");
                }
                if (script.DataChunks[7][0] > 9)
                {
                    throw new ArgumentException(
                              "Invalid digits after decimal! Expected 0-9 inclusive, but received " +
                              (int)script.DataChunks[7][0] + ".");
                }
                // mint_baton_vout can be 0 or 1 bytes, but must not equal 1
                if (script.DataChunks[8].Length > 1)
                {
                    throw new ArgumentException("Invalid MintBatonVOut! Expected 0 or 1 bytes but received " +
                                                script.DataChunks[8].Length + " bytes.");
                }
                if (script.DataChunks[8].Length == 1 &&
                    (script.DataChunks[8][0] == 1 || script.DataChunks[8][0] == 0))
                {
                    throw new ArgumentException("Invalid MintBatonVOut! Expected 0x02-0xff inclusive received " +
                                                (int)script.DataChunks[8][0] + ".");
                }
                // initial_token_mint_quantity must be 8 bytes
                if (script.DataChunks[9].Length != 8)
                {
                    throw new ArgumentException("Invalid InitialTokenMintQuantity! Expected 8 bytes but received " +
                                                script.DataChunks[8].Length + " bytes.");
                }

                // validation passed, so decode and return
                return(new TokenType1Message.GenesisMessage(script.DataChunks));

            case TransactionType.SEND:
                // minimum 2 fields, maximum 20 (19 outputs)
                if (script.DataChunks.Count < 5 || script.DataChunks.Count > 23)
                {
                    throw new InvalidSLPScriptException(
                              "Script contains incorrect number of data chunks for SEND operations. Expected 5-23 inclusive, but received " +
                              script.DataChunks.Count + ".");
                }
                // token_id must be 32 bytes
                if (script.DataChunks[3].Length != 32)
                {
                    throw new InvalidSLPScriptException("Invalid TokenId! Expected 32 bytes, but received " +
                                                        script.DataChunks[4].Length + " bytes.");
                }
                // there can be anywhere from 1 to 19 outputs, each must be 8 bytes
                for (var i = 4; i < script.DataChunks.Count; i++)
                {
                    if (script.DataChunks[i].Length != 8)
                    {
                        throw new InvalidSLPScriptException(
                                  "Invalid TokenOutputQuantity" + i + "! Expected 8 bytes, but received " +
                                  script.DataChunks[i].Length + " bytes.");
                    }
                }

                // validation passed, so decode and return
                return(new TokenType1Message.SendMessage(script.DataChunks));

            case TransactionType.MINT:
                if (script.DataChunks.Count != 6)
                {
                    throw new InvalidSLPScriptException(
                              "Script contains incorrect number of data chunks for SEND operations. Expected 6, but received " +
                              script.DataChunks.Count + ".");
                }

                // token_id must be 32 bytes
                if (script.DataChunks[3].Length != 32)
                {
                    throw new InvalidSLPScriptException("Invalid TokenId! Expected 32 bytes, received " +
                                                        script.DataChunks[4].Length + " bytes.");
                }
                // mint_baton_vout can be 0 or 1 bytes, but must not equal 1
                if (script.DataChunks[4].Length > 1)
                {
                    throw new ArgumentException("Invalid MintBatonVOut! Expected 0 or 1 bytes but received " +
                                                script.DataChunks[5].Length + " bytes.");
                }
                if (script.DataChunks[4].Length == 1 &&
                    (script.DataChunks[4][0] == 1 || script.DataChunks[4][0] == 0))
                {
                    throw new ArgumentException("Invalid MintBatonVOut! Expected 0x02-0xff inclusive received " +
                                                (int)script.DataChunks[4][0] + ".");
                }
                // additional_token_quantity must be 8 bytes
                if (script.DataChunks[5].Length != 8)
                {
                    throw new ArgumentException("Invalid AdditionalTokenQuantity! Expected 8 bytes but received " +
                                                script.DataChunks[5].Length + " bytes.");
                }

                // validation passed, so decode and return
                return(new TokenType1Message.MintMessage(script.DataChunks));

            case TransactionType.COMMIT:
                if (script.DataChunks.Count != 8)
                {
                    throw new InvalidSLPScriptException(
                              "Script contains incorrect number of data chunks for COMMIT operations. Expected 8, but received " +
                              script.DataChunks.Count + ".");
                }

                // token_id must be 32 bytes
                if (script.DataChunks[3].Length != 32)
                {
                    throw new InvalidSLPScriptException("Invalid TokenId! Expected 32 bytes, received " +
                                                        script.DataChunks[4].Length + " bytes.");
                }
                // for_bitcoin_block_hash must be 32 bytes
                if (script.DataChunks[4].Length != 32)
                {
                    throw new InvalidSLPScriptException("Invalid ForBitcoinBlockHash! Expected 32 bytes, received " +
                                                        script.DataChunks[4].Length + " bytes.");
                }
                // block_height must be 8 bytes
                if (script.DataChunks[5].Length != 8)
                {
                    throw new ArgumentException("Invalid BlockHeight! Expected 8 bytes but received " +
                                                script.DataChunks[5].Length + " bytes.");
                }
                // token_txn_set_hash must be 32 bytes
                if (script.DataChunks[6].Length != 32)
                {
                    throw new InvalidSLPScriptException("Invalid TokenTransactionSetHash! Expected 32 bytes, received " +
                                                        script.DataChunks[6].Length + " bytes.");
                }
                // txn_set_data_url requires no validation

                // validation passed, so decode and return
                return(new TokenType1Message.CommitMessage(script.DataChunks));

            default:
                // cannot happen (already validated)
                throw new ArgumentOutOfRangeException(nameof(script.DataChunks), "Invalid Transaction Type");
            }
        }