Esempio n. 1
0
        static Core()
	    {
            ABI = Yeppp.Library.ABI;
        }
Esempio n. 2
0
File: ABI.cs Progetto: silky/Spreads
 /// <summary>Compares for equality with another <see cref="ABI" /> object.</summary>
 /// <remarks>Comparison is performed by value.</remarks>
 public bool Equals(ABI other)
 {
     return(this.id == other.id);
 }
Esempio n. 3
0
		/// <summary>Compares for equality with another <see cref="ABI" /> object.</summary>
		/// <remarks>Comparison is performed by value.</remarks>
		public bool Equals(ABI other)
		{
			return this.id == other.id;
		}
        public bool LoadAvmFile(string avmPath)
        {
            //Decide what we need to open
            if (!String.IsNullOrEmpty(avmPath)) //use the explicit file provided
            {
                _avmFilePath = avmPath;
            }
            else if (!String.IsNullOrEmpty(Settings.lastOpenedFile)) //fallback to last opened
            {
                _avmFilePath = Settings.lastOpenedFile;
            }
            else
            {
                return(false); //We don't know what to open, just let the user specify with another call
            }
            //Housekeeping - let's find out what files we have and make sure we're good
            if (!File.Exists(_avmFilePath))
            {
                Log("File not found. " + avmPath);
                return(false);
            }

            _debugContent.Clear();

            _contractName     = Path.GetFileNameWithoutExtension(_avmFilePath);
            _contractByteCode = File.ReadAllBytes(_avmFilePath);
            _map = new NeoMapFile();
            try
            {
                avmDisassemble = NeoDisassembler.Disassemble(_contractByteCode);
                _disassembles[_contractByteCode] = avmDisassemble;
            }
            catch (DisassembleException e)
            {
                Log($"Disassembler Error: {e.Message}");
                return(false);
            }

            if (File.Exists(_abiFilePath))
            {
                _ABI = new ABI(_abiFilePath);
            }
            else
            {
                _ABI = new ABI();
                Log($"Warning: {_abiFilePath} was not found. Please recompile your AVM with the latest compiler.");
            }

            //Let's see if we have source code we can map
            if (File.Exists(_mapFilePath))
            {
                _map.LoadFromFile(_mapFilePath, _contractByteCode);
            }
            else
            {
                _map = null;

                if (File.Exists(_oldMapFilePath))
                {
                    Log("Old map file format found.  Please recompile your avm with the latest compiler.");
                }
                else
                {
                    Log($"Warning: Could not find {_mapFilePath}");
                }
            }

            if (_map != null)
            {
                foreach (var entry in _map.FileNames)
                {
                    if (string.IsNullOrEmpty(entry))
                    {
                        continue;
                    }

                    if (!File.Exists(entry))
                    {
                        Log($"Warning: Could not load the source code, check that this file exists: {entry}");
                        continue;
                    }

                    var sourceCode = File.ReadAllText(entry);
                    _debugContent[entry] = sourceCode;
                }
            }

            //We always should have the assembly content
            _debugContent[_avmFilePath] = avmDisassemble.ToString();

            //Save the settings
            Settings.lastOpenedFile = avmPath;
            Settings.Save();
            _avmFileLoaded = true;

            //Force a reset now that we're loaded
            _resetFlag = true;

            _currentFilePath = avmPath;

            return(true);
        }
Esempio n. 5
0
 /// <summary>
 /// Resolves an address-space-cast suffix.
 /// </summary>
 /// <param name="abi">The current ABI.</param>
 /// <returns>The resolved address-space-cast suffix.</returns>
 public static string GetAddressSpaceCastSuffix(ABI abi) =>
 AddressSpaceCastOperationSuffix[abi.PointerBasicValueType == BasicValueType.Int32 ? 0 : 1];
Esempio n. 6
0
        public List <ContractTrigger> ParseLogInfos(List <LogInfo> log_infos, IDeposit deposit)
        {
            List <ContractTrigger> triggers = new List <ContractTrigger>();

            if (log_infos == null || log_infos.Count <= 0)
            {
                return(triggers);
            }

            Dictionary <string, string> signs = new Dictionary <string, string>();
            Dictionary <string, string> abis  = new Dictionary <string, string>();

            foreach (LogInfo info in log_infos)
            {
                byte[] contract_address     = Wallet.ToAddAddressPrefix(info.Address);
                string contract_address_str = contract_address.IsNotNullOrEmpty() ?
                                              Wallet.AddressToBase58(contract_address) : "";


                if (signs.TryGetValue(contract_address_str, out _) == false)
                {
                    continue;
                }

                ContractCapsule contract = deposit.GetContract(contract_address);
                if (contract == null)
                {
                    signs.Add(contract_address_str, origin_address);
                    abis.Add(contract_address_str, "");
                    continue;
                }

                ABI    abi             = contract.Instance.Abi;
                string creator_address = Wallet.AddressToBase58(Wallet.ToAddAddressPrefix(contract.Instance.OriginAddress.ToByteArray()));
                signs.Add(contract_address_str, creator_address);

                if (abi != null && abi.Entrys.Count > 0)
                {
                    abis.Add(contract_address_str, JsonFormat.PrintToString(abi, false));
                }
                else
                {
                    abis.Add(contract_address_str, "");
                }
            }

            int index = 1;

            foreach (LogInfo info in log_infos)
            {
                byte[] contract_address     = Wallet.ToAddAddressPrefix(info.Address);
                string contract_address_str = contract_address.IsNotNullOrEmpty() ? Wallet.AddressToBase58(contract_address) : "";

                string          abi_value       = abis[contract_address_str];
                ContractTrigger trigger         = new ContractTrigger();
                string          creator_address = signs[contract_address_str];

                trigger.UniqueId        = this.transaction_id + "_" + index;
                trigger.TransactionId   = this.transaction_id;
                trigger.ContractAddress = contract_address_str;
                trigger.OriginAddress   = this.origin_address;
                trigger.CallerAddress   = "";
                trigger.CreatorAddress  = creator_address.IsNotNullOrEmpty() ? creator_address : "";
                trigger.BlockNumber     = this.block_num;
                trigger.Timestamp       = this.block_timestamp;
                trigger.LogInfo         = info;
                trigger.AbiString       = abi_value;

                triggers.Add(trigger);
                index++;
            }

            return(triggers);
        }
Esempio n. 7
0
        public void LoadDataFromFile(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            if (!File.Exists(path))
            {
                MessageBox.Show("Can't find '" + (String.IsNullOrEmpty(path) ? "(null)" : path + "'"), this.Text + " - " + Environment.CurrentDirectory);
            }
            else
            {
                MainForm.targetAVMPath = path;

                this.contractName = Path.GetFileNameWithoutExtension(path);

                this.contractBytecode = File.ReadAllBytes(path);

                var oldMapFileName = path.Replace(".avm", ".neomap");
                var newMapFileName = path.Replace(".avm", ".debug.json");

                debugMode      = DebugMode.Assembly;
                sourceLanguage = SourceLanguageKind.Other;

                if (File.Exists(newMapFileName))
                {
                    map = new NeoMapFile();
                    map.LoadFromFile(newMapFileName, contractBytecode);

                    this.contractName = map.contractName;
                }
                else
                {
                    if (File.Exists(oldMapFileName))
                    {
                        MessageBox.Show("Warning: The file format of debug map changed. Please recompile your AVM with the latest compiler.");
                    }
                    map = null;
                }

                string abiFilename = path.Replace(".avm", ".abi.json");
                if (File.Exists(abiFilename))
                {
                    abi = new ABI(abiFilename);
                }
                else
                {
                    MessageBox.Show($"Error: {abiFilename} was not found. Please recompile your AVM with the latest compiler.");
                    return;
                }

                this.debugger = null;
                this.avm_asm  = NeoDisassembler.Disassemble(contractBytecode);

                if (map != null && map.Entries.Any())
                {
                    var srcFile = map.Entries.FirstOrDefault().url;

                    if (string.IsNullOrEmpty(srcFile))
                    {
                        MessageBox.Show("Error: Could not load the debug map correct, no file entries.");
                        return;
                    }

                    if (!File.Exists(srcFile))
                    {
                        MessageBox.Show("Error: Could not load the source code, check that this file exists:" + srcFile);
                        return;
                    }

                    FileName.Text = srcFile;

                    sourceLanguage = LanguageSupport.DetectLanguage(srcFile);

                    debugMode = DebugMode.Source;
                    debugContent[DebugMode.Source] = File.ReadAllText(srcFile);
                }

                debugContent[DebugMode.Assembly] = avm_asm.ToString();
                FileName.Text = Path.GetFileName(path);

                ReloadTextArea();

                BlockchainLoad();

                UpdateSourceViewMenus();

                shouldReset = true;

                settings.lastOpenedFile = path;
                settings.Save();
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Constructs a new specializer configuration.
 /// </summary>
 /// <param name="abi">The ABI specification.</param>
 public AcceleratorSpecializerConfiguration(ABI abi)
 {
     ABI = abi;
 }