Beispiel #1
0
        public DataWord GetStorageRow(IEnumerable <byte> scAddr, DataWord key)
        {
            if (scAddr == null)
            {
                throw new ArgumentNullException(nameof(scAddr));
            }

            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            var result    = string.Empty;
            var scAddrHex = scAddr.ToHexString();
            var keyHex    = key.GetData().ToHexString();

            if (!_db.TryGet(string.Format(SMART_CONTRACT_STORE_ELT, scAddrHex, keyHex), ReadOptions.Default, out result))
            {
                var cacheDataRow = _cacheDataRows.FirstOrDefault(c => c.Key == string.Format(SMART_CONTRACT_STORE_ELT, scAddrHex, keyHex));
                if (cacheDataRow.Equals(default(KeyValuePair <string, string>)) || string.IsNullOrWhiteSpace(cacheDataRow.Value))
                {
                    return(DataWord.ZERO);
                }

                return(new DataWord(cacheDataRow.Value.FromHexString().ToArray()));
            }

            return(new DataWord(result.FromHexString().ToArray()));
        }
Beispiel #2
0
 public DataWord XOR(DataWord w2)
 {
     for (int i = 0; i < _data.Count(); ++i)
     {
         _data[i] ^= w2.GetData()[i];
     }
     return(this);
 }
Beispiel #3
0
        public void Add(DataWord word)
        {
            byte[] result = new byte[32];
            for (int i = 31, overflow = 0; i >= 0; i--)
            {
                int v = (_data[i] & 0xff) + (word.GetData()[i] & 0xff) + overflow;
                result[i] = (byte)v;
                overflow  = v >> 8;
            }

            _data = result;
        }
Beispiel #4
0
        public bool AddStorageRow(IEnumerable <byte> scAddr, DataWord key, DataWord value, bool addInTransaction = false)
        {
            if (scAddr == null)
            {
                throw new ArgumentNullException(nameof(scAddr));
            }

            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var writeBatch = new WriteBatch();

            if (addInTransaction)
            {
                writeBatch = _writeBatch;
            }

            string result    = string.Empty;
            var    scAddrHex = scAddr.ToHexString();
            var    keyHex    = key.GetData().ToHexString();
            var    valueHex  = value.GetData().ToHexString();

            if (!_db.TryGet(string.Format(SMART_CONTRACT_ELT, scAddrHex), ReadOptions.Default, out result))
            {
                return(false);
            }

            result = string.Empty;
            if (_db.TryGet(string.Format(SMART_CONTRACT_STORE_ELT, scAddrHex, keyHex), ReadOptions.Default, out result))
            {
                writeBatch.Delete(string.Format(SMART_CONTRACT_STORE_ELT, scAddrHex, keyHex));
            }

            writeBatch.Put(string.Format(SMART_CONTRACT_STORE_ELT, scAddrHex, keyHex), valueHex);
            if (!addInTransaction)
            {
                _db.Write(writeBatch, WriteOptions.Default);
            }
            else
            {
                _cacheDataRows.Add(string.Format(SMART_CONTRACT_STORE_ELT, scAddrHex, keyHex), keyHex);
            }

            return(true);
        }
 public void SaveMemory(DataWord addrB, DataWord value)
 {
     _memory.Write(addrB.GetInt(), value.GetData(), value.GetData().Length, false);
 }